sbc: fix frame length in DUAL_CHANNEL mode
cover sbc: fix frame length in DUAL_CHANNEL mode
Hi everyone,
I was playing with sbc encoder in GStreamer, which use bluez sbc library to encode and I found two issues related to DUAL_CHANNEL mode in it.
First the frame length calculation for DUAL_CHANNEL mode was wrong. I found the A2DP specification and it seems that for DUAL_CHANNEL mode, we should 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élien 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(-)
Signature · 1 line
1.7.10.4
PATCH 1/2 sbc: fix frame length calculation for DUAL_CHANNEL mode
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(-)
sbc/sbc.c +1 -1
@@ -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 ;
Signature · 1 line
1.7.10.4
PATCH 2/2 sbc: use an uint16 to store frame length in internal frame structure
In reply to Aurélien ZanelliOtherwise 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(-)
sbc/sbc.c +1 -1
@@ -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;
Signature · 1 line
1.7.10.4
Hi Aurélien,
Quoted 16 lines · Aurélien Zanelli
Hi everyone,
I was playing with sbc encoder in GStreamer, which use bluez sbc library to encode and I found two issues related toDUAL_CHANNELmode in it.First the frame length calculation for
DUAL_CHANNELmode was wrong. I found the A2DP specification and it seems that forDUAL_CHANNELmode, we should 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élien Zanelli (2):
sbc: fix frame length calculation forDUAL_CHANNELmode
sbc: use an uint16 to store frame length in internal frame structure
Quoted 5 lines
sbc/sbc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)--
1.7.10.4
Applied, thanks.
Signature · 1 line
Luiz Augusto von Dentz