Skip to content

Commit 13c42bd

Browse files
Thalleykartben
authored andcommitted
samples: Bluetooth: Use broadcast sink cbs in broadcast sink sample
Use the broadcast sink callbacks to set the semaphores rather than the stream callbacks, as the broadcast sink callbacks are better for that as they are called when all streams are ready. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 6e86b67 commit 13c42bd

File tree

1 file changed

+19
-15
lines changed
  • samples/bluetooth/bap_broadcast_sink/src

1 file changed

+19
-15
lines changed

samples/bluetooth/bap_broadcast_sink/src/main.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,6 @@ static void stream_started_cb(struct bt_bap_stream *stream)
536536
#endif /* CONFIG_LIBLC3 */
537537

538538
k_sem_give(&sem_stream_started);
539-
if (k_sem_count_get(&sem_stream_started) == stream_count) {
540-
big_synced = true;
541-
printk("BIG synced\n");
542-
k_sem_give(&sem_big_synced);
543-
}
544539
}
545540

546541
static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
@@ -553,11 +548,6 @@ static void stream_stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
553548
if (err != 0) {
554549
printk("Failed to take sem_stream_started: %d\n", err);
555550
}
556-
557-
if (k_sem_count_get(&sem_stream_started) != stream_count) {
558-
printk("BIG sync terminated\n");
559-
big_synced = false;
560-
}
561551
}
562552

563553
static void stream_recv_cb(struct bt_bap_stream *stream, const struct bt_iso_recv_info *info,
@@ -818,9 +808,27 @@ static void syncable_cb(struct bt_bap_broadcast_sink *sink, const struct bt_iso_
818808
}
819809
}
820810

811+
static void broadcast_sink_started_cb(struct bt_bap_broadcast_sink *sink)
812+
{
813+
printk("Broadcast sink %p started\n", sink);
814+
815+
big_synced = true;
816+
k_sem_give(&sem_big_synced);
817+
}
818+
819+
static void broadcast_sink_stopped_cb(struct bt_bap_broadcast_sink *sink, uint8_t reason)
820+
{
821+
printk("Broadcast sink %p stopped with reason 0x%02X\n", sink, reason);
822+
823+
big_synced = false;
824+
k_sem_give(&sem_broadcast_sink_stopped);
825+
}
826+
821827
static struct bt_bap_broadcast_sink_cb broadcast_sink_cbs = {
822828
.base_recv = base_recv_cb,
823829
.syncable = syncable_cb,
830+
.started = broadcast_sink_started_cb,
831+
.stopped = broadcast_sink_stopped_cb,
824832
};
825833

826834
static void pa_timer_handler(struct k_work *work)
@@ -1027,8 +1035,6 @@ static int bis_sync_req_cb(struct bt_conn *conn,
10271035

10281036
return err;
10291037
}
1030-
1031-
k_sem_give(&sem_broadcast_sink_stopped);
10321038
}
10331039

10341040
broadcaster_broadcast_id = recv_state->broadcast_id;
@@ -1242,7 +1248,7 @@ static void bap_pa_sync_terminated_cb(struct bt_le_per_adv_sync *sync,
12421248
if (info->reason != BT_HCI_ERR_LOCALHOST_TERM_CONN && req_recv_state != NULL) {
12431249
int err;
12441250

1245-
if (k_sem_count_get(&sem_stream_connected) > 0) {
1251+
if (big_synced) {
12461252
err = bt_bap_broadcast_sink_stop(broadcast_sink);
12471253
if (err != 0) {
12481254
printk("Failed to stop Broadcast Sink: %d\n", err);
@@ -1257,8 +1263,6 @@ static void bap_pa_sync_terminated_cb(struct bt_le_per_adv_sync *sync,
12571263

12581264
return;
12591265
}
1260-
1261-
k_sem_give(&sem_broadcast_sink_stopped);
12621266
}
12631267
}
12641268
}

0 commit comments

Comments
 (0)