Skip to contentSkip to conversation

cec-follower: increase accuracy Audio Rate Control

PATCH New Deborah Brouwer 1 participant 3 messages Apr 27, 2021 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

v3 cover cec-follower: increase accuracy Audio Rate Control

Changes since v2:
* Patch 1:
cec-follower: increase precision of Audio Rate Control active sensing
* Add the unit (nanoseconds) as a suffix to the define name.
* Write the defined value as a multiplication of seconds times nsecs_per_sec.
* Add ULL to help cast the expression to an unsigned long long.
* Note: for the sake of clarity in the diff, a blank line before the if statement is missing but it is subsequently added by Patch 2.

* Patch 2:
cec-follower: detect the cessation of Audio Rate Control messages
* Remove double negative in comment.
* Extend comment to specify (i.e. state.last_aud_rate_rx_ts != 0).
* Make warning message more succinct.

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

*Patch 2:
* 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 | 30 ++++++++++++++++-----------
 1 file changed, 18 insertions(+), 12 deletions(-)

--
2.17.1

#1 lore raw

PATCH v3 1/2 cec-follower: increase precision of Audio Rate Control active sensing

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.

---
 utils/cec-follower/cec-processing.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
utils/cec-follower/cec-processing.cpp +4 -4
index 93db4059..fcb55df2 100644
@@ -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_NS (2 * 1000000000ULL)
 
 struct cec_enum_values {
 	const char *type_name;
@@ -241,8 +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;
-		if (interval > MAX_AUD_RATE_MSG_INTERVAL) {
+		__u64 interval = ts_new - ts_old;
+		if (interval > MAX_AUD_RATE_MSG_INTERVAL_NS) {
 			warn("The interval between Audio Rate Control messages was greater\n");
 			warn("than the Maxiumum Audio Rate Message Interval (2s).\n");
 		}
Signature · 1 line
2.17.1
#2 lore raw

PATCH v3 2/2 cec-follower: detect the cessation of Audio Rate Control messages

In reply to 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.

---
 utils/cec-follower/cec-processing.cpp | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
utils/cec-follower/cec-processing.cpp +14 -8
index fcb55df2..c76ec54e 100644
@@ -233,18 +233,21 @@ 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 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_NS) {
-			warn("The interval between Audio Rate Control messages was greater\n");
-			warn("than the Maxiumum Audio Rate Message Interval (2s).\n");
+			warn("The interval since the last Audio Rate Control message was > 2s.\n");
+			node->state.last_aud_rate_rx_ts = 0;
 		}
 	}
 }
@@ -802,7 +805,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:
@@ -811,7 +814,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:
@@ -1033,6 +1036,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);
Signature · 1 line
2.17.1