Bluetooth: BAP: Shell: Modify bcast sink streams to use shell_stream
Modify the broadcast_sink_streams to be an array of shell_stream instead of bt_bap_stream, so that it can be used in a similar way as the rest of the streams. To help the transition, a new helper function, bap_stream_from_shell_stream, was added. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
2d11fbe532
commit
c1272195f0
1 changed files with 37 additions and 25 deletions
|
@ -64,7 +64,7 @@ struct shell_stream broadcast_source_streams[CONFIG_BT_BAP_BROADCAST_SRC_STREAM_
|
|||
struct broadcast_source default_source;
|
||||
#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */
|
||||
#if defined(CONFIG_BT_BAP_BROADCAST_SINK)
|
||||
static struct bt_bap_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
|
||||
static struct shell_stream broadcast_sink_streams[CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT];
|
||||
static struct broadcast_sink default_broadcast_sink;
|
||||
#endif /* CONFIG_BT_BAP_BROADCAST_SINK */
|
||||
|
||||
|
@ -165,6 +165,11 @@ static struct shell_stream *shell_stream_from_bap_stream(struct bt_bap_stream *b
|
|||
return sh_stream;
|
||||
}
|
||||
|
||||
static struct bt_bap_stream *bap_stream_from_shell_stream(struct shell_stream *sh_stream)
|
||||
{
|
||||
return &sh_stream->stream.bap_stream;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BT_AUDIO_TX)
|
||||
static uint16_t get_next_seq_num(struct bt_bap_stream *bap_stream)
|
||||
{
|
||||
|
@ -281,7 +286,7 @@ static void lc3_audio_send_data(struct k_work *work)
|
|||
{
|
||||
struct shell_stream *sh_stream = CONTAINER_OF(k_work_delayable_from_work(work),
|
||||
struct shell_stream, audio_send_work);
|
||||
struct bt_bap_stream *bap_stream = &sh_stream->stream.bap_stream;
|
||||
struct bt_bap_stream *bap_stream = bap_stream_from_shell_stream(sh_stream);
|
||||
const uint16_t tx_sdu_len = sh_stream->lc3_frames_per_sdu * sh_stream->lc3_octets_per_frame;
|
||||
struct net_buf *buf;
|
||||
uint8_t *net_buffer;
|
||||
|
@ -440,7 +445,7 @@ static void set_unicast_stream(struct bt_bap_stream *stream)
|
|||
default_stream = stream;
|
||||
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
|
||||
if (stream == &unicast_streams[i].stream.bap_stream) {
|
||||
if (stream == bap_stream_from_shell_stream(&unicast_streams[i])) {
|
||||
shell_print(ctx_shell, "Default stream: %u", i + 1);
|
||||
}
|
||||
}
|
||||
|
@ -465,7 +470,7 @@ static int cmd_select_unicast(const struct shell *sh, size_t argc, char *argv[])
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
stream = &unicast_streams[index].stream.bap_stream;
|
||||
stream = bap_stream_from_shell_stream(&unicast_streams[index]);
|
||||
|
||||
set_unicast_stream(stream);
|
||||
|
||||
|
@ -479,7 +484,7 @@ static const struct bt_audio_codec_qos_pref qos_pref =
|
|||
static struct bt_bap_stream *stream_alloc(void)
|
||||
{
|
||||
for (size_t i = 0; i < ARRAY_SIZE(unicast_streams); i++) {
|
||||
struct bt_bap_stream *stream = &unicast_streams[i].stream.bap_stream;
|
||||
struct bt_bap_stream *stream = bap_stream_from_shell_stream(&unicast_streams[i]);
|
||||
|
||||
if (!stream->conn) {
|
||||
return stream;
|
||||
|
@ -697,11 +702,13 @@ int bap_ac_create_unicast_group(const struct bap_unicast_ac_param *param,
|
|||
*/
|
||||
for (size_t i = 0U; i < snk_cnt; i++) {
|
||||
snk_group_stream_params[i].qos = snk_qos[i];
|
||||
snk_group_stream_params[i].stream = &snk_uni_streams[i]->stream.bap_stream;
|
||||
snk_group_stream_params[i].stream =
|
||||
bap_stream_from_shell_stream(snk_uni_streams[i]);
|
||||
}
|
||||
for (size_t i = 0U; i < src_cnt; i++) {
|
||||
src_group_stream_params[i].qos = src_qos[i];
|
||||
src_group_stream_params[i].stream = &src_uni_streams[i]->stream.bap_stream;
|
||||
src_group_stream_params[i].stream =
|
||||
bap_stream_from_shell_stream(src_uni_streams[i]);
|
||||
}
|
||||
|
||||
for (size_t i = 0U; i < param->conn_cnt; i++) {
|
||||
|
@ -1015,7 +1022,7 @@ static int cmd_config(const struct shell *sh, size_t argc, char *argv[])
|
|||
conn_index = bt_conn_index(default_conn);
|
||||
|
||||
if (default_stream == NULL) {
|
||||
bap_stream = &unicast_streams[0].stream.bap_stream;
|
||||
bap_stream = bap_stream_from_shell_stream(&unicast_streams[0]);
|
||||
} else {
|
||||
bap_stream = default_stream;
|
||||
}
|
||||
|
@ -1304,7 +1311,7 @@ static int create_unicast_group(const struct shell *sh)
|
|||
memset(&group_param, 0, sizeof(group_param));
|
||||
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
|
||||
struct bt_bap_stream *stream = &unicast_streams[i].stream.bap_stream;
|
||||
struct bt_bap_stream *stream = bap_stream_from_shell_stream(&unicast_streams[i]);
|
||||
struct shell_stream *uni_stream = &unicast_streams[i];
|
||||
|
||||
if (stream->ep != NULL) {
|
||||
|
@ -2434,7 +2441,9 @@ static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
|
|||
#endif /* CONFIG_LIBLC3 && CONFIG_BT_AUDIO_TX*/
|
||||
|
||||
#if defined(CONFIG_BT_BAP_BROADCAST_SINK)
|
||||
if (IS_ARRAY_ELEMENT(broadcast_sink_streams, stream)) {
|
||||
struct shell_stream *sh_stream = shell_stream_from_bap_stream(stream);
|
||||
|
||||
if (IS_ARRAY_ELEMENT(broadcast_sink_streams, sh_stream)) {
|
||||
if (default_broadcast_sink.stream_cnt != 0) {
|
||||
default_broadcast_sink.stream_cnt--;
|
||||
}
|
||||
|
@ -2528,7 +2537,7 @@ static void stream_released_cb(struct bt_bap_stream *stream)
|
|||
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
|
||||
const struct bt_bap_stream *bap_stream =
|
||||
&unicast_streams[i].stream.bap_stream;
|
||||
bap_stream_from_shell_stream(&unicast_streams[i]);
|
||||
|
||||
if (bap_stream->ep != NULL) {
|
||||
struct bt_bap_ep_info ep_info;
|
||||
|
@ -2602,7 +2611,7 @@ static int cmd_select_broadcast_source(const struct shell *sh, size_t argc,
|
|||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
default_stream = &broadcast_source_streams[index].stream.bap_stream;
|
||||
default_stream = bap_stream_from_shell_stream(&broadcast_source_streams[index]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -2677,7 +2686,8 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc,
|
|||
|
||||
(void)memset(stream_params, 0, sizeof(stream_params));
|
||||
for (size_t i = 0; i < ARRAY_SIZE(stream_params); i++) {
|
||||
stream_params[i].stream = &broadcast_source_streams[i].stream.bap_stream;
|
||||
stream_params[i].stream =
|
||||
bap_stream_from_shell_stream(&broadcast_source_streams[i]);
|
||||
}
|
||||
subgroup_param.params_count = ARRAY_SIZE(stream_params);
|
||||
subgroup_param.params = stream_params;
|
||||
|
@ -2696,7 +2706,7 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc,
|
|||
named_preset->name);
|
||||
|
||||
if (default_stream == NULL) {
|
||||
default_stream = &broadcast_source_streams[0].stream.bap_stream;
|
||||
default_stream = bap_stream_from_shell_stream(&broadcast_source_streams[0]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -2901,7 +2911,7 @@ static int cmd_sync_broadcast(const struct shell *sh, size_t argc, char *argv[])
|
|||
|
||||
(void)memset(streams, 0, sizeof(streams));
|
||||
for (size_t i = 0; i < ARRAY_SIZE(streams); i++) {
|
||||
streams[i] = &broadcast_sink_streams[i];
|
||||
streams[i] = bap_stream_from_shell_stream(&broadcast_sink_streams[i]);
|
||||
}
|
||||
|
||||
err = bt_bap_broadcast_sink_sync(default_broadcast_sink.bap_sink, bis_bitfield, streams,
|
||||
|
@ -3105,7 +3115,8 @@ static int cmd_init(const struct shell *sh, size_t argc, char *argv[])
|
|||
|
||||
#if defined(CONFIG_BT_BAP_UNICAST)
|
||||
for (i = 0; i < ARRAY_SIZE(unicast_streams); i++) {
|
||||
bt_bap_stream_cb_register(&unicast_streams[i].stream.bap_stream, &stream_ops);
|
||||
bt_bap_stream_cb_register(bap_stream_from_shell_stream(&unicast_streams[i]),
|
||||
&stream_ops);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BT_BAP_UNICAST_CLIENT) &&
|
||||
IS_ENABLED(CONFIG_BT_CAP_INITIATOR)) {
|
||||
|
@ -3124,15 +3135,15 @@ static int cmd_init(const struct shell *sh, size_t argc, char *argv[])
|
|||
bt_le_scan_cb_register(&bap_scan_cb);
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(broadcast_sink_streams); i++) {
|
||||
bt_bap_stream_cb_register(&broadcast_sink_streams[i],
|
||||
&stream_ops);
|
||||
bt_bap_stream_cb_register(bap_stream_from_shell_stream(&broadcast_sink_streams[i]),
|
||||
&stream_ops);
|
||||
}
|
||||
#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */
|
||||
|
||||
#if defined(CONFIG_BT_BAP_BROADCAST_SOURCE)
|
||||
for (i = 0; i < ARRAY_SIZE(broadcast_source_streams); i++) {
|
||||
bt_bap_stream_cb_register(&broadcast_source_streams[i].stream.bap_stream,
|
||||
&stream_ops);
|
||||
bt_bap_stream_cb_register(
|
||||
bap_stream_from_shell_stream(&broadcast_source_streams[i]), &stream_ops);
|
||||
}
|
||||
#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE */
|
||||
|
||||
|
@ -3240,7 +3251,7 @@ static int stream_start_sine(struct shell_stream *sh_stream)
|
|||
}
|
||||
|
||||
sh_stream->tx_active = true;
|
||||
sh_stream->seq_num = get_next_seq_num(&sh_stream->stream.bap_stream);
|
||||
sh_stream->seq_num = get_next_seq_num(bap_stream_from_shell_stream(sh_stream));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -3265,7 +3276,7 @@ static int cmd_start_sine(const struct shell *sh, size_t argc, char *argv[])
|
|||
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
|
||||
struct shell_stream *sh_stream = &unicast_streams[i];
|
||||
struct bt_bap_stream *bap_stream = &sh_stream->stream.bap_stream;
|
||||
struct bt_bap_stream *bap_stream = bap_stream_from_shell_stream(sh_stream);
|
||||
|
||||
if (!lc3_initialized) {
|
||||
err = init_lc3_encoder(sh_stream);
|
||||
|
@ -3294,7 +3305,7 @@ static int cmd_start_sine(const struct shell *sh, size_t argc, char *argv[])
|
|||
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) {
|
||||
struct shell_stream *sh_stream = &broadcast_source_streams[i];
|
||||
struct bt_bap_stream *bap_stream = &sh_stream->stream.bap_stream;
|
||||
struct bt_bap_stream *bap_stream = bap_stream_from_shell_stream(sh_stream);
|
||||
|
||||
if (!lc3_initialized) {
|
||||
err = init_lc3_encoder(sh_stream);
|
||||
|
@ -3364,7 +3375,8 @@ static int cmd_stop_sine(const struct shell *sh, size_t argc, char *argv[])
|
|||
|
||||
if (stop_all) {
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(unicast_streams); i++) {
|
||||
struct bt_bap_stream *bap_stream = &unicast_streams[i].stream.bap_stream;
|
||||
struct bt_bap_stream *bap_stream =
|
||||
bap_stream_from_shell_stream(&unicast_streams[i]);
|
||||
|
||||
if (unicast_streams[i].tx_active) {
|
||||
clear_lc3_sine_data(bap_stream);
|
||||
|
@ -3374,7 +3386,7 @@ static int cmd_stop_sine(const struct shell *sh, size_t argc, char *argv[])
|
|||
|
||||
for (size_t i = 0U; i < ARRAY_SIZE(broadcast_source_streams); i++) {
|
||||
struct bt_bap_stream *bap_stream =
|
||||
&broadcast_source_streams[i].stream.bap_stream;
|
||||
bap_stream_from_shell_stream(&broadcast_source_streams[i]);
|
||||
if (unicast_streams[i].tx_active) {
|
||||
clear_lc3_sine_data(bap_stream);
|
||||
shell_print(sh, "Stopped transmitting on stream %p", bap_stream);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue