Skip to content

Commit 5628b29

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: Audio: broadcast_source_create array of stream pointers
The bt_audio_broadcast_source_create function will now take an array of stream pointers, instead of an array of streams. This is to make the API more flexible as well as more consistent with the unicast API. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 6e60451 commit 5628b29

File tree

5 files changed

+43
-19
lines changed

5 files changed

+43
-19
lines changed

include/zephyr/bluetooth/audio/audio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group);
16341634
* called and no audio information (BIGInfo) will be visible to scanners
16351635
* (see bt_le_per_adv_sync_cb).
16361636
*
1637-
* @param[in] streams Array of stream objects being used for the
1637+
* @param[in] streams Array of stream object pointers being used for the
16381638
* broadcaster. This array shall remain valid for the
16391639
* duration of the broadcast source.
16401640
* @param[in] num_stream Number of streams in @p streams.
@@ -1644,7 +1644,7 @@ int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group);
16441644
*
16451645
* @return Zero on success or (negative) error code otherwise.
16461646
*/
1647-
int bt_audio_broadcast_source_create(struct bt_audio_stream *streams,
1647+
int bt_audio_broadcast_source_create(struct bt_audio_stream *streams[],
16481648
size_t num_stream,
16491649
struct bt_codec *codec,
16501650
struct bt_codec_qos *qos,

subsys/bluetooth/audio/broadcast_source.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,11 @@ static int bt_audio_set_base(const struct bt_audio_broadcast_source *source,
372372
static void broadcast_source_cleanup(struct bt_audio_broadcast_source *source)
373373
{
374374
for (size_t i = 0; i < source->stream_count; i++) {
375-
struct bt_audio_stream *stream = &source->streams[i];
375+
struct bt_audio_stream *stream = source->streams[i];
376+
377+
if (stream == NULL) {
378+
continue;
379+
}
376380

377381
stream->ep->stream = NULL;
378382
stream->ep = NULL;
@@ -385,7 +389,7 @@ static void broadcast_source_cleanup(struct bt_audio_broadcast_source *source)
385389
(void)memset(source, 0, sizeof(*source));
386390
}
387391

388-
int bt_audio_broadcast_source_create(struct bt_audio_stream *streams,
392+
int bt_audio_broadcast_source_create(struct bt_audio_stream *streams[],
389393
size_t num_stream,
390394
struct bt_codec *codec,
391395
struct bt_codec_qos *qos,
@@ -437,6 +441,13 @@ int bt_audio_broadcast_source_create(struct bt_audio_stream *streams,
437441
return -EINVAL;
438442
}
439443

444+
for (size_t i = 0; i < num_stream; i++) {
445+
CHECKIF(streams[i] == NULL) {
446+
BT_DBG("streams[%zu] is NULL", i);
447+
return -EINVAL;
448+
}
449+
}
450+
440451
source = NULL;
441452
for (index = 0; index < ARRAY_SIZE(broadcast_sources); index++) {
442453
if (broadcast_sources[index].bis[0] == NULL) { /* Find free entry */
@@ -453,7 +464,7 @@ int bt_audio_broadcast_source_create(struct bt_audio_stream *streams,
453464
source->streams = streams;
454465
source->stream_count = num_stream;
455466
for (size_t i = 0; i < num_stream; i++) {
456-
struct bt_audio_stream *stream = &streams[i];
467+
struct bt_audio_stream *stream = streams[i];
457468

458469
err = bt_audio_broadcast_source_setup_stream(index, stream,
459470
codec, qos);
@@ -534,7 +545,7 @@ int bt_audio_broadcast_source_create(struct bt_audio_stream *streams,
534545
}
535546

536547
for (size_t i = 0; i < source->stream_count; i++) {
537-
struct bt_audio_ep *ep = streams[i].ep;
548+
struct bt_audio_ep *ep = streams[i]->ep;
538549

539550
ep->broadcast_source = source;
540551
broadcast_source_set_ep_state(ep,
@@ -562,7 +573,7 @@ int bt_audio_broadcast_source_reconfig(struct bt_audio_broadcast_source *source,
562573
return -EINVAL;
563574
}
564575

565-
stream = &source->streams[0];
576+
stream = source->streams[0];
566577

567578
if (stream == NULL) {
568579
BT_DBG("stream is NULL");
@@ -581,7 +592,12 @@ int bt_audio_broadcast_source_reconfig(struct bt_audio_broadcast_source *source,
581592
}
582593

583594
for (size_t i = 0; i < source->stream_count; i++) {
584-
stream = &source->streams[i];
595+
stream = source->streams[i];
596+
597+
if (stream == NULL) {
598+
BT_DBG("streams[i] is NULL");
599+
return -EINVAL;
600+
}
585601

586602
bt_audio_stream_attach(NULL, stream, stream->ep, codec);
587603
}
@@ -608,7 +624,7 @@ int bt_audio_broadcast_source_start(struct bt_audio_broadcast_source *source)
608624
return -EINVAL;
609625
}
610626

611-
stream = &source->streams[0];
627+
stream = source->streams[0];
612628

613629
if (stream == NULL) {
614630
BT_DBG("stream is NULL");
@@ -653,7 +669,7 @@ int bt_audio_broadcast_source_stop(struct bt_audio_broadcast_source *source)
653669
return -EINVAL;
654670
}
655671

656-
stream = &source->streams[0];
672+
stream = source->streams[0];
657673

658674
if (stream == NULL) {
659675
BT_DBG("stream is NULL");
@@ -698,7 +714,7 @@ int bt_audio_broadcast_source_delete(struct bt_audio_broadcast_source *source)
698714
return -EINVAL;
699715
}
700716

701-
stream = &source->streams[0];
717+
stream = source->streams[0];
702718

703719
if (stream != NULL) {
704720
if (stream->ep == NULL) {

subsys/bluetooth/audio/endpoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ struct bt_audio_broadcast_source {
8181
struct bt_iso_chan *bis[BROADCAST_STREAM_CNT];
8282
struct bt_codec_qos *qos;
8383
/* The streams used to create the broadcast source */
84-
struct bt_audio_stream *streams;
84+
struct bt_audio_stream **streams;
8585
};
8686

8787
struct bt_audio_broadcast_sink {

subsys/bluetooth/shell/audio.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,7 @@ static int cmd_select_broadcast_source(const struct shell *sh, size_t argc,
11191119
static int cmd_create_broadcast(const struct shell *sh, size_t argc,
11201120
char *argv[])
11211121
{
1122+
static struct bt_audio_stream *streams[ARRAY_SIZE(broadcast_source_streams)];
11221123
struct named_lc3_preset *named_preset;
11231124
int err;
11241125

@@ -1138,8 +1139,12 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc,
11381139
}
11391140
}
11401141

1141-
err = bt_audio_broadcast_source_create(broadcast_source_streams,
1142-
ARRAY_SIZE(broadcast_source_streams),
1142+
(void)memset(streams, 0, sizeof(streams));
1143+
for (size_t i = 0; i < ARRAY_SIZE(streams); i++) {
1144+
streams[i] = &broadcast_source_streams[i];
1145+
}
1146+
1147+
err = bt_audio_broadcast_source_create(streams, ARRAY_SIZE(streams),
11431148
&named_preset->preset.codec,
11441149
&named_preset->preset.qos,
11451150
&default_source);
@@ -1152,7 +1157,7 @@ static int cmd_create_broadcast(const struct shell *sh, size_t argc,
11521157
named_preset->name);
11531158

11541159
if (default_stream == NULL) {
1155-
default_stream = &broadcast_source_streams[0];
1160+
default_stream = streams[0];
11561161
}
11571162

11581163
return 0;

tests/bluetooth/bsim_bt/bsim_test_audio/src/broadcast_source_test.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ static void test_main(void)
1818
struct bt_audio_lc3_preset preset_16_2_1 = BT_AUDIO_LC3_BROADCAST_PRESET_16_2_1;
1919
struct bt_audio_lc3_preset preset_16_2_2 = BT_AUDIO_LC3_BROADCAST_PRESET_16_2_2;
2020
struct bt_audio_stream broadcast_source_streams[CONFIG_BT_AUDIO_BROADCAST_SRC_STREAM_COUNT];
21+
struct bt_audio_stream *streams[ARRAY_SIZE(broadcast_source_streams)];
2122
struct bt_audio_broadcast_source *source;
2223

2324
err = bt_enable(NULL);
@@ -31,9 +32,12 @@ static void test_main(void)
3132
(void)memset(broadcast_source_streams, 0,
3233
sizeof(broadcast_source_streams));
3334

35+
for (size_t i = 0; i < ARRAY_SIZE(streams); i++) {
36+
streams[i] = &broadcast_source_streams[i];
37+
}
38+
3439
printk("Creating broadcast source\n");
35-
err = bt_audio_broadcast_source_create(broadcast_source_streams,
36-
ARRAY_SIZE(broadcast_source_streams),
40+
err = bt_audio_broadcast_source_create(streams, ARRAY_SIZE(streams),
3741
&preset_16_2_1.codec,
3842
&preset_16_2_1.qos,
3943
&source);
@@ -62,8 +66,7 @@ static void test_main(void)
6266

6367
/* Recreate broadcast source to verify that it's possible */
6468
printk("Recreating broadcast source\n");
65-
err = bt_audio_broadcast_source_create(broadcast_source_streams,
66-
ARRAY_SIZE(broadcast_source_streams),
69+
err = bt_audio_broadcast_source_create(streams, ARRAY_SIZE(streams),
6770
&preset_16_2_1.codec,
6871
&preset_16_2_1.qos,
6972
&source);

0 commit comments

Comments
 (0)