diff options
Diffstat (limited to 'libAACdec')
-rw-r--r-- | libAACdec/include/aacdecoder_lib.h | 2 | ||||
-rw-r--r-- | libAACdec/src/aacdecoder.cpp | 136 | ||||
-rw-r--r-- | libAACdec/src/aacdecoder_lib.cpp | 7 | ||||
-rw-r--r-- | libAACdec/src/rvlc.cpp | 15 |
4 files changed, 129 insertions, 31 deletions
diff --git a/libAACdec/include/aacdecoder_lib.h b/libAACdec/include/aacdecoder_lib.h index 56f4ec1..d7928c0 100644 --- a/libAACdec/include/aacdecoder_lib.h +++ b/libAACdec/include/aacdecoder_lib.h @@ -1032,7 +1032,7 @@ LINKSPEC_H AAC_DECODER_ERROR aacDecoder_Fill(HANDLE_AACDECODER self, * \param self AAC decoder handle. * \param pTimeData Pointer to external output buffer where the decoded PCM * samples will be stored into. - * \param timeDataSize Size of external output buffer. + * \param timeDataSize Size of external output buffer in PCM samples. * \param flags Bit field with flags for the decoder: \n * (flags & AACDEC_CONCEAL) == 1: Do concealment. \n * (flags & AACDEC_FLUSH) == 2: Discard input data. Flush diff --git a/libAACdec/src/aacdecoder.cpp b/libAACdec/src/aacdecoder.cpp index c18e5e9..d5f0cea 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 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -494,6 +494,75 @@ static AAC_DECODER_ERROR CDataStreamElement_Read(HANDLE_AACDECODER self, return error; } +static INT findElementInstanceTag( + INT elementTag, MP4_ELEMENT_ID elementId, + CAacDecoderChannelInfo **pAacDecoderChannelInfo, INT nChannels, + MP4_ELEMENT_ID *pElementIdTab, INT nElements) { + int el, chCnt = 0; + + for (el = 0; el < nElements; el++) { + switch (pElementIdTab[el]) { + case ID_CPE: + case ID_SCE: + case ID_LFE: + if ((elementTag == pAacDecoderChannelInfo[chCnt]->ElementInstanceTag) && + (elementId == pElementIdTab[el])) { + return 1; /* element instance tag found */ + } + chCnt += (pElementIdTab[el] == ID_CPE) ? 2 : 1; + break; + default: + break; + } + if (chCnt >= nChannels) break; + if (pElementIdTab[el] == ID_END) break; + } + + return 0; /* element instance tag not found */ +} + +static INT validateElementInstanceTags( + CProgramConfig *pce, CAacDecoderChannelInfo **pAacDecoderChannelInfo, + INT nChannels, MP4_ELEMENT_ID *pElementIdTab, INT nElements) { + if (nChannels >= pce->NumChannels) { + for (int el = 0; el < pce->NumFrontChannelElements; el++) { + if (!findElementInstanceTag(pce->FrontElementTagSelect[el], + pce->FrontElementIsCpe[el] ? ID_CPE : ID_SCE, + pAacDecoderChannelInfo, nChannels, + pElementIdTab, nElements)) { + return 0; /* element instance tag not in raw_data_block() */ + } + } + for (int el = 0; el < pce->NumSideChannelElements; el++) { + if (!findElementInstanceTag(pce->SideElementTagSelect[el], + pce->SideElementIsCpe[el] ? ID_CPE : ID_SCE, + pAacDecoderChannelInfo, nChannels, + pElementIdTab, nElements)) { + return 0; /* element instance tag not in raw_data_block() */ + } + } + for (int el = 0; el < pce->NumBackChannelElements; el++) { + if (!findElementInstanceTag(pce->BackElementTagSelect[el], + pce->BackElementIsCpe[el] ? ID_CPE : ID_SCE, + pAacDecoderChannelInfo, nChannels, + pElementIdTab, nElements)) { + return 0; /* element instance tag not in raw_data_block() */ + } + } + for (int el = 0; el < pce->NumLfeChannelElements; el++) { + if (!findElementInstanceTag(pce->LfeElementTagSelect[el], ID_LFE, + pAacDecoderChannelInfo, nChannels, + pElementIdTab, nElements)) { + return 0; /* element instance tag not in raw_data_block() */ + } + } + } else { + return 0; /* too less decoded audio channels */ + } + + return 1; /* all element instance tags found in raw_data_block() */ +} + /*! \brief Read Program Config Element @@ -1417,11 +1486,7 @@ static void CAacDecoder_AcceptFlags(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, UINT flags, UINT *elFlags, int streamIndex, int elementOffset) { - { - FDKmemcpy( - self->elFlags, elFlags, - sizeof(*elFlags) * (3 * ((8) * 2) + (((8) * 2)) / 2 + 4 * (1) + 1)); - } + FDKmemcpy(self->elFlags, elFlags, sizeof(self->elFlags)); self->flags[streamIndex] = flags; } @@ -1524,8 +1589,14 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, INT flushChannels = 0; UINT flags; + /* elFlags[(3*MAX_CHANNELS + (MAX_CHANNELS)/2 + 4 * (MAX_TRACKS) + 1] + where MAX_CHANNELS is (8*2) and MAX_TRACKS is 1 */ UINT elFlags[(3 * ((8) * 2) + (((8) * 2)) / 2 + 4 * (1) + 1)]; + UCHAR sbrEnabled = self->sbrEnabled; + UCHAR sbrEnabledPrev = self->sbrEnabledPrev; + UCHAR mpsEnableCurr = self->mpsEnableCurr; + if (!self) return AAC_DEC_INVALID_HANDLE; UCHAR downscaleFactor = self->downscaleFactor; @@ -1709,7 +1780,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, asc->m_sc.m_usacConfig.m_usacNumElements; } - self->mpsEnableCurr = 0; + mpsEnableCurr = 0; for (int _el = 0; _el < (int)self->pUsacConfig[streamIndex]->m_usacNumElements; _el++) { @@ -1729,7 +1800,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, self->usacStereoConfigIndex[el] = asc->m_sc.m_usacConfig.element[_el].m_stereoConfigIndex; if (self->elements[el] == ID_USAC_CPE) { - self->mpsEnableCurr |= self->usacStereoConfigIndex[el] ? 1 : 0; + mpsEnableCurr |= self->usacStereoConfigIndex[el] ? 1 : 0; } } @@ -1865,7 +1936,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, self->useLdQmfTimeAlign = asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign; } - if (self->sbrEnabled != asc->m_sbrPresentFlag) { + if (sbrEnabled != asc->m_sbrPresentFlag) { ascChanged = 1; } } @@ -1881,13 +1952,13 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, flags |= (asc->m_sbrPresentFlag) ? AC_SBR_PRESENT : 0; flags |= (asc->m_psPresentFlag) ? AC_PS_PRESENT : 0; if (asc->m_sbrPresentFlag) { - self->sbrEnabled = 1; - self->sbrEnabledPrev = 1; + sbrEnabled = 1; + sbrEnabledPrev = 1; } else { - self->sbrEnabled = 0; - self->sbrEnabledPrev = 0; + sbrEnabled = 0; + sbrEnabledPrev = 0; } - if (self->sbrEnabled && asc->m_extensionSamplingFrequency) { + if (sbrEnabled && asc->m_extensionSamplingFrequency) { if (downscaleFactor != 1 && (downscaleFactor)&1) { return AAC_DEC_UNSUPPORTED_SAMPLINGRATE; /* SBR needs an even downscale factor */ @@ -1914,7 +1985,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, flags |= (asc->m_hcrFlag) ? AC_ER_HCR : 0; if (asc->m_aot == AOT_ER_AAC_ELD) { - self->mpsEnableCurr = 0; + mpsEnableCurr = 0; flags |= AC_ELD; flags |= (asc->m_sbrPresentFlag) ? AC_SBR_PRESENT @@ -1925,7 +1996,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, ? AC_MPS_PRESENT : 0; if (self->mpsApplicable) { - self->mpsEnableCurr = asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign; + mpsEnableCurr = asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign; } } flags |= (asc->m_aot == AOT_ER_AAC_LD) ? AC_LD : 0; @@ -2006,7 +2077,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, /* set AC_USAC_SCFGI3 globally if any usac element uses */ switch (asc->m_aot) { case AOT_USAC: - if (self->sbrEnabled) { + if (sbrEnabled) { for (int _el = 0; _el < (int)self->pUsacConfig[streamIndex]->m_usacNumElements; _el++) { @@ -2043,7 +2114,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, */ switch (asc->m_aot) { case AOT_USAC: - if (self->sbrEnabled) { + if (sbrEnabled) { const UCHAR map_sbrRatio_2_nAnaBands[] = {16, 24, 32}; FDK_ASSERT(asc->m_sc.m_usacConfig.m_sbrRatioIndex > 0); @@ -2071,11 +2142,11 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, } break; case AOT_ER_AAC_ELD: - if (self->mpsEnableCurr && + if (mpsEnableCurr && asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign) { - SAC_INPUT_CONFIG sac_interface = - (self->sbrEnabled && self->hSbrDecoder) ? SAC_INTERFACE_QMF - : SAC_INTERFACE_TIME; + SAC_INPUT_CONFIG sac_interface = (sbrEnabled && self->hSbrDecoder) + ? SAC_INTERFACE_QMF + : SAC_INTERFACE_TIME; mpegSurroundDecoder_ConfigureQmfDomain( (CMpegSurroundDecoder *)self->pMpegSurroundDecoder, sac_interface, (UINT)self->streamInfo.aacSampleRate, asc->m_aot); @@ -2430,6 +2501,9 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc, CAacDecoder_AcceptFlags(self, asc, flags, elFlags, streamIndex, elementOffset); + self->sbrEnabled = sbrEnabled; + self->sbrEnabledPrev = sbrEnabledPrev; + self->mpsEnableCurr = mpsEnableCurr; /* Update externally visible copy of flags */ self->streamInfo.flags = self->flags[0]; @@ -2968,6 +3042,24 @@ LINKSPEC_CPP AAC_DECODER_ERROR CAacDecoder_DecodeFrame( } /* while ( (type != ID_END) ... ) */ + if (!(self->flags[streamIndex] & + (AC_USAC | AC_RSVD50 | AC_RSV603DA | AC_BSAC | AC_LD | AC_ELD | AC_ER | + AC_SCALABLE)) && + (self->streamInfo.channelConfig == 0) && pce->isValid && + (ErrorStatus == AAC_DEC_OK) && self->frameOK && + !(flags & (AACDEC_CONCEAL | AACDEC_FLUSH))) { + /* Check whether all PCE listed element instance tags are present in + * raw_data_block() */ + if (!validateElementInstanceTags( + &self->pce, self->pAacDecoderChannelInfo, aacChannels, + channel_elements, + fMin(channel_element_count, (int)(sizeof(channel_elements) / + sizeof(*channel_elements))))) { + ErrorStatus = AAC_DEC_DECODE_FRAME_ERROR; + self->frameOK = 0; + } + } + if (!(flags & (AACDEC_CONCEAL | AACDEC_FLUSH))) { /* float decoder checks if bitsLeft is in range 0-7; only prerollAUs are * byteAligned with respect to the first bit */ diff --git a/libAACdec/src/aacdecoder_lib.cpp b/libAACdec/src/aacdecoder_lib.cpp index 9d36d10..0c83191 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 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten +© Copyright 1995 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -1626,6 +1626,11 @@ LINKSPEC_CPP AAC_DECODER_ERROR aacDecoder_DecodeFrame(HANDLE_AACDECODER self, /* set params */ sbrDecoder_SetParam(self->hSbrDecoder, SBR_SYSTEM_BITSTREAM_DELAY, self->sbrParams.bsDelay); + sbrDecoder_SetParam( + self->hSbrDecoder, SBR_FLUSH_DATA, + (flags & AACDEC_FLUSH) | + ((self->flushStatus && !(flags & AACDEC_CONCEAL)) ? AACDEC_FLUSH + : 0)); sbrDecoder_SetParam(self->hSbrDecoder, SBR_SKIP_QMF, 1); diff --git a/libAACdec/src/rvlc.cpp b/libAACdec/src/rvlc.cpp index b7a9be1..0b80364 100644 --- a/libAACdec/src/rvlc.cpp +++ b/libAACdec/src/rvlc.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 - 2021 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. All rights reserved. 1. INTRODUCTION @@ -628,7 +628,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc, SHORT *pScfBwd = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfBwd; SHORT *pScfEsc = pAacDecoderChannelInfo->pComData->overlay.aac.aRvlcScfEsc; - UCHAR *pEscEscCnt = &(pRvlc->numDecodedEscapeWordsEsc); + UCHAR escEscCnt = pRvlc->numDecodedEscapeWordsEsc; UCHAR *pEscBwdCnt = &(pRvlc->numDecodedEscapeWordsBwd); pRvlc->pRvlBitCnt_RVL = &(pRvlc->length_of_rvlc_sf_bwd); @@ -636,7 +636,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc, *pEscBwdCnt = 0; pRvlc->direction = BWD; - pScfEsc += *pEscEscCnt - 1; /* set pScfEsc to last entry */ + pScfEsc += escEscCnt - 1; /* set pScfEsc to last entry */ pRvlc->firstScf = 0; pRvlc->firstNrg = 0; pRvlc->firstIs = 0; @@ -651,7 +651,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc, } dpcm -= TABLE_OFFSET; if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) { - if (pRvlc->length_of_rvlc_escapes) { + if ((pRvlc->length_of_rvlc_escapes) || (*pEscBwdCnt >= escEscCnt)) { pRvlc->conceal_min = bnds; return; } else { @@ -694,7 +694,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc, } dpcm -= TABLE_OFFSET; if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) { - if (pRvlc->length_of_rvlc_escapes) { + if ((pRvlc->length_of_rvlc_escapes) || (*pEscBwdCnt >= escEscCnt)) { pScfBwd[bnds] = position; pRvlc->conceal_min = fMax(0, bnds - offset); return; @@ -731,7 +731,8 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc, } dpcm -= TABLE_OFFSET; if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) { - if (pRvlc->length_of_rvlc_escapes) { + if ((pRvlc->length_of_rvlc_escapes) || + (*pEscBwdCnt >= escEscCnt)) { pScfBwd[bnds] = noisenrg; pRvlc->conceal_min = fMax(0, bnds - offset); return; @@ -762,7 +763,7 @@ static void rvlcDecodeBackward(CErRvlcInfo *pRvlc, } dpcm -= TABLE_OFFSET; if ((dpcm == MIN_RVL) || (dpcm == MAX_RVL)) { - if (pRvlc->length_of_rvlc_escapes) { + if ((pRvlc->length_of_rvlc_escapes) || (*pEscBwdCnt >= escEscCnt)) { pScfBwd[bnds] = factor; pRvlc->conceal_min = fMax(0, bnds - offset); return; |