bluetooth: allow increasing SBC output bitrate

SBC codec decrements bitpool value by fixed amount each time it is asked to
reduce output bitrate. This results in reduced audio quality with SBC codec.

Implement increase_encoder_bitrate for SBC codec by adding 1 to bitpool value
each time encoder bitrate needs to be increased to restore SBC audio quality.
While at it, remove bitpool decrement limit to use connection agreed value
instead as we will be able to restore quality later.

Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/474>
This commit is contained in:
Igor V. Kovalenko 2021-01-13 19:19:52 +03:00 committed by PulseAudio Marge Bot
parent 9699511215
commit 7e9e9e271a

View file

@ -36,8 +36,8 @@
#include "a2dp-codec-api.h" #include "a2dp-codec-api.h"
#include "rtp.h" #include "rtp.h"
#define SBC_BITPOOL_DEC_LIMIT 32
#define SBC_BITPOOL_DEC_STEP 5 #define SBC_BITPOOL_DEC_STEP 5
#define SBC_BITPOOL_INC_STEP 1
struct sbc_info { struct sbc_info {
sbc_t sbc; /* Codec data */ sbc_t sbc; /* Codec data */
@ -503,14 +503,20 @@ static size_t reduce_encoder_bitrate(void *codec_info, size_t write_link_mtu) {
struct sbc_info *sbc_info = (struct sbc_info *) codec_info; struct sbc_info *sbc_info = (struct sbc_info *) codec_info;
uint8_t bitpool; uint8_t bitpool;
/* Check if bitpool is already at its limit */ bitpool = PA_MAX(sbc_info->sbc.bitpool - SBC_BITPOOL_DEC_STEP, sbc_info->min_bitpool);
if (sbc_info->sbc.bitpool <= SBC_BITPOOL_DEC_LIMIT)
if (sbc_info->sbc.bitpool == bitpool)
return 0; return 0;
bitpool = sbc_info->sbc.bitpool - SBC_BITPOOL_DEC_STEP; set_bitpool(sbc_info, bitpool);
return get_block_size(codec_info, write_link_mtu);
}
if (bitpool < SBC_BITPOOL_DEC_LIMIT) static size_t increase_encoder_bitrate(void *codec_info, size_t write_link_mtu) {
bitpool = SBC_BITPOOL_DEC_LIMIT; struct sbc_info *sbc_info = (struct sbc_info *) codec_info;
uint8_t bitpool;
bitpool = PA_MIN(sbc_info->sbc.bitpool + SBC_BITPOOL_INC_STEP, sbc_info->max_bitpool);
if (sbc_info->sbc.bitpool == bitpool) if (sbc_info->sbc.bitpool == bitpool)
return 0; return 0;
@ -682,6 +688,7 @@ const pa_a2dp_codec pa_a2dp_codec_sbc = {
.get_read_block_size = get_block_size, .get_read_block_size = get_block_size,
.get_write_block_size = get_block_size, .get_write_block_size = get_block_size,
.reduce_encoder_bitrate = reduce_encoder_bitrate, .reduce_encoder_bitrate = reduce_encoder_bitrate,
.increase_encoder_bitrate = increase_encoder_bitrate,
.encode_buffer = encode_buffer, .encode_buffer = encode_buffer,
.decode_buffer = decode_buffer, .decode_buffer = decode_buffer,
}; };