@@ -33,7 +33,7 @@ static struct bt_le_scan_recv_info broadcaster_info;
3333static bt_addr_le_t broadcaster_addr ;
3434static struct bt_le_per_adv_sync * pa_sync ;
3535static 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 ];
3737
3838static const struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP_LC3 (
3939 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)
260260static void recv_cb (struct bt_bap_stream * stream , const struct bt_iso_recv_info * info ,
261261 struct net_buf * buf )
262262{
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+ }
264304}
265305
266306static struct bt_bap_stream_ops broadcast_stream_ops = {
@@ -604,8 +644,9 @@ static void init(void)
604644 UNSET_FLAG (flag_pa_synced );
605645
606646 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 );
609650 }
610651 }
611652
@@ -678,6 +719,7 @@ static int pa_sync_create(void)
678719static void test_cap_acceptor_broadcast (void )
679720{
680721 static struct bt_bap_stream * bap_streams [ARRAY_SIZE (broadcast_sink_streams )];
722+ size_t stream_count ;
681723 int err ;
682724
683725 init ();
@@ -724,24 +766,32 @@ static void test_cap_acceptor_broadcast(void)
724766 WAIT_FOR_FLAG (flag_syncable );
725767
726768 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 ]) ;
728770 }
729771
730772 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+
731780 err = bt_bap_broadcast_sink_sync (g_broadcast_sink , bis_index_bitfield , bap_streams , NULL );
732781 if (err != 0 ) {
733782 FAIL ("Unable to sync the sink: %d\n" , err );
734783 return ;
735784 }
736785
737786 /* 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 ++ ) {
740789 k_sem_take (& sem_broadcast_started , K_FOREVER );
741790 }
742791
743792 printk ("Waiting for data\n" );
744793 WAIT_FOR_FLAG (flag_received );
794+ backchannel_sync_send_all (); /* let other devices know we have received what we wanted */
745795
746796 /* The order of PA sync lost and BIG Sync lost is irrelevant
747797 * and depend on timeout parameters. We just wait for PA first, but
@@ -750,8 +800,8 @@ static void test_cap_acceptor_broadcast(void)
750800 printk ("Waiting for PA disconnected\n" );
751801 WAIT_FOR_FLAG (flag_pa_sync_lost );
752802
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 ++ ) {
755805 k_sem_take (& sem_broadcast_stopped , K_FOREVER );
756806 }
757807
0 commit comments