sbc: detect when bitpool has changed
Luiz Augusto von Dentz
maintainerPATCH 1/1 sbc: detect when bitpool has changed
From: Luiz Augusto von Dentz <[email protected]>
--- sbc/sbc.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
sbc/sbc.c +5 -3
@@ -965,7 +965,8 @@ ssize_t sbc_decode(sbc_t *sbc, const void *input, size_t input_len, framelen =sbc_unpack_frame (input, &priv->frame, input_len); -if (!priv->init) { +/* init if no previous frame was encode or bitpool has changed */ +if (!priv->init || priv->frame.bitpool != sbc->bitpool) {sbc_decoder_init (&priv->dec_state, &priv->frame); priv->init =1 ;
@@ -1035,7 +1036,8 @@ ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len,if (written) *written =0 ; -if (!priv->init) { +/* init if no previous frame was encode or bitpool has changed */ +if (!priv->init || priv->frame.bitpool != sbc->bitpool) { priv->frame.frequency = sbc->frequency; priv->frame.mode = sbc->mode; priv->frame.channels = sbc->mode ==SBC_MODE_MONO ?1 :2 ;
@@ -1120,7 +1122,7 @@ size_t sbc_get_frame_length(sbc_t *sbc)struct sbc_priv *priv; priv = sbc->priv; -if (priv->init) +if (priv->init && priv->frame.bitpool == sbc->bitpool)return priv->frame.length; subbands = sbc->subbands ?8 :4 ;
Signature · 1 line
1.7.1
Hello Luiz,
Quoted 11 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
--- sbc/sbc.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)sbc/sbc.c +0
-0
sbc/sbc.c ssize_t sbc_decode(sbc_t *sbc, const void *input, size_t input_len, · line 971
Quoted 8 lines
sbc/sbc.c +2
-1@@ -965,7 +965,8 @@ ssize_t sbc_decode(sbc_t *sbc, const void *input, size_t input_len, framelen =sbc_unpack_frame (input, &priv->frame, input_len); -if (!priv->init) { +/* init if no previous frame was encode or bitpool has changed */ +if (!priv->init || priv->frame.bitpool != sbc->bitpool) {sbc_decoder_init (&priv->dec_state, &priv->frame); priv->init =1 ;
I don't think it is a good idea to reinitialize the SBC decoder if a change in bitpool size is detected.
The A2DP and AVDTP specifications do not allow most of the parameters to change from one frame to the next (mode, channels, subbands, blocks, allocation, frequency) but explicitly DO allow changes in bitpool size midstream. This allows for Variable Bit Rate (VBR) streaming, and adds efficiency to the over-the-air link with no quality loss. Also, the space required for decoding does not change just because the bitpool has changed, so re-initialization should not be required.
The only things that should be different from one SBC frame to the next is the bitpool of course, and the framelen. That said, if a bitpool change is detected the only thing within that "IF" block that should be updated is:sbc->bitpool
If any of the other afore mentioned parameters change, the stream should be terminated.
sbc/sbc.c ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len, · line 1043
Quoted 11 lines
sbc/sbc.c +2
-1@@ -1035,7 +1036,8 @@ ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len,if (written) *written =0 ; -if (!priv->init) { +/* init if no previous frame was encode or bitpool has changed */ +if (!priv->init || priv->frame.bitpool != sbc->bitpool) { priv->frame.frequency = sbc->frequency; priv->frame.mode = sbc->mode; priv->frame.channels = sbc->mode ==SBC_MODE_MONO ?1 :2 ;
Same basic comment here, although it is perfectly allowable for the Encoder to not support VBR. However if the Encoder does change the bitpool, then the list of fields that need to be updated are:priv->frame.bitpoolpriv->frame.length
But again, the sbc_encoder_init should *not* be re-run. I would pull those two variables out of that IF block, and set them in their own IF block either directly before or directly after the !priv->init IF block.
sbc/sbc.c size_t sbc_get_frame_length(sbc_t *sbc) · line 1128
Quoted 9 lines
sbc/sbc.c +1
-1@@ -1120,7 +1122,7 @@ size_t sbc_get_frame_length(sbc_t *sbc)struct sbc_priv *priv; priv = sbc->priv; -if (priv->init) +if (priv->init && priv->frame.bitpool == sbc->bitpool)return priv->frame.length; subbands = sbc->subbands ?8 :4 ;
This is a valid change, because bitpool changes do indeed change the frame.length.
Signature · 4 lines
Brian Gix [email protected] Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Luiz Augusto von Dentz
maintainerHi,
Quoted 34 lines · Brian Gix
Hello Luiz,
Quoted 11 lines · Luiz Augusto von Dentz
From: Luiz Augusto von Dentz <[email protected]>
---
sbc/sbc.c | 8 +++++---1 files changed, 5 insertions(+), 3 deletions(-)sbc/sbc.c +0
-0sbc/sbc.c ssize_t sbc_decode(sbc_t *sbc, const void *input, size_t input_len, · line 971
Quoted 8 lines
sbc/sbc.c +2
-1@@ -965,7 +965,8 @@ ssize_t sbc_decode(sbc_t *sbc, const void *input, size_t input_len, framelen = sbc_unpack_frame(input, &priv->frame, input_len); - if (!priv->init) { + /* init if no previous frame was encode or bitpool has changed */ + if (!priv->init || priv->frame.bitpool != sbc->bitpool) { sbc_decoder_init(&priv->dec_state, &priv->frame); priv->init = 1;I don't think it is a good idea to reinitialize the SBC decoder if a change in bitpool size is detected.
The A2DP and AVDTP specifications do not allow most of the parameters to change from one frame to the next (mode, channels, subbands, blocks, allocation, frequency) but explicitly DO allow changes in bitpool size midstream. This allows for Variable Bit Rate (VBR) streaming, and adds efficiency to the over-the-air link with no quality loss. Also, the space required for decoding does not change just because the bitpool has changed, so re-initialization should not be required.
Quoted 5 lines
The only things that should be different from one SBC frame to the next is the bitpool of course, and the framelen. That said, if a bitpool change is detected the only thing within that "IF" block that should be updated is:
sbc->bitpool
You are mostly right, but we should also do priv->frame.length = framelen to make sure sbc_get_frame_length return it properly.
Quoted 35 lines
If any of the other afore mentioned parameters change, the stream should be terminated.
sbc/sbc.c ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len, · line 1043
Quoted 11 lines
sbc/sbc.c +2
-1@@ -1035,7 +1036,8 @@ ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len, if (written) *written = 0; - if (!priv->init) { + /* init if no previous frame was encode or bitpool has changed */ + if (!priv->init || priv->frame.bitpool != sbc->bitpool) { priv->frame.frequency = sbc->frequency; priv->frame.mode = sbc->mode; priv->frame.channels = sbc->mode == SBC_MODE_MONO ? 1 : 2;Same basic comment here, although it is perfectly allowable for the Encoder to not support VBR. However if the Encoder does change the bitpool, then the list of fields that need to be updated are:
priv->frame.bitpoolpriv->frame.lengthBut again, the
sbc_encoder_initshould *not* be re-run. I would pull those two variables out of that IF block, and set them in their own IF block either directly before or directly after the !priv->init IF block.Quoted 8 lines
sbc/sbc.c +1
-1@@ -1120,7 +1122,7 @@ size_t sbc_get_frame_length(sbc_t *sbc) struct sbc_priv *priv; priv = sbc->priv; - if (priv->init) + if (priv->init && priv->frame.bitpool == sbc->bitpool) return priv->frame.length;
Quoted 4 lines
sbc/sbc.c size_t sbc_get_frame_length(sbc_t *sbc) · line 1128
Quoted 1 line
sbc/sbc.c +0
-0subbands = sbc->subbands ? 8 : 4;This is a valid change, because bitpool changes do indeed change the frame.length.
Ive sent a v2 patch but will update with a v3 with a proper description why it is needed.
Signature · 2 lines
Luiz Augusto von Dentz Computer Engineer