@@ -23,6 +23,8 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL);
23
23
#include "btp_bap_audio_stream.h"
24
24
#include "btp_bap_broadcast.h"
25
25
26
+ static K_SEM_DEFINE (sem_stream_stopped , 0U , CONFIG_BT_BAP_BROADCAST_SRC_STREAM_COUNT ) ;
27
+
26
28
static struct btp_bap_broadcast_remote_source remote_broadcast_sources [1 ];
27
29
static struct btp_bap_broadcast_local_source local_source ;
28
30
/* Only one PA sync supported for now. */
@@ -132,8 +134,9 @@ static void stream_stopped(struct bt_bap_stream *stream, uint8_t reason)
132
134
LOG_DBG ("Stopped stream %p with reason 0x%02X" , stream , reason );
133
135
134
136
btp_bap_audio_stream_stopped (& b_stream -> audio_stream );
135
-
136
137
b_stream -> bis_synced = false;
138
+
139
+ k_sem_give (& sem_stream_stopped );
137
140
}
138
141
139
142
static void send_bis_stream_received_ev (const bt_addr_le_t * address , uint32_t broadcast_id ,
@@ -327,6 +330,8 @@ uint8_t btp_bap_broadcast_source_setup(const void *cmd, uint16_t cmd_len,
327
330
source -> qos .pd = sys_get_le24 (cp -> presentation_delay );
328
331
source -> qos .sdu = sys_le16_to_cpu (cp -> max_sdu );
329
332
333
+ source -> stream_count = cp -> subgroups * cp -> streams_per_subgroup ;
334
+
330
335
err = setup_broadcast_source (cp -> streams_per_subgroup , cp -> subgroups , source , & codec_cfg );
331
336
if (err != 0 ) {
332
337
LOG_DBG ("Unable to setup broadcast source: %d" , err );
@@ -484,13 +489,24 @@ uint8_t btp_bap_broadcast_source_stop(const void *cmd, uint16_t cmd_len,
484
489
485
490
LOG_DBG ("" );
486
491
492
+ k_sem_reset (& sem_stream_stopped );
493
+
487
494
err = bt_bap_broadcast_source_stop (source -> bap_broadcast );
488
495
if (err != 0 ) {
489
496
LOG_DBG ("Unable to stop broadcast source: %d" , err );
490
497
491
498
return BTP_STATUS_FAILED ;
492
499
}
493
500
501
+ for (int i = 0 ; i < source -> stream_count ; i ++ ) {
502
+ err = k_sem_take (& sem_stream_stopped , K_MSEC (1000 ));
503
+ if (err != 0 ) {
504
+ LOG_DBG ("Timed out waiting for stream nr %d to stop" , i );
505
+
506
+ return BTP_STATUS_FAILED ;
507
+ }
508
+ }
509
+
494
510
return BTP_STATUS_SUCCESS ;
495
511
}
496
512
0 commit comments