Skip to content

Commit a4df95f

Browse files
Thalleykartben
authored andcommitted
samples: Bluetooth: BAP: Refactor stream_recv_lc3_codec
Refactor the function to use net_buf_pull_mem instead of the offset variable when decoding. Since the offset value was always 0 before, this fixes the incorrect decoding. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
1 parent a8182aa commit a4df95f

File tree

1 file changed

+11
-28
lines changed
  • samples/bluetooth/bap_unicast_server/src

1 file changed

+11
-28
lines changed

samples/bluetooth/bap_unicast_server/src/main.c

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -509,49 +509,32 @@ static void stream_recv_lc3_codec(struct bt_bap_stream *stream,
509509
const struct bt_iso_recv_info *info,
510510
struct net_buf *buf)
511511
{
512-
const uint8_t *in_buf;
513-
uint8_t err = -1;
512+
const bool valid_data = (info->flags & BT_ISO_FLAGS_VALID) == 0;
514513
const int octets_per_frame = buf->len / frames_per_sdu;
515514

516515
if (lc3_decoder == NULL) {
517516
printk("LC3 decoder not setup, cannot decode data.\n");
518517
return;
519518
}
520519

521-
if ((info->flags & BT_ISO_FLAGS_VALID) == 0) {
520+
if (!valid_data) {
522521
printk("Bad packet: 0x%02X\n", info->flags);
523-
524-
in_buf = NULL;
525-
} else {
526-
in_buf = buf->data;
527522
}
528523

529-
/* This code is to demonstrate the use of the LC3 codec. On an actual implementation
530-
* it might be required to offload the processing to another task to avoid blocking the
531-
* BT stack.
532-
*/
533524
for (int i = 0; i < frames_per_sdu; i++) {
534-
535-
int offset = 0;
536-
537-
err = lc3_decode(lc3_decoder, in_buf + offset, octets_per_frame,
538-
LC3_PCM_FORMAT_S16, audio_buf, 1);
539-
540-
if (in_buf != NULL) {
541-
offset += octets_per_frame;
525+
/* Passing NULL performs PLC */
526+
const int err = lc3_decode(
527+
lc3_decoder, valid_data ? net_buf_pull_mem(buf, octets_per_frame) : NULL,
528+
octets_per_frame, LC3_PCM_FORMAT_S16, audio_buf, 1);
529+
530+
if (err == 1) {
531+
printk("[%d]: Decoder performed PLC\n", i);
532+
} else if (err < 0) {
533+
printk("[%d]: Decoder failed - wrong parameters?: %d\n", i, err);
542534
}
543535
}
544536

545537
printk("RX stream %p len %u\n", stream, buf->len);
546-
547-
if (err == 1) {
548-
printk(" decoder performed PLC\n");
549-
return;
550-
551-
} else if (err < 0) {
552-
printk(" decoder failed - wrong parameters?\n");
553-
return;
554-
}
555538
}
556539

557540
#else

0 commit comments

Comments
 (0)