Skip to contentSkip to conversation

monitor: Add audio quality statistics for ISO streams

PATCH In review Luiz Augusto von Dentz 2 participants 9 messages Oct 2 – Oct 17 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/7 monitor: Add audio quality statistics for ISO streams

From: Luiz Augusto von Dentz <[email protected]>

Track the bursts of erased samples, the Gilbert model burst ratio and the RFC 3550 interarrival jitter of received ISO data, using the controller timestamp when present or the SN paced at ISO Interval over BN otherwise.

Live decoding now prints the loss only for the sample revealing it, along with late samples:

Quoted 1 line

LE-CIS: Handle 2304 SN... flags 0x02 dlen 4 sflags 2 #302 [hci0] 83.728300

        Lost: 0/34 (0.00%) dropped 1 invalid 0 burst 1
        Late: +7.50 msec (interval 7.50 msec)

The new --quality option prints a periodic summary per stream:

= Quality: LE-CIS 2304 [hci0] 55.004307
RX loss: 5/101 (4.95%) burst max 4
RX jitter: 1.10 msec late 2

The analyze mode reports the bursts and the jitter per connection:

Found LE-CIS connection with handle 2304

        ...
        RX loss: 2896/30733 (9.42%) dropped 0 invalid 0
        RX bursts: 1304 (max 7) [1: 799, 2: 52, 3-5: 326, 6-10: 127, >10: 0]
        RX burstiness: p 0.0468 q 0.4503 BurstR 2.01
        RX jitter: 6.66 msec (max 13.06 msec, late 4275)
        RX interval: 10.00 msec (0-91 msec, ~8 msec +/- 10 msec)

A reordered sample is no longer accounted as lost.

Assisted-by OpenCode:claude-opus-5.5
---
 doc/btmon.rst     |   6 +
 monitor/analyze.c |  42 +++--
 monitor/main.c    |  12 +-
 monitor/packet.c  | 387 ++++++++++++++++++++++++++++++++++++++++++++--
 monitor/packet.h  |  46 ++++++
 5 files changed, 465 insertions(+), 28 deletions(-)
doc/btmon.rst +6 -0
index 1129ceb2e616..fd19b73b22b3 100644
@@ -93,6 +93,12 @@ OPTIONS
 -I, --iso                   Dump ISO stream traffic in raw hex format. Required
                             to see LE Audio isochronous data in the output.
 
+-Q MSEC, --quality MSEC     Print a summary of the received audio stream
+                            quality every MSEC milliseconds: erasures, the
+                            longest burst of erasures, jitter and late
+                            samples. Only LE Audio isochronous streams are
+                            currently supported.
+
 -E IP, --ellisys IP         Send Ellisys HCI Injection.
 
 -P, --no-pager              Disable pager usage while reading the log file.
monitor/analyze.c +31 -11

93 lines not on this page · raw message

monitor/main.c +11 -1
index 1a7a25713de1..c285832612b8 100644
@@ -68,6 +68,8 @@ static void usage(void)
 		"\t-S, --sco              Dump SCO traffic\n"
 		"\t-A, --a2dp             Dump A2DP stream traffic\n"
 		"\t-I, --iso              Dump ISO traffic\n"
+		"\t-Q, --quality <msec>   Print a periodic quality summary\n"
+		"\t                       of the audio streams\n"
 		"\t-E, --ellisys [ip]     Send Ellisys HCI Injection\n"
 		"\t-P, --no-pager         Disable pager usage\n"
 		"\t-0, --print0           Separate frames with a NUL, for a\n"
