Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions include/zephyr/bluetooth/audio/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,6 @@ struct bt_audio_stream {
struct bt_iso_chan *iso;
/** Audio stream operations */
struct bt_audio_stream_ops *ops;
sys_snode_t node;

union {
void *group;
Expand All @@ -1297,6 +1296,9 @@ struct bt_audio_stream {

/** Stream user data */
void *user_data;

/* Internally used list node */
sys_snode_t _node;
};

/** Unicast Server callback structure */
Expand Down Expand Up @@ -1606,7 +1608,7 @@ struct bt_audio_broadcast_sink_cb {
void (*pa_sync_lost)(struct bt_audio_broadcast_sink *sink);

/* Internally used list node */
sys_snode_t node;
sys_snode_t _node;
};

/** @brief Stream operation. */
Expand Down Expand Up @@ -2093,8 +2095,7 @@ int bt_audio_unicast_group_delete(struct bt_audio_unicast_group *unicast_group);
* (see bt_le_per_adv_sync_cb).
*
* @param[in] streams Array of stream object pointers being used for the
* broadcaster. This array shall remain valid for the
* duration of the broadcast source.
* broadcaster.
* @param[in] num_stream Number of streams in @p streams.
* @param[in] codec Codec configuration.
* @param[in] qos Quality of Service configuration
Expand Down Expand Up @@ -2195,7 +2196,7 @@ 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 pointers to be used for the
* @param streams Stream object pointers to be used for the
* receiver. If multiple BIS indexes shall be
* synchronized, multiple streams shall be provided.
* @param broadcast_code The 16-octet broadcast code. Shall be supplied if
Expand Down
4 changes: 3 additions & 1 deletion include/zephyr/bluetooth/audio/capabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ struct bt_audio_capability {
/** Capability operations reference */
struct bt_audio_capability_ops *ops;
#endif /* CONFIG_BT_AUDIO_UNICAST_SERVER */
sys_snode_t node;

/* Internally used list node */
sys_snode_t _node;
};

/** @brief Register Audio Capability.
Expand Down
71 changes: 41 additions & 30 deletions subsys/bluetooth/audio/broadcast_sink.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ static void broadcast_sink_cleanup(struct bt_audio_broadcast_sink *sink);
static void broadcast_sink_clear_big(struct bt_audio_broadcast_sink *sink)
{
sink->big = NULL;
sink->stream_count = 0;
sink->streams = NULL;
}

static struct bt_audio_broadcast_sink *broadcast_sink_lookup_iso_chan(
Expand Down Expand Up @@ -279,7 +277,7 @@ static void pa_synced(struct bt_le_per_adv_sync *sync,

bt_audio_broadcast_sink_scan_stop();

SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, node) {
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->pa_synced != NULL) {
listener->pa_synced(sink, sink->pa_sync, sink->broadcast_id);
}
Expand All @@ -305,7 +303,7 @@ static void pa_term(struct bt_le_per_adv_sync *sync,
BT_DBG("PA sync with broadcast source with ID 0x%06X lost",
sink->broadcast_id);
broadcast_sink_cleanup(sink);
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, node) {
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->pa_sync_lost != NULL) {
listener->pa_sync_lost(sink);
}
Expand Down Expand Up @@ -581,7 +579,7 @@ static bool pa_decode_base(struct bt_data *data, void *user_data)
*/
(void)memcpy(&sink->base, &base, sizeof(base));

SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, node) {
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->base_recv != NULL) {
listener->base_recv(sink, &base);
}
Expand Down Expand Up @@ -626,7 +624,7 @@ static void biginfo_recv(struct bt_le_per_adv_sync *sync,
sink->biginfo_num_bis = biginfo->num_bis;
sink->big_encrypted = biginfo->encryption;

SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, node) {
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->syncable != NULL) {
listener->syncable(sink, biginfo->encryption);
}
Expand Down Expand Up @@ -691,7 +689,7 @@ static void sync_broadcast_pa(const struct bt_le_scan_recv_info *info,
BT_ERR("Could not stop scan: %d", err);
}

SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, node) {
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->scan_term != NULL) {
listener->scan_term(err);
}
Expand Down Expand Up @@ -768,7 +766,7 @@ static void broadcast_scan_recv(const struct bt_le_scan_recv_info *info,
BT_DBG("Found broadcast source with address %s and id 0x%6X",
bt_addr_le_str(info->addr), broadcast_id);

SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, node) {
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->scan_recv != NULL) {
bool sync_pa;

Expand Down Expand Up @@ -798,7 +796,7 @@ static void broadcast_scan_timeout(void)

bt_le_scan_cb_unregister(&broadcast_scan_cb);

SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, node) {
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->scan_term != NULL) {
listener->scan_term(-ETIME);
}
Expand All @@ -807,7 +805,7 @@ static void broadcast_scan_timeout(void)

