@@ -48,6 +48,7 @@ CREATE_FLAG(flag_pa_sync_lost);
48
48
CREATE_FLAG (flag_pa_request );
49
49
CREATE_FLAG (flag_bis_sync_requested );
50
50
CREATE_FLAG (flag_big_sync_mic_failure );
51
+ CREATE_FLAG (flag_sink_started );
51
52
52
53
static struct bt_bap_broadcast_sink * g_sink ;
53
54
static struct bt_le_scan_recv_info broadcaster_info ;
@@ -80,8 +81,8 @@ static const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3(
80
81
SUPPORTED_MIN_OCTETS_PER_FRAME , SUPPORTED_MAX_OCTETS_PER_FRAME ,
81
82
SUPPORTED_MAX_FRAMES_PER_SDU , SUPPORTED_CONTEXTS );
82
83
83
- static K_SEM_DEFINE (sem_started , 0U , ARRAY_SIZE (streams )) ;
84
- static K_SEM_DEFINE (sem_stopped , 0U , ARRAY_SIZE (streams )) ;
84
+ static K_SEM_DEFINE (sem_stream_started , 0U , ARRAY_SIZE (streams )) ;
85
+ static K_SEM_DEFINE (sem_stream_stopped , 0U , ARRAY_SIZE (streams )) ;
85
86
86
87
/* Create a mask for the maximum BIS we can sync to using the number of streams
87
88
* we have. We add an additional 1 since the bis indexes start from 1 and not
@@ -257,9 +258,27 @@ static void syncable_cb(struct bt_bap_broadcast_sink *sink, const struct bt_iso_
257
258
SET_FLAG (flag_syncable );
258
259
}
259
260
261
+ static void broadcast_sink_started_cb (struct bt_bap_broadcast_sink * sink )
262
+ {
263
+ printk ("Broadcast sink %p started\n" , sink );
264
+ SET_FLAG (flag_sink_started );
265
+ }
266
+
267
+ static void broadcast_sink_stopped_cb (struct bt_bap_broadcast_sink * sink , uint8_t reason )
268
+ {
269
+ printk ("Broadcast sink %p stopped with reason 0x%02X\n" , sink , reason );
270
+ UNSET_FLAG (flag_sink_started );
271
+
272
+ if (reason == BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL ) {
273
+ SET_FLAG (flag_big_sync_mic_failure );
274
+ }
275
+ }
276
+
260
277
static struct bt_bap_broadcast_sink_cb broadcast_sink_cbs = {
261
278
.base_recv = base_recv_cb ,
262
279
.syncable = syncable_cb ,
280
+ .started = broadcast_sink_started_cb ,
281
+ .stopped = broadcast_sink_stopped_cb ,
263
282
};
264
283
265
284
static bool scan_check_and_sync_broadcast (struct bt_data * data , void * user_data )
@@ -526,7 +545,7 @@ static void validate_stream_codec_cfg(const struct bt_bap_stream *stream)
526
545
}
527
546
}
528
547
529
- static void started_cb (struct bt_bap_stream * stream )
548
+ static void stream_started_cb (struct bt_bap_stream * stream )
530
549
{
531
550
struct audio_test_stream * test_stream = audio_test_stream_from_bap_stream (stream );
532
551
struct bt_bap_ep_info info ;
@@ -567,24 +586,20 @@ static void started_cb(struct bt_bap_stream *stream)
567
586
}
568
587
569
588
printk ("Stream %p started\n" , stream );
570
- k_sem_give (& sem_started );
589
+ k_sem_give (& sem_stream_started );
571
590
572
591
validate_stream_codec_cfg (stream );
573
592
}
574
593
575
- static void stopped_cb (struct bt_bap_stream * stream , uint8_t reason )
594
+ static void stream_stopped_cb (struct bt_bap_stream * stream , uint8_t reason )
576
595
{
577
596
printk ("Stream %p stopped with reason 0x%02X\n" , stream , reason );
578
- k_sem_give (& sem_stopped );
579
-
580
- if (reason == BT_HCI_ERR_TERM_DUE_TO_MIC_FAIL ) {
581
- SET_FLAG (flag_big_sync_mic_failure );
582
- }
597
+ k_sem_give (& sem_stream_stopped );
583
598
}
584
599
585
600
static struct bt_bap_stream_ops stream_ops = {
586
- .started = started_cb ,
587
- .stopped = stopped_cb ,
601
+ .started = stream_started_cb ,
602
+ .stopped = stream_stopped_cb ,
588
603
.recv = bap_stream_rx_recv_cb ,
589
604
};
590
605
@@ -707,6 +722,8 @@ static void test_broadcast_sink_create(void)
707
722
FAIL ("Unable to create the sink: %d\n" , err );
708
723
return ;
709
724
}
725
+
726
+ printk ("Created broadcast sink %p\n" , g_sink );
710
727
}
711
728
712
729
static void test_broadcast_sink_create_inval (void )
@@ -736,7 +753,7 @@ static void test_broadcast_sync(const uint8_t broadcast_code[BT_ISO_BROADCAST_CO
736
753
{
737
754
int err ;
738
755
739
- printk ("Syncing the sink\n" );
756
+ printk ("Syncing sink %p \n" , g_sink );
740
757
err = bt_bap_broadcast_sink_sync (g_sink , bis_index_bitfield , streams , broadcast_code );
741
758
if (err != 0 ) {
742
759
FAIL ("Unable to sync the sink: %d\n" , err );
@@ -808,16 +825,20 @@ static void test_broadcast_stop(void)
808
825
{
809
826
int err ;
810
827
828
+ printk ("Stopping broadcast sink %p\n" , g_sink );
829
+
811
830
err = bt_bap_broadcast_sink_stop (g_sink );
812
831
if (err != 0 ) {
813
832
FAIL ("Unable to stop sink: %d" , err );
814
833
return ;
815
834
}
816
835
817
- printk ("Waiting for streams to be stopped\n" );
836
+ printk ("Waiting for %zu streams to be stopped\n" , ARRAY_SIZE ( streams ) );
818
837
for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
819
- k_sem_take (& sem_stopped , K_FOREVER );
838
+ k_sem_take (& sem_stream_stopped , K_FOREVER );
820
839
}
840
+
841
+ WAIT_FOR_UNSET_FLAG (flag_sink_started );
821
842
}
822
843
823
844
static void test_broadcast_stop_inval (void )
@@ -914,10 +935,12 @@ static void test_common(void)
914
935
test_broadcast_sync_inval ();
915
936
test_broadcast_sync (NULL );
916
937
938
+ WAIT_FOR_FLAG (flag_sink_started );
939
+
917
940
/* Wait for all to be started */
918
- printk ("Waiting for streams to be started\n" );
941
+ printk ("Waiting for %zu streams to be started\n" , ARRAY_SIZE ( streams ) );
919
942
for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
920
- k_sem_take (& sem_started , K_FOREVER );
943
+ k_sem_take (& sem_stream_started , K_FOREVER );
921
944
}
922
945
923
946
printk ("Waiting for data\n" );
@@ -944,10 +967,11 @@ static void test_main(void)
944
967
printk ("Waiting for PA disconnected\n" );
945
968
WAIT_FOR_FLAG (flag_pa_sync_lost );
946
969
947
- printk ("Waiting for streams to be stopped\n" );
970
+ printk ("Waiting for %zu streams to be stopped\n" , ARRAY_SIZE ( streams ) );
948
971
for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
949
- k_sem_take (& sem_stopped , K_FOREVER );
972
+ k_sem_take (& sem_stream_stopped , K_FOREVER );
950
973
}
974
+ WAIT_FOR_UNSET_FLAG (flag_sink_started );
951
975
952
976
PASS ("Broadcast sink passed\n" );
953
977
}
@@ -962,10 +986,12 @@ static void test_sink_disconnect(void)
962
986
/* Retry sync*/
963
987
test_broadcast_sync (NULL );
964
988
989
+ WAIT_FOR_FLAG (flag_sink_started );
990
+
965
991
/* Wait for all to be started */
966
- printk ("Waiting for streams to be started\n" );
992
+ printk ("Waiting for %zu streams to be started\n" , ARRAY_SIZE ( streams ) );
967
993
for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
968
- k_sem_take (& sem_started , K_FOREVER );
994
+ k_sem_take (& sem_stream_started , K_FOREVER );
969
995
}
970
996
971
997
test_broadcast_stop ();
@@ -1001,10 +1027,12 @@ static void test_sink_encrypted(void)
1001
1027
1002
1028
test_broadcast_sync (BROADCAST_CODE );
1003
1029
1030
+ WAIT_FOR_FLAG (flag_sink_started );
1031
+
1004
1032
/* Wait for all to be started */
1005
- printk ("Waiting for streams to be started\n" );
1033
+ printk ("Waiting for %zu streams to be started\n" , ARRAY_SIZE ( streams ) );
1006
1034
for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
1007
- k_sem_take (& sem_started , K_FOREVER );
1035
+ k_sem_take (& sem_stream_started , K_FOREVER );
1008
1036
}
1009
1037
1010
1038
printk ("Waiting for data\n" );
@@ -1021,9 +1049,9 @@ static void test_sink_encrypted(void)
1021
1049
printk ("Waiting for PA disconnected\n" );
1022
1050
WAIT_FOR_FLAG (flag_pa_sync_lost );
1023
1051
1024
- printk ("Waiting for streams to be stopped\n" );
1052
+ printk ("Waiting for %zu streams to be stopped\n" , ARRAY_SIZE ( streams ) );
1025
1053
for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
1026
- k_sem_take (& sem_stopped , K_FOREVER );
1054
+ k_sem_take (& sem_stream_stopped , K_FOREVER );
1027
1055
}
1028
1056
1029
1057
PASS ("Broadcast sink encrypted passed\n" );
@@ -1090,10 +1118,12 @@ static void broadcast_sink_with_assistant(void)
1090
1118
WAIT_FOR_FLAG (flag_bis_sync_requested );
1091
1119
test_broadcast_sync (NULL );
1092
1120
1121
+ WAIT_FOR_FLAG (flag_sink_started );
1122
+
1093
1123
/* Wait for all to be started */
1094
- printk ("Waiting for streams to be started\n" );
1124
+ printk ("Waiting for %zu streams to be started\n" , ARRAY_SIZE ( streams ) );
1095
1125
for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
1096
- k_sem_take (& sem_started , K_FOREVER );
1126
+ k_sem_take (& sem_stream_started , K_FOREVER );
1097
1127
}
1098
1128
1099
1129
printk ("Waiting for data\n" );
0 commit comments