mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
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:
parent
1b3b577b8f
commit
2d30ab94c2
10 changed files with 151 additions and 10 deletions
|
|
@ -40,6 +40,9 @@ struct impl {
|
|||
uint32_t rate;
|
||||
uint32_t channels;
|
||||
int samplesize;
|
||||
|
||||
uint32_t enc_delay;
|
||||
uint32_t dec_delay;
|
||||
};
|
||||
|
||||
static bool eld_supported(void)
|
||||
|
|
@ -443,6 +446,8 @@ static void *codec_init(const struct media_codec *codec, uint32_t flags,
|
|||
if (res != AACENC_OK)
|
||||
goto error;
|
||||
|
||||
this->enc_delay = enc_info.nDelay;
|
||||
|
||||
this->codesize = enc_info.frameLength * this->channels * this->samplesize;
|
||||
|
||||
this->aacdec = aacDecoder_Open(TT_MP4_LATM_MCP1, 1);
|
||||
|
|
@ -471,6 +476,8 @@ static void *codec_init(const struct media_codec *codec, uint32_t flags,
|
|||
}
|
||||
#endif
|
||||
|
||||
this->dec_delay = 0;
|
||||
|
||||
return this;
|
||||
|
||||
error:
|
||||
|
|
@ -650,6 +657,21 @@ static int codec_increase_bitpool(void *data)
|
|||
return codec_change_bitrate(this, (this->cur_bitrate * 4) / 3);
|
||||
}
|
||||
|
||||
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) {
|
||||
CStreamInfo *info = aacDecoder_GetStreamInfo(this->aacdec);
|
||||
if (info)
|
||||
this->dec_delay = info->outputDelay;
|
||||
*decoder = this->dec_delay;
|
||||
}
|
||||
}
|
||||
|
||||
static void codec_set_log(struct spa_log *global_log)
|
||||
{
|
||||
log = global_log;
|
||||
|
|
@ -678,6 +700,7 @@ const struct media_codec a2dp_codec_aac = {
|
|||
.reduce_bitpool = codec_reduce_bitpool,
|
||||
.increase_bitpool = codec_increase_bitpool,
|
||||
.set_log = codec_set_log,
|
||||
.get_delay = codec_get_delay,
|
||||
};
|
||||
|
||||
const struct media_codec a2dp_codec_aac_eld = {
|
||||
|
|
@ -703,6 +726,7 @@ const struct media_codec a2dp_codec_aac_eld = {
|
|||
.reduce_bitpool = codec_reduce_bitpool,
|
||||
.increase_bitpool = codec_increase_bitpool,
|
||||
.set_log = codec_set_log,
|
||||
.get_delay = codec_get_delay,
|
||||
};
|
||||
|
||||
MEDIA_CODEC_EXPORT_DEF(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue