All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] cec-follower: increase accuracy Audio Rate Control
@ 2021-04-25 22:54 Deborah Brouwer
  2021-04-25 22:54 ` [PATCH v2 1/2] cec-follower: increase precision of Audio Rate Control active sensing Deborah Brouwer
  2021-04-25 22:54 ` [PATCH v2 2/2] cec-follower: detect the cessation of Audio Rate Control messages Deborah Brouwer
  0 siblings, 2 replies; 5+ messages in thread
From: Deborah Brouwer @ 2021-04-25 22:54 UTC (permalink / raw)
  To: linux-media; +Cc: hverkuil, Deborah Brouwer

Changes since v1:
* Patch 1:
  cec-follower: increase precision of Audio Rate Control active sensing
	* new patch

* Patch 2:
  cec-follower: detect the cessation of Audio Rate Control messages
	* Keep the aud_rate_msg_interval_check in processMsg to avoid missing
	  late messages that arrive between periodic interval checks.
	* Swap arguments so that struct node appears first.
	* Add blank line for readability.

Deborah Brouwer (2):
  cec-follower: increase precision of Audio Rate Control active sensing
  cec-follower: detect the cessation of Audio Rate Control messages

 utils/cec-follower/cec-processing.cpp | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

--
2.17.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] cec-follower: increase precision of Audio Rate Control active sensing
  2021-04-25 22:54 [PATCH v2 0/2] cec-follower: increase accuracy Audio Rate Control Deborah Brouwer
@ 2021-04-25 22:54 ` Deborah Brouwer
  2021-04-26  6:33   ` Hans Verkuil
  2021-04-25 22:54 ` [PATCH v2 2/2] cec-follower: detect the cessation of Audio Rate Control messages Deborah Brouwer
  1 sibling, 1 reply; 5+ messages in thread
From: Deborah Brouwer @ 2021-04-25 22:54 UTC (permalink / raw)
  To: linux-media; +Cc: hverkuil, Deborah Brouwer

Measure the interval since the last audio rate control message in
nanoseconds instead of seconds. Increasing the precision catches audio
rate messages that are late by less than a second.

Signed-off-by: Deborah Brouwer <deborahbrouwer3563@gmail.com>
---
 utils/cec-follower/cec-processing.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp
index 93db4059..243c9d09 100644
--- a/utils/cec-follower/cec-processing.cpp
+++ b/utils/cec-follower/cec-processing.cpp
@@ -29,8 +29,8 @@
 /* Time between each polling message sent to a device */
 #define POLL_PERIOD 15000
 
-/* The maximum interval in seconds between audio rate messages as defined in the spec */
-#define MAX_AUD_RATE_MSG_INTERVAL 2
+/* The maximum interval in nanoseconds between audio rate messages as defined in the spec */
+#define MAX_AUD_RATE_MSG_INTERVAL 2000000000
 
 struct cec_enum_values {
 	const char *type_name;
@@ -241,7 +241,8 @@ static void aud_rate_msg_interval_check(__u64 ts_new, __u64 ts_old)
 	 * turned off the audio rate control.
 	 */
 	if (ts_old) {
-		unsigned interval = (ts_new - ts_old) / 1000000000;
+		__u64 interval = ts_new - ts_old;
+
 		if (interval > MAX_AUD_RATE_MSG_INTERVAL) {
 			warn("The interval between Audio Rate Control messages was greater\n");
 			warn("than the Maxiumum Audio Rate Message Interval (2s).\n");
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] cec-follower: detect the cessation of Audio Rate Control messages
  2021-04-25 22:54 [PATCH v2 0/2] cec-follower: increase accuracy Audio Rate Control Deborah Brouwer
  2021-04-25 22:54 ` [PATCH v2 1/2] cec-follower: increase precision of Audio Rate Control active sensing Deborah Brouwer
@ 2021-04-25 22:54 ` Deborah Brouwer
  2021-04-26  6:37   ` Hans Verkuil
  1 sibling, 1 reply; 5+ messages in thread
From: Deborah Brouwer @ 2021-04-25 22:54 UTC (permalink / raw)
  To: linux-media; +Cc: hverkuil, Deborah Brouwer

If the controlling device simply stops sending audio rate messages, give
the cec-follower the ability to detect that it has not received an audio
rate message within 2 seconds as required.  The cec-follower will quit the
audio rate controlled mode.  Eliminate the need to measure an interval
between two audio rate messages.

Signed-off-by: Deborah Brouwer <deborahbrouwer3563@gmail.com>
---
 utils/cec-follower/cec-processing.cpp | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp
index 243c9d09..dd6fd05c 100644
--- a/utils/cec-follower/cec-processing.cpp
+++ b/utils/cec-follower/cec-processing.cpp
@@ -233,19 +233,22 @@ static __u8 current_power_state(struct node *node)
 	return CEC_OP_POWER_STATUS_TO_STANDBY;
 }
 
