@@ -100,7 +100,6 @@ static int check_start_scan(void)
100100static void broadcast_stream_started_cb (struct bt_bap_stream * bap_stream )
101101{
102102 LOG_INF ("Started bap_stream %p" , bap_stream );
103- total_broadcast_rx_iso_packet_count = 0U ;
104103
105104 atomic_clear_bit (flags , FLAG_BROADCAST_SYNCING );
106105 atomic_set_bit (flags , FLAG_BROADCAST_SYNCED );
@@ -256,11 +255,20 @@ static void syncable_cb(struct bt_bap_broadcast_sink *sink, const struct bt_iso_
256255 }
257256}
258257
258+ static void sink_started_cb (struct bt_bap_broadcast_sink * sink )
259+ {
260+ LOG_INF ("Broadcast sink started" );
261+
262+ /* Clear requested BIS sync */
263+ broadcast_sink .requested_bis_sync = 0 ;
264+ atomic_clear_bit (flags , FLAG_BROADCAST_SYNC_REQUESTED );
265+ }
266+
259267static void sink_stopped_cb (struct bt_bap_broadcast_sink * sink , uint8_t reason )
260268{
261269 int err ;
262270
263- LOG_INF ("Broadcast sink stopped with reason %u " , reason );
271+ LOG_INF ("Broadcast sink stopped with reason 0x%02X " , reason );
264272
265273 err = bt_bap_broadcast_sink_delete (sink );
266274 if (err != 0 ) {
@@ -481,7 +489,10 @@ static int bis_sync_req_cb(struct bt_conn *conn,
481489 return - ENOMEM ;
482490 }
483491
484- if (broadcast_sink .requested_bis_sync == new_bis_sync_req ) {
492+ if (atomic_test_bit (flags , FLAG_BROADCAST_SYNC_REQUESTED ) &&
493+ broadcast_sink .requested_bis_sync == new_bis_sync_req ) {
494+ LOG_INF ("New request (0x%08x) is the same as last request; ignoring" ,
495+ new_bis_sync_req );
485496 return 0 ; /* no op */
486497 }
487498
@@ -491,6 +502,8 @@ static int bis_sync_req_cb(struct bt_conn *conn,
491502 */
492503 int err ;
493504
505+ LOG_INF ("Already synced. Stopping current sync and attempt resyncing" );
506+
494507 /* The stream stopped callback will be called as part of this,
495508 * and we do not need to wait for any events from the
496509 * controller. Thus, when this returns, the broadcast sink is stopped
@@ -502,13 +515,7 @@ static int bis_sync_req_cb(struct bt_conn *conn,
502515 return err ;
503516 }
504517
505- err = bt_bap_broadcast_sink_delete (broadcast_sink .bap_broadcast_sink );
506- if (err != 0 ) {
507- LOG_ERR ("Failed to delete Broadcast Sink: %d" , err );
508-
509- return err ;
510- }
511- broadcast_sink .bap_broadcast_sink = NULL ;
518+ /* Broadcast sink will be deleted and set to NULL in `sink_stopped_cb` */
512519
513520 atomic_clear_bit (flags , FLAG_BROADCAST_SYNCED );
514521 }
@@ -517,8 +524,6 @@ static int bis_sync_req_cb(struct bt_conn *conn,
517524 if (broadcast_sink .requested_bis_sync != 0U ) {
518525 atomic_set_bit (flags , FLAG_BROADCAST_SYNC_REQUESTED );
519526 check_sync_broadcast ();
520- } else {
521- atomic_clear_bit (flags , FLAG_BROADCAST_SYNC_REQUESTED );
522527 }
523528
524529 return 0 ;
@@ -568,10 +573,9 @@ static void bap_pa_sync_terminated_cb(struct bt_le_per_adv_sync *sync,
568573 if (sync == broadcast_sink .pa_sync ) {
569574 int err ;
570575
571- LOG_INF ("PA sync %p lost with reason %u " , (void * )sync , info -> reason );
576+ LOG_INF ("PA sync %p lost with reason 0x%02X " , (void * )sync , info -> reason );
572577
573578 /* Without PA we cannot sync to any new BIG - Clear data */
574- broadcast_sink .requested_bis_sync = 0 ;
575579 broadcast_sink .pa_sync = NULL ;
576580 k_work_cancel_delayable (& pa_timer );
577581 atomic_clear_bit (flags , FLAG_BROADCAST_SYNCABLE );
@@ -736,6 +740,7 @@ int init_cap_acceptor_broadcast(void)
736740 static struct bt_bap_broadcast_sink_cb broadcast_sink_cbs = {
737741 .base_recv = base_recv_cb ,
738742 .syncable = syncable_cb ,
743+ .started = sink_started_cb ,
739744 .stopped = sink_stopped_cb ,
740745 };
741746 static struct bt_bap_stream_ops broadcast_stream_ops = {
0 commit comments