@@ -99,6 +101,7 @@ static const struct option main_options[] = {
 	{ "sco",       no_argument,       NULL, 'S' },
 	{ "a2dp",      no_argument,       NULL, 'A' },
 	{ "iso",       no_argument,       NULL, 'I' },
+	{ "quality",   required_argument, NULL, 'Q' },
 	{ "ellisys",   required_argument, NULL, 'E' },
 	{ "no-pager",  no_argument,       NULL, 'P' },
 	{ "print0",    no_argument,       NULL, '0' },
@@ -137,7 +140,7 @@ int main(int argc, char *argv[])
 		struct sockaddr_un addr;
 
 		opt = getopt_long(argc, argv,
-				"r:w:a:s:p:i:d:B:V:MKNtTSAIE:P0J:R:C:c:vh",
+				"r:w:a:s:p:i:d:B:V:MKNtTSAIQ:E:P0J:R:C:c:vh",
 				main_options, NULL);
 		if (opt < 0)
 			break;
@@ -214,6 +217,13 @@ int main(int argc, char *argv[])
 		case 'I':
 			filter_mask |= PACKET_FILTER_SHOW_ISO_DATA;
 			break;
+		case 'Q':
+			if (atoi(optarg) <= 0) {
+				usage();
+				return EXIT_FAILURE;
+			}
+			packet_set_quality_period(atoi(optarg));
+			break;
 		case 'E':
 			ellisys_server = optarg;
 			ellisys_port = 24352;
monitor/packet.c +371 -16

477 lines not on this page · raw message

monitor/packet.h +46 -0

64 lines not on this page · raw message

Signature · 1 line
2.55.0
author maintainer
#1 lore raw

PATCH 2/7 monitor/analyze: Fix a new connection for each BIS or eSCO packet

From: Luiz Augusto von Dentz <[email protected]>

The lookup of a CIS, and of a SCO, allocates a connection when the handle belongs to another type, so the fallback to BIS, and to eSCO, was never reached and each packet ended up on a connection of its own.

Fixes 8157e2fde5d3 ("monitor: Print connection type in Disconnect Complete")
Assisted-by OpenCode:claude-opus-5.5
---
 monitor/analyze.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)
monitor/analyze.c +21 -16
index 13d470ff566d..168efdb4b882 100644
@@ -463,6 +463,23 @@ static struct hci_conn *conn_lookup_type(struct hci_dev *dev, uint16_t handle,
 	return conn;
 }
 
