From 9ab67882eca7454dc001e158bc1e6e2219d6650b Mon Sep 17 00:00:00 2001 From: Fraunhofer IIS FDK Date: Fri, 4 May 2018 15:51:23 +0200 Subject: [PATCH] FDKv2 additional fixes Bug: 71430241 Bug: 79220129 Test: cts-tradefed run commandAndExit cts-dev -m CtsMediaTestCases -t android.media.cts.DecoderTestXheAac cts-tradefed run commandAndExit cts-dev -m CtsMediaTestCases -t android.media.cts.DecoderTestAacDrc Add restriction to call intensity stereo tool only for applicable configurations Change-Id: I30ec6640bd484c56cc9d5b8b35186fc1c875e021 Fix high band energy calculation in sbr encoder Change-Id: I964dd46fab2ed797c440a983512bbab7e1aff98a Fix out-of-bounds read access in noiseless coder Change-Id: I9a669435dbdca421ff9e4affec57811002d75b3b Use temporary buffer for dummy parsing to check presence of audioPreroll data Change-Id: I2d42c5c8deddde34351c3d2858b9fe196b3a0906 Set applyAsc to 1 in case that the ASC parsing fails Change-Id: I552a8b960270bc18cae459ad28a3ba241035668e Parametric stereo together with mps not supported Change-Id: Icde14a2774a4303bb0c41046861a59d04b624365 Align ssc callback error path for drm Change-Id: Ie8ecbfa42c702e6df81c1aec532a9ff1e653dac9 Ensure that the bit counter starts at a multiple of TPDEC_SYNCSKIP Change-Id: I08d69ec361b2e2ed800282e333fd248b4b3ca245 Allow flushing only when audioPreroll is enabled in current and new config Change-Id: I52e95d75de4bbed692be922a59a23bda58870625 Omit reverse channel mapping in pass through mode Change-Id: I335e209c29a700cc091be069f1d08e4288b40793 --- libAACdec/src/aacdecoder_lib.cpp | 11 ++++++----- libAACdec/src/channel.cpp | 21 ++++++++++++--------- libAACdec/src/channelinfo.h | 4 +--- libAACdec/src/stereo.cpp | 5 ++--- libMpegTPDec/src/tpdec_asc.cpp | 2 +- libMpegTPDec/src/tpdec_latm.cpp | 10 +++++++--- libMpegTPDec/src/tpdec_lib.cpp | 6 ++++++ libSACdec/src/sac_dec_lib.cpp | 15 +++++++++++---- libSACenc/src/sacenc_nlc_enc.cpp | 10 ++++++++-- libSBRenc/src/tran_det.cpp | 2 +- 10 files changed, 55 insertions(+), 31 deletions(-) diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp index b7ea8df..e62d187 100644 --- a/libAACdec/src/aacdecoder_lib.cpp +++ b/libAACdec/src/aacdecoder_lib.cpp @@ -396,7 +396,8 @@ static INT aacDecoder_SscCallback(void *handle, HANDLE_FDK_BITSTREAM hBs, /* MPS found but invalid or not decodable by this instance */ hAacDecoder->mpsEnableCurr = 0; hAacDecoder->mpsApplicable = 0; - if ((coreCodec == AOT_USAC) || IS_LOWDELAY(coreCodec)) { + if ((coreCodec == AOT_USAC) || (coreCodec == AOT_DRM_USAC) || + IS_LOWDELAY(coreCodec)) { errTp = TRANSPORTDEC_PARSE_ERROR; } else { errTp = TRANSPORTDEC_OK; @@ -1654,14 +1655,14 @@ aacDecoder_DecodeFrame(HANDLE_AACDECODER self, INT_PCM *pTimeData_extern, self->streamInfo.frameSize; for (ch = 0; ch < self->streamInfo.numChannels; ch++) { - int mapValue = FDK_chMapDescr_getMapValue( + UCHAR mapValue = FDK_chMapDescr_getMapValue( &self->mapDescr, (UCHAR)ch, self->chMapIndex); - reverseInChannelMap[mapValue] = ch; + if (mapValue < (8)) reverseInChannelMap[mapValue] = ch; } for (ch = 0; ch < (int)numDrcOutChannels; ch++) { - int mapValue = FDK_chMapDescr_getMapValue( + UCHAR mapValue = FDK_chMapDescr_getMapValue( &self->mapDescr, (UCHAR)ch, numDrcOutChannels); - reverseOutChannelMap[mapValue] = ch; + if (mapValue < (8)) reverseOutChannelMap[mapValue] = ch; } /* The output of SBR and MPS is interleaved. Deinterleaving may be diff --git a/libAACdec/src/channel.cpp b/libAACdec/src/channel.cpp index dbbf58a..cfffd57 100644 --- a/libAACdec/src/channel.cpp +++ b/libAACdec/src/channel.cpp @@ -225,15 +225,18 @@ void CChannelElement_Decode( /* apply intensity stereo */ /* modifies pAacDecoderChannelInfo[]->aSpecSfb */ if (!(flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA))) { - CJointStereo_ApplyIS( - pAacDecoderChannelInfo, - GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, - pSamplingRateInfo), - GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), - GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), - GetScaleFactorBandsTransmitted(&pAacDecoderChannelInfo[L]->icsInfo), - pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow ? 1 - : 0); + if ((pAacDecoderChannelInfo[L]->pDynData->RawDataInfo.CommonWindow == + 1) && + (el_channels == 2)) { + CJointStereo_ApplyIS( + pAacDecoderChannelInfo, + GetScaleFactorBandOffsets(&pAacDecoderChannelInfo[L]->icsInfo, + pSamplingRateInfo), + GetWindowGroupLengthTable(&pAacDecoderChannelInfo[L]->icsInfo), + GetWindowGroups(&pAacDecoderChannelInfo[L]->icsInfo), + GetScaleFactorBandsTransmitted( + &pAacDecoderChannelInfo[L]->icsInfo)); + } } } /* maybe_stereo */ diff --git a/libAACdec/src/channelinfo.h b/libAACdec/src/channelinfo.h index 7c95e12..45a288f 100644 --- a/libAACdec/src/channelinfo.h +++ b/libAACdec/src/channelinfo.h @@ -478,15 +478,13 @@ void CJointStereo_ApplyMS( \param pWindowGroupLength pointer to window group length array. \param windowGroups number of window groups. \param scaleFactorBandsTransmitted number of transmitted scalefactor bands. - \param CommonWindow common window bit. \return none */ void CJointStereo_ApplyIS(CAacDecoderChannelInfo *pAacDecoderChannelInfo[2], const short *pScaleFactorBandOffsets, const UCHAR *pWindowGroupLength, const int windowGroups, - const int scaleFactorBandsTransmitted, - const UINT CommonWindow); + const int scaleFactorBandsTransmitted); /* aacdec_pns.cpp */ int CPns_IsPnsUsed(const CPnsData *pPnsData, const int group, const int band); diff --git a/libAACdec/src/stereo.cpp b/libAACdec/src/stereo.cpp index bb4f050..eed826b 100644 --- a/libAACdec/src/stereo.cpp +++ b/libAACdec/src/stereo.cpp @@ -1177,8 +1177,7 @@ void CJointStereo_ApplyIS(CAacDecoderChannelInfo *pAacDecoderChannelInfo[2], const SHORT *pScaleFactorBandOffsets, const UCHAR *pWindowGroupLength, const int windowGroups, - const int scaleFactorBandsTransmitted, - const UINT CommonWindow) { + const int scaleFactorBandsTransmitted) { CJointStereoData *pJointStereoData = &pAacDecoderChannelInfo[L]->pComData->jointStereoData; @@ -1228,7 +1227,7 @@ void CJointStereo_ApplyIS(CAacDecoderChannelInfo *pAacDecoderChannelInfo[2], rightScale[band] = leftScale[band] + msb + 1; - if (CommonWindow && (pJointStereoData->MsUsed[band] & groupMask)) { + if (pJointStereoData->MsUsed[band] & groupMask) { if (CodeBook[band] == INTENSITY_HCB) /* _NOT_ in-phase */ { scale = -scale; diff --git a/libMpegTPDec/src/tpdec_asc.cpp b/libMpegTPDec/src/tpdec_asc.cpp index abe66e5..74beaa6 100644 --- a/libMpegTPDec/src/tpdec_asc.cpp +++ b/libMpegTPDec/src/tpdec_asc.cpp @@ -2488,7 +2488,7 @@ TRANSPORTDEC_ERROR DrmRawSdcAudioConfig_Parse( switch (audioCoding) { case 0: /* AAC */ - if (coderField >> 2) { + if ((coderField >> 2) && (audioMode != 1)) { self->m_aot = AOT_DRM_SURROUND; /* Set pseudo AOT for Drm Surround */ } else { self->m_aot = AOT_DRM_AAC; /* Set pseudo AOT for Drm AAC */ diff --git a/libMpegTPDec/src/tpdec_latm.cpp b/libMpegTPDec/src/tpdec_latm.cpp index b4f7372..2edf055 100644 --- a/libMpegTPDec/src/tpdec_latm.cpp +++ b/libMpegTPDec/src/tpdec_latm.cpp @@ -126,7 +126,6 @@ static TRANSPORTDEC_ERROR CLatmDemux_ReadAudioMuxElement( CSTpCallBacks *pTpDecCallbacks, CSAudioSpecificConfig *pAsc, int *pfConfigFound) { TRANSPORTDEC_ERROR ErrorStatus = TRANSPORTDEC_OK; - UCHAR applyAsc = pLatmDemux->applyAsc; if (m_muxConfigPresent) { pLatmDemux->m_useSameStreamMux = FDKreadBits(bs, 1); @@ -152,7 +151,12 @@ static TRANSPORTDEC_ERROR CLatmDemux_ReadAudioMuxElement( goto bail; } - if (pLatmDemux->newCfgHasAudioPreRoll) { + /* Allow flushing only when audioPreroll functionality is enabled in + * current and new config otherwise the new config can be applied + * immediately. */ + if (pAsc->m_sc.m_usacConfig.element[0] + .extElement.usacExtElementHasAudioPreRoll && + pLatmDemux->newCfgHasAudioPreRoll) { pLatmDemux->newCfgHasAudioPreRoll = 0; /* with audioPreRoll we must flush before applying new cfg */ pLatmDemux->applyAsc = 0; @@ -223,7 +227,7 @@ static TRANSPORTDEC_ERROR CLatmDemux_ReadAudioMuxElement( bail: if (ErrorStatus != TRANSPORTDEC_OK) { - pLatmDemux->applyAsc = applyAsc; + pLatmDemux->applyAsc = 1; } return (ErrorStatus); diff --git a/libMpegTPDec/src/tpdec_lib.cpp b/libMpegTPDec/src/tpdec_lib.cpp index 10e3352..306bec0 100644 --- a/libMpegTPDec/src/tpdec_lib.cpp +++ b/libMpegTPDec/src/tpdec_lib.cpp @@ -1151,6 +1151,12 @@ static TRANSPORTDEC_ERROR synchronization(HANDLE_TRANSPORTDEC hTp, &syncLayerFrameBits, &fConfigFound, &headerBits); if (TPDEC_IS_FATAL_ERROR(err)) { + /* Rewind - TPDEC_SYNCSKIP, in order to look for a synch one bit ahead + * next time. Ensure that the bit amount lands at a multiple of + * TPDEC_SYNCSKIP. */ + FDKpushBiDirectional( + hBs, -headerBits + TPDEC_SYNCSKIP + (bitsAvail % TPDEC_SYNCSKIP)); + goto bail; } } diff --git a/libSACdec/src/sac_dec_lib.cpp b/libSACdec/src/sac_dec_lib.cpp index 56d8693..ebf9bee 100644 --- a/libSACdec/src/sac_dec_lib.cpp +++ b/libSACdec/src/sac_dec_lib.cpp @@ -698,6 +698,7 @@ SACDEC_ERROR mpegSurroundDecoder_Config( INT coreSbrFrameLengthIndex, INT configBytes, const UCHAR configMode, UCHAR *configChanged) { SACDEC_ERROR err = MPS_OK; + SPATIAL_SPECIFIC_CONFIG spatialSpecificConfig; switch (coreCodec) { case AOT_DRM_USAC: @@ -705,7 +706,6 @@ SACDEC_ERROR mpegSurroundDecoder_Config( if (configMode == AC_CM_DET_CFG_CHANGE) { /* In config detection mode write spatial specific config parameters * into temporarily allocated structure */ - SPATIAL_SPECIFIC_CONFIG spatialSpecificConfig; err = SpatialDecParseMps212Config( hBs, &spatialSpecificConfig, samplingRate, coreCodec, stereoConfigIndex, coreSbrFrameLengthIndex); @@ -718,9 +718,16 @@ SACDEC_ERROR mpegSurroundDecoder_Config( break; case AOT_ER_AAC_ELD: case AOT_ER_AAC_LD: - err = SpatialDecParseSpecificConfig( - hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup, configBytes, - coreCodec); + if (configMode == AC_CM_DET_CFG_CHANGE) { + /* In config detection mode write spatial specific config parameters + * into temporarily allocated structure */ + err = SpatialDecParseSpecificConfig(hBs, &spatialSpecificConfig, + configBytes, coreCodec); + } else { + err = SpatialDecParseSpecificConfig( + hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup, + configBytes, coreCodec); + } break; default: err = MPS_UNSUPPORTED_FORMAT; diff --git a/libSACenc/src/sacenc_nlc_enc.cpp b/libSACenc/src/sacenc_nlc_enc.cpp index ecb89b7..0ba6cc9 100644 --- a/libSACenc/src/sacenc_nlc_enc.cpp +++ b/libSACenc/src/sacenc_nlc_enc.cpp @@ -379,16 +379,22 @@ static UINT huff_enc_1D(HANDLE_FDK_BITSTREAM strm, const DATA_TYPE data_type, switch (data_type) { case t_CLD: - part0 = fdk_sacenc_huffPart0Tab.cld[in_data[0]]; pHuffTab = fdk_sacenc_huffCLDTab.h1D[dim1]; break; case t_ICC: - part0 = fdk_sacenc_huffPart0Tab.icc[in_data[0]]; pHuffTab = fdk_sacenc_huffICCTab.h1D[dim1]; break; } if (p0_flag) { + switch (data_type) { + case t_CLD: + part0 = fdk_sacenc_huffPart0Tab.cld[in_data[0]]; + break; + case t_ICC: + part0 = fdk_sacenc_huffPart0Tab.icc[in_data[0]]; + break; + } huffBits += FDKwriteBits(strm, HUFF_VALUE(part0), HUFF_LENGTH(part0)); offset = 1; } diff --git a/libSBRenc/src/tran_det.cpp b/libSBRenc/src/tran_det.cpp index ba9ae68..b6f1b9f 100644 --- a/libSBRenc/src/tran_det.cpp +++ b/libSBRenc/src/tran_det.cpp @@ -366,7 +366,7 @@ static FIXP_DBL addHighbandEnergies( accu += (EnergiesM[slotOut][j] >> scale[0]); } } - nrgTotal = accu >> (scaleEnergies[1] - scale[1]); + nrgTotal = fAddSaturate(nrgTotal, accu >> (scaleEnergies[1] - scale[1])); } return (nrgTotal);