Skip to content

Commit bc25ddb

Browse files
committed
samples: Bluetooth: BAP Unicast Client improve reporting
Make the reporting interval configurable to make it easier to actually follow. Improve what gets reported. Add check for SDU size to ensure correctness when not using LIBLC3. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 6ee55e4 commit bc25ddb

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "Bluetooth: BAP Unicast Client"
5+
6+
config INFO_REPORTING_INTERVAL
7+
int "Number of SDUs received between each information report"
8+
default 1000
9+
help
10+
Determines how often information about received data is logged.
11+
Set to 0 to disable reporting.
12+
13+
source "Kconfig.zephyr"

samples/bluetooth/bap_unicast_client/src/main.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021-2024 Nordic Semiconductor ASA
2+
* Copyright (c) 2021-2025 Nordic Semiconductor ASA
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -270,6 +270,8 @@ static void stream_connected_cb(struct bt_bap_stream *stream)
270270
static void stream_started(struct bt_bap_stream *stream)
271271
{
272272
printk("Audio Stream %p started\n", stream);
273+
unicast_audio_recv_ctr = 0U;
274+
273275
/* Register the stream for TX if it can send */
274276
if (IS_ENABLED(CONFIG_BT_AUDIO_TX) && stream_tx_can_send(stream)) {
275277
const int err = stream_tx_register(stream);
@@ -317,8 +319,12 @@ static void stream_recv(struct bt_bap_stream *stream,
317319
{
318320
if (info->flags & BT_ISO_FLAGS_VALID) {
319321
unicast_audio_recv_ctr++;
320-
printk("Incoming audio on stream %p len %u (%"PRIu64")\n", stream, buf->len,
321-
unicast_audio_recv_ctr);
322+
323+
if (CONFIG_INFO_REPORTING_INTERVAL > 0 &&
324+
(unicast_audio_recv_ctr % CONFIG_INFO_REPORTING_INTERVAL) == 0U) {
325+
printk("Incoming audio on stream %p len %u (%" PRIu64 ")\n", stream,
326+
buf->len, unicast_audio_recv_ctr);
327+
}
322328
}
323329
}
324330

samples/bluetooth/bap_unicast_client/src/stream_lc3.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Nordic Semiconductor ASA
2+
* Copyright (c) 2024-2025 Nordic Semiconductor ASA
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -158,6 +158,7 @@ static bool encode_frame_block(struct tx_stream *stream, struct net_buf *out_buf
158158
* purposes
159159
*/
160160
if (!encode_frame(stream, i, out_buf)) {
161+
LOG_WRN("Failed to encode frame %u", i);
161162
return false;
162163
}
163164
}
@@ -169,6 +170,7 @@ void stream_lc3_add_data(struct tx_stream *stream, struct net_buf *buf)
169170
{
170171
for (uint8_t i = 0U; i < stream->lc3_tx.frame_blocks_per_sdu; i++) {
171172
if (!encode_frame_block(stream, buf)) {
173+
LOG_WRN("Failed to encode frame block %u", i);
172174
break;
173175
}
174176
}

samples/bluetooth/bap_unicast_client/src/stream_tx.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Nordic Semiconductor ASA
2+
* Copyright (c) 2024-2025 Nordic Semiconductor ASA
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -20,6 +20,7 @@
2020
#include <zephyr/logging/log.h>
2121
#include <zephyr/logging/log_core.h>
2222
#include <zephyr/net_buf.h>
23+
#include <zephyr/sys/__assert.h>
2324
#include <zephyr/sys/byteorder.h>
2425
#include <zephyr/sys/util.h>
2526
#include <zephyr/sys/util_macro.h>
@@ -79,6 +80,7 @@ static void tx_thread_func(void *arg1, void *arg2, void *arg3)
7980
struct bt_bap_stream *bap_stream = tx_streams[i].bap_stream;
8081

8182
if (stream_is_streaming(bap_stream)) {
83+
uint16_t sdu_len;
8284
struct net_buf *buf;
8385

8486
buf = net_buf_alloc(&tx_pool, K_FOREVER);
@@ -88,12 +90,25 @@ static void tx_thread_func(void *arg1, void *arg2, void *arg3)
8890
bap_stream->codec_cfg->id == BT_HCI_CODING_FORMAT_LC3) {
8991
stream_lc3_add_data(&tx_streams[i], buf);
9092
} else {
93+
__ASSERT(bap_stream->qos->sdu <= ARRAY_SIZE(mock_data),
94+
"Configured codec SDU len %u does not match mock "
95+
"data size %zu",
96+
bap_stream->qos->sdu, ARRAY_SIZE(mock_data));
9197
net_buf_add_mem(buf, mock_data, bap_stream->qos->sdu);
9298
}
9399

100+
sdu_len = buf->len;
101+
94102
err = bt_bap_stream_send(bap_stream, buf, tx_streams[i].seq_num);
95103
if (err == 0) {
96104
tx_streams[i].seq_num++;
105+
106+
if (CONFIG_INFO_REPORTING_INTERVAL > 0 &&
107+
(tx_streams[i].seq_num %
108+
CONFIG_INFO_REPORTING_INTERVAL) == 0U) {
109+
LOG_INF("Stream %p: Sent %u total SDUs of size %u",
110+
bap_stream, tx_streams[i].seq_num, sdu_len);
111+
}
97112
} else {
98113
LOG_ERR("Unable to send: %d", err);
99114
net_buf_unref(buf);
@@ -131,6 +146,11 @@ int stream_tx_register(struct bt_bap_stream *bap_stream)
131146
}
132147

133148
LOG_INF("Registered %p for TX", bap_stream);
149+
if (bap_stream->qos->sdu > CONFIG_BT_ISO_TX_MTU) {
150+
LOG_WRN("Stream configured for SDUs larger (%u) than "
151+
"CONFIG_BT_ISO_TX_MTU (%d)",
152+
bap_stream->qos->sdu, CONFIG_BT_ISO_TX_MTU);
153+
}
134154

135155
return 0;
136156
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright (c) 2024 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
source "${ZEPHYR_BASE}/samples/bluetooth/bap_unicast_client/Kconfig"

0 commit comments

Comments
 (0)