35
35
#include <zephyr/sys/util_macro.h>
36
36
37
37
#include "bap_stream_rx.h"
38
+ #include "bap_stream_tx.h"
38
39
#include "bstests.h"
39
40
#include "common.h"
40
41
#include "bap_common.h"
41
42
42
43
#if defined(CONFIG_BT_CAP_ACCEPTOR )
43
44
extern enum bst_result_t bst_result ;
44
45
46
+ #define CAP_INITIATOR_DEV_ID 0 /* CAP initiator shall be ID 0 for these tests */
47
+
45
48
CREATE_FLAG (flag_broadcaster_found );
46
49
CREATE_FLAG (flag_broadcast_code );
47
50
CREATE_FLAG (flag_base_received );
@@ -59,6 +62,7 @@ static bt_addr_le_t broadcaster_addr;
59
62
static struct bt_le_per_adv_sync * pa_sync ;
60
63
static uint32_t broadcaster_broadcast_id ;
61
64
static struct audio_test_stream broadcast_sink_streams [CONFIG_BT_BAP_BROADCAST_SNK_STREAM_COUNT ];
65
+ static bool expect_rx ;
62
66
63
67
static const struct bt_bap_qos_cfg_pref unicast_qos_pref =
64
68
BT_BAP_QOS_CFG_PREF (true, BT_GAP_LE_PHY_2M , 0u , 60u , 20000u , 40000u , 20000u , 40000u );
@@ -72,8 +76,8 @@ static uint32_t bis_index_bitfield;
72
76
73
77
#define UNICAST_CHANNEL_COUNT_1 BIT(0)
74
78
75
- static struct bt_cap_stream unicast_streams [ CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT +
76
- CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT ];
79
+ static struct audio_test_stream
80
+ unicast_streams [ CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT + CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT ];
77
81
78
82
static bool subgroup_data_func_cb (struct bt_data * data , void * user_data )
79
83
{
@@ -275,6 +279,7 @@ static void started_cb(struct bt_bap_stream *stream)
275
279
276
280
memset (& test_stream -> last_info , 0 , sizeof (test_stream -> last_info ));
277
281
test_stream -> rx_cnt = 0U ;
282
+ test_stream -> valid_rx_cnt = 0U ;
278
283
test_stream -> seq_num = 0U ;
279
284
test_stream -> tx_cnt = 0U ;
280
285
@@ -319,8 +324,52 @@ static void unicast_stream_enabled_cb(struct bt_bap_stream *stream)
319
324
}
320
325
}
321
326
327
+ static void unicast_stream_started (struct bt_bap_stream * stream )
328
+ {
329
+ struct audio_test_stream * test_stream = audio_test_stream_from_bap_stream (stream );
330
+
331
+ memset (& test_stream -> last_info , 0 , sizeof (test_stream -> last_info ));
332
+ test_stream -> rx_cnt = 0U ;
333
+ test_stream -> valid_rx_cnt = 0U ;
334
+ test_stream -> seq_num = 0U ;
335
+ test_stream -> tx_cnt = 0U ;
336
+
337
+ printk ("Started stream %p\n" , stream );
338
+
339
+ if (bap_stream_tx_can_send (stream )) {
340
+ int err ;
341
+
342
+ err = bap_stream_tx_register (stream );
343
+ if (err != 0 ) {
344
+ FAIL ("Failed to register stream %p for TX: %d\n" , stream , err );
345
+ return ;
346
+ }
347
+ } else if (bap_stream_rx_can_recv (stream )) {
348
+ expect_rx = true;
349
+ }
350
+ }
351
+
352
+ static void unicast_stream_stopped (struct bt_bap_stream * stream , uint8_t reason )
353
+ {
354
+ printk ("Stopped stream %p with reason 0x%02X\n" , stream , reason );
355
+
356
+ if (bap_stream_tx_can_send (stream )) {
357
+ int err ;
358
+
359
+ err = bap_stream_tx_unregister (stream );
360
+ if (err != 0 ) {
361
+ FAIL ("Failed to unregister stream %p for TX: %d\n" , stream , err );
362
+ return ;
363
+ }
364
+ }
365
+ }
366
+
322
367
static struct bt_bap_stream_ops unicast_stream_ops = {
323
368
.enabled = unicast_stream_enabled_cb ,
369
+ .started = unicast_stream_started ,
370
+ .stopped = unicast_stream_stopped ,
371
+ .sent = bap_stream_tx_sent_cb ,
372
+ .recv = bap_stream_rx_recv_cb ,
324
373
};
325
374
326
375
static int pa_sync_req_cb (struct bt_conn * conn ,
@@ -404,7 +453,8 @@ static struct bt_csip_set_member_svc_inst *csip_set_member;
404
453
static struct bt_bap_stream * unicast_stream_alloc (void )
405
454
{
406
455
for (size_t i = 0 ; i < ARRAY_SIZE (unicast_streams ); i ++ ) {
407
- struct bt_bap_stream * stream = & unicast_streams [i ].bap_stream ;
456
+ struct bt_bap_stream * stream =
457
+ bap_stream_from_audio_test_stream (& unicast_streams [i ]);
408
458
409
459
if (!stream -> conn ) {
410
460
return stream ;
@@ -660,6 +710,7 @@ static void init(void)
660
710
}
661
711
662
712
printk ("Bluetooth initialized\n" );
713
+ bap_stream_tx_init ();
663
714
664
715
err = bt_pacs_register (& pacs_param );
665
716
if (err ) {
@@ -711,7 +762,9 @@ static void init(void)
711
762
}
712
763
713
764
for (size_t i = 0U ; i < ARRAY_SIZE (unicast_streams ); i ++ ) {
714
- bt_cap_stream_ops_register (& unicast_streams [i ], & unicast_stream_ops );
765
+ bt_cap_stream_ops_register (
766
+ cap_stream_from_audio_test_stream (& unicast_streams [i ]),
767
+ & unicast_stream_ops );
715
768
}
716
769
}
717
770
@@ -827,6 +880,13 @@ static void init(void)
827
880
}
828
881
}
829
882
883
+ static void wait_for_data (void )
884
+ {
885
+ printk ("Waiting for data\n" );
886
+ WAIT_FOR_FLAG (flag_audio_received );
887
+ printk ("Data received\n" );
888
+ }
889
+
830
890
static void test_cap_acceptor_unicast (void )
831
891
{
832
892
init ();
@@ -835,10 +895,17 @@ static void test_cap_acceptor_unicast(void)
835
895
836
896
auto_start_sink_streams = true;
837
897
838
- /* TODO: wait for audio stream to pass */
839
-
840
898
WAIT_FOR_FLAG (flag_connected );
841
899
900
+ /* Wait until initiator is done starting streams */
901
+ backchannel_sync_wait (CAP_INITIATOR_DEV_ID );
902
+
903
+ if (expect_rx ) {
904
+ wait_for_data ();
905
+ }
906
+ /* let initiator know we have received what we wanted */
907
+ backchannel_sync_send (CAP_INITIATOR_DEV_ID );
908
+
842
909
PASS ("CAP acceptor unicast passed\n" );
843
910
}
844
911
@@ -850,8 +917,6 @@ static void test_cap_acceptor_unicast_timeout(void)
850
917
851
918
auto_start_sink_streams = false; /* Cause unicast_audio_start timeout */
852
919
853
- /* TODO: wait for audio stream to pass */
854
-
855
920
WAIT_FOR_FLAG (flag_connected );
856
921
857
922
PASS ("CAP acceptor unicast passed\n" );
@@ -947,13 +1012,6 @@ static void create_and_sync_sink(struct bt_bap_stream *bap_streams[], size_t *st
947
1012
}
948
1013
}
949
1014
950
- static void sink_wait_for_data (void )
951
- {
952
- printk ("Waiting for data\n" );
953
- WAIT_FOR_FLAG (flag_audio_received );
954
- backchannel_sync_send_all (); /* let other devices know we have received what we wanted */
955
- }
956
-
957
1015
static void wait_for_broadcast_code (void )
958
1016
{
959
1017
printk ("Waiting for broadcast code\n" );
@@ -986,7 +1044,9 @@ static void test_cap_acceptor_broadcast(void)
986
1044
987
1045
create_and_sync_sink (bap_streams , & stream_count );
988
1046
989
- sink_wait_for_data ();
1047
+ wait_for_data ();
1048
+ /* let other devices know we have received what we wanted */
1049
+ backchannel_sync_send_all ();
990
1050
991
1051
wait_for_streams_stop (stream_count );
992
1052
@@ -1011,7 +1071,9 @@ static void test_cap_acceptor_broadcast_reception(void)
1011
1071
create_and_sync_sink (bap_streams , & stream_count );
1012
1072
1013
1073
wait_for_broadcast_code ();
1014
- sink_wait_for_data ();
1074
+ wait_for_data ();
1075
+ /* let other devices know we have received what we wanted */
1076
+ backchannel_sync_send_all ();
1015
1077
1016
1078
/* when flag_bis_sync_requested is unset the bis_sync for all subgroups were set to 0 */
1017
1079
WAIT_FOR_UNSET_FLAG (flag_bis_sync_requested );
0 commit comments