@@ -33,7 +33,7 @@ static struct bt_le_scan_recv_info broadcaster_info;
33
33
static bt_addr_le_t broadcaster_addr ;
34
34
static struct bt_le_per_adv_sync * pa_sync ;
35
35
static uint32_t broadcaster_broadcast_id ;
36
- static struct bt_cap_stream broadcast_sink_streams [CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT ];
36
+ static struct audio_test_stream broadcast_sink_streams [CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT ];
37
37
38
38
static const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3 (
39
39
BT_AUDIO_CODEC_LC3_FREQ_ANY , BT_AUDIO_CODEC_LC3_DURATION_ANY ,
@@ -260,7 +260,47 @@ static void stopped_cb(struct bt_bap_stream *stream, uint8_t reason)
260
260
static void recv_cb (struct bt_bap_stream * stream , const struct bt_iso_recv_info * info ,
261
261
struct net_buf * buf )
262
262
{
263
- SET_FLAG (flag_received );
263
+ struct audio_test_stream * test_stream = audio_test_stream_from_bap_stream (stream );
264
+
265
+ if ((test_stream -> rx_cnt % 100U ) == 0U ) {
266
+ printk ("[%zu]: Incoming audio on stream %p len %u and ts %u\n" , test_stream -> rx_cnt ,
267
+ stream , buf -> len , info -> ts );
268
+ }
269
+
270
+ if (test_stream -> rx_cnt > 0U && info -> ts == test_stream -> last_info .ts ) {
271
+ FAIL ("Duplicated timestamp received: %u\n" , test_stream -> last_info .ts );
272
+ return ;
273
+ }
274
+
275
+ if (test_stream -> rx_cnt > 0U && info -> seq_num == test_stream -> last_info .seq_num ) {
276
+ FAIL ("Duplicated PSN received: %u\n" , test_stream -> last_info .seq_num );
277
+ return ;
278
+ }
279
+
280
+ if (info -> flags & BT_ISO_FLAGS_ERROR ) {
281
+ /* Fail the test if we have not received what we expected */
282
+ if (!TEST_FLAG (flag_received )) {
283
+ FAIL ("ISO receive error\n" );
284
+ }
285
+
286
+ return ;
287
+ }
288
+
289
+ if (info -> flags & BT_ISO_FLAGS_LOST ) {
290
+ FAIL ("ISO receive lost\n" );
291
+ return ;
292
+ }
293
+
294
+ if (memcmp (buf -> data , mock_iso_data , buf -> len ) == 0 ) {
295
+ test_stream -> rx_cnt ++ ;
296
+
297
+ if (test_stream -> rx_cnt >= MIN_SEND_COUNT ) {
298
+ /* We set the flag is just one stream has received the expected */
299
+ SET_FLAG (flag_received );
300
+ }
301
+ } else {
302
+ FAIL ("Unexpected data received\n" );
303
+ }
264
304
}
265
305
266
306
static struct bt_bap_stream_ops broadcast_stream_ops = {
@@ -604,8 +644,9 @@ static void init(void)
604
644
UNSET_FLAG (flag_pa_synced );
605
645
606
646
for (size_t i = 0U ; i < ARRAY_SIZE (broadcast_sink_streams ); i ++ ) {
607
- bt_cap_stream_ops_register (& broadcast_sink_streams [i ],
608
- & broadcast_stream_ops );
647
+ bt_cap_stream_ops_register (
648
+ cap_stream_from_audio_test_stream (& broadcast_sink_streams [i ]),
649
+ & broadcast_stream_ops );
609
650
}
610
651
}
611
652
@@ -678,6 +719,7 @@ static int pa_sync_create(void)
678
719
static void test_cap_acceptor_broadcast (void )
679
720
{
680
721
static struct bt_bap_stream * bap_streams [ARRAY_SIZE (broadcast_sink_streams )];
722
+ size_t stream_count ;
681
723
int err ;
682
724
683
725
init ();
@@ -724,24 +766,32 @@ static void test_cap_acceptor_broadcast(void)
724
766
WAIT_FOR_FLAG (flag_syncable );
725
767
726
768
for (size_t i = 0U ; i < ARRAY_SIZE (broadcast_sink_streams ); i ++ ) {
727
- bap_streams [i ] = & broadcast_sink_streams [i ]. bap_stream ;
769
+ bap_streams [i ] = bap_stream_from_audio_test_stream ( & broadcast_sink_streams [i ]) ;
728
770
}
729
771
730
772
printk ("Syncing the sink\n" );
773
+ stream_count = 0 ;
774
+ for (int i = 1 ; i < BT_ISO_MAX_GROUP_ISO_COUNT ; i ++ ) {
775
+ if ((bis_index_bitfield & BIT (i )) != 0 ) {
776
+ stream_count ++ ;
777
+ }
778
+ }
779
+
731
780
err = bt_bap_broadcast_sink_sync (g_broadcast_sink , bis_index_bitfield , bap_streams , NULL );
732
781
if (err != 0 ) {
733
782
FAIL ("Unable to sync the sink: %d\n" , err );
734
783
return ;
735
784
}
736
785
737
786
/* Wait for all to be started */
738
- printk ("Waiting for broadcast_sink_streams to be started\n" );
739
- for (size_t i = 0U ; i < ARRAY_SIZE ( broadcast_sink_streams ) ; i ++ ) {
787
+ printk ("Waiting for %zu streams to be started\n" , stream_count );
788
+ for (size_t i = 0U ; i < stream_count ; i ++ ) {
740
789
k_sem_take (& sem_broadcast_started , K_FOREVER );
741
790
}
742
791
743
792
printk ("Waiting for data\n" );
744
793
WAIT_FOR_FLAG (flag_received );
794
+ backchannel_sync_send_all (); /* let other devices know we have received what we wanted */
745
795
746
796
/* The order of PA sync lost and BIG Sync lost is irrelevant
747
797
* and depend on timeout parameters. We just wait for PA first, but
@@ -750,8 +800,8 @@ static void test_cap_acceptor_broadcast(void)
750
800
printk ("Waiting for PA disconnected\n" );
751
801
WAIT_FOR_FLAG (flag_pa_sync_lost );
752
802
753
- printk ("Waiting for streams to be stopped\n" );
754
- for (size_t i = 0U ; i < ARRAY_SIZE ( broadcast_sink_streams ) ; i ++ ) {
803
+ printk ("Waiting for %zu streams to be stopped\n" , stream_count );
804
+ for (size_t i = 0U ; i < stream_count ; i ++ ) {
755
805
k_sem_take (& sem_broadcast_stopped , K_FOREVER );
756
806
}
757
807
0 commit comments