diff --git a/include/zephyr/bluetooth/audio/audio.h b/include/zephyr/bluetooth/audio/audio.h index 50d851b9f02..a3c64d2f0c9 100644 --- a/include/zephyr/bluetooth/audio/audio.h +++ b/include/zephyr/bluetooth/audio/audio.h @@ -1737,9 +1737,9 @@ int bt_audio_broadcast_sink_scan_stop(void); * @param indexes_bitfield Bitfield of the BIS index to sync to. To sync to * e.g. BIS index 1 and 2, this should have the value * of BIT(1) | BIT(2). - * @param streams Stream objects to be used for the receiver. If - * multiple BIS indexes shall be synchronized, - * multiple streams shall be provided. + * @param streams Stream object pointerss to be used for the + * receiver. If multiple BIS indexes shall be + * synchronized, multiple streams shall be provided. * @param codec Codec configuration. * @param broadcast_code The 16-octet broadcast code. Shall be supplied if * the broadcast is encrypted (see the syncable @@ -1749,7 +1749,7 @@ int bt_audio_broadcast_sink_scan_stop(void); */ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink, uint32_t indexes_bitfield, - struct bt_audio_stream *streams, + struct bt_audio_stream *streams[], struct bt_codec *codec, const uint8_t broadcast_code[16]); diff --git a/subsys/bluetooth/audio/broadcast_sink.c b/subsys/bluetooth/audio/broadcast_sink.c index 248fc4a2068..987e0ec2b54 100644 --- a/subsys/bluetooth/audio/broadcast_sink.c +++ b/subsys/bluetooth/audio/broadcast_sink.c @@ -849,7 +849,10 @@ static void broadcast_sink_cleanup_streams(struct bt_audio_broadcast_sink *sink) for (size_t i = 0; i < sink->stream_count; i++) { struct bt_audio_stream *stream; - stream = &sink->streams[i]; + stream = sink->streams[i]; + if (stream == NULL) { + continue; + } if (stream->ep != NULL) { stream->ep->stream = NULL; @@ -871,7 +874,7 @@ static void broadcast_sink_cleanup(struct bt_audio_broadcast_sink *sink) int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink, uint32_t indexes_bitfield, - struct bt_audio_stream *streams, + struct bt_audio_stream *streams[], struct bt_codec *codec, const uint8_t broadcast_code[16]) { @@ -926,13 +929,20 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink, } } + for (size_t i = 0; i < stream_count; i++) { + CHECKIF(streams[i] == NULL) { + BT_DBG("streams[%zu] is NULL", i); + return -EINVAL; + } + } + sink->stream_count = stream_count; sink->streams = streams; sink->codec = codec; for (size_t i = 0; i < stream_count; i++) { struct bt_audio_stream *stream; - stream = &streams[i]; + stream = streams[i]; err = bt_audio_broadcast_sink_setup_stream(sink->index, stream, sink->codec); @@ -964,7 +974,7 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink, } for (size_t i = 0; i < stream_count; i++) { - struct bt_audio_ep *ep = streams[i].ep; + struct bt_audio_ep *ep = streams[i]->ep; ep->broadcast_sink = sink; broadcast_sink_set_ep_state(ep, @@ -984,7 +994,7 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink) return -EINVAL; } - stream = &sink->streams[0]; + stream = sink->streams[0]; if (stream == NULL) { BT_DBG("stream is NULL"); @@ -1011,6 +1021,7 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink) sink->big = NULL; sink->stream_count = 0; + sink->streams = NULL; /* Channel states will be updated in the ep_iso_disconnected function */ return 0; @@ -1018,7 +1029,7 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink) int bt_audio_broadcast_sink_delete(struct bt_audio_broadcast_sink *sink) { - struct bt_audio_stream *stream; + struct bt_audio_stream **streams; int err; CHECKIF(sink == NULL) { @@ -1026,9 +1037,8 @@ int bt_audio_broadcast_sink_delete(struct bt_audio_broadcast_sink *sink) return -EINVAL; } - stream = &sink->streams[0]; - - if (stream != NULL && stream->ep != NULL) { + streams = sink->streams; + if (streams != NULL && streams[0] != NULL && streams[0]->ep != NULL) { BT_DBG("Sink is not stopped"); return -EBADMSG; } diff --git a/subsys/bluetooth/audio/endpoint.h b/subsys/bluetooth/audio/endpoint.h index 141d2ece79e..cfe40b69a56 100644 --- a/subsys/bluetooth/audio/endpoint.h +++ b/subsys/bluetooth/audio/endpoint.h @@ -100,7 +100,7 @@ struct bt_audio_broadcast_sink { struct bt_iso_big *big; struct bt_iso_chan *bis[BROADCAST_SNK_STREAM_CNT]; /* The streams used to create the broadcast sink */ - struct bt_audio_stream *streams; + struct bt_audio_stream **streams; }; static inline const char *bt_audio_ep_state_str(uint8_t state) diff --git a/subsys/bluetooth/shell/audio.c b/subsys/bluetooth/shell/audio.c index 9ebc9310330..0b697903e9c 100644 --- a/subsys/bluetooth/shell/audio.c +++ b/subsys/bluetooth/shell/audio.c @@ -1260,6 +1260,7 @@ static int cmd_accept_broadcast(const struct shell *sh, size_t argc, static int cmd_sync_broadcast(const struct shell *sh, size_t argc, char *argv[]) { + static struct bt_audio_stream *streams[ARRAY_SIZE(broadcast_sink_streams)]; uint32_t bis_bitfield; int err; @@ -1278,8 +1279,13 @@ static int cmd_sync_broadcast(const struct shell *sh, size_t argc, char *argv[]) return -ENOEXEC; } + (void)memset(streams, 0, sizeof(streams)); + for (size_t i = 0; i < ARRAY_SIZE(streams); i++) { + streams[i] = &broadcast_sink_streams[i]; + } + err = bt_audio_broadcast_sink_sync(default_sink, bis_bitfield, - broadcast_sink_streams, + streams, &default_preset->preset.codec, NULL); if (err != 0) {