bluez5: account for codec internal delay in latency values

Encoders and some decoders have additional internal latency that needs
to be accounted for.

This mostly matters for AAC (~40ms), as the other BT codecs have much
lower delays (~5ms).
This commit is contained in:
Pauli Virtanen 2024-02-23 21:04:47 +02:00 committed by Wim Taymans
parent 1b3b577b8f
commit 2d30ab94c2
10 changed files with 151 additions and 10 deletions

View file

@ -29,6 +29,8 @@ struct impl {
int min_bitpool;
int max_bitpool;
uint32_t enc_delay;
};
static int codec_fill_caps(const struct media_codec *codec, uint32_t flags,
@ -497,9 +499,11 @@ static void *codec_init(const struct media_codec *codec, uint32_t flags,
switch (conf->subbands) {
case SBC_SUBBANDS_4:
this->sbc.subbands = SBC_SB_4;
this->enc_delay = 37;
break;
case SBC_SUBBANDS_8:
this->sbc.subbands = SBC_SB_8;
this->enc_delay = 73;
break;
default:
res = -EINVAL;
@ -618,6 +622,16 @@ static int codec_decode(void *data,
return res;
}
static void codec_get_delay(void *data, uint32_t *encoder, uint32_t *decoder)
{
struct impl *this = data;
if (encoder)
*encoder = this->enc_delay;
if (decoder)
*decoder = 0;
}
const struct media_codec a2dp_codec_sbc = {
.id = SPA_BLUETOOTH_AUDIO_CODEC_SBC,
.codec_id = A2DP_CODEC_SBC,
@ -638,6 +652,7 @@ const struct media_codec a2dp_codec_sbc = {
.decode = codec_decode,
.reduce_bitpool = codec_reduce_bitpool,
.increase_bitpool = codec_increase_bitpool,
.get_delay = codec_get_delay,
};
const struct media_codec a2dp_codec_sbc_xq = {
@ -661,6 +676,7 @@ const struct media_codec a2dp_codec_sbc_xq = {
.decode = codec_decode,
.reduce_bitpool = codec_reduce_bitpool,
.increase_bitpool = codec_increase_bitpool,
.get_delay = codec_get_delay,
};
MEDIA_CODEC_EXPORT_DEF(