From 49d5f4f2363564cd05236a22d1a3e1d13bf57b39 Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Sun, 5 Apr 2026 19:52:53 +0300 Subject: [PATCH] bluez5: aac: use maximum possible peak bitrate according to MTU Android 11 and newer, in both CBR and VBR modes, * Sets bitrate (AACENC_BITRATE) to the max_bitrate value of A2DP * Sets peak bitrate (AACENC_PEAK_BITRATE) according to the maximum data which could fit into single audio packet based on MTU AACENC_BITRATE is used only in CBR mode. For VBR mode, the only limiting factor is AACENC_PEAK_BITRATE. Do the same in Pipewire. Link: https://gitlab.freedesktop.org/pipewire/pipewire/-/work_items/1482#note_2949680 Link: https://cs.android.com/android/platform/superproject/+/android16-qpr2-release:packages/modules/Bluetooth/system/stack/a2dp/a2dp_aac_encoder.cc;drc=37d7b4549f7b8740df1a290f04c20c591a2d3391;l=269 --- spa/plugins/bluez5/a2dp-codec-aac.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spa/plugins/bluez5/a2dp-codec-aac.c b/spa/plugins/bluez5/a2dp-codec-aac.c index a82efe983..689e26ba6 100644 --- a/spa/plugins/bluez5/a2dp-codec-aac.c +++ b/spa/plugins/bluez5/a2dp-codec-aac.c @@ -380,8 +380,12 @@ static void *codec_init(const struct media_codec *codec, uint32_t flags, // Fragmentation is not implemented yet, // so make sure every encoded AAC frame fits in (mtu - header) this->max_bitrate = ((this->mtu - sizeof(struct rtp_header)) * 8 * this->rate) / 1024; - this->max_bitrate = SPA_MIN(this->max_bitrate, get_valid_aac_bitrate(conf)); - this->cur_bitrate = this->max_bitrate; + this->cur_bitrate = SPA_MIN(this->max_bitrate, get_valid_aac_bitrate(conf)); + spa_log_debug(log, "AAC: max (peak) bitrate: %d, cur bitrate: %d, mode: %d (vbr: %d)", + this->max_bitrate, + this->cur_bitrate, + bitratemode, + conf->vbr); res = aacEncoder_SetParam(this->aacenc, AACENC_BITRATE, this->cur_bitrate); if (res != AACENC_OK)