Skip to content

Commit

Permalink
Bluetooth: BAP: Shell: Improve recv statistics
Browse files Browse the repository at this point in the history
Add more information when we print the recv every 100th
packet, and remove all per-recv printing.

This also resets all information on stream start. This does,
however, no properly support multiple streams.

Signed-off-by: Emil Gydesen <[email protected]>
  • Loading branch information
Thalley committed Jun 27, 2023
1 parent a7498c3 commit e36d849
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions subsys/bluetooth/audio/shell/bap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1649,34 +1649,46 @@ static struct bt_bap_broadcast_sink_cb sink_cbs = {
#endif /* CONFIG_BT_BAP_BROADCAST_SINK */

#if defined(CONFIG_BT_AUDIO_RX)
static size_t lost_pkts;
static size_t err_pkts;
static size_t dup_psn;
static size_t rx_cnt;
static size_t dup_ts;

static void audio_recv(struct bt_bap_stream *stream,
const struct bt_iso_recv_info *info,
struct net_buf *buf)
{
static struct bt_iso_recv_info last_info;
static size_t rx_cnt;

/* TODO: Make it possible to only print every X packets, and make X settable by the shell */
if ((rx_cnt % 100) == 0) {
shell_print(ctx_shell,
"[%zu]: Incoming audio on stream %p len %u ts %u seq_num %u flags %u",
rx_cnt, stream, buf->len, info->ts, info->seq_num,
info->flags);
}
rx_cnt++;

if (info->ts == last_info.ts) {
shell_error(ctx_shell, "[%zu]: Duplicate TS: %u",
rx_cnt, info->ts);
dup_ts++;
}

if (info->seq_num == last_info.seq_num) {
shell_error(ctx_shell, "[%zu]: Duplicate seq_num: %u",
rx_cnt, info->seq_num);
dup_psn++;
}

(void)memcpy(&last_info, info, sizeof(last_info));
if (info->flags & BT_ISO_FLAGS_ERROR) {
err_pkts++;
}

rx_cnt++;
if (info->flags & BT_ISO_FLAGS_LOST) {
lost_pkts++;
}

/* TODO: Make it possible to only print every X packets, and make X settable by the shell */
if ((rx_cnt % 100) == 0) {
shell_print(ctx_shell,
"[%zu]: Incoming audio on stream %p len %u ts %u seq_num %u flags %u "
"(dup ts %zu; dup psn %zu, err_pkts %zu, lost_pkts %zu)",
rx_cnt, stream, buf->len, info->ts, info->seq_num, info->flags, dup_ts,
dup_psn, err_pkts, lost_pkts);
}

(void)memcpy(&last_info, info, sizeof(last_info));
}
#endif /* CONFIG_BT_AUDIO_RX */

Expand Down Expand Up @@ -1720,6 +1732,14 @@ static void stream_enabled_cb(struct bt_bap_stream *stream)
static void stream_started_cb(struct bt_bap_stream *stream)
{
printk("Stream %p started\n", stream);

#if defined(CONFIG_BT_AUDIO_RX)
lost_pkts = 0U;
err_pkts = 0U;
dup_psn = 0U;
rx_cnt = 0U;
dup_ts = 0U;
#endif
}

static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
Expand Down

0 comments on commit e36d849

Please sign in to comment.