void bt_audio_broadcast_sink_register_cb(struct bt_audio_broadcast_sink_cb *cb)
{
sys_slist_append(&sink_cbs, &cb->node);
sys_slist_append(&sink_cbs, &cb->_node);
}

int bt_audio_broadcast_sink_scan_start(const struct bt_le_scan_param *param)
Expand Down Expand Up @@ -870,7 +868,7 @@ int bt_audio_broadcast_sink_scan_stop(void)
bt_le_scan_cb_unregister(&broadcast_scan_cb);
}

SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, node) {
SYS_SLIST_FOR_EACH_CONTAINER(&sink_cbs, listener, _node) {
if (listener->scan_term != NULL) {
listener->scan_term(0);
}
Expand Down Expand Up @@ -962,14 +960,9 @@ static int bt_audio_broadcast_sink_setup_stream(uint8_t index,

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];
if (stream == NULL) {
continue;
}
struct bt_audio_stream *stream, *next;

SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&sink->streams, stream, next, _node) {
if (stream->ep != NULL) {
stream->ep->stream = NULL;
stream->ep = NULL;
Expand All @@ -979,7 +972,11 @@ static void broadcast_sink_cleanup_streams(struct bt_audio_broadcast_sink *sink)
stream->codec = NULL;
stream->iso = NULL;
stream->group = NULL;

sys_slist_remove(&sink->streams, NULL, &stream->_node);
}

sink->stream_count = 0;
}

static void broadcast_sink_cleanup(struct bt_audio_broadcast_sink *sink)
Expand Down Expand Up @@ -1078,8 +1075,6 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
}
}

sink->stream_count = stream_count;
sink->streams = streams;
for (size_t i = 0; i < stream_count; i++) {
struct bt_audio_stream *stream;
struct bt_codec *codec;
Expand All @@ -1096,6 +1091,8 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
}

sink->bis[i] = &stream->ep->iso->iso_chan;
sys_slist_append(&sink->streams, &stream->_node);
sink->stream_count++;
}

param.bis_channels = sink->bis;
Expand Down Expand Up @@ -1130,20 +1127,25 @@ int bt_audio_broadcast_sink_sync(struct bt_audio_broadcast_sink *sink,
int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink)
{
struct bt_audio_stream *stream;
sys_snode_t *head_node;
int err;

CHECKIF(sink == NULL) {
BT_DBG("sink is NULL");
return -EINVAL;
}

stream = sink->streams[0];

if (stream == NULL) {
BT_DBG("stream is NULL");
if (sys_slist_is_empty(&sink->streams)) {
BT_DBG("Source does not have any streams");
return -EINVAL;
}

head_node = sys_slist_peek_head(&sink->streams);
stream = CONTAINER_OF(head_node, struct bt_audio_stream, _node);

/* All streams in a broadcast source is in the same state,
* so we can just check the first stream
*/
if (stream->ep == NULL) {
BT_DBG("stream->ep is NULL");
return -EINVAL;
Expand All @@ -1163,25 +1165,34 @@ int bt_audio_broadcast_sink_stop(struct bt_audio_broadcast_sink *sink)
}

broadcast_sink_clear_big(sink);
/* Channel states will be updated in the ep_iso_disconnected function */
/* Channel states will be updated in the broadcast_sink_iso_disconnected function */

return 0;
}

int bt_audio_broadcast_sink_delete(struct bt_audio_broadcast_sink *sink)
{
struct bt_audio_stream **streams;
int err;

CHECKIF(sink == NULL) {
BT_DBG("sink is NULL");
return -EINVAL;
}

streams = sink->streams;
if (streams != NULL && streams[0] != NULL && streams[0]->ep != NULL) {
BT_DBG("Sink is not stopped");
return -EBADMSG;
if (!sys_slist_is_empty(&sink->streams)) {
struct bt_audio_stream *stream;
sys_snode_t *head_node;

head_node = sys_slist_peek_head(&sink->streams);
stream = CONTAINER_OF(head_node, struct bt_audio_stream, _node);

/* All streams in a broadcast source is in the same state,
* so we can just check the first stream
*/
if (stream->ep != NULL) {
BT_DBG("Sink is not stopped");
return -EBADMSG;
}
}

if (sink->pa_sync == NULL) {
Expand Down
Loading