+/*
+ * Look up a connection of either type, only allocating one of the first type
+ * when there is none, so the packets of the second type do not end up on a
+ * new connection each.
+ */
+static struct hci_conn *conn_lookup_types(struct hci_dev *dev,
+					uint16_t handle, uint8_t type1,
+					uint8_t type2)
+{
+	struct hci_conn *conn = conn_lookup(dev, handle);
+
+	if (conn && (conn->type == type1 || conn->type == type2))
+		return conn;
+
+	return conn_lookup_type(dev, handle, type1);
+}
+
 static void dev_destroy(void *data)
 {
 	struct hci_dev *dev = data;
@@ -1386,14 +1403,8 @@ static void sco_pkt(struct timeval *tv, uint16_t index, bool out,
 	dev->num_hci++;
 	dev->num_sco++;
 
-	conn = conn_lookup_type(dev, le16_to_cpu(hdr->handle) & 0x0fff,
-							BTMON_CONN_SCO);
-	if (!conn) {
-		conn = conn_lookup_type(dev, le16_to_cpu(hdr->handle) & 0x0fff,
-							BTMON_CONN_ESCO);
-		if (!conn)
-			return;
-	}
+	conn = conn_lookup_types(dev, le16_to_cpu(hdr->handle) & 0x0fff,
+					BTMON_CONN_SCO, BTMON_CONN_ESCO);
 
 	if (out) {
 		conn_pkt_tx(conn, tv, size - sizeof(*hdr), NULL);
@@ -1481,14 +1492,8 @@ static void iso_pkt(struct timeval *tv, uint16_t index, bool out,
 	dev->num_hci++;
 	dev->num_iso++;
 
-	conn = conn_lookup_type(dev, le16_to_cpu(hdr->handle) & 0x0fff,
-							BTMON_CONN_CIS);
-	if (!conn) {
-		conn = conn_lookup_type(dev, le16_to_cpu(hdr->handle) & 0x0fff,
-							BTMON_CONN_BIS);
-		if (!conn)
-			return;
-	}
+	conn = conn_lookup_types(dev, le16_to_cpu(hdr->handle) & 0x0fff,
+					BTMON_CONN_CIS, BTMON_CONN_BIS);
 
 	handle = le16_to_cpu(hdr->handle);
 	flags = ISO_FLAGS(handle);
Signature · 1 line
2.55.0
author maintainer
#2 lore raw

PATCH 3/7 monitor/analyze: Fix the size of SCO packets

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

The SCO header is one octet shorter than the ACL one used to strip it, so the packets were accounted one octet short.

Fixes dce3971d227d ("monitor/analyze: Fix not calculating latency for ISO/SCO packets")
Assisted-by OpenCode:claude-opus-5.5
---
 monitor/analyze.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
monitor/analyze.c +1 -1
index 168efdb4b882..b132643154f2 100644
@@ -1392,7 +1392,7 @@ static void acl_pkt(struct timeval *tv, uint16_t index, bool out,
 static void sco_pkt(struct timeval *tv, uint16_t index, bool out,
 					const void *data, uint16_t size)
 {
-	const struct bt_hci_acl_hdr *hdr = data;
+	const struct bt_hci_sco_hdr *hdr = data;
 	struct hci_dev *dev;
 	struct hci_conn *conn;
 
Signature · 1 line
2.55.0
author maintainer
#3 lore raw

PATCH 4/7 monitor/analyze: Fix the type of synchronous connections

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

The Link_Type of the Synchronous Connection Complete event was used as the connection type, so an eSCO connection was tracked as SCO and a SCO one as of any type.

Fixes 1f6e606c8504 ("monitor: Add connection tracking for SCO/ISO with -a/--analyze")
Assisted-by OpenCode:claude-opus-5.5
---
 monitor/analyze.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
monitor/analyze.c +3 -1
index b132643154f2..c5bf88216408 100644
@@ -1063,7 +1063,9 @@ static void evt_sync_conn_complete(struct hci_dev *dev, struct timeval *tv,
 	if (evt->status)
 		return;
 
-	conn = conn_lookup_type(dev, le16_to_cpu(evt->handle), evt->link_type);
+	conn = conn_lookup_type(dev, le16_to_cpu(evt->handle),
+				evt->link_type ? BTMON_CONN_ESCO :
+				BTMON_CONN_SCO);
 	if (!conn)
 		return;
 
Signature · 1 line
2.55.0
author maintainer
#4 lore raw

PATCH 5/7 monitor: Add audio quality statistics for SCO data

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Account the Packet_Status_Flag of received SCO data, reported with Erroneous Data Reporting, as erasures, and the jitter against the time the data of a packet takes to play, derived from the air mode:

Quoted 1 line

BR-ESCO: Handle 257 [90:09.. flags 0x01 dlen 120 #1455 [hci0] 19979.296105

Status: Possibly invalid (0x01)
Lost: 0/1 (0.00%) missing 0 dropped 0 invalid 1 partial 0 burst 0

Found BR-ESCO connection with handle 257

        ...
        RX loss: 0/8 (0.00%) missing 0 dropped 0 invalid 1 partial 0
        RX jitter: 0.11 msec (max 0.48 msec, late 0)
        RX interval: 7.50 msec (7-7 msec, ~7 msec +/- 0 msec)

The loss now reports all the erasures, with the missing samples apart.

Assisted-by OpenCode:claude-opus-5.5
---
 monitor/analyze.c |  15 +++
 monitor/packet.c  | 287 ++++++++++++++++++++++++++++++++--------------
 monitor/packet.h  |   6 +
 3 files changed, 220 insertions(+), 88 deletions(-)
monitor/analyze.c +15 -0
index c5bf88216408..3a11590a0061 100644
@@ -108,6 +108,7 @@ struct hci_conn {
 	struct hci_stats tx;
 	struct packet_loss rx_loss;
 	struct packet_jitter rx_jitter;
+	uint8_t sco_rate;
 };
 
 struct hci_conn_tx {
@@ -1072,6 +1073,7 @@ static void evt_sync_conn_complete(struct hci_dev *dev, struct timeval *tv,
 	memcpy(conn->bdaddr, evt->bdaddr, 6);
 	conn->frame_connected = frame;
 	conn->setup_seen = true;
+	conn->sco_rate = packet_sco_rate(evt->air_mode);
 }
 
 /* Nominal SDU interval of an unframed stream: ISO Interval over BN */
@@ -1408,6 +1410,19 @@ static void sco_pkt(struct timeval *tv, uint16_t index, bool out,
 	conn = conn_lookup_types(dev, le16_to_cpu(hdr->handle) & 0x0fff,
 					BTMON_CONN_SCO, BTMON_CONN_ESCO);
 
+	if (!out && size > sizeof(*hdr)) {
+		uint8_t status = (le16_to_cpu(hdr->handle) >> 12) & 0x03;
+
+		packet_loss_add_status(&conn->rx_loss, status);
+
+		if (conn->sco_rate) {
+			conn->rx_jitter.interval = hdr->dlen * 1000 /
+							conn->sco_rate;
+			packet_jitter_add(&conn->rx_jitter, tv,
+						conn->rx_jitter.interval);
+		}
+	}
+
 	if (out) {
 		conn_pkt_tx(conn, tv, size - sizeof(*hdr), NULL);
 	} else {
monitor/packet.c +199 -88

339 lines not on this page · raw message

monitor/packet.h +6 -0
index c3e3608bdede..85b7f2ff762c 100644
@@ -42,6 +42,7 @@ struct packet_loss {
 	size_t lost;		/* Samples missing from the SN sequence */
 	size_t invalid;		/* Samples flagged possibly invalid */
 	size_t dropped;		/* Samples flagged as lost data */
+	size_t partial;		/* Samples flagged as partially lost */
 	size_t total;		/* Samples seen, including the lost ones */
 	/* Bursts of erased samples, either missing or flagged as lost */
 	size_t erased;		/* Erased samples */
@@ -118,6 +119,7 @@ struct packet_conn_data {
 	struct packet_loss rx_loss;
 	struct packet_jitter rx_jitter;
 	struct packet_quality rx_quality;
+	uint8_t  sco_rate;	/* SCO octets per msec, 0 if unknown */
 	struct queue *req_q;
 	void     *data;
 	void     (*destroy)(struct packet_conn_data *conn, void *data);
@@ -131,6 +133,10 @@ size_t packet_loss_burst_max(const struct packet_loss *loss);
 bool packet_loss_burst_ratio(const struct packet_loss *loss, double *p,
 						double *q, double *ratio);
 void packet_loss_print(const struct packet_loss *loss, const char *label);
+void packet_loss_add_status(struct packet_loss *loss, uint8_t status);
+void packet_jitter_add(struct packet_jitter *jitter, struct timeval *tv,
+							uint32_t expected);
+uint8_t packet_sco_rate(uint8_t air_mode);
 void packet_jitter_add_sn(struct packet_jitter *jitter, struct timeval *tv,
 								uint16_t sn);
 void packet_jitter_add_ts(struct packet_jitter *jitter, struct timeval *tv,
Signature · 1 line
2.55.0
author maintainer
#5 lore raw

PATCH 6/7 monitor: Add ISO link details to the analyze mode

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Print the link parameters of CIS and BIS connections along with the last LE Read ISO Link Quality counters:

Found LE-BIS connection with handle 2560
...
Link: ISO interval 30.00 msec NSE 12 BN 3 PTO 0 IRC 4 latency 28880 usec
...
Link quality: 1 reads
TX unacked 140 flushed 9 last subevent 31 retransmitted 210 RX CRC errors 402 unreceived 12 duplicated 3

With a burst number above one the SDUs of an ISO interval are delivered together, so pace them by the interval they belong to rather than by the SDU interval, which reported most of them as jitter. On the BIS above:

- RX jitter: 13.05 msec (max 45.73 msec, late 2556)
+ RX jitter: 0.68 msec (max 30.00 msec, late 0)

Assisted-by OpenCode:claude-opus-5.5
---
 monitor/analyze.c | 73 +++++++++++++++++++++++++++++++++++++++++++++--
 monitor/packet.c  | 20 +++++++++++--
 monitor/packet.h  |  2 ++
 3 files changed, 89 insertions(+), 6 deletions(-)
monitor/analyze.c +70 -3
index 3a11590a0061..2b5e3087197c 100644
@@ -109,6 +109,9 @@ struct hci_conn {
 	struct packet_loss rx_loss;
 	struct packet_jitter rx_jitter;
 	uint8_t sco_rate;
+	size_t lq_num;
+	struct bt_hci_rsp_le_read_iso_link_quality lq;
+	char iso_link[96];
 };
 
 struct hci_conn_tx {
@@ -382,9 +385,26 @@ static void conn_destroy(void *data)
 	print_stats(&conn->rx, "RX");
 	print_stats(&conn->tx, "TX");
 
+	if (conn->iso_link[0])
+		print_field("Link: %s", conn->iso_link);
+
 	packet_loss_print(&conn->rx_loss, "RX");
 	packet_jitter_print(&conn->rx_jitter, "RX");
 
+	if (conn->lq_num) {
+		print_field("Link quality: %zu reads", conn->lq_num);
+		print_field("  TX unacked %u flushed %u last subevent %u "
+				"retransmitted %u",
+				le32_to_cpu(conn->lq.tx_unacked_packets),
+				le32_to_cpu(conn->lq.tx_flushed_packets),
+				le32_to_cpu(conn->lq.tx_last_subevent_packets),
+				le32_to_cpu(conn->lq.retransmitted_packets));
+		print_field("  RX CRC errors %u unreceived %u duplicated %u",
+				le32_to_cpu(conn->lq.crc_error_packets),
+				le32_to_cpu(conn->lq.rx_unreceived_packets),
+				le32_to_cpu(conn->lq.duplicated_packets));
+	}
+
 	if (conn->setup_seen) {
 		print_field("Connected: #%lu", conn->frame_connected);
 		if (conn->terminated) {
@@ -902,6 +922,24 @@ static void rsp_read_bd_addr(struct hci_dev *dev, struct timeval *tv,
 	memcpy(dev->bdaddr, rsp->bdaddr, 6);
 }
 
+static void rsp_le_read_iso_link_quality(struct hci_dev *dev,
+					const void *data, uint16_t size)
+{
+	const struct bt_hci_rsp_le_read_iso_link_quality *rsp = data;
+	struct hci_conn *conn;
+
+	if (size < sizeof(*rsp) || rsp->status)
+		return;
+
+	conn = conn_lookup(dev, le16_to_cpu(rsp->handle));
+	if (!conn)
+		return;
+
+	/* The counters are cumulative so the last read has them all */
+	conn->lq = *rsp;
+	conn->lq_num++;
+}
+
 static void evt_cmd_complete(struct hci_dev *dev, struct timeval *tv,
 					const void *data, uint16_t size)
 {
@@ -919,6 +957,9 @@ static void evt_cmd_complete(struct hci_dev *dev, struct timeval *tv,
 	case BT_HCI_CMD_READ_BD_ADDR:
 		rsp_read_bd_addr(dev, tv, data, size);
 		break;
+	case BT_HCI_CMD_LE_READ_ISO_LINK_QUALITY:
+		rsp_le_read_iso_link_quality(dev, data, size);
+		break;
 	}
 }
 
@@ -1080,9 +1121,22 @@ static void evt_sync_conn_complete(struct hci_dev *dev, struct timeval *tv,
 static void set_iso_interval(struct hci_conn *conn, uint16_t interval,
 								uint8_t bn)
 {
-	if (bn)
-		conn->rx_jitter.interval = (uint32_t)le16_to_cpu(interval) *
-								1250 / bn;
+	if (!bn)
+		return;
+
+	conn->rx_jitter.interval = (uint32_t)le16_to_cpu(interval) * 1250 / bn;
+	conn->rx_jitter.bn = bn;
+}
+
+static void set_bis_link(struct hci_conn *conn, uint16_t interval,
+				uint8_t nse, uint8_t bn, uint8_t pto,
+				uint8_t irc, const uint8_t *latency)
+{
+	snprintf(conn->iso_link, sizeof(conn->iso_link), "ISO interval "
+			"%u.%02u msec NSE %u BN %u PTO %u IRC %u latency %u "
+			"usec", le16_to_cpu(interval) * 125 / 100,
+			le16_to_cpu(interval) * 125 % 100, nse, bn, pto, irc,
+			get_le24(latency));
 }
 
 static void evt_le_cis_established(struct hci_dev *dev, struct timeval *tv,
@@ -1110,6 +1164,15 @@ static void evt_le_cis_established(struct hci_dev *dev, struct timeval *tv,
 
 	/* Only the Peripheral gets a CIS Request for the handle */
 	set_iso_interval(conn, evt->interval, link ? evt->c_bn : evt->p_bn);
+
+	snprintf(conn->iso_link, sizeof(conn->iso_link), "ISO interval "
+			"%u.%02u msec NSE %u BN %u/%u FT %u/%u latency %u/%u "
+			"usec (C/P)",
+			le16_to_cpu(evt->interval) * 125 / 100,
+			le16_to_cpu(evt->interval) * 125 % 100, evt->nse,
+			evt->c_bn, evt->p_bn, evt->c_ft, evt->p_ft,
+			get_le24(evt->c_latency),
+			get_le24(evt->p_latency));
 }
 
 static void evt_le_cis_req(struct hci_dev *dev, struct timeval *tv,
@@ -1152,6 +1215,8 @@ static void evt_le_big_complete(struct hci_dev *dev, struct timeval *tv,
 			conn->setup_seen = true;
 			conn->frame_connected = frame;
 			set_iso_interval(conn, evt->interval, evt->bn);
+			set_bis_link(conn, evt->interval, evt->nse, evt->bn,
+					evt->pto, evt->irc, evt->latency);
 		}
 	}
 }
@@ -1179,6 +1244,8 @@ static void evt_le_big_sync_established(struct hci_dev *dev, struct timeval *tv,
 			conn->setup_seen = true;
 			conn->frame_connected = frame;
 			set_iso_interval(conn, evt->interval, evt->bn);
+			set_bis_link(conn, evt->interval, evt->nse, evt->bn,
+					evt->pto, evt->irc, evt->latency);
 		}
 	}
 }
monitor/packet.c +17 -3
index 1e177d0abd3d..c21c79f75971 100644
@@ -12161,7 +12161,7 @@ static void jitter_add(struct packet_jitter *jitter, struct timeval *tv,
 							int64_t expected)
 {
 	struct timeval delta;
-	int64_t arrival, d;
+	int64_t arrival, d, period;
 
 	timersub(tv, &jitter->prev_tv, &delta);
 	jitter->prev_tv = *tv;
@@ -12177,7 +12177,8 @@ static void jitter_add(struct packet_jitter *jitter, struct timeval *tv,
 	jitter->last_dev = d;
 
 	/* A sample arriving an interval or more later than expected */
-	if (jitter->interval && d >= jitter->interval)
+	period = (int64_t)jitter->interval * (jitter->bn > 1 ? jitter->bn : 1);
+	if (jitter->interval && d >= period)
 		jitter->late++;
 
 	if (d < 0)
@@ -12212,6 +12213,7 @@ void packet_jitter_add_sn(struct packet_jitter *jitter, struct timeval *tv,
 	if (!jitter->have_prev) {
 		jitter->prev_tv = *tv;
 		jitter->prev_sn = sn;
+		jitter->ext_sn = sn;
 		jitter->have_prev = true;
 		return;
 	}
@@ -12221,7 +12223,18 @@ void packet_jitter_add_sn(struct packet_jitter *jitter, struct timeval *tv,
 		return;
 
 	jitter->prev_sn = sn;
-	jitter_add(jitter, tv, (int64_t)diff * jitter->interval);
+	jitter->ext_sn += diff;
+
+	/*
+	 * With a burst number above one the samples of an ISO interval are
+	 * delivered together, so pace them by the interval they belong to.
+	 */
+	if (jitter->bn > 1)
+		jitter_add(jitter, tv, (int64_t)(jitter->ext_sn / jitter->bn -
+				(jitter->ext_sn - diff) / jitter->bn) *
+				jitter->interval * jitter->bn);
+	else
+		jitter_add(jitter, tv, (int64_t)diff * jitter->interval);
 }
 
 void packet_jitter_add_ts(struct packet_jitter *jitter, struct timeval *tv,
@@ -13617,6 +13630,7 @@ static void set_iso_interval(uint16_t handle, uint16_t interval, uint8_t bn)
 		return;
 
 	conn->rx_jitter.interval = (uint32_t)le16_to_cpu(interval) * 1250 / bn;
+	conn->rx_jitter.bn = bn;
 }
 
 static void le_cis_established_evt(struct timeval *tv, uint16_t index,
monitor/packet.h +2 -0
index 85b7f2ff762c..77921af39263 100644
@@ -59,6 +59,8 @@ struct packet_loss {
 
 struct packet_jitter {
 	uint32_t interval;	/* Nominal interval in usec, 0 if unknown */
+	uint8_t bn;		/* Samples delivered together, 0 if 1 */
+	uint64_t ext_sn;	/* Extended sequence number */
 	bool have_prev;
 	struct timeval prev_tv;
 	uint32_t prev_ts;
Signature · 1 line
2.55.0
author maintainer
#6 lore raw

PATCH 7/7 monitor: Add audio quality statistics for A2DP streams

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Track the RTP sequence numbers and timestamps of AVDTP media channels, in both directions, with the clock rate derived from the arrival times. A pause in the arrivals of a second or more, such as a suspended stream, restarts the pacing instead of reporting a late packet:

< BR-ACL: Handle 256 [E8:EE:C.. flags 0x02 dlen 602 #15682 [hci0] 141.214796

      Channel: 41024 len 598 [PSM 25 mode Basic (0x00)] {chan 3}
        Late: +374.81 msec (interval 14.51 msec)

= Quality: A2DP 256 CID 0xa040 [hci0] 36.379012
TX loss: 0/345 (0.00%) burst max 0
TX jitter: 0.12 msec late 0

Found TX L2CAP channel with CID 41024

        ...
        TX RTP: payload type 96 clock 44100 Hz gaps 1
        TX loss: 0/14786 (0.00%) missing 0 dropped 0 invalid 0 partial 0
        TX jitter: 0.06 msec (max 915.34 msec, late 2)
        TX interval: 14.51 msec (0-929 msec, ~14 msec +/- 8 msec)
Assisted-by OpenCode:claude-opus-5.5
---
 doc/btmon.rst     |   5 +-
 monitor/analyze.c |  13 +++
 monitor/avdtp.c   |  59 ++++++++++++
 monitor/packet.c  | 229 +++++++++++++++++++++++++++++++++++++---------
 monitor/packet.h  |  20 ++++
 5 files changed, 283 insertions(+), 43 deletions(-)
doc/btmon.rst +3 -2
index fd19b73b22b3..9383fe74941b 100644
@@ -96,8 +96,9 @@ OPTIONS
 -Q MSEC, --quality MSEC     Print a summary of the received audio stream
                             quality every MSEC milliseconds: erasures, the
                             longest burst of erasures, jitter and late
-                            samples. Only LE Audio isochronous streams are
-                            currently supported.
+                            samples. Covers LE Audio isochronous streams,
+                            SCO/eSCO data over HCI and the RTP of A2DP media
+                            channels.
 
 -E IP, --ellisys IP         Send Ellisys HCI Injection.
 
monitor/analyze.c +13 -0
index 2b5e3087197c..7e19b61978f9 100644
@@ -132,6 +132,7 @@ struct l2cap_chan {
 	uint8_t mode;
 	bool out;
 	struct timeval last_rx;
+	struct packet_rtp rtp;
 	struct hci_stats rx;
 	struct hci_stats tx;
 };
@@ -301,6 +302,7 @@ static void chan_destroy(void *data)
 
 	print_stats(&chan->rx, "RX");
 	print_stats(&chan->tx, "TX");
+	packet_rtp_print(&chan->rtp, chan->out ? "TX" : "RX");
 
 done:
 	queue_destroy(chan->rx.plot, free);
@@ -1444,12 +1446,23 @@ static void acl_pkt(struct timeval *tv, uint16_t index, bool out,
 	switch (le16_to_cpu(hdr->handle) >> 12) {
 	case 0x00:
 	case 0x02:
+		/* The start of a frame carries the L2CAP header */
+		if (size < 4)
+			break;
+
 		cid = get_le16(data + 2);
 		chan = chan_lookup(conn, cid, out);
 		if (cid == 1)
 			l2cap_sig(conn, out, data + 4, size - 4);
 		else if (cid == 5)
 			l2cap_le_sig(conn, out, data + 4, size - 4);
+		else if (chan && cid >= 0x0040 &&
+				(chan->psm == 0x0019 || !chan->psm))
+			/*
+			 * AVDTP media transport, also attempted on channels
+			 * whose setup was not captured.
+			 */
+			packet_rtp_add(&chan->rtp, tv, data + 4, size - 4);
 		break;
 	}
 
monitor/avdtp.c +59 -0

71 lines not on this page · raw message

monitor/packet.c +188 -41

291 lines not on this page · raw message

monitor/packet.h +20 -0
index 77921af39263..3c57fa3f8e34 100644
@@ -72,6 +72,19 @@ struct packet_jitter {
 	struct packet_latency delta;	/* Arrival intervals */
 };
 
+/* RTP media stream, the clock rate is derived from the arrival times */
+struct packet_rtp {
+	struct packet_loss loss;
+	struct packet_jitter jitter;
+	uint32_t rate;		/* Clock rate in Hz, 0 until known */
+	size_t probe;		/* Samples taken to derive the rate */
+	struct timeval first_tv;
+	uint32_t first_ts;
+	uint32_t prev_ts;
+	uint8_t pt;		/* Payload type */
+	size_t gaps;		/* Pauses, such as a suspended stream */
+};
+
 /* Window of the periodic quality summary */
 struct packet_quality {
 	struct timeval start;
@@ -145,6 +158,13 @@ void packet_jitter_add_ts(struct packet_jitter *jitter, struct timeval *tv,
 								uint32_t ts);
 void packet_jitter_print(const struct packet_jitter *jitter,
 							const char *label);
+bool packet_rtp_add(struct packet_rtp *rtp, struct timeval *tv,
+					const void *data, uint16_t size);
+void packet_rtp_print(const struct packet_rtp *rtp, const char *label);
+void packet_rtp_quality(struct timeval *tv, uint16_t index, uint16_t handle,
+				uint16_t cid, bool in, struct packet_rtp *rtp,
+				struct packet_quality *q, size_t erased,
+				size_t late);
 void packet_set_quality_period(unsigned int msec);
 
 void packet_get_context(struct timeval *tv, size_t *num);
Signature · 1 line
2.55.0
#7 lore raw
In reply to Luiz Augusto von Dentz

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1178559/

---Test result---

Test Summary:

CheckPatch                    FAIL      4.07 seconds
GitLint                       FAIL      1.59 seconds
BuildEll                      PASS      19.30 seconds
BluezMake                     PASS      372.71 seconds
MakeCheck                     PASS      14.45 seconds
MakeDistcheck                 PASS      139.51 seconds
CheckValgrind                 PASS      228.69 seconds
CheckSmatch                   WARNING   288.24 seconds
bluezmakeextell               PASS      92.37 seconds
TestFunctional                PASS      1112.13 seconds
IncrementalBuild              PASS      424.40 seconds
ScanBuild                     PASS      1110.12 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script
Output:
[BlueZ,vRFC,1/7] monitor: Add audio quality statistics for ISO streams WARNING:COMMIT_LOG_LONG_LINE: Prefer a maximum 75 chars per line (possible unwrapped commit description?) #105:

Quoted 1 line

LE-CIS: Handle 2304 SN... flags 0x02 dlen 4 sflags 2 #302 [hci0] 83.728300

/home/runner/work/bluez/bluez/src/patch/14864145.patch total: 0 errors, 1 warnings, 682 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluez/bluez/src/patch/14864145.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[BlueZ,vRFC,5/7] monitor: Add audio quality statistics for SCO data WARNING:COMMIT_LOG_LONG_LINE: Prefer a maximum 75 chars per line (possible unwrapped commit description?) #106:

Quoted 1 line

BR-ESCO: Handle 257 [90:09.. flags 0x01 dlen 120 #1455 [hci0] 19979.296105

/home/runner/work/bluez/bluez/src/patch/14864148.patch total: 0 errors, 1 warnings, 396 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluez/bluez/src/patch/14864148.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[BlueZ,vRFC,6/7] monitor: Add ISO link details to the analyze mode WARNING:COMMIT_LOG_WRONG_LINK: 'Link:' should be followed by a public http(s) link #107:
Link: ISO interval 30.00 msec NSE 12 BN 3 PTO 0 IRC 4 latency 28880 usec

/home/runner/work/bluez/bluez/src/patch/14864149.patch total: 0 errors, 1 warnings, 182 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluez/bluez/src/patch/14864149.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

[BlueZ,vRFC,7/7] monitor: Add audio quality statistics for A2DP streams WARNING:COMMIT_LOG_LONG_LINE: Prefer a maximum 75 chars per line (possible unwrapped commit description?) #107:
< BR-ACL: Handle 256 [E8:EE:C.. flags 0x02 dlen 602 #15682 [hci0] 141.214796

/home/runner/work/bluez/bluez/src/patch/14864150.patch total: 0 errors, 1 warnings, 442 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.

/home/runner/work/bluez/bluez/src/patch/14864150.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.

##############################
Test: GitLint - FAIL
Desc: Run gitlint
Output:
[BlueZ,vRFC,2/7] monitor/analyze: Fix a new connection for each BIS or eSCO packet

1: T1 Title exceeds max length (82>80): "[BlueZ,vRFC,2/7] monitor/analyze: Fix a new connection for each BIS or eSCO packet"
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
monitor/packet.c:2290:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3924:52: warning: array of flexible structuresmonitor/bt.h:3912:40: warning: array of flexible structuresmonitor/packet.c:2290:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3924:52: warning: array of flexible structuresmonitor/bt.h:3912:40: warning: array of flexible structuresmonitor/packet.c:2290:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3924:52: warning: array of flexible structuresmonitor/bt.h:3912:40: warning: array of flexible structuresmonitor/packet.c:2290:26: warning: Variable length array is used.monitor/packet.c: note: in included file:monitor/bt.h:3924:52: warning: array of flexible structuresmonitor/bt.h:3912:40: warning: array of flexible structures

https://github.com/bluez/bluez/pull/2623

---
Regards,
Linux Bluetooth

#8 lore raw
In reply to Luiz Augusto von Dentz

This is an automated email and please do not reply to this email.

Dear Submitter,

This series was picked up by the CI more than 2 weeks ago and the pull request created for it is still open, which means the series was never applied to the tree.

Series: [BlueZ,vRFC,1/7] monitor: Add audio quality statistics for ISO streams
Pull Request: https://github.com/bluez/bluez/pull/2623
Created: 2026-10-02 21:01:59+00:00

The pull request has been closed and no further action is taken on this series.

If the change should still be considered, it must be resent to the Linux Bluetooth mailing list ([email protected]) so that it is picked up again.

---
Regards,
Linux Bluetooth