diff options
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | libAACdec/src/aacdecoder_lib.cpp | 21 | ||||
-rw-r--r-- | libAACdec/src/block.cpp | 12 | ||||
-rw-r--r-- | libAACdec/src/ldfiltbank.cpp | 8 | ||||
-rw-r--r-- | libAACdec/src/usacdec_lpd.cpp | 3 | ||||
-rw-r--r-- | libDRCdec/src/drcDec_selectionProcess.cpp | 34 | ||||
-rw-r--r-- | libFDK/src/FDK_decorrelate.cpp | 18 | ||||
-rw-r--r-- | libSACdec/src/sac_bitdec.cpp | 4 |
8 files changed, 70 insertions, 31 deletions
@@ -22,6 +22,7 @@ cc_library_static { "-Wno-#warnings", "-Wuninitialized", "-Wno-self-assign", + "-Wno-implicit-fallthrough", ], sanitize: { misc_undefined:["unsigned-integer-overflow", "signed-integer-overflow"], diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp index d98cf5a..b528ef1 100644 --- a/libAACdec/src/aacdecoder_lib.cpp +++ b/libAACdec/src/aacdecoder_lib.cpp @@ -368,6 +368,23 @@ static INT aacDecoder_CtrlCFGChangeCallback( return errTp; } +static INT aacDecoder_SbrCallback( + void *handle, HANDLE_FDK_BITSTREAM hBs, const INT sampleRateIn, + const INT sampleRateOut, const INT samplesPerFrame, + const AUDIO_OBJECT_TYPE coreCodec, const MP4_ELEMENT_ID elementID, + const INT elementIndex, const UCHAR harmonicSBR, + const UCHAR stereoConfigIndex, const UCHAR configMode, UCHAR *configChanged, + const INT downscaleFactor) { + HANDLE_SBRDECODER self = (HANDLE_SBRDECODER)handle; + + INT errTp = sbrDecoder_Header(self, hBs, sampleRateIn, sampleRateOut, + samplesPerFrame, coreCodec, elementID, + elementIndex, harmonicSBR, stereoConfigIndex, + configMode, configChanged, downscaleFactor); + + return errTp; +} + static INT aacDecoder_SscCallback(void *handle, HANDLE_FDK_BITSTREAM hBs, const AUDIO_OBJECT_TYPE coreCodec, const INT samplingRate, @@ -959,7 +976,7 @@ LINKSPEC_CPP HANDLE_AACDECODER aacDecoder_Open(TRANSPORT_TYPE transportFmt, goto bail; } aacDec->qmfModeUser = NOT_DEFINED; - transportDec_RegisterSbrCallback(aacDec->hInput, (cbSbr_t)sbrDecoder_Header, + transportDec_RegisterSbrCallback(aacDec->hInput, aacDecoder_SbrCallback, (void *)aacDec->hSbrDecoder); if (mpegSurroundDecoder_Open( @@ -1865,7 +1882,7 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern, } /* USAC DASH IPF flushing possible end */ if (accessUnit < numPrerollAU) { - FDKpushBack(hBsAu, auStartAnchor - FDKgetValidBits(hBsAu)); + FDKpushBack(hBsAu, auStartAnchor - (INT)FDKgetValidBits(hBsAu)); } else { if ((self->buildUpStatus == AACDEC_RSV60_BUILD_UP_ON) || (self->buildUpStatus == AACDEC_RSV60_BUILD_UP_ON_IN_BAND) || diff --git a/libAACdec/src/block.cpp b/libAACdec/src/block.cpp index 7d2a4b9..b3d09a6 100644 --- a/libAACdec/src/block.cpp +++ b/libAACdec/src/block.cpp @@ -127,9 +127,11 @@ amm-info@iis.fraunhofer.de The function reads the escape sequence from the bitstream, if the absolute value of the quantized coefficient has the value 16. - A limitation is implemented to maximal 31 bits to prevent endless loops. - If it strikes, MAX_QUANTIZED_VALUE + 1 is returned, independent of the sign of - parameter q. + A limitation is implemented to maximal 21 bits according to + ISO/IEC 14496-3:2009(E) 4.6.3.3. + This limits the escape prefix to a maximum of eight 1's. + If more than eight 1's are read, MAX_QUANTIZED_VALUE + 1 is + returned, independent of the sign of parameter q. \return quantized coefficient */ @@ -139,11 +141,11 @@ LONG CBlock_GetEscape(HANDLE_FDK_BITSTREAM bs, /*!< pointer to bitstream */ if (fAbs(q) != 16) return (q); LONG i, off; - for (i = 4; i < 32; i++) { + for (i = 4; i < 13; i++) { if (FDKreadBit(bs) == 0) break; } - if (i == 32) return (MAX_QUANTIZED_VALUE + 1); + if (i == 13) return (MAX_QUANTIZED_VALUE + 1); off = FDKreadBits(bs, i); i = off + (1 << i); diff --git a/libAACdec/src/ldfiltbank.cpp b/libAACdec/src/ldfiltbank.cpp index 66a5914..c7d2928 100644 --- a/libAACdec/src/ldfiltbank.cpp +++ b/libAACdec/src/ldfiltbank.cpp @@ -216,6 +216,7 @@ int InvMdctTransformLowDelay_fdk(FIXP_DBL *mdctData, const int mdctData_e, int scale = mdctData_e + MDCT_OUT_HEADROOM - LDFB_HEADROOM; /* The LDFB_HEADROOM is compensated inside multE2_DinvF_fdk() below */ + int i; /* Select LD window slope */ switch (N) { @@ -261,10 +262,11 @@ int InvMdctTransformLowDelay_fdk(FIXP_DBL *mdctData, const int mdctData_e, } if (gain != (FIXP_DBL)0) { - scaleValuesWithFactor(mdctData, gain, N, scale); - } else { - scaleValues(mdctData, N, scale); + for (i = 0; i < N; i++) { + mdctData[i] = fMult(mdctData[i], gain); + } } + scaleValuesSaturate(mdctData, N, scale); /* Since all exponent and factors have been applied, current exponent is zero. */ diff --git a/libAACdec/src/usacdec_lpd.cpp b/libAACdec/src/usacdec_lpd.cpp index 22069a6..fde34ef 100644 --- a/libAACdec/src/usacdec_lpd.cpp +++ b/libAACdec/src/usacdec_lpd.cpp @@ -1221,8 +1221,7 @@ AAC_DECODER_ERROR CLpdChannelStream_Read( (INT)(samplingRate * PIT_MIN_12k8 + (FSCALE_DENOM / 2)) / FSCALE_DENOM - (INT)PIT_MIN_12k8; - if (pSamplingRateInfo->samplingRate > - FAC_FSCALE_MAX /* maximum allowed core sampling frequency */) { + if ((samplingRate < FAC_FSCALE_MIN) || (samplingRate > FAC_FSCALE_MAX)) { error = AAC_DEC_PARSE_ERROR; goto bail; } diff --git a/libDRCdec/src/drcDec_selectionProcess.cpp b/libDRCdec/src/drcDec_selectionProcess.cpp index 54b731d..9228197 100644 --- a/libDRCdec/src/drcDec_selectionProcess.cpp +++ b/libDRCdec/src/drcDec_selectionProcess.cpp @@ -1006,15 +1006,23 @@ static DRCDEC_SELECTION_PROCESS_RETURN _preSelectionRequirement7( return DRCDEC_SELECTION_PROCESS_NO_ERROR; } -static void _setSelectionDataInfo(DRCDEC_SELECTION_DATA* pData, - FIXP_DBL loudness, - FIXP_DBL loudnessNormalizationGainDb, - FIXP_DBL loudnessNormalizationGainDbMax, - FIXP_DBL loudnessDeviationMax, - FIXP_DBL signalPeakLevel, - FIXP_DBL outputPeakLevelMax, - int applyAdjustment) { - FIXP_DBL adjustment = 0; +static void _setSelectionDataInfo( + DRCDEC_SELECTION_DATA* pData, FIXP_DBL loudness, /* e = 7 */ + FIXP_DBL loudnessNormalizationGainDb, /* e = 7 */ + FIXP_DBL loudnessNormalizationGainDbMax, /* e = 7 */ + FIXP_DBL loudnessDeviationMax, /* e = 7 */ + FIXP_DBL signalPeakLevel, /* e = 7 */ + FIXP_DBL outputPeakLevelMax, /* e = 7 */ + int applyAdjustment) { + FIXP_DBL adjustment = 0; /* e = 8 */ + + /* use e = 8 for all function parameters to prevent overflow */ + loudness >>= 1; + loudnessNormalizationGainDb >>= 1; + loudnessNormalizationGainDbMax >>= 1; + loudnessDeviationMax >>= 1; + signalPeakLevel >>= 1; + outputPeakLevelMax >>= 1; if (applyAdjustment) { adjustment = @@ -1028,6 +1036,14 @@ static void _setSelectionDataInfo(DRCDEC_SELECTION_DATA* pData, pData->outputLoudness = loudness + pData->loudnessNormalizationGainDbAdjusted; pData->outputPeakLevel = signalPeakLevel + pData->loudnessNormalizationGainDbAdjusted; + + /* shift back to e = 7 using saturation */ + pData->loudnessNormalizationGainDbAdjusted = SATURATE_LEFT_SHIFT( + pData->loudnessNormalizationGainDbAdjusted, 1, DFRACT_BITS); + pData->outputLoudness = + SATURATE_LEFT_SHIFT(pData->outputLoudness, 1, DFRACT_BITS); + pData->outputPeakLevel = + SATURATE_LEFT_SHIFT(pData->outputPeakLevel, 1, DFRACT_BITS); } static int _targetLoudnessInRange( diff --git a/libFDK/src/FDK_decorrelate.cpp b/libFDK/src/FDK_decorrelate.cpp index 8e665b7..c5de79a 100644 --- a/libFDK/src/FDK_decorrelate.cpp +++ b/libFDK/src/FDK_decorrelate.cpp @@ -1086,8 +1086,9 @@ static INT DuckerCalcEnergy(DUCKER_INSTANCE *const self, pb = SpatialDecGetProcessingBand(maxHybBand, self->mapHybBands2ProcBands); for (qs = startHybBand; qs <= maxHybBand; qs++) { pb = SpatialDecGetProcessingBand(qs, self->mapHybBands2ProcBands); - energy[pb] += - (fPow2Div2(inputReal[qs] << clz) + fPow2Div2(inputImag[qs] << clz)); + energy[pb] = + fAddSaturate(energy[pb], fPow2Div2(inputReal[qs] << clz) + + fPow2Div2(inputImag[qs] << clz)); } pb++; @@ -1100,7 +1101,7 @@ static INT DuckerCalcEnergy(DUCKER_INSTANCE *const self, FIXP_DBL nrg = 0; qs_next = (int)self->qs_next[pb]; for (; qs < qs_next; qs++) { - nrg += fPow2Div2(inputReal[qs] << clz); + nrg = fAddSaturate(nrg, fPow2Div2(inputReal[qs] << clz)); } energy[pb] = nrg; } @@ -1138,13 +1139,14 @@ static INT DuckerCalcEnergy(DUCKER_INSTANCE *const self, #else for (qs = startHybBand; qs <= maxHybBand; qs++) { int pb = SpatialDecGetProcessingBand(qs, self->mapHybBands2ProcBands); - energy[pb] += - (fPow2Div2(inputReal[qs] << clz) + fPow2Div2(inputImag[qs] << clz)); + energy[pb] = + fAddSaturate(energy[pb], fPow2Div2(inputReal[qs] << clz) + + fPow2Div2(inputImag[qs] << clz)); } for (; qs <= maxHybridBand; qs++) { int pb = SpatialDecGetProcessingBand(qs, self->mapHybBands2ProcBands); - energy[pb] += fPow2Div2(inputReal[qs] << clz); + energy[pb] = fAddSaturate(energy[pb], fPow2Div2(inputReal[qs] << clz)); } #endif /* FUNCTION_DuckerCalcEnergy_func4 */ } @@ -1237,9 +1239,9 @@ static INT DuckerApply(DUCKER_INSTANCE *const self, tmp1 = scaleValue(tmp1, scaleSmoothDirRevNrg_asExponent); tmp2 = scaleValue(tmp2, scaleSmoothDirRevNrg_asExponent); - tmp1 = fMultAddDiv2(tmp1, directNrg[pb] >> scaleDirectNrg, + tmp1 = fMultAddDiv2(tmp1, scaleValue(directNrg[pb], -scaleDirectNrg), DUCK_ONE_MINUS_ALPHA_X4_FDK); - tmp2 = fMultAddDiv2(tmp2, reverbNrg[pb] >> scaleReverbNrg, + tmp2 = fMultAddDiv2(tmp2, scaleValue(reverbNrg[pb], -scaleReverbNrg), DUCK_ONE_MINUS_ALPHA_X4_FDK); } else { tmp1 = fMultAddDiv2(tmp1, directNrg[pb], DUCK_ONE_MINUS_ALPHA_X4_FDK); diff --git a/libSACdec/src/sac_bitdec.cpp b/libSACdec/src/sac_bitdec.cpp index 37e0cf2..45fb17a 100644 --- a/libSACdec/src/sac_bitdec.cpp +++ b/libSACdec/src/sac_bitdec.cpp @@ -291,13 +291,13 @@ SACDEC_ERROR SpatialDecParseSpecificConfigHeader( if (sacHeaderLen == 127) { sacHeaderLen += FDKreadBits(bitstream, 16); } - numFillBits = FDKgetValidBits(bitstream); + numFillBits = (INT)FDKgetValidBits(bitstream); err = SpatialDecParseSpecificConfig(bitstream, pSpatialSpecificConfig, sacHeaderLen, coreCodec); numFillBits -= - FDKgetValidBits(bitstream); /* the number of read bits (tmpBits) */ + (INT)FDKgetValidBits(bitstream); /* the number of read bits (tmpBits) */ numFillBits = (8 * sacHeaderLen) - numFillBits; if (numFillBits < 0) { /* Parsing went wrong */ |