@@ -153,8 +153,8 @@ static int16_t send_pcm_data[MAX_NUM_SAMPLES];
153
153
static uint16_t seq_num ;
154
154
static bool stopping ;
155
155
156
- static K_SEM_DEFINE (sem_started , 0U , ARRAY_SIZE ( streams ) ) ;
157
- static K_SEM_DEFINE (sem_stopped , 0U , ARRAY_SIZE ( streams ) ) ;
156
+ static K_SEM_DEFINE (sem_started , 0U , 1U ) ;
157
+ static K_SEM_DEFINE (sem_stopped , 0U , 1U ) ;
158
158
159
159
#define BROADCAST_SOURCE_LIFETIME 120U /* seconds */
160
160
@@ -365,12 +365,6 @@ static void stream_started_cb(struct bt_bap_stream *stream)
365
365
366
366
source_stream -> seq_num = 0U ;
367
367
source_stream -> sent_cnt = 0U ;
368
- k_sem_give (& sem_started );
369
- }
370
-
371
- static void stream_stopped_cb (struct bt_bap_stream * stream , uint8_t reason )
372
- {
373
- k_sem_give (& sem_stopped );
374
368
}
375
369
376
370
static void stream_sent_cb (struct bt_bap_stream * stream )
@@ -387,7 +381,9 @@ static void stream_sent_cb(struct bt_bap_stream *stream)
387
381
}
388
382
389
383
static struct bt_bap_stream_ops stream_ops = {
390
- .started = stream_started_cb , .stopped = stream_stopped_cb , .sent = stream_sent_cb };
384
+ .started = stream_started_cb ,
385
+ .sent = stream_sent_cb ,
386
+ };
391
387
392
388
static int setup_broadcast_source (struct bt_bap_broadcast_source * * source )
393
389
{
@@ -439,8 +435,24 @@ static int setup_broadcast_source(struct bt_bap_broadcast_source **source)
439
435
return 0 ;
440
436
}
441
437
438
+ static void source_started_cb (struct bt_bap_broadcast_source * source )
439
+ {
440
+ printk ("Broadcast source %p started\n" , source );
441
+ k_sem_give (& sem_started );
442
+ }
443
+
444
+ static void source_stopped_cb (struct bt_bap_broadcast_source * source , uint8_t reason )
445
+ {
446
+ printk ("Broadcast source %p stopped with reason 0x%02X\n" , source , reason );
447
+ k_sem_give (& sem_stopped );
448
+ }
449
+
442
450
int main (void )
443
451
{
452
+ static struct bt_bap_broadcast_source_cb broadcast_source_cb = {
453
+ .started = source_started_cb ,
454
+ .stopped = source_stopped_cb ,
455
+ };
444
456
struct bt_le_ext_adv * adv ;
445
457
int err ;
446
458
@@ -451,6 +463,12 @@ int main(void)
451
463
}
452
464
printk ("Bluetooth initialized\n" );
453
465
466
+ err = bt_bap_broadcast_source_register_cb (& broadcast_source_cb );
467
+ if (err != 0 ) {
468
+ printk ("Failed to register broadcast source callbacks (err %d)\n" , err );
469
+ return 0 ;
470
+ }
471
+
454
472
for (size_t i = 0U ; i < ARRAY_SIZE (send_pcm_data ); i ++ ) {
455
473
/* Initialize mock data */
456
474
send_pcm_data [i ] = i ;
@@ -581,10 +599,8 @@ int main(void)
581
599
return 0 ;
582
600
}
583
601
584
- /* Wait for all to be started */
585
- for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
586
- k_sem_take (& sem_started , K_FOREVER );
587
- }
602
+ /* Wait for broadcast source to be started */
603
+ k_sem_take (& sem_started , K_FOREVER );
588
604
printk ("Broadcast source started\n" );
589
605
590
606
/* Initialize sending */
@@ -608,10 +624,8 @@ int main(void)
608
624
return 0 ;
609
625
}
610
626
611
- /* Wait for all to be stopped */
612
- for (size_t i = 0U ; i < ARRAY_SIZE (streams ); i ++ ) {
613
- k_sem_take (& sem_stopped , K_FOREVER );
614
- }
627
+ /* Wait for broadcast source to be stopped */
628
+ k_sem_take (& sem_stopped , K_FOREVER );
615
629
printk ("Broadcast source stopped\n" );
616
630
617
631
printk ("Deleting broadcast source\n" );
0 commit comments