-static void aud_rate_msg_interval_check(__u64 ts_new, __u64 ts_old)
+static void aud_rate_msg_interval_check(struct node *node, __u64 ts_new)
 {
 	/*
-	 * The interval between messages is not relevant if this is the
-	 * first audio rate control message or if the previous message
-	 * turned off the audio rate control.
+	 * The interval since the last audio rate message is not relevant
+	 * unless the Source is currently in audio rate controlled mode.
 	 */
+	__u64 ts_old = node->state.last_aud_rate_rx_ts;
+
 	if (ts_old) {
 		__u64 interval = ts_new - ts_old;
 
 		if (interval > MAX_AUD_RATE_MSG_INTERVAL) {
-			warn("The interval between Audio Rate Control messages was greater\n");
+			warn("The interval since the last Audio Rate Control message was greater\n");
 			warn("than the Maxiumum Audio Rate Message Interval (2s).\n");
+			warn("Turning off audio rate control.\n");
+			node->state.last_aud_rate_rx_ts = 0;
 		}
 	}
 }
@@ -803,7 +806,7 @@ static void processMsg(struct node *node, struct cec_msg &msg, unsigned me)
 
 		switch (msg.msg[2]) {
 		case CEC_OP_AUD_RATE_OFF:
-			aud_rate_msg_interval_check(msg.rx_ts, node->state.last_aud_rate_rx_ts);
+			aud_rate_msg_interval_check(node, msg.rx_ts);
 			node->state.last_aud_rate_rx_ts = 0;
 			return;
 		case CEC_OP_AUD_RATE_WIDE_STD:
@@ -812,7 +815,7 @@ static void processMsg(struct node *node, struct cec_msg &msg, unsigned me)
 		case CEC_OP_AUD_RATE_NARROW_STD:
 		case CEC_OP_AUD_RATE_NARROW_FAST:
 		case CEC_OP_AUD_RATE_NARROW_SLOW:
-			aud_rate_msg_interval_check(msg.rx_ts, node->state.last_aud_rate_rx_ts);
+			aud_rate_msg_interval_check(node, msg.rx_ts);
 			node->state.last_aud_rate_rx_ts = msg.rx_ts;
 			return;
 		default:
@@ -1034,6 +1037,9 @@ void testProcessing(struct node *node, bool wallclock)
 				node->state.rc_state = NOPRESS;
 			}
 		}
+
+		if (node->has_aud_rate)
+			aud_rate_msg_interval_check(node, ts_now);
 	}
 	mode = CEC_MODE_INITIATOR;
 	doioctl(node, CEC_S_MODE, &mode);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 1/2] cec-follower: increase precision of Audio Rate Control active sensing
  2021-04-25 22:54 ` [PATCH v2 1/2] cec-follower: increase precision of Audio Rate Control active sensing Deborah Brouwer
@ 2021-04-26  6:33   ` Hans Verkuil
  0 siblings, 0 replies; 5+ messages in thread
From: Hans Verkuil @ 2021-04-26  6:33 UTC (permalink / raw)
  To: Deborah Brouwer, linux-media

On 26/04/2021 00:54, Deborah Brouwer wrote:
> Measure the interval since the last audio rate control message in
> nanoseconds instead of seconds. Increasing the precision catches audio
> rate messages that are late by less than a second.
> 
> Signed-off-by: Deborah Brouwer <deborahbrouwer3563@gmail.com>
> ---
>  utils/cec-follower/cec-processing.cpp | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp
> index 93db4059..243c9d09 100644
> --- a/utils/cec-follower/cec-processing.cpp
> +++ b/utils/cec-follower/cec-processing.cpp
> @@ -29,8 +29,8 @@
>  /* Time between each polling message sent to a device */
>  #define POLL_PERIOD 15000
>  
> -/* The maximum interval in seconds between audio rate messages as defined in the spec */
> -#define MAX_AUD_RATE_MSG_INTERVAL 2
> +/* The maximum interval in nanoseconds between audio rate messages as defined in the spec */
> +#define MAX_AUD_RATE_MSG_INTERVAL 2000000000

It's a bit easier to read if you write this as:

#define MAX_AUD_RATE_MSG_INTERVAL_NS (2 * 1000000000ULL)

It's helpful to add the unit as a suffix to the define name and to
write it as a multiplication of seconds times nsecs_per_sec.

Also ULL helps cast the expression to an unsigned long long (64 bit).

Not strictly necessary, but since we check intervals using __u64 it
doesn't hurt either.

Regards,

	Hans

