Discussion:
[PATCH 0/2] sbc: fix frame length in DUAL_CHANNEL mode
Aurélien Zanelli
2014-10-23 14:32:19 UTC
Permalink
Hi everyone,
I was playing with sbc encoder in GStreamer, which use bluez sbc librar=
y to
encode and I found two issues related to DUAL_CHANNEL mode in it.

=46irst the frame length calculation for DUAL_CHANNEL mode was wrong. I=
found
the A2DP specification and it seems that for DUAL_CHANNEL mode, we shou=
ld use
the same formula as MONO mode to calculate the frame length. The first =
patch
intend to fix this.

The second patch try to fix an overflow which can occur when the frame =
length
is greater than 255.

Aur=C3=A9lien Zanelli (2):
sbc: fix frame length calculation for DUAL_CHANNEL mode
sbc: use an uint16 to store frame length in internal frame structure

sbc/sbc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

--=20
1.7.10.4
Aurélien Zanelli
2014-10-23 14:32:20 UTC
Permalink
According to A2DP specification, section 12.9, for DUAL_CHANNEL mode, we
shall use the same formula as for MONO mode.
---
sbc/sbc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbc/sbc.c b/sbc/sbc.c
index 534027e..e830388 100644
--- a/sbc/sbc.c
+++ b/sbc/sbc.c
@@ -1402,7 +1402,7 @@ SBC_EXPORT size_t sbc_get_frame_length(sbc_t *sbc)

ret = 4 + (4 * subbands * channels) / 8;
/* This term is not always evenly divide so we round it up */
- if (channels == 1)
+ if (channels == 1 || sbc->mode == SBC_MODE_DUAL_CHANNEL)
ret += ((blocks * channels * bitpool) + 7) / 8;
else
ret += (((joint ? subbands : 0) + blocks * bitpool) + 7) / 8;
--
1.7.10.4
Aurélien Zanelli
2014-10-23 14:32:21 UTC
Permalink
Otherwise it could overflow in some cases.
For instance in DUAL_CHANNEL mode, with subbands set to SBC_SB_8, blocks
set to SBC_BLK_16 and bitpool set to 64 results in a frame length of 268.
---
sbc/sbc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbc/sbc.c b/sbc/sbc.c
index e830388..606f11c 100644
--- a/sbc/sbc.c
+++ b/sbc/sbc.c
@@ -119,7 +119,7 @@ struct sbc_frame {
uint8_t subbands;
uint8_t bitpool;
uint16_t codesize;
- uint8_t length;
+ uint16_t length;

/* bit number x set means joint stereo has been used in subband x */
uint8_t joint;
--
1.7.10.4
Loading...