All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cec-follower: detect the cessation of Audio Rate Control messages
@ 2021-04-25  5:46 Deborah Brouwer
  2021-04-25  9:42 ` Hans Verkuil
  0 siblings, 1 reply; 2+ messages in thread
From: Deborah Brouwer @ 2021-04-25  5:46 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 | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp
index 93db4059..111b3604 100644
--- a/utils/cec-follower/cec-processing.cpp
+++ b/utils/cec-follower/cec-processing.cpp
@@ -233,18 +233,20 @@ 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(__u64 ts_new, struct node *node)
 {
 	/*
-	 * 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) {
 		unsigned interval = (ts_new - ts_old) / 1000000000;
 		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;
 		}
 	}
 }
@@ -802,7 +804,6 @@ 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);
 			node->state.last_aud_rate_rx_ts = 0;
 			return;
 		case CEC_OP_AUD_RATE_WIDE_STD:
@@ -811,7 +812,6 @@ 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);
 			node->state.last_aud_rate_rx_ts = msg.rx_ts;
 			return;
 		default:
@@ -1033,6 +1033,9 @@ void testProcessing(struct node *node, bool wallclock)
 				node->state.rc_state = NOPRESS;
 			}
 		}
+
+		if (node->has_aud_rate)
+			aud_rate_msg_interval_check(ts_now, node);
 	}
 	mode = CEC_MODE_INITIATOR;
 	doioctl(node, CEC_S_MODE, &mode);
-- 
2.17.1


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

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

Hi Deb,

Some comment below:

On 25/04/2021 07:46, 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 | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/utils/cec-follower/cec-processing.cpp b/utils/cec-follower/cec-processing.cpp
> index 93db4059..111b3604 100644
> --- a/utils/cec-follower/cec-processing.cpp
> +++ b/utils/cec-follower/cec-processing.cpp
> @@ -233,18 +233,20 @@ 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(__u64 ts_new, struct node *node)

Swap the arguments: node is typically the first argument.

>  {
>  	/*
> -	 * 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;

Add a newline here.

>  	if (ts_old) {
>  		unsigned interval = (ts_new - ts_old) / 1000000000;

Ditto.

Also, I just realized that the test below is actually wrong: by dividing the
interval above by 1000000000 you reduce the precision to one second intervals.

>  		if (interval > MAX_AUD_RATE_MSG_INTERVAL) {

Instead multiple MAX_AUD_RATE_MSG_INTERVAL by 1000000000, that way the
check is much more precise.

> -			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;
>  		}
>  	}
>  }
> @@ -802,7 +804,6 @@ 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);

You want to keep this check...

>  			node->state.last_aud_rate_rx_ts = 0;
>  			return;
>  		case CEC_OP_AUD_RATE_WIDE_STD:
> @@ -811,7 +812,6 @@ 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);

...and this check, because...

>  			node->state.last_aud_rate_rx_ts = msg.rx_ts;
>  			return;
>  		default:
> @@ -1033,6 +1033,9 @@ void testProcessing(struct node *node, bool wallclock)
>  				node->state.rc_state = NOPRESS;
>  			}
>  		}
> +
> +		if (node->has_aud_rate)
> +			aud_rate_msg_interval_check(ts_now, node);

...this periodic check only happens once a second, so is less precise. I.e., it might not
catch the case where the audio rate message arrived 2.1 seconds too late if this check was
performed e.g. 2.2 seconds later.

Regards,

	Hans

>  	}
>  	mode = CEC_MODE_INITIATOR;
>  	doioctl(node, CEC_S_MODE, &mode);
> 


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

end of thread, other threads:[~2021-04-25  9:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-25  5:46 [PATCH] cec-follower: detect the cessation of Audio Rate Control messages Deborah Brouwer
2021-04-25  9:42 ` 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.