Skip to content

Commit 9defebb

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: Audio: broadcast_sink_sync array of stream pointers
Change bt_audio_broadcast_sink_sync to use an array of pointers to bt_audio_streams, instead of an array of streams. This makes the API more flexible, as well consistent with the broadcast source and unicast APIs. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 5628b29 commit 9defebb

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

include/zephyr/bluetooth/audio/audio.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,9 +1737,9 @@ int bt_audio_broadcast_sink_scan_stop(void);
17371737
* @param indexes_bitfield Bitfield of the BIS index to sync to. To sync to
17381738
* e.g. BIS index 1 and 2, this should have the value
17391739
* of BIT(1) | BIT(2).
1740-
* @param streams Stream objects to be used for the receiver. If
1741-
* multiple BIS indexes shall be synchronized,
1742-
* multiple streams shall be provided.
1740+
* @param streams Stream object pointerss to be used for the
1741+
* receiver. If multiple BIS indexes shall be
1742+
* synchronized, multiple streams shall be provided.
17431743
* @param codec Codec configuration.
17441744
* @param broadcast_code The 16-octet broadcast code. Shall be supplied if
17451745
* the broadcast is encrypted (see the syncable
@@ -1749,7 +1749,7 @@ int bt_audio_broadcast_sink_scan_stop(void);
17491749
*/
17501750
int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
17511751
uint32_t indexes_bitfield,
1752-
struct bt_audio_stream *streams,
1752+
struct bt_audio_stream *streams[],
17531753
struct bt_codec *codec,
17541754
const uint8_t broadcast_code[16]);
17551755

subsys/bluetooth/audio/broadcast_sink.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,10 @@ static void broadcast_sink_cleanup_streams(struct bt_audio_broadcast_sink *sink)
849849
for (size_t i = 0; i < sink->stream_count; i++) {
850850
struct bt_audio_stream *stream;
851851

852-
stream = &sink->streams[i];
852+
stream = sink->streams[i];
853+
if (stream == NULL) {
854+
continue;
855+
}
853856

854857
if (stream->ep != NULL) {
855858
stream->ep->stream = NULL;
@@ -871,7 +874,7 @@ static void broadcast_sink_cleanup(struct bt_audio_broadcast_sink *sink)
871874

872875
int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
873876
uint32_t indexes_bitfield,
874-
struct bt_audio_stream *streams,
877+
struct bt_audio_stream *streams[],
875878
struct bt_codec *codec,
876879
const uint8_t broadcast_code[16])
877880
{
@@ -926,13 +929,20 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
926929
}
927930
}
928931

932+
for (size_t i = 0; i < stream_count; i++) {
933+
CHECKIF(streams[i] == NULL) {
934+
BT_DBG("streams[%zu] is NULL", i);
935+
return -EINVAL;
936+
}
937+
}
938+
929939
sink->stream_count = stream_count;
930940
sink->streams = streams;
931941
sink->codec = codec;
932942
for (size_t i = 0; i < stream_count; i++) {
933943
struct bt_audio_stream *stream;
934944

935-
stream = &streams[i];
945+
stream = streams[i];
936946

937947
err = bt_audio_broadcast_sink_setup_stream(sink->index, stream,
938948
sink->codec);
@@ -964,7 +974,7 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
964974
}
965975

966976
for (size_t i = 0; i < stream_count; i++) {
967-
struct bt_audio_ep *ep = streams[i].ep;
977+
struct bt_audio_ep *ep = streams[i]->ep;
968978

969979
ep->broadcast_sink = sink;
970980
broadcast_sink_set_ep_state(ep,
@@ -984,7 +994,7 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink)
984994
return -EINVAL;
985995
}
986996

987-
stream = &sink->streams[0];
997+
stream = sink->streams[0];
988998

989999
if (stream == NULL) {
9901000
BT_DBG("stream is NULL");
@@ -1011,24 +1021,24 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink)
10111021

10121022
sink->big = NULL;
10131023
sink->stream_count = 0;
1024+
sink->streams = NULL;
10141025
/* Channel states will be updated in the ep_iso_disconnected function */
10151026

10161027
return 0;
10171028
}
10181029

10191030
int bt_audio_broadcast_sink_delete(struct bt_audio_broadcast_sink *sink)
10201031
{
1021-
struct bt_audio_stream *stream;
1032+
struct bt_audio_stream **streams;
10221033
int err;
10231034

10241035
CHECKIF(sink == NULL) {
10251036
BT_DBG("sink is NULL");
10261037
return -EINVAL;
10271038
}
10281039

1029-
stream = &sink->streams[0];
1030-
1031-
if (stream != NULL && stream->ep != NULL) {
1040+
streams = sink->streams;
1041+
if (streams != NULL && streams[0] != NULL && streams[0]->ep != NULL) {
10321042
BT_DBG("Sink is not stopped");
10331043
return -EBADMSG;
10341044
}

subsys/bluetooth/audio/endpoint.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ struct bt_audio_broadcast_sink {
100100
struct bt_iso_big *big;
101101
struct bt_iso_chan *bis[BROADCAST_SNK_STREAM_CNT];
102102
/* The streams used to create the broadcast sink */
103-
struct bt_audio_stream *streams;
103+
struct bt_audio_stream **streams;
104104
};
105105

106106
static inline const char *bt_audio_ep_state_str(uint8_t state)

subsys/bluetooth/shell/audio.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,7 @@ static int cmd_accept_broadcast(const struct shell *sh, size_t argc,
12601260

12611261
static int cmd_sync_broadcast(const struct shell *sh, size_t argc, char *argv[])
12621262
{
1263+
static struct bt_audio_stream *streams[ARRAY_SIZE(broadcast_sink_streams)];
12631264
uint32_t bis_bitfield;
12641265
int err;
12651266

@@ -1278,8 +1279,13 @@ static int cmd_sync_broadcast(const struct shell *sh, size_t argc, char *argv[])
12781279
return -ENOEXEC;
12791280
}
12801281

1282+
(void)memset(streams, 0, sizeof(streams));
1283+
for (size_t i = 0; i < ARRAY_SIZE(streams); i++) {
1284+
streams[i] = &broadcast_sink_streams[i];
1285+
}
1286+
12811287
err = bt_audio_broadcast_sink_sync(default_sink, bis_bitfield,
1282-
broadcast_sink_streams,
1288+
streams,
12831289
&default_preset->preset.codec,
12841290
NULL);
12851291
if (err != 0) {

0 commit comments

Comments
 (0)