1
1
/*
2
- * Copyright (c) 2021-2024 Nordic Semiconductor ASA
2
+ * Copyright (c) 2021-2025 Nordic Semiconductor ASA
3
3
*
4
4
* SPDX-License-Identifier: Apache-2.0
5
5
*/
@@ -54,12 +54,14 @@ static const struct bt_audio_codec_cap lc3_codec_cap = BT_AUDIO_CODEC_CAP_LC3(
54
54
55
55
static struct bt_conn * default_conn ;
56
56
static struct k_work_delayable audio_send_work ;
57
- static struct bt_bap_stream sink_streams [CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT ];
57
+ static struct audio_sink {
58
+ struct bt_bap_stream stream ;
59
+ size_t recv_cnt ;
60
+ } sink_streams [CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT ];
58
61
static struct audio_source {
59
62
struct bt_bap_stream stream ;
60
63
uint16_t seq_num ;
61
- uint16_t max_sdu ;
62
- size_t len_to_send ;
64
+ size_t send_cnt ;
63
65
} source_streams [CONFIG_BT_ASCS_MAX_ASE_SRC_COUNT ];
64
66
static size_t configured_source_stream_count ;
65
67
@@ -237,20 +239,21 @@ static void audio_timer_timeout(struct k_work *work)
237
239
}
238
240
net_buf_reserve (buf , BT_ISO_CHAN_SEND_RESERVE );
239
241
240
- net_buf_add_mem (buf , buf_data , ++ source_streams [ i ]. len_to_send );
242
+ net_buf_add_mem (buf , buf_data , stream -> qos -> sdu );
241
243
242
244
ret = bt_bap_stream_send (stream , buf , get_and_incr_seq_num (stream ));
243
245
if (ret < 0 ) {
244
246
printk ("Failed to send audio data on streams[%zu] (%p): (%d)\n" ,
245
247
i , stream , ret );
246
248
net_buf_unref (buf );
247
249
} else {
248
- printk ("Sending mock data with len %zu on streams[%zu] (%p)\n" ,
249
- source_streams [i ].len_to_send , i , stream );
250
- }
250
+ source_streams [i ].send_cnt ++ ;
251
251
252
- if (source_streams [i ].len_to_send >= source_streams [i ].max_sdu ) {
253
- source_streams [i ].len_to_send = 0 ;
252
+ if (CONFIG_INFO_REPORTING_INTERVAL > 0 &&
253
+ (source_streams [i ].send_cnt % CONFIG_INFO_REPORTING_INTERVAL ) == 0U ) {
254
+ printk ("Stream %p: Sent %u total SDUs of size %u\n" , stream ,
255
+ source_streams [i ].send_cnt , stream -> qos -> sdu );
256
+ }
254
257
}
255
258
}
256
259
@@ -270,7 +273,7 @@ static enum bt_audio_dir stream_dir(const struct bt_bap_stream *stream)
270
273
}
271
274
272
275
for (size_t i = 0U ; i < ARRAY_SIZE (sink_streams ); i ++ ) {
273
- if (stream == & sink_streams [i ]) {
276
+ if (stream == & sink_streams [i ]. stream ) {
274
277
return BT_AUDIO_DIR_SINK ;
275
278
}
276
279
}
@@ -291,7 +294,7 @@ static struct bt_bap_stream *stream_alloc(enum bt_audio_dir dir)
291
294
}
292
295
} else {
293
296
for (size_t i = 0 ; i < ARRAY_SIZE (sink_streams ); i ++ ) {
294
- struct bt_bap_stream * stream = & sink_streams [i ];
297
+ struct bt_bap_stream * stream = & sink_streams [i ]. stream ;
295
298
296
299
if (!stream -> conn ) {
297
300
return stream ;
@@ -360,13 +363,6 @@ static int lc3_qos(struct bt_bap_stream *stream, const struct bt_bap_qos_cfg *qo
360
363
361
364
print_qos (qos );
362
365
363
- for (size_t i = 0U ; i < configured_source_stream_count ; i ++ ) {
364
- if (stream == & source_streams [i ].stream ) {
365
- source_streams [i ].max_sdu = qos -> sdu ;
366
- break ;
367
- }
368
- }
369
-
370
366
return 0 ;
371
367
}
372
368
@@ -428,7 +424,6 @@ static int lc3_start(struct bt_bap_stream *stream, struct bt_bap_ascs_rsp *rsp)
428
424
for (size_t i = 0U ; i < configured_source_stream_count ; i ++ ) {
429
425
if (stream == & source_streams [i ].stream ) {
430
426
source_streams [i ].seq_num = 0U ;
431
- source_streams [i ].len_to_send = 0U ;
432
427
break ;
433
428
}
434
429
}
@@ -509,18 +504,26 @@ static void stream_recv_lc3_codec(struct bt_bap_stream *stream,
509
504
const struct bt_iso_recv_info * info ,
510
505
struct net_buf * buf )
511
506
{
507
+ struct audio_sink * sink_stream = CONTAINER_OF (stream , struct audio_sink , stream );
512
508
const bool valid_data = (info -> flags & BT_ISO_FLAGS_VALID ) != 0 ;
513
509
const int octets_per_frame = buf -> len / frames_per_sdu ;
514
510
511
+ if (valid_data ) {
512
+ sink_stream -> recv_cnt ++ ;
513
+
514
+ if (CONFIG_INFO_REPORTING_INTERVAL > 0 &&
515
+ (sink_stream -> recv_cnt % CONFIG_INFO_REPORTING_INTERVAL ) == 0U ) {
516
+ printk ("Incoming audio on stream %p len %u\n" , stream , buf -> len );
517
+ }
518
+ } else {
519
+ printk ("Bad packet: 0x%02X\n" , info -> flags );
520
+ }
521
+
515
522
if (lc3_decoder == NULL ) {
516
523
printk ("LC3 decoder not setup, cannot decode data.\n" );
517
524
return ;
518
525
}
519
526
520
- if (!valid_data ) {
521
- printk ("Bad packet: 0x%02X\n" , info -> flags );
522
- }
523
-
524
527
for (int i = 0 ; i < frames_per_sdu ; i ++ ) {
525
528
/* Passing NULL performs PLC */
526
529
const int err = lc3_decode (
@@ -533,8 +536,6 @@ static void stream_recv_lc3_codec(struct bt_bap_stream *stream,
533
536
printk ("[%d]: Decoder failed - wrong parameters?: %d\n" , i , err );
534
537
}
535
538
}
536
-
537
- printk ("RX stream %p len %u\n" , stream , buf -> len );
538
539
}
539
540
540
541
#else
@@ -544,7 +545,14 @@ static void stream_recv(struct bt_bap_stream *stream,
544
545
struct net_buf * buf )
545
546
{
546
547
if (info -> flags & BT_ISO_FLAGS_VALID ) {
547
- printk ("Incoming audio on stream %p len %u\n" , stream , buf -> len );
548
+ struct audio_sink * sink_stream = CONTAINER_OF (stream , struct audio_sink , stream );
549
+
550
+ sink_stream -> recv_cnt ++ ;
551
+
552
+ if (CONFIG_INFO_REPORTING_INTERVAL > 0 &&
553
+ (sink_stream -> recv_cnt % CONFIG_INFO_REPORTING_INTERVAL ) == 0U ) {
554
+ printk ("Incoming audio on stream %p len %u\n" , stream , buf -> len );
555
+ }
548
556
}
549
557
}
550
558
@@ -561,6 +569,12 @@ static void stream_stopped(struct bt_bap_stream *stream, uint8_t reason)
561
569
static void stream_started (struct bt_bap_stream * stream )
562
570
{
563
571
printk ("Audio Stream %p started\n" , stream );
572
+
573
+ if (stream_dir (stream ) == BT_AUDIO_DIR_SINK ) {
574
+ struct audio_sink * sink_stream = CONTAINER_OF (stream , struct audio_sink , stream );
575
+
576
+ sink_stream -> recv_cnt = 0U ;
577
+ }
564
578
}
565
579
566
580
static void stream_enabled_cb (struct bt_bap_stream * stream )
@@ -754,7 +768,7 @@ int main(void)
754
768
bt_pacs_cap_register (BT_AUDIO_DIR_SOURCE , & cap_source );
755
769
756
770
for (size_t i = 0 ; i < ARRAY_SIZE (sink_streams ); i ++ ) {
757
- bt_bap_stream_cb_register (& sink_streams [i ], & stream_ops );
771
+ bt_bap_stream_cb_register (& sink_streams [i ]. stream , & stream_ops );
758
772
}
759
773
760
774
for (size_t i = 0 ; i < ARRAY_SIZE (source_streams ); i ++ ) {
0 commit comments