aboutsummaryrefslogtreecommitdiffstats
path: root/libAACenc/src/aacenc_lib.cpp
diff options
context:
space:
mode:
authorFraunhofer IIS FDK <audio-fdk@iis.fraunhofer.de>2020-12-10 18:32:03 +0100
committerJean-Michel Trivi <jmtrivi@google.com>2020-12-23 18:57:54 -0800
commitc8a38ef6474f174f4b09ff69f5a8d746019307c0 (patch)
tree4da7ceb3a15830192f25f66c743ca0d708248d7d /libAACenc/src/aacenc_lib.cpp
parentf4f79ae49cae206a978abc37c711cb38ddff0625 (diff)
downloadfdk-aac-c8a38ef6474f174f4b09ff69f5a8d746019307c0.tar.gz
fdk-aac-c8a38ef6474f174f4b09ff69f5a8d746019307c0.tar.bz2
fdk-aac-c8a38ef6474f174f4b09ff69f5a8d746019307c0.zip
Adjust VBR mode depending on given peak bitrate and fix crash recovery usage.
Operating the FDK encoder in A2DP with variable bitrate mode configuration resulted in unexpected encoder return value AACENC_ENCODE_ERROR. Due to peak bitrate restriction the encoder quite often runs into requantization. In case the bitrate constraint is not fulfilled, the so-called crash recovery is used as final emergency step. The crash recovery reduces the overall bit consumption considering the given number of bits to be saved. The bit difference is extracted from audio element structures. In VBR mode the element wise bit consumption state was not updated since there is typically no bitrate limitation required. The patch solves the choppy audio problems and increases audio quality for AAC VBR encoding. The changes in FDKaacEnc_QCMain() ensure that audio element bit info is always updated. This is achieved by always calling FDKaacEnc_BitResRedistribution() and FDKaacEnc_prepareBitDistribution() with maxBitsPerFrame variable as total bits parameter. Furthermore, VBR assumes a certain target bitrate which is used for internal configuration and limitations. In case the peak bitrate parameter is less than the VBR mode target bitrate the maximum of both bitrate configurations was used. The function FDKaacEnc_AdjustVBRBitrateMode() is added to adjust the encoder internal VBR mode to a desired target bitrate less than given peak bitrate. It is possible that the peak bitrate is very close to the desired target bitrate. The virtual available bitreservoir is quite low and the encoder would run quite often into requantization with needless audio quality reduction. In such a configuration, it is a better choice to use the CBR targeted threshold adaption to avoid audio quality reduction. In FDKaacEnc_Initialize(), there was already a bitResMode selection depending on available bitreservoir for CBR. This selection will now also be used for VBR. In case the bitResMode is AACENC_BR_MODE_FULL and VBR mode is selected, the VBR threshold adaption is used. Otherwise, CBR threshold adaption strategy is used and therefore, no unnecessary fill bits are written. Bug: 161400526 Test: see bug Change-Id: I1865f817180150da6add2623a64f1a102622784a
Diffstat (limited to 'libAACenc/src/aacenc_lib.cpp')
-rw-r--r--libAACenc/src/aacenc_lib.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/libAACenc/src/aacenc_lib.cpp b/libAACenc/src/aacenc_lib.cpp
index c3977f3..0ae329b 100644
--- a/libAACenc/src/aacenc_lib.cpp
+++ b/libAACenc/src/aacenc_lib.cpp
@@ -1028,6 +1028,13 @@ static AACENC_ERROR FDKaacEnc_AdjustEncSettings(HANDLE_AACENCODER hAacEncoder,
case AACENC_BR_MODE_VBR_3:
case AACENC_BR_MODE_VBR_4:
case AACENC_BR_MODE_VBR_5:
+ /* Adjust bitrate mode in case given peak bitrate is lower than expected
+ * VBR bitrate. */
+ if ((INT)config->userPeakBitrate != -1) {
+ hAacConfig->bitrateMode = FDKaacEnc_AdjustVBRBitrateMode(
+ hAacConfig->bitrateMode, config->userPeakBitrate,
+ hAacConfig->channelMode);
+ }
/* Get bitrate in VBR configuration */
/* In VBR mode; SBR-modul depends on bitrate, core encoder on bitrateMode.
*/