>  
>  struct cec_enum_values {
>  	const char *type_name;
> @@ -241,7 +241,8 @@ static void aud_rate_msg_interval_check(__u64 ts_new, __u64 ts_old)
>  	 * turned off the audio rate control.
>  	 */
>  	if (ts_old) {
> -		unsigned interval = (ts_new - ts_old) / 1000000000;
> +		__u64 interval = ts_new - ts_old;
> +
>  		if (interval > MAX_AUD_RATE_MSG_INTERVAL) {
>  			warn("The interval between Audio Rate Control messages was greater\n");
>  			warn("than the Maxiumum Audio Rate Message Interval (2s).\n");
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 2/2] cec-follower: detect the cessation of Audio Rate Control messages
  2021-04-25 22:54 ` [PATCH v2 2/2] cec-follower: detect the cessation of Audio Rate Control messages Deborah Brouwer
@ 2021-04-26  6:37   ` Hans Verkuil
  0 siblings, 0 replies; 5+ messages in thread
From: Hans Verkuil @ 2021-04-26  6:37 UTC (permalink / raw)
  To: Deborah Brouwer, linux-media

On 26/04/2021 00:54, Deborah Brouwer wrote:
> If the controlling device simply stops sending audio rate messages, give
> the cec-follower the ability to detect that it has not received an audio
> rate message within 2 seconds as required.  The cec-follower will quit the
> audio rate controlled mode.  Eliminate the need to measure an interval
> between two audio rate messages.
> 
> Signed-off-by: Deborah Brouwer <deborahbrouwer3563@gmail.com>
> ---
>  utils/cec-follower/cec-processing.cpp | 20 +++++++++++++-------
>  1 file changed, 13 insertions(+), 7 deletions(-)
> 
> diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp
> index 243c9d09..dd6fd05c 100644
> --- a/utils/cec-follower/cec-processing.cpp
> +++ b/utils/cec-follower/cec-processing.cpp
> @@ -233,19 +233,22 @@ static __u8 current_power_state(struct node *node)
>  	return CEC_OP_POWER_STATUS_TO_STANDBY;
>  }
>  
> -static void aud_rate_msg_interval_check(__u64 ts_new, __u64 ts_old)
> +static void aud_rate_msg_interval_check(struct node *node, __u64 ts_new)
>  {
>  	/*
> -	 * The interval between messages is not relevant if this is the
> -	 * first audio rate control message or if the previous message
> -	 * turned off the audio rate control.
> +	 * The interval since the last audio rate message is not relevant
> +	 * unless the Source is currently in audio rate controlled mode.

I think this can be clarified if you extend the comment a bit and avoid
the double negation (not...unless):

	 * The interval since the last audio rate message is only relevant
	 * if the Source is currently in audio rate controlled mode
	 * (i.e. state.last_aud_rate_rx_ts != 0).

>  	 */
> +	__u64 ts_old = node->state.last_aud_rate_rx_ts;
> +
>  	if (ts_old) {
>  		__u64 interval = ts_new - ts_old;
>  
>  		if (interval > MAX_AUD_RATE_MSG_INTERVAL) {
> -			warn("The interval between Audio Rate Control messages was greater\n");
> +			warn("The interval since the last Audio Rate Control message was greater\n");
>  			warn("than the Maxiumum Audio Rate Message Interval (2s).\n");

This is a bit too verbose. How about this:

			warn("The interval since the last Audio Rate Control message was > 2s.\n");

Regards,

	Hans

> +			warn("Turning off audio rate control.\n");
> +			node->state.last_aud_rate_rx_ts = 0;
>  		}
>  	}
>  }
> @@ -803,7 +806,7 @@ static void processMsg(struct node *node, struct cec_msg &msg, unsigned me)
>  
>  		switch (msg.msg[2]) {
>  		case CEC_OP_AUD_RATE_OFF:
> -			aud_rate_msg_interval_check(msg.rx_ts, node->state.last_aud_rate_rx_ts);
> +			aud_rate_msg_interval_check(node, msg.rx_ts);
>  			node->state.last_aud_rate_rx_ts = 0;
>  			return;
>  		case CEC_OP_AUD_RATE_WIDE_STD:
> @@ -812,7 +815,7 @@ static void processMsg(struct node *node, struct cec_msg &msg, unsigned me)
>  		case CEC_OP_AUD_RATE_NARROW_STD:
>  		case CEC_OP_AUD_RATE_NARROW_FAST:
>  		case CEC_OP_AUD_RATE_NARROW_SLOW:
> -			aud_rate_msg_interval_check(msg.rx_ts, node->state.last_aud_rate_rx_ts);
> +			aud_rate_msg_interval_check(node, msg.rx_ts);
>  			node->state.last_aud_rate_rx_ts = msg.rx_ts;
>  			return;
>  		default:
> @@ -1034,6 +1037,9 @@ void testProcessing(struct node *node, bool wallclock)
>  				node->state.rc_state = NOPRESS;
>  			}
>  		}
> +
> +		if (node->has_aud_rate)
> +			aud_rate_msg_interval_check(node, ts_now);
>  	}
>  	mode = CEC_MODE_INITIATOR;
>  	doioctl(node, CEC_S_MODE, &mode);
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-04-26  6:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-25 22:54 [PATCH v2 0/2] cec-follower: increase accuracy Audio Rate Control Deborah Brouwer
2021-04-25 22:54 ` [PATCH v2 1/2] cec-follower: increase precision of Audio Rate Control active sensing Deborah Brouwer
2021-04-26  6:33   ` Hans Verkuil
2021-04-25 22:54 ` [PATCH v2 2/2] cec-follower: detect the cessation of Audio Rate Control messages Deborah Brouwer
2021-04-26  6:37   ` Hans Verkuil

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.