From 62623d8d797a3d7314834c59ebc785e738965635 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 8 Jun 2018 18:03:16 +0200 Subject: FDK sanitization fixes Bug: 110641440 Bug: 109936783 Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Prevent bit buffer counter overflow. While long-term test we discovered a bit counter overflow in the bit buffer. The bit buffer state was only used by HCR and RVLC tool and can easily be substituted with FDKgetValidBits() call. The following patch completely removes the bit counter and all its obsolete functions. Change-Id: Icee0519d26a2aa62367d2dece59cd3d60ffcade7 Fix call to function sbrDecoder_Header() through pointer to incorrect function type. While testing FDK in Android P DP3 x86 64bit emulator we observed a runtime error. The function parameter of the callback didn't use a typeless pointer. Following patch contains a revised sbr decoder callback function with explicit data type cast to be inline with all other callbacks in FDK. Change-Id: Id224de22beaf2eb9631babd838c4c3ceae0a801e Fix huffman decoder escape sequence length limitation. Change-Id: Ib05cc2c065739c27b9720a24f90d0ce4d15bf601 Prevent overflow in MPEG-D DRC _setSelectionDataInfo(). Change-Id: I3b90ef7a5168e20766a2574d57d81bb39d2a5fb9 Add sanity check for allowed LPD sampling rate. Change-Id: I0702024adc07ed463db795dd48f4efd3de1d7896 Always check whether given channel config is supported. Change-Id: I169161dd31bc624f2cab6be2b4c6518946ed32ba Unsigned Integer Overflow in aacDecoder_DecodeFrame(). Change-Id: I617dd545f9ea0aca5a5e7d214bbc35f089bc355d Unsigned Integer Overflow in SpatialDecParseSpecificConfigHeader(). Change-Id: I5994a55f993835fa511ff61a337726b3e51aed5d Unsigned Integer Overflows in mpegSurroundDecoder_Parse(). Change-Id: I3714e88d7a9a866297bb2e93571804665a97773f Unsigned Integer Overflow in transportDec_AdjustEndOfAccessUnit(). Change-Id: Ie4924460d30ea4ef76917704ded809d04db78993 Unsigned Integer Overflow in transportDec_readHeader(). Change-Id: I0beedab38175fc57e5bd9eb5700a3850ef2bebf7 UBSAN overflow in FFT An overflow in the fft was observed for certain configurations. The root cause was in the scaling of the fft input data in dct_IV and dst_IV. The following patch revises the scaling in dct and removes the unused arm implementation. Change-Id: Idc9c44a9755b8151d5c7d8107696f43ac592413b --- libAACdec/src/aacdec_hcr.cpp | 82 ++++++++++++++++++++-------------------- libAACdec/src/aacdec_hcr_bit.cpp | 7 ++-- libAACdec/src/aacdec_hcr_bit.h | 3 +- libAACdec/src/aacdec_hcr_types.h | 2 +- libAACdec/src/aacdec_hcrs.cpp | 42 ++++++++++---------- libAACdec/src/aacdecoder.cpp | 14 +++---- libAACdec/src/aacdecoder_lib.cpp | 21 +++++++++- libAACdec/src/block.cpp | 12 +++--- libAACdec/src/rvlc.cpp | 29 +++++++------- libAACdec/src/rvlc_info.h | 1 + libAACdec/src/rvlcbit.cpp | 6 +-- libAACdec/src/rvlcbit.h | 4 +- libAACdec/src/usacdec_lpd.cpp | 3 +- 13 files changed, 125 insertions(+), 101 deletions(-) (limited to 'libAACdec/src') diff --git a/libAACdec/src/aacdec_hcr.cpp b/libAACdec/src/aacdec_hcr.cpp index 84e05b0..6114756 100644 --- a/libAACdec/src/aacdec_hcr.cpp +++ b/libAACdec/src/aacdec_hcr.cpp @@ -134,17 +134,18 @@ static void DeriveNumberOfExtendedSortedSectionsInSets( USHORT *pNumExtendedSortedSectionsInSets, int numExtendedSortedSectionsInSetsIdx); -static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, INT quantSpecCoef, - INT *pLeftStartOfSegment, +static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, + INT quantSpecCoef, INT *pLeftStartOfSegment, SCHAR *pRemainingBitsInSegment, int *pNumDecodedBits); -static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, UINT codebookDim, - const SCHAR *pQuantVal, FIXP_DBL *pQuantSpecCoef, - int *quantSpecCoefIdx, INT *pLeftStartOfSegment, +static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, + UINT codebookDim, const SCHAR *pQuantVal, + FIXP_DBL *pQuantSpecCoef, int *quantSpecCoefIdx, + INT *pLeftStartOfSegment, SCHAR *pRemainingBitsInSegment, int *pNumDecodedBits); -static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, +static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, const UINT *pCurrentTree, const SCHAR *pQuantValBase, INT *pLeftStartOfSegment, @@ -291,7 +292,7 @@ UINT HcrInit(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo, SPEC_LONG(pAacDecoderChannelInfo->pSpectralCoefficient); FDKsyncCache(bs); - pHcr->decInOut.bitstreamIndex = FDKgetBitCnt(bs); + pHcr->decInOut.bitstreamAnchor = (INT)FDKgetValidBits(bs); if (!IsLongBlock(&pAacDecoderChannelInfo->icsInfo)) /* short block */ { @@ -436,7 +437,7 @@ UINT HcrDecoder(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo, int pTmp5; INT bitCntOffst; - INT saveBitCnt = FDKgetBitCnt(bs); /* save bitstream position */ + INT saveBitCnt = (INT)FDKgetValidBits(bs); /* save bitstream position */ HcrCalcNumCodeword(pHcr); @@ -487,7 +488,7 @@ UINT HcrDecoder(H_HCR_INFO pHcr, CAacDecoderChannelInfo *pAacDecoderChannelInfo, pSamplingRateInfo); /* restore bitstream position */ - bitCntOffst = saveBitCnt - FDKgetBitCnt(bs); + bitCntOffst = (INT)FDKgetValidBits(bs) - saveBitCnt; if (bitCntOffst) { FDKpushBiDirectional(bs, bitCntOffst); } @@ -815,7 +816,6 @@ static void HcrPrepareSegmentationGrid(H_HCR_INFO pHcr) { INT *pLeftStartOfSegment = pHcr->segmentInfo.pLeftStartOfSegment; INT *pRightStartOfSegment = pHcr->segmentInfo.pRightStartOfSegment; SCHAR *pRemainingBitsInSegment = pHcr->segmentInfo.pRemainingBitsInSegment; - INT bitstreamIndex = pHcr->decInOut.bitstreamIndex; const UCHAR *pMaxCwLength = aMaxCwLen; for (i = numSortedSection; i != 0; i--) { @@ -825,7 +825,7 @@ static void HcrPrepareSegmentationGrid(H_HCR_INFO pHcr) { for (j = *pNumSortedCodewordInSection; j != 0; j--) { /* width allows a new segment */ - intermediateResult = bitstreamIndex + segmentStart; + intermediateResult = segmentStart; if ((segmentStart + segmentWidth) <= lengthOfReorderedSpectralData) { /* store segment start, segment length and increment the number of * segments */ @@ -841,12 +841,11 @@ static void HcrPrepareSegmentationGrid(H_HCR_INFO pHcr) { pLeftStartOfSegment--; pRightStartOfSegment--; pRemainingBitsInSegment--; - segmentStart = *pLeftStartOfSegment - bitstreamIndex; + segmentStart = *pLeftStartOfSegment; lastSegmentWidth = lengthOfReorderedSpectralData - segmentStart; *pRemainingBitsInSegment = lastSegmentWidth; - *pRightStartOfSegment = - bitstreamIndex + segmentStart + lastSegmentWidth - 1; + *pRightStartOfSegment = segmentStart + lastSegmentWidth - 1; endFlag = 1; break; } @@ -1071,9 +1070,9 @@ static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) { numDecodedBits = 0; /* decode PCW_BODY */ - pQuantVal = - DecodePCW_Body(bs, pCurrentTree, pQuantValBase, pLeftStartOfSegment, - pRemainingBitsInSegment, &numDecodedBits); + pQuantVal = DecodePCW_Body( + bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase, + pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits); /* result is written out here because NO sign bits follow the body */ for (i = dimension; i != 0; i--) { @@ -1115,14 +1114,14 @@ static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) { int err; numDecodedBits = 0; - pQuantVal = - DecodePCW_Body(bs, pCurrentTree, pQuantValBase, pLeftStartOfSegment, - pRemainingBitsInSegment, &numDecodedBits); + pQuantVal = DecodePCW_Body( + bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase, + pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits); err = DecodePCW_Sign( - bs, dimension, pQuantVal, pQuantizedSpectralCoefficients, - &quantizedSpectralCoefficientsIdx, pLeftStartOfSegment, - pRemainingBitsInSegment, &numDecodedBits); + bs, pHcr->decInOut.bitstreamAnchor, dimension, pQuantVal, + pQuantizedSpectralCoefficients, &quantizedSpectralCoefficientsIdx, + pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits); if (err != 0) { return; } @@ -1157,14 +1156,14 @@ static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) { numDecodedBits = 0; /* decode PCW_BODY */ - pQuantVal = - DecodePCW_Body(bs, pCurrentTree, pQuantValBase, pLeftStartOfSegment, - pRemainingBitsInSegment, &numDecodedBits); + pQuantVal = DecodePCW_Body( + bs, pHcr->decInOut.bitstreamAnchor, pCurrentTree, pQuantValBase, + pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits); err = DecodePCW_Sign( - bs, dimension, pQuantVal, pQuantizedSpectralCoefficients, - &quantizedSpectralCoefficientsIdx, pLeftStartOfSegment, - pRemainingBitsInSegment, &numDecodedBits); + bs, pHcr->decInOut.bitstreamAnchor, dimension, pQuantVal, + pQuantizedSpectralCoefficients, &quantizedSpectralCoefficientsIdx, + pLeftStartOfSegment, pRemainingBitsInSegment, &numDecodedBits); if (err != 0) { return; } @@ -1177,7 +1176,7 @@ static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) { (FIXP_DBL)ESCAPE_VALUE) { pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] = (FIXP_DBL)DecodeEscapeSequence( - bs, + bs, pHcr->decInOut.bitstreamAnchor, pQuantizedSpectralCoefficients [quantizedSpectralCoefficientsIdx], pLeftStartOfSegment, pRemainingBitsInSegment, @@ -1193,7 +1192,7 @@ static void DecodePCWs(HANDLE_FDK_BITSTREAM bs, H_HCR_INFO pHcr) { (FIXP_DBL)ESCAPE_VALUE) { pQuantizedSpectralCoefficients[quantizedSpectralCoefficientsIdx] = (FIXP_DBL)DecodeEscapeSequence( - bs, + bs, pHcr->decInOut.bitstreamAnchor, pQuantizedSpectralCoefficients [quantizedSpectralCoefficientsIdx], pLeftStartOfSegment, pRemainingBitsInSegment, @@ -1331,7 +1330,7 @@ void CarryBitToBranchValue(UCHAR carryBit, UINT treeNode, UINT *branchValue, spectral coefficients -------------------------------------------------------------------------------------------- */ -static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, +static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, const UINT *pCurrentTree, const SCHAR *pQuantValBase, INT *pLeftStartOfSegment, @@ -1349,7 +1348,7 @@ static const SCHAR *DecodePCW_Body(HANDLE_FDK_BITSTREAM bs, /* decode whole PCW-codeword-body */ while (1) { - carryBit = HcrGetABitFromBitstream(bs, pLeftStartOfSegment, + carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment, pLeftStartOfSegment, /* dummy */ FROM_LEFT_TO_RIGHT); *pRemainingBitsInSegment -= 1; @@ -1384,8 +1383,8 @@ value == 16, a escapeSequence is decoded in two steps: -------------------------------------------------------------------------------------------- */ -static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, INT quantSpecCoef, - INT *pLeftStartOfSegment, +static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, + INT quantSpecCoef, INT *pLeftStartOfSegment, SCHAR *pRemainingBitsInSegment, int *pNumDecodedBits) { UINT i; @@ -1396,7 +1395,7 @@ static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, INT quantSpecCoef, /* decode escape prefix */ while (1) { - carryBit = HcrGetABitFromBitstream(bs, pLeftStartOfSegment, + carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment, pLeftStartOfSegment, /* dummy */ FROM_LEFT_TO_RIGHT); *pRemainingBitsInSegment -= 1; @@ -1412,7 +1411,7 @@ static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, INT quantSpecCoef, /* decode escape word */ for (i = escapeOnesCounter; i != 0; i--) { - carryBit = HcrGetABitFromBitstream(bs, pLeftStartOfSegment, + carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment, pLeftStartOfSegment, /* dummy */ FROM_LEFT_TO_RIGHT); *pRemainingBitsInSegment -= 1; @@ -1441,9 +1440,10 @@ the last of eight function of HCR) line) -------------------------------------------------------------------------------------------- */ -static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, UINT codebookDim, - const SCHAR *pQuantVal, FIXP_DBL *pQuantSpecCoef, - int *quantSpecCoefIdx, INT *pLeftStartOfSegment, +static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, + UINT codebookDim, const SCHAR *pQuantVal, + FIXP_DBL *pQuantSpecCoef, int *quantSpecCoefIdx, + INT *pLeftStartOfSegment, SCHAR *pRemainingBitsInSegment, int *pNumDecodedBits) { UINT i; @@ -1453,7 +1453,7 @@ static int DecodePCW_Sign(HANDLE_FDK_BITSTREAM bs, UINT codebookDim, for (i = codebookDim; i != 0; i--) { quantSpecCoef = *pQuantVal++; if (quantSpecCoef != 0) { - carryBit = HcrGetABitFromBitstream(bs, pLeftStartOfSegment, + carryBit = HcrGetABitFromBitstream(bs, bsAnchor, pLeftStartOfSegment, pLeftStartOfSegment, /* dummy */ FROM_LEFT_TO_RIGHT); *pRemainingBitsInSegment -= 1; diff --git a/libAACdec/src/aacdec_hcr_bit.cpp b/libAACdec/src/aacdec_hcr_bit.cpp index a53ef16..0198659 100644 --- a/libAACdec/src/aacdec_hcr_bit.cpp +++ b/libAACdec/src/aacdec_hcr_bit.cpp @@ -132,13 +132,14 @@ read direction. It is called very often, therefore it makes sense to inline it return: - bit from bitstream -------------------------------------------------------------------------------------------- */ -UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, INT *pLeftStartOfSegment, +UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, + INT *pLeftStartOfSegment, INT *pRightStartOfSegment, UCHAR readDirection) { UINT bit; INT readBitOffset; if (readDirection == FROM_LEFT_TO_RIGHT) { - readBitOffset = *pLeftStartOfSegment - FDKgetBitCnt(bs); + readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pLeftStartOfSegment; if (readBitOffset) { FDKpushBiDirectional(bs, readBitOffset); } @@ -147,7 +148,7 @@ UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, INT *pLeftStartOfSegment, *pLeftStartOfSegment += 1; } else { - readBitOffset = *pRightStartOfSegment - FDKgetBitCnt(bs); + readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pRightStartOfSegment; if (readBitOffset) { FDKpushBiDirectional(bs, readBitOffset); } diff --git a/libAACdec/src/aacdec_hcr_bit.h b/libAACdec/src/aacdec_hcr_bit.h index 7a57c8c..77242ac 100644 --- a/libAACdec/src/aacdec_hcr_bit.h +++ b/libAACdec/src/aacdec_hcr_bit.h @@ -107,7 +107,8 @@ amm-info@iis.fraunhofer.de UCHAR ToggleReadDirection(UCHAR readDirection); -UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, INT *pLeftStartOfSegment, +UINT HcrGetABitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, + INT *pLeftStartOfSegment, INT *pRightStartOfSegment, UCHAR readDirection); #endif /* AACDEC_HCR_BIT_H */ diff --git a/libAACdec/src/aacdec_hcr_types.h b/libAACdec/src/aacdec_hcr_types.h index d550bc2..1cc3cb0 100644 --- a/libAACdec/src/aacdec_hcr_types.h +++ b/libAACdec/src/aacdec_hcr_types.h @@ -350,7 +350,7 @@ typedef struct { SHORT lengthOfReorderedSpectralData; SHORT numSection; SHORT *pNumLineInSect; - INT bitstreamIndex; + INT bitstreamAnchor; SCHAR lengthOfLongestCodeword; UCHAR *pCodebook; } HCR_INPUT_OUTPUT; diff --git a/libAACdec/src/aacdec_hcrs.cpp b/libAACdec/src/aacdec_hcrs.cpp index e2b7cd8..1d5aa27 100644 --- a/libAACdec/src/aacdec_hcrs.cpp +++ b/libAACdec/src/aacdec_hcrs.cpp @@ -615,9 +615,9 @@ UINT Hcr_State_BODY_ONLY(HANDLE_FDK_BITSTREAM bs, void *ptr) { for (; pRemainingBitsInSegment[segmentOffset] > 0; pRemainingBitsInSegment[segmentOffset] -= 1) { - carryBit = HcrGetABitFromBitstream(bs, &pLeftStartOfSegment[segmentOffset], - &pRightStartOfSegment[segmentOffset], - readDirection); + carryBit = HcrGetABitFromBitstream( + bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset], + &pRightStartOfSegment[segmentOffset], readDirection); CarryBitToBranchValue(carryBit, /* make a step in decoding tree */ treeNode, &branchValue, &branchNode); @@ -749,9 +749,9 @@ UINT Hcr_State_BODY_SIGN__BODY(HANDLE_FDK_BITSTREAM bs, void *ptr) { for (; pRemainingBitsInSegment[segmentOffset] > 0; pRemainingBitsInSegment[segmentOffset] -= 1) { - carryBit = HcrGetABitFromBitstream(bs, &pLeftStartOfSegment[segmentOffset], - &pRightStartOfSegment[segmentOffset], - readDirection); + carryBit = HcrGetABitFromBitstream( + bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset], + &pRightStartOfSegment[segmentOffset], readDirection); CarryBitToBranchValue(carryBit, /* make a step in decoding tree */ treeNode, &branchValue, &branchNode); @@ -884,9 +884,9 @@ UINT Hcr_State_BODY_SIGN__SIGN(HANDLE_FDK_BITSTREAM bs, void *ptr) { /* loop for sign bit decoding */ for (; pRemainingBitsInSegment[segmentOffset] > 0; pRemainingBitsInSegment[segmentOffset] -= 1) { - carryBit = HcrGetABitFromBitstream(bs, &pLeftStartOfSegment[segmentOffset], - &pRightStartOfSegment[segmentOffset], - readDirection); + carryBit = HcrGetABitFromBitstream( + bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset], + &pRightStartOfSegment[segmentOffset], readDirection); cntSign -= 1; /* decrement sign counter because one sign bit has been read */ @@ -997,9 +997,9 @@ UINT Hcr_State_BODY_SIGN_ESC__BODY(HANDLE_FDK_BITSTREAM bs, void *ptr) { for (; pRemainingBitsInSegment[segmentOffset] > 0; pRemainingBitsInSegment[segmentOffset] -= 1) { - carryBit = HcrGetABitFromBitstream(bs, &pLeftStartOfSegment[segmentOffset], - &pRightStartOfSegment[segmentOffset], - readDirection); + carryBit = HcrGetABitFromBitstream( + bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset], + &pRightStartOfSegment[segmentOffset], readDirection); /* make a step in tree */ CarryBitToBranchValue(carryBit, treeNode, &branchValue, &branchNode); @@ -1159,9 +1159,9 @@ UINT Hcr_State_BODY_SIGN_ESC__SIGN(HANDLE_FDK_BITSTREAM bs, void *ptr) { /* loop for sign bit decoding */ for (; pRemainingBitsInSegment[segmentOffset] > 0; pRemainingBitsInSegment[segmentOffset] -= 1) { - carryBit = HcrGetABitFromBitstream(bs, &pLeftStartOfSegment[segmentOffset], - &pRightStartOfSegment[segmentOffset], - readDirection); + carryBit = HcrGetABitFromBitstream( + bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset], + &pRightStartOfSegment[segmentOffset], readDirection); /* decrement sign counter because one sign bit has been read */ cntSign -= 1; @@ -1314,9 +1314,9 @@ UINT Hcr_State_BODY_SIGN_ESC__ESC_PREFIX(HANDLE_FDK_BITSTREAM bs, void *ptr) { /* decode escape prefix */ for (; pRemainingBitsInSegment[segmentOffset] > 0; pRemainingBitsInSegment[segmentOffset] -= 1) { - carryBit = HcrGetABitFromBitstream(bs, &pLeftStartOfSegment[segmentOffset], - &pRightStartOfSegment[segmentOffset], - readDirection); + carryBit = HcrGetABitFromBitstream( + bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset], + &pRightStartOfSegment[segmentOffset], readDirection); /* count ones and store sum in escapePrefixUp */ if (carryBit == 1) { @@ -1435,9 +1435,9 @@ UINT Hcr_State_BODY_SIGN_ESC__ESC_WORD(HANDLE_FDK_BITSTREAM bs, void *ptr) { /* decode escape word */ for (; pRemainingBitsInSegment[segmentOffset] > 0; pRemainingBitsInSegment[segmentOffset] -= 1) { - carryBit = HcrGetABitFromBitstream(bs, &pLeftStartOfSegment[segmentOffset], - &pRightStartOfSegment[segmentOffset], - readDirection); + carryBit = HcrGetABitFromBitstream( + bs, pHcr->decInOut.bitstreamAnchor, &pLeftStartOfSegment[segmentOffset], + &pRightStartOfSegment[segmentOffset], readDirection); /* build escape word */ escapeWord <<= diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp index b8b1327..2a228c8 100644 --- a/libAACdec/src/aacdecoder.cpp +++ b/libAACdec/src/aacdecoder.cpp @@ -1630,14 +1630,14 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, aacChannelsOffset = 0; aacChannelsOffsetIdx = 0; elementOffset = 0; + if ((ascChannels <= 0) || + (asc->m_channelConfiguration > AACDEC_MAX_CH_CONF)) { + return AAC_DEC_UNSUPPORTED_CHANNELCONFIG; + } + if ((ascChannels + aacChannelsOffsetIdx) > ((8) * 2)) { + return AAC_DEC_UNSUPPORTED_CHANNELCONFIG; + } if (configMode & AC_CM_ALLOC_MEM) { - if ((ascChannels <= 0) || - (asc->m_channelConfiguration > AACDEC_MAX_CH_CONF)) { - return AAC_DEC_UNSUPPORTED_CHANNELCONFIG; - } - if ((ascChannels + aacChannelsOffsetIdx) > ((8) * 2)) { - return AAC_DEC_UNSUPPORTED_CHANNELCONFIG; - } if ((ascChannels + aacChannelsOffset) > (8)) { return AAC_DEC_UNSUPPORTED_CHANNELCONFIG; } 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/rvlc.cpp b/libAACdec/src/rvlc.cpp index 92f9f02..b7a9be1 100644 --- a/libAACdec/src/rvlc.cpp +++ b/libAACdec/src/rvlc.cpp @@ -168,13 +168,14 @@ static void rvlcInit(CErRvlcInfo *pRvlc, /* set base bitstream ptr to the RVL-coded part (start of RVLC data (ESC 2)) */ FDKsyncCache(bs); + pRvlc->bsAnchor = (INT)FDKgetValidBits(bs); - pRvlc->bitstreamIndexRvlFwd = FDKgetBitCnt( - bs); /* first bit within RVL coded block as start address for forward - decoding */ - pRvlc->bitstreamIndexRvlBwd = FDKgetBitCnt(bs) + pRvlc->length_of_rvlc_sf - - 1; /* last bit within RVL coded block as start - address for backward decoding */ + pRvlc->bitstreamIndexRvlFwd = + 0; /* first bit within RVL coded block as start address for forward + decoding */ + pRvlc->bitstreamIndexRvlBwd = + pRvlc->length_of_rvlc_sf - 1; /* last bit within RVL coded block as start + address for backward decoding */ /* skip RVLC-bitstream-part -- pointing now to escapes (if present) or to TNS * data (if present) */ @@ -183,7 +184,7 @@ static void rvlcInit(CErRvlcInfo *pRvlc, if (pRvlc->sf_escapes_present != 0) { /* locate internal bitstream ptr at escapes (which is the second part) */ FDKsyncCache(bs); - pRvlc->bitstreamIndexEsc = FDKgetBitCnt(bs); + pRvlc->bitstreamIndexEsc = pRvlc->bsAnchor - (INT)FDKgetValidBits(bs); /* skip escapeRVLC-bitstream-part -- pointing to TNS data (if present) to * make decoder continue */ @@ -259,8 +260,9 @@ static SCHAR rvlcDecodeEscapeWord(CErRvlcInfo *pRvlc, HANDLE_FDK_BITSTREAM bs) { treeNode = *pEscTree; /* init at starting node */ for (i = MAX_LEN_RVLC_ESCAPE_WORD - 1; i >= 0; i--) { - carryBit = rvlcReadBitFromBitstream(bs, /* get next bit */ - pBitstreamIndexEsc, FWD); + carryBit = + rvlcReadBitFromBitstream(bs, /* get next bit */ + pRvlc->bsAnchor, pBitstreamIndexEsc, FWD); CarryBitToBranchValue(carryBit, /* huffman decoding, do a single step in huffman decoding tree */ @@ -370,8 +372,9 @@ SCHAR decodeRVLCodeword(HANDLE_FDK_BITSTREAM bs, CErRvlcInfo *pRvlc) { UINT treeNode = *pRvlCodeTree; for (i = MAX_LEN_RVLC_CODE_WORD - 1; i >= 0; i--) { - carryBit = rvlcReadBitFromBitstream(bs, /* get next bit */ - pBitstrIndxRvl, direction); + carryBit = + rvlcReadBitFromBitstream(bs, /* get next bit */ + pRvlc->bsAnchor, pBitstrIndxRvl, direction); CarryBitToBranchValue(carryBit, /* huffman decoding, do a single step in huffman decoding tree */ @@ -1140,7 +1143,7 @@ void CRvlc_Decode(CAacDecoderChannelInfo *pAacDecoderChannelInfo, rvlcInit(pRvlc, pAacDecoderChannelInfo, bs); /* save bitstream position */ - saveBitCnt = FDKgetBitCnt(bs); + saveBitCnt = (INT)FDKgetValidBits(bs); if (pRvlc->sf_escapes_present) rvlcDecodeEscapes( @@ -1155,7 +1158,7 @@ void CRvlc_Decode(CAacDecoderChannelInfo *pAacDecoderChannelInfo, pAacDecoderChannelInfo->data.aac.PnsData.PnsActive = pRvlc->noise_used; /* restore bitstream position */ - bitCntOffst = saveBitCnt - FDKgetBitCnt(bs); + bitCntOffst = (INT)FDKgetValidBits(bs) - saveBitCnt; if (bitCntOffst) { FDKpushBiDirectional(bs, bitCntOffst); } diff --git a/libAACdec/src/rvlc_info.h b/libAACdec/src/rvlc_info.h index fc9c19d..e7b3b99 100644 --- a/libAACdec/src/rvlc_info.h +++ b/libAACdec/src/rvlc_info.h @@ -164,6 +164,7 @@ typedef struct { UCHAR direction; /* bitstream indices */ + INT bsAnchor; /* hcr bit buffer reference index */ INT bitstreamIndexRvlFwd; /* base address of RVL-coded-scalefactor data (ESC 2) for forward decoding */ INT bitstreamIndexRvlBwd; /* base address of RVL-coded-scalefactor data (ESC diff --git a/libAACdec/src/rvlcbit.cpp b/libAACdec/src/rvlcbit.cpp index c06cf96..b0c4596 100644 --- a/libAACdec/src/rvlcbit.cpp +++ b/libAACdec/src/rvlcbit.cpp @@ -123,10 +123,10 @@ read direction. It is called very often, therefore it makes sense to inline it -------------------------------------------------------------------------------------------- */ -UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, INT *pPosition, - UCHAR readDirection) { +UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, + INT *pPosition, UCHAR readDirection) { UINT bit; - INT readBitOffset = *pPosition - FDKgetBitCnt(bs); + INT readBitOffset = (INT)FDKgetValidBits(bs) - bsAnchor + *pPosition; if (readBitOffset) { FDKpushBiDirectional(bs, readBitOffset); diff --git a/libAACdec/src/rvlcbit.h b/libAACdec/src/rvlcbit.h index 5c6a3f1..2578453 100644 --- a/libAACdec/src/rvlcbit.h +++ b/libAACdec/src/rvlcbit.h @@ -105,7 +105,7 @@ amm-info@iis.fraunhofer.de #include "rvlc.h" -UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, INT *pPosition, - UCHAR readDirection); +UCHAR rvlcReadBitFromBitstream(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, + INT *pPosition, UCHAR readDirection); #endif /* RVLCBIT_H */ diff --git a/libAACdec/src/usacdec_lpd.cpp b/libAACdec/src/usacdec_lpd.cpp index 22069a6..f53e39f 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 < 6000) || (samplingRate > 24000)) { error = AAC_DEC_PARSE_ERROR; goto bail; } -- cgit v1.2.3 From 3dd382275553f6c234e9ec758312d0ac6ef76dc1 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 8 Jun 2018 18:07:14 +0200 Subject: Always check whether given channel config is supported. Bug: 112660981 Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I169161dd31bc624f2cab6be2b4c6518946ed32ba --- libAACdec/src/aacdecoder.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'libAACdec/src') diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp index 2f43fc0..fab30de 100644 --- a/libAACdec/src/aacdecoder.cpp +++ b/libAACdec/src/aacdecoder.cpp @@ -1630,18 +1630,10 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, aacChannelsOffset = 0; aacChannelsOffsetIdx = 0; elementOffset = 0; - if ((ascChannels <= 0) || + if ((ascChannels <= 0) || (ascChannels > (8)) || (asc->m_channelConfiguration > AACDEC_MAX_CH_CONF)) { return AAC_DEC_UNSUPPORTED_CHANNELCONFIG; } - if ((ascChannels + aacChannelsOffsetIdx) > ((8) * 2)) { - return AAC_DEC_UNSUPPORTED_CHANNELCONFIG; - } - if (configMode & AC_CM_ALLOC_MEM) { - if ((ascChannels + aacChannelsOffset) > (8)) { - return AAC_DEC_UNSUPPORTED_CHANNELCONFIG; - } - } /* Set syntax flags */ self->flags[streamIndex] = 0; -- cgit v1.2.3 From 856e3d339e6e9c190d06df7a67bc3ee90cba3ecf Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 8 Mar 2019 15:55:05 +0100 Subject: Trigger config change after a change in SBR activity has been recognized. Change-Id: I7715e61fdfcd16dfae6029171888aef9c6f0738e --- libAACdec/src/aacdecoder.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libAACdec/src') diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp index 8f03328..7617937 100644 --- a/libAACdec/src/aacdecoder.cpp +++ b/libAACdec/src/aacdecoder.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -1815,6 +1815,9 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, self->useLdQmfTimeAlign = asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign; } + if (self->sbrEnabled != asc->m_sbrPresentFlag) { + ascChanged = 1; + } } self->streamInfo.extAot = asc->m_extensionAudioObjectType; -- cgit v1.2.3 From 37972d5a1f175173c2747c043ae6f3d1a142d28a Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 8 Mar 2019 16:01:59 +0100 Subject: Add support for Album Mode (FDKdec v3.1.0). Bug: 131255165 Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I6b4b176ec497587238537bddd89889341733d4e2 --- documentation/aacDecoder.pdf | Bin 500827 -> 487685 bytes libAACdec/include/aacdecoder_lib.h | 8 +++++++- libAACdec/src/aacdecoder_lib.cpp | 9 +++++++-- libDRCdec/include/FDK_drcDecLib.h | 3 ++- libDRCdec/src/FDK_drcDecLib.cpp | 8 +++++++- libDRCdec/src/drcDec_selectionProcess.cpp | 7 ++++++- libDRCdec/src/drcDec_selectionProcess.h | 3 ++- 7 files changed, 31 insertions(+), 7 deletions(-) (limited to 'libAACdec/src') diff --git a/documentation/aacDecoder.pdf b/documentation/aacDecoder.pdf index 1dec334..5c4ef5e 100644 Binary files a/documentation/aacDecoder.pdf and b/documentation/aacDecoder.pdf differ diff --git a/libAACdec/include/aacdecoder_lib.h b/libAACdec/include/aacdecoder_lib.h index 3a9b910..ee34b22 100644 --- a/libAACdec/include/aacdecoder_lib.h +++ b/libAACdec/include/aacdecoder_lib.h @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -781,6 +781,12 @@ typedef enum { to 127 (31.75 dB below full-scale). This parameter is used only with ::AAC_DRC_PARAMETER_HANDLING_ENABLED and ignored otherwise.\n Default: 127 (worst-case assumption).\n */ + AAC_UNIDRC_ALBUM_MODE = + 0x0207, /*!< MPEG-D DRC: Enable album mode. 0: Disabled (default), 1: + Enabled.\n Disabled album mode leads to application of gain + sequences for fading in and out, if provided in the + bitstream.\n Enabled album mode makes use of dedicated album + loudness information, if provided in the bitstream.\n */ AAC_QMF_LOWPOWER = 0x0300, /*!< Quadrature Mirror Filter (QMF) Bank processing mode. \n -1: Use internal default. Implies MPEG Surround partially complex accordingly. \n 0: diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp index c214ba1..d0e4ebc 100644 --- a/libAACdec/src/aacdecoder_lib.cpp +++ b/libAACdec/src/aacdecoder_lib.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -119,7 +119,7 @@ amm-info@iis.fraunhofer.de /* Decoder library info */ #define AACDECODER_LIB_VL0 3 -#define AACDECODER_LIB_VL1 0 +#define AACDECODER_LIB_VL1 1 #define AACDECODER_LIB_VL2 0 #define AACDECODER_LIB_TITLE "AAC Decoder Lib" #ifdef __ANDROID__ @@ -871,6 +871,11 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_SetParam( uniDrcErr = FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_EFFECT_TYPE, (FIXP_DBL)value); break; + case AAC_UNIDRC_ALBUM_MODE: + uniDrcErr = FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_ALBUM_MODE, + (FIXP_DBL)value); + break; + case AAC_TPDEC_CLEAR_BUFFER: errTp = transportDec_SetParam(hTpDec, TPDEC_PARAM_RESET, 1); self->streamInfo.numLostAccessUnits = 0; diff --git a/libDRCdec/include/FDK_drcDecLib.h b/libDRCdec/include/FDK_drcDecLib.h index e187e18..9a99ed1 100644 --- a/libDRCdec/include/FDK_drcDecLib.h +++ b/libDRCdec/include/FDK_drcDecLib.h @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -134,6 +134,7 @@ typedef enum { DRC_DEC_EFFECT_TYPE, DRC_DEC_EFFECT_TYPE_FALLBACK_CODE, DRC_DEC_LOUDNESS_MEASUREMENT_METHOD, + DRC_DEC_ALBUM_MODE, /* set only system (not user) parameters */ DRC_DEC_DOWNMIX_ID, DRC_DEC_TARGET_CHANNEL_COUNT_REQUESTED, /**< number of output channels diff --git a/libDRCdec/src/FDK_drcDecLib.cpp b/libDRCdec/src/FDK_drcDecLib.cpp index 16b8152..8f3faa0 100644 --- a/libDRCdec/src/FDK_drcDecLib.cpp +++ b/libDRCdec/src/FDK_drcDecLib.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -440,6 +440,12 @@ FDK_drcDec_SetParam(HANDLE_DRC_DECODER hDrcDec, requestValue, &(hDrcDec->selProcInputDiff)); if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; break; + case DRC_DEC_ALBUM_MODE: + sErr = drcDec_SelectionProcess_SetParam(hDrcDec->hSelectionProc, + SEL_PROC_ALBUM_MODE, requestValue, + &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; default: return DRC_DEC_INVALID_PARAM; } diff --git a/libDRCdec/src/drcDec_selectionProcess.cpp b/libDRCdec/src/drcDec_selectionProcess.cpp index 5653e22..37f5722 100644 --- a/libDRCdec/src/drcDec_selectionProcess.cpp +++ b/libDRCdec/src/drcDec_selectionProcess.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -555,6 +555,11 @@ drcDec_SelectionProcess_SetParam(HANDLE_DRC_SELECTION_PROCESS hInstance, diff |= _compAssign(&pSelProcInput->loudnessMeasurementMethod, requestValueInt); break; + case SEL_PROC_ALBUM_MODE: + if ((requestValueInt < 0) || (requestValueInt > 1)) + return DRCDEC_SELECTION_PROCESS_PARAM_OUT_OF_RANGE; + diff |= _compAssign(&pSelProcInput->albumMode, requestValueInt); + break; case SEL_PROC_DOWNMIX_ID: diff |= _compAssign(&pSelProcInput->targetConfigRequestType, TCRT_DOWNMIX_ID); diff --git a/libDRCdec/src/drcDec_selectionProcess.h b/libDRCdec/src/drcDec_selectionProcess.h index 9e0e3fb..420bae6 100644 --- a/libDRCdec/src/drcDec_selectionProcess.h +++ b/libDRCdec/src/drcDec_selectionProcess.h @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -146,6 +146,7 @@ typedef enum { SEL_PROC_EFFECT_TYPE, SEL_PROC_EFFECT_TYPE_FALLBACK_CODE, SEL_PROC_LOUDNESS_MEASUREMENT_METHOD, + SEL_PROC_ALBUM_MODE, SEL_PROC_DOWNMIX_ID, SEL_PROC_TARGET_LAYOUT, SEL_PROC_TARGET_CHANNEL_COUNT, -- cgit v1.2.3 From 14f7e1369382c0a399b991648c96fbcf8940efc8 Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 8 Mar 2019 16:03:49 +0100 Subject: MPEG-4/D DRC unification, loudness norm default at -24 Unify API parameter of MPEG-4/D DRC and introduce rounding to boost/compress setParam function (FDKdec v3.1.1). Enable Loudness Normalization with target loudness -24 by default (FDKdec v3.1.2). Bug: 131255165 Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I249a36b4861d0c8d4a0ed2df4dc1f444576bac6b --- documentation/aacDecoder.pdf | Bin 487685 -> 488412 bytes libAACdec/include/aacdecoder_lib.h | 99 ++++++++++++++++-------------- libAACdec/src/aacdec_drc.cpp | 6 +- libAACdec/src/aacdecoder_lib.cpp | 6 +- libDRCdec/src/drcDec_selectionProcess.cpp | 13 +++- 5 files changed, 70 insertions(+), 54 deletions(-) (limited to 'libAACdec/src') diff --git a/documentation/aacDecoder.pdf b/documentation/aacDecoder.pdf index 5c4ef5e..eb2a75e 100644 Binary files a/documentation/aacDecoder.pdf and b/documentation/aacDecoder.pdf differ diff --git a/libAACdec/include/aacdecoder_lib.h b/libAACdec/include/aacdecoder_lib.h index ee34b22..6c2fda4 100644 --- a/libAACdec/include/aacdecoder_lib.h +++ b/libAACdec/include/aacdecoder_lib.h @@ -741,46 +741,62 @@ typedef enum { ::CONCEAL_INTER. only some AOTs are supported). \n */ AAC_DRC_BOOST_FACTOR = - 0x0200, /*!< Dynamic Range Control: Scaling factor for boosting gain - values. Defines how the boosting DRC factors (conveyed in the - bitstream) will be applied to the decoded signal. The valid - values range from 0 (don't apply boost factors) to 127 (fully - apply boost factors). Default value is 0. */ - AAC_DRC_ATTENUATION_FACTOR = - 0x0201, /*!< Dynamic Range Control: Scaling factor for attenuating gain - values. Same as - ::AAC_DRC_BOOST_FACTOR but for attenuating DRC factors. */ + 0x0200, /*!< MPEG-4 / MPEG-D Dynamic Range Control (DRC): Scaling factor + for boosting gain values. Defines how the boosting DRC factors + (conveyed in the bitstream) will be applied to the decoded + signal. The valid values range from 0 (don't apply boost + factors) to 127 (fully apply boost factors). Default value is 0 + for MPEG-4 DRC and 127 for MPEG-D DRC. */ + AAC_DRC_ATTENUATION_FACTOR = 0x0201, /*!< MPEG-4 / MPEG-D DRC: Scaling factor + for attenuating gain values. Same as + ::AAC_DRC_BOOST_FACTOR but for + attenuating DRC factors. */ AAC_DRC_REFERENCE_LEVEL = - 0x0202, /*!< Dynamic Range Control (DRC): Target reference level. Defines - the level below full-scale (quantized in steps of 0.25dB) to - which the output audio signal will be normalized to by the DRC - module. The parameter controls loudness normalization for both - MPEG-4 DRC and MPEG-D DRC. The valid values range from 40 (-10 - dBFS) to 127 (-31.75 dBFS). Any value smaller than 0 switches - off loudness normalization and MPEG-4 DRC. By default, loudness - normalization and MPEG-4 DRC is switched off. */ + 0x0202, /*!< MPEG-4 / MPEG-D DRC: Target reference level / decoder target + loudness.\n Defines the level below full-scale (quantized in + steps of 0.25dB) to which the output audio signal will be + normalized to by the DRC module.\n The parameter controls + loudness normalization for both MPEG-4 DRC and MPEG-D DRC. The + valid values range from 40 (-10 dBFS) to 127 (-31.75 dBFS).\n + Example values:\n + 124 (-31 dBFS) for audio/video receivers (AVR) or other + devices allowing audio playback with high dynamic range,\n 96 + (-24 dBFS) for TV sets or equivalent devices (default),\n 64 + (-16 dBFS) for mobile devices where the dynamic range of audio + playback is restricted.\n Any value smaller than 0 switches off + loudness normalization and MPEG-4 DRC. */ AAC_DRC_HEAVY_COMPRESSION = - 0x0203, /*!< Dynamic Range Control: En-/Disable DVB specific heavy - compression (aka RF mode). If set to 1, the decoder will apply - the compression values from the DVB specific ancillary data - field. At the same time the MPEG-4 Dynamic Range Control tool - will be disabled. By default, heavy compression is disabled. */ + 0x0203, /*!< MPEG-4 DRC: En-/Disable DVB specific heavy compression (aka + RF mode). If set to 1, the decoder will apply the compression + values from the DVB specific ancillary data field. At the same + time the MPEG-4 Dynamic Range Control tool will be disabled. By + default, heavy compression is disabled. */ AAC_DRC_DEFAULT_PRESENTATION_MODE = - 0x0204, /*!< Dynamic Range Control: Default presentation mode (DRC - parameter handling). \n Defines the handling of the DRC - parameters boost factor, attenuation factor and heavy - compression, if no presentation mode is indicated in the - bitstream.\n For options, see - ::AAC_DRC_DEFAULT_PRESENTATION_MODE_OPTIONS.\n Default: + 0x0204, /*!< MPEG-4 DRC: Default presentation mode (DRC parameter + handling). \n Defines the handling of the DRC parameters boost + factor, attenuation factor and heavy compression, if no + presentation mode is indicated in the bitstream.\n For options, + see ::AAC_DRC_DEFAULT_PRESENTATION_MODE_OPTIONS.\n Default: ::AAC_DRC_PARAMETER_HANDLING_DISABLED */ AAC_DRC_ENC_TARGET_LEVEL = - 0x0205, /*!< Dynamic Range Control: Encoder target level for light (i.e. - not heavy) compression.\n If known, this declares the target - reference level that was assumed at the encoder for calculation - of limiting gains. The valid values range from 0 (full-scale) - to 127 (31.75 dB below full-scale). This parameter is used only + 0x0205, /*!< MPEG-4 DRC: Encoder target level for light (i.e. not heavy) + compression.\n If known, this declares the target reference + level that was assumed at the encoder for calculation of + limiting gains. The valid values range from 0 (full-scale) to + 127 (31.75 dB below full-scale). This parameter is used only with ::AAC_DRC_PARAMETER_HANDLING_ENABLED and ignored otherwise.\n Default: 127 (worst-case assumption).\n */ + AAC_UNIDRC_SET_EFFECT = 0x0206, /*!< MPEG-D DRC: Request a DRC effect type for + selection of a DRC set.\n Supported indices + are:\n -1: DRC off. Completely disables + MPEG-D DRC.\n 0: None (default). Disables + MPEG-D DRC, but automatically enables DRC + if necessary to prevent clipping.\n 1: Late + night\n 2: Noisy environment\n 3: Limited + playback range\n 4: Low playback level\n 5: + Dialog enhancement\n 6: General + compression. Used for generally enabling + MPEG-D DRC without particular request.\n */ AAC_UNIDRC_ALBUM_MODE = 0x0207, /*!< MPEG-D DRC: Enable album mode. 0: Disabled (default), 1: Enabled.\n Disabled album mode leads to application of gain @@ -793,20 +809,9 @@ typedef enum { Use complex QMF data mode. \n 1: Use real (low power) QMF data mode. \n */ AAC_TPDEC_CLEAR_BUFFER = - 0x0603, /*!< Clear internal bit stream buffer of transport layers. The - decoder will start decoding at new data passed after this event - and any previous data is discarded. */ - AAC_UNIDRC_SET_EFFECT = 0x0903 /*!< MPEG-D DRC: Request a DRC effect type for - selection of a DRC set.\n Supported indices - are:\n -1: DRC off. Completely disables - MPEG-D DRC.\n 0: None (default). Disables - MPEG-D DRC, but automatically enables DRC if - necessary to prevent clipping.\n 1: Late - night\n 2: Noisy environment\n 3: Limited - playback range\n 4: Low playback level\n 5: - Dialog enhancement\n 6: General compression. - Used for generally enabling MPEG-D DRC - without particular request.\n */ + 0x0603 /*!< Clear internal bit stream buffer of transport layers. The + decoder will start decoding at new data passed after this event + and any previous data is discarded. */ } AACDEC_PARAM; diff --git a/libAACdec/src/aacdec_drc.cpp b/libAACdec/src/aacdec_drc.cpp index 922a09e..4129d0f 100644 --- a/libAACdec/src/aacdec_drc.cpp +++ b/libAACdec/src/aacdec_drc.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -174,9 +174,9 @@ void aacDecoder_drcInit(HANDLE_AAC_DRC self) { pParams->usrCut = FL2FXCONST_DBL(0.0f); pParams->boost = FL2FXCONST_DBL(0.0f); pParams->usrBoost = FL2FXCONST_DBL(0.0f); - pParams->targetRefLevel = -1; + pParams->targetRefLevel = 96; pParams->expiryFrame = AACDEC_DRC_DFLT_EXPIRY_FRAMES; - pParams->applyDigitalNorm = OFF; + pParams->applyDigitalNorm = ON; pParams->applyHeavyCompression = OFF; pParams->usrApplyHeavyCompression = OFF; diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp index d0e4ebc..4046d66 100644 --- a/libAACdec/src/aacdecoder_lib.cpp +++ b/libAACdec/src/aacdecoder_lib.cpp @@ -120,7 +120,7 @@ amm-info@iis.fraunhofer.de /* Decoder library info */ #define AACDECODER_LIB_VL0 3 #define AACDECODER_LIB_VL1 1 -#define AACDECODER_LIB_VL2 0 +#define AACDECODER_LIB_VL2 2 #define AACDECODER_LIB_TITLE "AAC Decoder Lib" #ifdef __ANDROID__ #define AACDECODER_LIB_BUILD_DATE "" @@ -823,11 +823,15 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_SetParam( case AAC_DRC_ATTENUATION_FACTOR: /* DRC compression factor (where 0 is no and 127 is max compression) */ errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_CUT_SCALE, value); + uniDrcErr = FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_COMPRESS, + value * (FL2FXCONST_DBL(0.5f / 127.0f))); break; case AAC_DRC_BOOST_FACTOR: /* DRC boost factor (where 0 is no and 127 is max boost) */ errorStatus = aacDecoder_drcSetParam(hDrcInfo, DRC_BOOST_SCALE, value); + uniDrcErr = FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_BOOST, + value * (FL2FXCONST_DBL(0.5f / 127.0f))); break; case AAC_DRC_REFERENCE_LEVEL: diff --git a/libDRCdec/src/drcDec_selectionProcess.cpp b/libDRCdec/src/drcDec_selectionProcess.cpp index 37f5722..c33bf74 100644 --- a/libDRCdec/src/drcDec_selectionProcess.cpp +++ b/libDRCdec/src/drcDec_selectionProcess.cpp @@ -603,14 +603,21 @@ drcDec_SelectionProcess_SetParam(HANDLE_DRC_SELECTION_PROCESS hInstance, if ((requestValue < (FIXP_DBL)0) || (requestValue > FL2FXCONST_DBL(1.0f / (float)(1 << 1)))) return DRCDEC_SELECTION_PROCESS_PARAM_OUT_OF_RANGE; - diff |= _compAssign(&pSelProcInput->boost, FX_DBL2FX_SGL(requestValue)); + diff |= _compAssign( + &pSelProcInput->boost, + FX_DBL2FX_SGL( + requestValue + + (FIXP_DBL)(1 << 15))); /* convert to FIXP_SGL with rounding */ break; case SEL_PROC_COMPRESS: if ((requestValue < (FIXP_DBL)0) || (requestValue > FL2FXCONST_DBL(1.0f / (float)(1 << 1)))) return DRCDEC_SELECTION_PROCESS_PARAM_OUT_OF_RANGE; - diff |= - _compAssign(&pSelProcInput->compress, FX_DBL2FX_SGL(requestValue)); + diff |= _compAssign( + &pSelProcInput->compress, + FX_DBL2FX_SGL( + requestValue + + (FIXP_DBL)(1 << 15))); /* convert to FIXP_SGL with rounding */ break; default: return DRCDEC_SELECTION_PROCESS_INVALID_PARAM; -- cgit v1.2.3 From e970ac4c95e2e1016c72caa5218fc8f1bafe58fe Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 8 Mar 2019 16:08:07 +0100 Subject: Fix HE-AAC using MPEG-D DRC with implicit SBR signaling. Bug: 132641988 Test: atest DecoderTestXheAac ; atest DecoderTestAacDrc Change-Id: I97c5d3972528092f627153ad3127c7db977a0e5d --- libAACdec/src/aacdecoder_lib.cpp | 7 ++ libDRCdec/include/FDK_drcDecLib.h | 2 + libDRCdec/src/FDK_drcDecLib.cpp | 160 ++++++++++++++++++++--------------- libDRCdec/src/drcDec_gainDecoder.cpp | 26 +++++- libDRCdec/src/drcDec_gainDecoder.h | 12 ++- libDRCdec/src/drcGainDec_init.cpp | 21 +---- libDRCdec/src/drcGainDec_init.h | 5 +- 7 files changed, 139 insertions(+), 94 deletions(-) (limited to 'libAACdec/src') diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp index 4046d66..86ec899 100644 --- a/libAACdec/src/aacdecoder_lib.cpp +++ b/libAACdec/src/aacdecoder_lib.cpp @@ -1676,6 +1676,13 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern, reverseOutChannelMap[ch] = ch; } + /* Update sampleRate and frameSize. This may be necessary in case of + * implicit SBR signaling */ + FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_SAMPLE_RATE, + self->streamInfo.sampleRate); + FDK_drcDec_SetParam(self->hUniDrcDecoder, DRC_DEC_FRAME_SIZE, + self->streamInfo.frameSize); + /* If SBR and/or MPS is active, the DRC gains are aligned to the QMF domain signal before the QMF synthesis. Therefore the DRC gains need to be delayed by the QMF synthesis delay. */ diff --git a/libDRCdec/include/FDK_drcDecLib.h b/libDRCdec/include/FDK_drcDecLib.h index 9a99ed1..2d28d23 100644 --- a/libDRCdec/include/FDK_drcDecLib.h +++ b/libDRCdec/include/FDK_drcDecLib.h @@ -142,6 +142,8 @@ typedef enum { choosing an appropriate downmixInstruction */ DRC_DEC_BASE_CHANNEL_COUNT, + DRC_DEC_FRAME_SIZE, + DRC_DEC_SAMPLE_RATE, /* get only system parameters */ DRC_DEC_IS_MULTIBAND_DRC_1, DRC_DEC_IS_MULTIBAND_DRC_2, diff --git a/libDRCdec/src/FDK_drcDecLib.cpp b/libDRCdec/src/FDK_drcDecLib.cpp index 8f3faa0..4f8ebc7 100644 --- a/libDRCdec/src/FDK_drcDecLib.cpp +++ b/libDRCdec/src/FDK_drcDecLib.cpp @@ -336,7 +336,13 @@ FDK_drcDec_Init(HANDLE_DRC_DECODER hDrcDec, const int frameSize, } if (hDrcDec->functionalRange & DRC_DEC_GAIN) { - dErr = drcDec_GainDecoder_Init(hDrcDec->hGainDec, frameSize, sampleRate); + dErr = drcDec_GainDecoder_SetParam(hDrcDec->hGainDec, GAIN_DEC_FRAME_SIZE, + frameSize); + if (dErr) return DRC_DEC_NOT_OK; + dErr = drcDec_GainDecoder_SetParam(hDrcDec->hGainDec, GAIN_DEC_SAMPLE_RATE, + sampleRate); + if (dErr) return DRC_DEC_NOT_OK; + dErr = drcDec_GainDecoder_Init(hDrcDec->hGainDec); if (dErr) return DRC_DEC_NOT_OK; } @@ -377,79 +383,99 @@ DRC_DEC_ERROR FDK_drcDec_SetParam(HANDLE_DRC_DECODER hDrcDec, const DRC_DEC_USERPARAM requestType, const FIXP_DBL requestValue) { + DRC_ERROR dErr = DE_OK; DRCDEC_SELECTION_PROCESS_RETURN sErr = DRCDEC_SELECTION_PROCESS_NO_ERROR; + int invalidParameter = 0; if (hDrcDec == NULL) return DRC_DEC_NOT_OPENED; - if (hDrcDec->functionalRange == DRC_DEC_GAIN) - return DRC_DEC_NOT_OK; /* not supported for DRC_DEC_GAIN. All parameters are - handed over to selection process lib. */ + if (hDrcDec->functionalRange & DRC_DEC_GAIN) { + switch (requestType) { + case DRC_DEC_SAMPLE_RATE: + dErr = drcDec_GainDecoder_SetParam( + hDrcDec->hGainDec, GAIN_DEC_SAMPLE_RATE, (int)requestValue); + if (dErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + case DRC_DEC_FRAME_SIZE: + dErr = drcDec_GainDecoder_SetParam( + hDrcDec->hGainDec, GAIN_DEC_FRAME_SIZE, (int)requestValue); + if (dErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + default: + invalidParameter |= DRC_DEC_GAIN; + } + } - switch (requestType) { - case DRC_DEC_BOOST: - sErr = drcDec_SelectionProcess_SetParam(hDrcDec->hSelectionProc, - SEL_PROC_BOOST, requestValue, - &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; - break; - case DRC_DEC_COMPRESS: - sErr = drcDec_SelectionProcess_SetParam(hDrcDec->hSelectionProc, - SEL_PROC_COMPRESS, requestValue, - &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; - break; - case DRC_DEC_LOUDNESS_NORMALIZATION_ON: - sErr = drcDec_SelectionProcess_SetParam( - hDrcDec->hSelectionProc, SEL_PROC_LOUDNESS_NORMALIZATION_ON, - requestValue, &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; - break; - case DRC_DEC_TARGET_LOUDNESS: - sErr = drcDec_SelectionProcess_SetParam( - hDrcDec->hSelectionProc, SEL_PROC_TARGET_LOUDNESS, requestValue, - &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; - break; - case DRC_DEC_EFFECT_TYPE: - sErr = drcDec_SelectionProcess_SetParam( - hDrcDec->hSelectionProc, SEL_PROC_EFFECT_TYPE, requestValue, - &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; - break; - case DRC_DEC_DOWNMIX_ID: - sErr = drcDec_SelectionProcess_SetParam(hDrcDec->hSelectionProc, - SEL_PROC_DOWNMIX_ID, requestValue, - &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; - break; - case DRC_DEC_TARGET_CHANNEL_COUNT_REQUESTED: - sErr = drcDec_SelectionProcess_SetParam( - hDrcDec->hSelectionProc, SEL_PROC_TARGET_CHANNEL_COUNT, requestValue, - &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; - break; - case DRC_DEC_BASE_CHANNEL_COUNT: - sErr = drcDec_SelectionProcess_SetParam( - hDrcDec->hSelectionProc, SEL_PROC_BASE_CHANNEL_COUNT, requestValue, - &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_NOT_OK; - break; - case DRC_DEC_LOUDNESS_MEASUREMENT_METHOD: - sErr = drcDec_SelectionProcess_SetParam( - hDrcDec->hSelectionProc, SEL_PROC_LOUDNESS_MEASUREMENT_METHOD, - requestValue, &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; - break; - case DRC_DEC_ALBUM_MODE: - sErr = drcDec_SelectionProcess_SetParam(hDrcDec->hSelectionProc, - SEL_PROC_ALBUM_MODE, requestValue, - &(hDrcDec->selProcInputDiff)); - if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; - break; - default: - return DRC_DEC_INVALID_PARAM; + if (hDrcDec->functionalRange & DRC_DEC_SELECTION) { + switch (requestType) { + case DRC_DEC_BOOST: + sErr = drcDec_SelectionProcess_SetParam(hDrcDec->hSelectionProc, + SEL_PROC_BOOST, requestValue, + &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + case DRC_DEC_COMPRESS: + sErr = drcDec_SelectionProcess_SetParam(hDrcDec->hSelectionProc, + SEL_PROC_COMPRESS, requestValue, + &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + case DRC_DEC_LOUDNESS_NORMALIZATION_ON: + sErr = drcDec_SelectionProcess_SetParam( + hDrcDec->hSelectionProc, SEL_PROC_LOUDNESS_NORMALIZATION_ON, + requestValue, &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + case DRC_DEC_TARGET_LOUDNESS: + sErr = drcDec_SelectionProcess_SetParam( + hDrcDec->hSelectionProc, SEL_PROC_TARGET_LOUDNESS, requestValue, + &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + case DRC_DEC_EFFECT_TYPE: + sErr = drcDec_SelectionProcess_SetParam( + hDrcDec->hSelectionProc, SEL_PROC_EFFECT_TYPE, requestValue, + &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + case DRC_DEC_DOWNMIX_ID: + sErr = drcDec_SelectionProcess_SetParam( + hDrcDec->hSelectionProc, SEL_PROC_DOWNMIX_ID, requestValue, + &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + case DRC_DEC_TARGET_CHANNEL_COUNT_REQUESTED: + sErr = drcDec_SelectionProcess_SetParam( + hDrcDec->hSelectionProc, SEL_PROC_TARGET_CHANNEL_COUNT, + requestValue, &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + case DRC_DEC_BASE_CHANNEL_COUNT: + sErr = drcDec_SelectionProcess_SetParam( + hDrcDec->hSelectionProc, SEL_PROC_BASE_CHANNEL_COUNT, requestValue, + &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_NOT_OK; + break; + case DRC_DEC_LOUDNESS_MEASUREMENT_METHOD: + sErr = drcDec_SelectionProcess_SetParam( + hDrcDec->hSelectionProc, SEL_PROC_LOUDNESS_MEASUREMENT_METHOD, + requestValue, &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + case DRC_DEC_ALBUM_MODE: + sErr = drcDec_SelectionProcess_SetParam( + hDrcDec->hSelectionProc, SEL_PROC_ALBUM_MODE, requestValue, + &(hDrcDec->selProcInputDiff)); + if (sErr) return DRC_DEC_PARAM_OUT_OF_RANGE; + break; + default: + invalidParameter |= DRC_DEC_SELECTION; + } } + if (invalidParameter == hDrcDec->functionalRange) + return DRC_DEC_INVALID_PARAM; + /* All parameters need a new start of the selection process */ startSelectionProcess(hDrcDec); diff --git a/libDRCdec/src/drcDec_gainDecoder.cpp b/libDRCdec/src/drcDec_gainDecoder.cpp index ca81fad..9d91267 100644 --- a/libDRCdec/src/drcDec_gainDecoder.cpp +++ b/libDRCdec/src/drcDec_gainDecoder.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -170,11 +170,10 @@ drcDec_GainDecoder_Open(HANDLE_DRC_GAIN_DECODER* phGainDec) { } DRC_ERROR -drcDec_GainDecoder_Init(HANDLE_DRC_GAIN_DECODER hGainDec, const int frameSize, - const int sampleRate) { +drcDec_GainDecoder_Init(HANDLE_DRC_GAIN_DECODER hGainDec) { DRC_ERROR err = DE_OK; - err = initGainDec(hGainDec, frameSize, sampleRate); + err = initGainDec(hGainDec); if (err) return err; initDrcGainBuffers(hGainDec->frameSize, &hGainDec->drcGainBuffers); @@ -182,6 +181,25 @@ drcDec_GainDecoder_Init(HANDLE_DRC_GAIN_DECODER hGainDec, const int frameSize, return err; } +DRC_ERROR +drcDec_GainDecoder_SetParam(HANDLE_DRC_GAIN_DECODER hGainDec, + const GAIN_DEC_PARAM paramType, + const int paramValue) { + switch (paramType) { + case GAIN_DEC_FRAME_SIZE: + if (paramValue < 0) return DE_PARAM_OUT_OF_RANGE; + hGainDec->frameSize = paramValue; + break; + case GAIN_DEC_SAMPLE_RATE: + if (paramValue < 0) return DE_PARAM_OUT_OF_RANGE; + hGainDec->deltaTminDefault = getDeltaTmin(paramValue); + break; + default: + return DE_PARAM_INVALID; + } + return DE_OK; +} + DRC_ERROR drcDec_GainDecoder_SetCodecDependentParameters( HANDLE_DRC_GAIN_DECODER hGainDec, const DELAY_MODE delayMode, diff --git a/libDRCdec/src/drcDec_gainDecoder.h b/libDRCdec/src/drcDec_gainDecoder.h index 2f4df4c..394b455 100644 --- a/libDRCdec/src/drcDec_gainDecoder.h +++ b/libDRCdec/src/drcDec_gainDecoder.h @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -134,6 +134,8 @@ typedef enum { GAIN_DEC_DRC2_DRC3 } GAIN_DEC_LOCATION; +typedef enum { GAIN_DEC_FRAME_SIZE, GAIN_DEC_SAMPLE_RATE } GAIN_DEC_PARAM; + typedef struct { FIXP_DBL gainLin; /* e = 7 */ SHORT time; @@ -195,8 +197,12 @@ DRC_ERROR drcDec_GainDecoder_Open(HANDLE_DRC_GAIN_DECODER* phGainDec); DRC_ERROR -drcDec_GainDecoder_Init(HANDLE_DRC_GAIN_DECODER hGainDec, const int frameSize, - const int sampleRate); +drcDec_GainDecoder_Init(HANDLE_DRC_GAIN_DECODER hGainDec); + +DRC_ERROR +drcDec_GainDecoder_SetParam(HANDLE_DRC_GAIN_DECODER hGainDec, + const GAIN_DEC_PARAM paramType, + const int paramValue); DRC_ERROR drcDec_GainDecoder_SetCodecDependentParameters( diff --git a/libDRCdec/src/drcGainDec_init.cpp b/libDRCdec/src/drcGainDec_init.cpp index c9f87d7..89d0f55 100644 --- a/libDRCdec/src/drcGainDec_init.cpp +++ b/libDRCdec/src/drcGainDec_init.cpp @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -184,24 +184,11 @@ static DRC_ERROR _generateDrcInstructionsDerivedData( } DRC_ERROR -initGainDec(HANDLE_DRC_GAIN_DECODER hGainDec, const int frameSize, - const int sampleRate) { +initGainDec(HANDLE_DRC_GAIN_DECODER hGainDec) { int i, j, k; - if (frameSize < 1) { - return DE_NOT_OK; - } - - hGainDec->frameSize = frameSize; - - if (hGainDec->frameSize * 1000 < sampleRate) { - return DE_NOT_OK; - } - - hGainDec->deltaTminDefault = getDeltaTmin(sampleRate); - if (hGainDec->deltaTminDefault > hGainDec->frameSize) { - return DE_NOT_OK; - } + /* sanity check */ + if (hGainDec->deltaTminDefault > hGainDec->frameSize) return DE_NOT_OK; for (i = 0; i < MAX_ACTIVE_DRCS; i++) { for (j = 0; j < 8; j++) { diff --git a/libDRCdec/src/drcGainDec_init.h b/libDRCdec/src/drcGainDec_init.h index 9215bc3..c0b9853 100644 --- a/libDRCdec/src/drcGainDec_init.h +++ b/libDRCdec/src/drcGainDec_init.h @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- Software License for The Fraunhofer FDK AAC Codec Library for Android -© Copyright 1995 - 2018 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -104,8 +104,7 @@ amm-info@iis.fraunhofer.de #define DRCGAINDEC_INIT_H DRC_ERROR -initGainDec(HANDLE_DRC_GAIN_DECODER hGainDec, const int frameSize, - const int sampleRate); +initGainDec(HANDLE_DRC_GAIN_DECODER hGainDec); void initDrcGainBuffers(const int frameSize, DRC_GAIN_BUFFERS* drcGainBuffers); -- cgit v1.2.3 From ec58a940e2b6f9514d34973dcdaa18730394309a Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Mon, 22 Jun 2020 13:27:41 +0300 Subject: Avoid undefined shifts Fixes: 23522/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_LIBFDK_AAC_fuzzer-5468272958111744 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg --- libAACdec/src/aacdec_hcr.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'libAACdec/src') diff --git a/libAACdec/src/aacdec_hcr.cpp b/libAACdec/src/aacdec_hcr.cpp index 6114756..26fdd97 100644 --- a/libAACdec/src/aacdec_hcr.cpp +++ b/libAACdec/src/aacdec_hcr.cpp @@ -1423,6 +1423,9 @@ static INT DecodeEscapeSequence(HANDLE_FDK_BITSTREAM bs, const INT bsAnchor, sign = (quantSpecCoef >= 0) ? 1 : -1; + if (escapeOnesCounter > 30) + escapeOnesCounter = 30; + quantSpecCoef = sign * (((INT)1 << escapeOnesCounter) + escape_word); return quantSpecCoef; -- cgit v1.2.3