Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: BAP: Shell: Improve recv statistics #59386

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 68 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 unsigned long recv_stats_interval = 100U;
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++;
}

if ((rx_cnt % recv_stats_interval) == 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 Expand Up @@ -2416,6 +2436,35 @@ static int cmd_stop_sine(const struct shell *sh, size_t argc, char *argv[])
#endif /* CONFIG_LIBLC3 */
#endif /* CONFIG_BT_AUDIO_TX */

#if defined(CONFIG_BT_AUDIO_RX)
static int cmd_recv_stats(const struct shell *sh, size_t argc, char *argv[])
{
if (argc == 1) {
shell_info(sh, "Current receive stats interval: %lu", recv_stats_interval);
} else {
int err = 0;
unsigned long interval;

interval = shell_strtoul(argv[1], 0, &err);
if (err != 0) {
shell_error(sh, "Could not parse interval: %d", err);

return -ENOEXEC;
}

if (interval == 0U) {
shell_error(sh, "Interval cannot be 0");

return -ENOEXEC;
}

recv_stats_interval = interval;
}

return 0;
}
#endif /* CONFIG_BT_AUDIO_RX */

#if defined(CONFIG_BT_BAP_UNICAST_SERVER)
static void print_ase_info(struct bt_bap_ep *ep, void *user_data)
{
Expand Down Expand Up @@ -2490,6 +2539,11 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
SHELL_CMD_ARG(stop_sine, NULL, "Stop sending a LC3 encoded sine wave", cmd_stop_sine, 1, 0),
#endif /* CONFIG_LIBLC3 */
#endif /* CONFIG_BT_AUDIO_TX */
#if defined(CONFIG_BT_AUDIO_RX)
SHELL_CMD_ARG(recv_stats, NULL,
"Sets or gets the receive statistics reporting interval in # of packets",
cmd_recv_stats, 1, 1),
#endif /* CONFIG_BT_AUDIO_RX */
SHELL_COND_CMD_ARG(CONFIG_BT_PACS, set_location, NULL,
"<direction: sink, source> <location bitmask>", cmd_set_loc, 3, 0),
SHELL_COND_CMD_ARG(CONFIG_BT_PACS, set_context, NULL,
Expand Down
Loading