diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-01-08 16:25:06 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-01-08 16:25:06 +0000 |
commit | a108a6cafaa67ef58da0c33838077de086b9d532 (patch) | |
tree | 3907998d7ca9d6c2d05884d11a266df6351434c8 /libAACenc/src/aacenc.cpp | |
parent | a5f0e4af6d4c7d169ae52df33b2671321b163052 (diff) | |
parent | 31529975883fb1ccce9f4e5692f56eb403cf9e74 (diff) | |
download | fdk-aac-a108a6cafaa67ef58da0c33838077de086b9d532.tar.gz fdk-aac-a108a6cafaa67ef58da0c33838077de086b9d532.tar.bz2 fdk-aac-a108a6cafaa67ef58da0c33838077de086b9d532.zip |
Merge "Adjust VBR mode depending on given peak bitrate and fix crash recovery usage." am: 5d8224586c am: 3152997588
Original change: https://android-review.googlesource.com/c/platform/external/aac/+/1542709
MUST ONLY BE SUBMITTED BY AUTOMERGER
Change-Id: Id89e1389e52aaf7ed338f7cf431ed5e9d1fba9f8
Diffstat (limited to 'libAACenc/src/aacenc.cpp')
-rw-r--r-- | libAACenc/src/aacenc.cpp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/libAACenc/src/aacenc.cpp b/libAACenc/src/aacenc.cpp index b6f733d..1af8a2e 100644 --- a/libAACenc/src/aacenc.cpp +++ b/libAACenc/src/aacenc.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -245,6 +245,46 @@ INT FDKaacEnc_GetVBRBitrate(AACENC_BITRATE_MODE bitrateMode, return bitrate; } +/*----------------------------------------------------------------------------- + + functionname: FDKaacEnc_AdjustVBRBitrateMode + description: Adjust bitrate mode to given bitrate parameter + input params: int vbrQuality (VBR0, VBR1, VBR2) + bitrate + channelMode + returns: vbr bitrate mode + + ------------------------------------------------------------------------------*/ +AACENC_BITRATE_MODE FDKaacEnc_AdjustVBRBitrateMode( + AACENC_BITRATE_MODE bitrateMode, INT bitrate, CHANNEL_MODE channelMode) { + AACENC_BITRATE_MODE newBitrateMode = bitrateMode; + + if (bitrate != -1) { + const INT monoStereoMode = + (FDKaacEnc_GetMonoStereoMode(channelMode) == EL_MODE_STEREO) ? 1 : 0; + const INT nChannelsEff = + FDKaacEnc_GetChannelModeConfiguration(channelMode)->nChannelsEff; + newBitrateMode = AACENC_BR_MODE_INVALID; + + for (int idx = (int)(sizeof(configTabVBR) / sizeof(*configTabVBR)) - 1; + idx >= 0; idx--) { + if (bitrate >= + configTabVBR[idx].chanBitrate[monoStereoMode] * nChannelsEff) { + if (configTabVBR[idx].chanBitrate[monoStereoMode] * nChannelsEff < + FDKaacEnc_GetVBRBitrate(bitrateMode, channelMode)) { + newBitrateMode = configTabVBR[idx].bitrateMode; + } else { + newBitrateMode = bitrateMode; + } + break; + } + } + } + + return AACENC_BR_MODE_IS_VBR(newBitrateMode) ? newBitrateMode + : AACENC_BR_MODE_INVALID; +} + /** * \brief Convert encoder bitreservoir value for transport library. * @@ -397,7 +437,6 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize( FIXP_DBL mbfac, bw_ratio; QC_INIT qcInit; INT averageBitsPerFrame = 0; - int bitresMin = 0; /* the bitreservoir is always big for AAC-LC */ const CHANNEL_MODE prevChannelMode = hAacEnc->encoderMode; if (config == NULL) return AAC_ENC_INVALID_HANDLE; @@ -553,7 +592,6 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize( qcInit.minBits = fixMin(qcInit.minBits, averageBitsPerFrame & ~7); } else { INT bitreservoir = -1; /* default bitreservoir size*/ - bitresMin = BITRES_MIN; if (isLowDelay(config->audioObjectType)) { INT brPerChannel = config->bitRate / config->nChannels; brPerChannel = fMin(BITRATE_MAX_LD, fMax(BITRATE_MIN_LD, brPerChannel)); @@ -567,7 +605,6 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize( bitreservoir = fMultI(slope, (INT)(BITRES_MAX_LD - BITRES_MIN_LD)) + BITRES_MIN_LD; /* interpolate */ bitreservoir = bitreservoir & ~7; /* align to bytes */ - bitresMin = BITRES_MIN_LD; } int maxBitres; @@ -604,7 +641,8 @@ AAC_ENCODER_ERROR FDKaacEnc_Initialize( qcInit.nSubFrames = config->nSubFrames; qcInit.padding.paddingRest = config->sampleRate; - if (qcInit.maxBits - qcInit.averageBits >= bitresMin * config->nChannels) { + if (qcInit.maxBits - qcInit.averageBits >= + ((qcInit.isLowDelay) ? BITRES_MIN_LD : BITRES_MIN) * config->nChannels) { qcInit.bitResMode = AACENC_BR_MODE_FULL; /* full bitreservoir */ } else if (qcInit.maxBits > qcInit.averageBits) { qcInit.bitResMode = AACENC_BR_MODE_REDUCED; /* reduced bitreservoir */ |