Improve decoder robustness by storing flags and elFlags temporarily.

Bug: 176246647
Test: atest DecoderTestXheAac DecoderTestAacDrc
Change-Id: I6aaeef87e1f2ce5d5031f088b8c57e6f5806929d
This commit is contained in:
Fraunhofer IIS FDK 2020-04-09 17:57:46 +02:00 committed by Ray Essick
parent a1a8f69b14
commit b93f896f37
1 changed files with 82 additions and 53 deletions

View File

@ -1396,6 +1396,31 @@ static void CAacDecoder_DeInit(HANDLE_AACDECODER self,
self->samplingRateInfo[subStreamIndex].samplingRate = 0; self->samplingRateInfo[subStreamIndex].samplingRate = 0;
} }
/*!
* \brief CAacDecoder_AcceptFlags Accept flags and element flags
*
* \param self [o] handle to AACDECODER structure
* \param asc [i] handle to ASC structure
* \param flags [i] flags
* \param elFlags [i] pointer to element flags
* \param streamIndex [i] stream index
* \param elementOffset [i] element offset
*
* \return void
*/
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));
}
self->flags[streamIndex] = flags;
}
/*! /*!
* \brief CAacDecoder_CtrlCFGChange Set config change parameters. * \brief CAacDecoder_CtrlCFGChange Set config change parameters.
* *
@ -1493,6 +1518,9 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
const int streamIndex = 0; const int streamIndex = 0;
INT flushChannels = 0; INT flushChannels = 0;
UINT flags;
UINT elFlags[(3 * ((8) * 2) + (((8) * 2)) / 2 + 4 * (1) + 1)];
if (!self) return AAC_DEC_INVALID_HANDLE; if (!self) return AAC_DEC_INVALID_HANDLE;
UCHAR downscaleFactor = self->downscaleFactor; UCHAR downscaleFactor = self->downscaleFactor;
@ -1649,8 +1677,8 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
} }
/* Set syntax flags */ /* Set syntax flags */
self->flags[streamIndex] = 0; flags = 0;
{ FDKmemclear(self->elFlags, sizeof(self->elFlags)); } { FDKmemclear(elFlags, sizeof(elFlags)); }
if ((asc->m_channelConfiguration > 0) || IS_USAC(asc->m_aot)) { if ((asc->m_channelConfiguration > 0) || IS_USAC(asc->m_aot)) {
if (IS_USAC(asc->m_aot)) { if (IS_USAC(asc->m_aot)) {
@ -1700,31 +1728,30 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
} }
} }
self->elFlags[el] |= elFlags[el] |= (asc->m_sc.m_usacConfig.element[_el].m_noiseFilling)
(asc->m_sc.m_usacConfig.element[_el].m_noiseFilling) ? AC_EL_USAC_NOISE
? AC_EL_USAC_NOISE : 0;
: 0; elFlags[el] |=
self->elFlags[el] |=
(asc->m_sc.m_usacConfig.element[_el].m_stereoConfigIndex > 0) (asc->m_sc.m_usacConfig.element[_el].m_stereoConfigIndex > 0)
? AC_EL_USAC_MPS212 ? AC_EL_USAC_MPS212
: 0; : 0;
self->elFlags[el] |= (asc->m_sc.m_usacConfig.element[_el].m_interTes) elFlags[el] |= (asc->m_sc.m_usacConfig.element[_el].m_interTes)
? AC_EL_USAC_ITES ? AC_EL_USAC_ITES
: 0; : 0;
self->elFlags[el] |= elFlags[el] |=
(asc->m_sc.m_usacConfig.element[_el].m_pvc) ? AC_EL_USAC_PVC : 0; (asc->m_sc.m_usacConfig.element[_el].m_pvc) ? AC_EL_USAC_PVC : 0;
self->elFlags[el] |= elFlags[el] |=
(asc->m_sc.m_usacConfig.element[_el].usacElementType == ID_USAC_LFE) (asc->m_sc.m_usacConfig.element[_el].usacElementType == ID_USAC_LFE)
? AC_EL_USAC_LFE ? AC_EL_USAC_LFE
: 0; : 0;
self->elFlags[el] |= elFlags[el] |=
(asc->m_sc.m_usacConfig.element[_el].usacElementType == ID_USAC_LFE) (asc->m_sc.m_usacConfig.element[_el].usacElementType == ID_USAC_LFE)
? AC_EL_LFE ? AC_EL_LFE
: 0; : 0;
if ((asc->m_sc.m_usacConfig.element[_el].usacElementType == if ((asc->m_sc.m_usacConfig.element[_el].usacElementType ==
ID_USAC_CPE) && ID_USAC_CPE) &&
((self->usacStereoConfigIndex[el] == 0))) { ((self->usacStereoConfigIndex[el] == 0))) {
self->elFlags[el] |= AC_EL_USAC_CP_POSSIBLE; elFlags[el] |= AC_EL_USAC_CP_POSSIBLE;
} }
} }
@ -1838,8 +1865,8 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
if (configMode & AC_CM_ALLOC_MEM) { if (configMode & AC_CM_ALLOC_MEM) {
self->streamInfo.extSamplingRate = asc->m_extensionSamplingFrequency; self->streamInfo.extSamplingRate = asc->m_extensionSamplingFrequency;
} }
self->flags[streamIndex] |= (asc->m_sbrPresentFlag) ? AC_SBR_PRESENT : 0; flags |= (asc->m_sbrPresentFlag) ? AC_SBR_PRESENT : 0;
self->flags[streamIndex] |= (asc->m_psPresentFlag) ? AC_PS_PRESENT : 0; flags |= (asc->m_psPresentFlag) ? AC_PS_PRESENT : 0;
if (asc->m_sbrPresentFlag) { if (asc->m_sbrPresentFlag) {
self->sbrEnabled = 1; self->sbrEnabled = 1;
self->sbrEnabledPrev = 1; self->sbrEnabledPrev = 1;
@ -1865,51 +1892,47 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
} }
/* --------- vcb11 ------------ */ /* --------- vcb11 ------------ */
self->flags[streamIndex] |= (asc->m_vcb11Flag) ? AC_ER_VCB11 : 0; flags |= (asc->m_vcb11Flag) ? AC_ER_VCB11 : 0;
/* ---------- rvlc ------------ */ /* ---------- rvlc ------------ */
self->flags[streamIndex] |= (asc->m_rvlcFlag) ? AC_ER_RVLC : 0; flags |= (asc->m_rvlcFlag) ? AC_ER_RVLC : 0;
/* ----------- hcr ------------ */ /* ----------- hcr ------------ */
self->flags[streamIndex] |= (asc->m_hcrFlag) ? AC_ER_HCR : 0; flags |= (asc->m_hcrFlag) ? AC_ER_HCR : 0;
if (asc->m_aot == AOT_ER_AAC_ELD) { if (asc->m_aot == AOT_ER_AAC_ELD) {
self->mpsEnableCurr = 0; self->mpsEnableCurr = 0;
self->flags[streamIndex] |= AC_ELD; flags |= AC_ELD;
self->flags[streamIndex] |= flags |= (asc->m_sbrPresentFlag)
(asc->m_sbrPresentFlag) ? AC_SBR_PRESENT
? AC_SBR_PRESENT : 0; /* Need to set the SBR flag for backward-compatibility
: 0; /* Need to set the SBR flag for backward-compatibility reasons. Even if SBR is not supported. */
reasons. Even if SBR is not supported. */ flags |= (asc->m_sc.m_eldSpecificConfig.m_sbrCrcFlag) ? AC_SBRCRC : 0;
self->flags[streamIndex] |= flags |= (asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign)
(asc->m_sc.m_eldSpecificConfig.m_sbrCrcFlag) ? AC_SBRCRC : 0; ? AC_MPS_PRESENT
self->flags[streamIndex] |= : 0;
(asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign) ? AC_MPS_PRESENT
: 0;
if (self->mpsApplicable) { if (self->mpsApplicable) {
self->mpsEnableCurr = asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign; self->mpsEnableCurr = asc->m_sc.m_eldSpecificConfig.m_useLdQmfTimeAlign;
} }
} }
self->flags[streamIndex] |= (asc->m_aot == AOT_ER_AAC_LD) ? AC_LD : 0; flags |= (asc->m_aot == AOT_ER_AAC_LD) ? AC_LD : 0;
self->flags[streamIndex] |= (asc->m_epConfig >= 0) ? AC_ER : 0; flags |= (asc->m_epConfig >= 0) ? AC_ER : 0;
if (asc->m_aot == AOT_USAC) { if (asc->m_aot == AOT_USAC) {
self->flags[streamIndex] |= AC_USAC; flags |= AC_USAC;
self->flags[streamIndex] |= flags |= (asc->m_sc.m_usacConfig.element[0].m_stereoConfigIndex > 0)
(asc->m_sc.m_usacConfig.element[0].m_stereoConfigIndex > 0) ? AC_MPS_PRESENT
? AC_MPS_PRESENT : 0;
: 0;
} }
if (asc->m_aot == AOT_DRM_AAC) { if (asc->m_aot == AOT_DRM_AAC) {
self->flags[streamIndex] |= AC_DRM | AC_SBRCRC | AC_SCALABLE; flags |= AC_DRM | AC_SBRCRC | AC_SCALABLE;
} }
if (asc->m_aot == AOT_DRM_SURROUND) { if (asc->m_aot == AOT_DRM_SURROUND) {
self->flags[streamIndex] |= flags |= AC_DRM | AC_SBRCRC | AC_SCALABLE | AC_MPS_PRESENT;
AC_DRM | AC_SBRCRC | AC_SCALABLE | AC_MPS_PRESENT;
FDK_ASSERT(!asc->m_psPresentFlag); FDK_ASSERT(!asc->m_psPresentFlag);
} }
if ((asc->m_aot == AOT_AAC_SCAL) || (asc->m_aot == AOT_ER_AAC_SCAL)) { if ((asc->m_aot == AOT_AAC_SCAL) || (asc->m_aot == AOT_ER_AAC_SCAL)) {
self->flags[streamIndex] |= AC_SCALABLE; flags |= AC_SCALABLE;
} }
if ((asc->m_epConfig >= 0) && (asc->m_channelConfiguration <= 0)) { if ((asc->m_epConfig >= 0) && (asc->m_channelConfiguration <= 0)) {
@ -1960,6 +1983,10 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
if (ascChanged != 0) { if (ascChanged != 0) {
*configChanged = 1; *configChanged = 1;
} }
CAacDecoder_AcceptFlags(self, asc, flags, elFlags, streamIndex,
elementOffset);
return err; return err;
} }
@ -1988,7 +2015,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
} }
if (usacStereoConfigIndex == 3) { if (usacStereoConfigIndex == 3) {
self->flags[streamIndex] |= AC_USAC_SCFGI3; flags |= AC_USAC_SCFGI3;
} }
} }
break; break;
@ -2069,14 +2096,14 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
ch = aacChannelsOffset; ch = aacChannelsOffset;
int _numElements; int _numElements;
_numElements = (((8)) + (8)); _numElements = (((8)) + (8));
if (self->flags[streamIndex] & (AC_RSV603DA | AC_USAC)) { if (flags & (AC_RSV603DA | AC_USAC)) {
_numElements = (int)asc->m_sc.m_usacConfig.m_usacNumElements; _numElements = (int)asc->m_sc.m_usacConfig.m_usacNumElements;
} }
for (int _el = 0; _el < _numElements; _el++) { for (int _el = 0; _el < _numElements; _el++) {
int el_channels = 0; int el_channels = 0;
int el = elementOffset + _el; int el = elementOffset + _el;
if (self->flags[streamIndex] & if (flags &
(AC_ER | AC_LD | AC_ELD | AC_RSV603DA | AC_USAC | AC_RSVD50)) { (AC_ER | AC_LD | AC_ELD | AC_RSV603DA | AC_USAC | AC_RSVD50)) {
if (ch >= ascChannels) { if (ch >= ascChannels) {
break; break;
@ -2176,15 +2203,14 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
if (self->pAacDecoderStaticChannelInfo[ch]->pOverlapBuffer == NULL) { if (self->pAacDecoderStaticChannelInfo[ch]->pOverlapBuffer == NULL) {
goto bail; goto bail;
} }
if (self->flags[streamIndex] & if (flags & (AC_USAC | AC_RSVD50 | AC_RSV603DA /*|AC_BSAC*/)) {
(AC_USAC | AC_RSVD50 | AC_RSV603DA /*|AC_BSAC*/)) {
self->pAacDecoderStaticChannelInfo[ch]->hArCo = CArco_Create(); self->pAacDecoderStaticChannelInfo[ch]->hArCo = CArco_Create();
if (self->pAacDecoderStaticChannelInfo[ch]->hArCo == NULL) { if (self->pAacDecoderStaticChannelInfo[ch]->hArCo == NULL) {
goto bail; goto bail;
} }
} }
if (!(self->flags[streamIndex] & (AC_USAC | AC_RSV603DA))) { if (!(flags & (AC_USAC | AC_RSV603DA))) {
CPns_UpdateNoiseState( CPns_UpdateNoiseState(
&self->pAacDecoderChannelInfo[ch]->data.aac.PnsData, &self->pAacDecoderChannelInfo[ch]->data.aac.PnsData,
&self->pAacDecoderStaticChannelInfo[ch]->pnsCurrentSeed, &self->pAacDecoderStaticChannelInfo[ch]->pnsCurrentSeed,
@ -2195,7 +2221,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
chIdx++; chIdx++;
} }
if (self->flags[streamIndex] & AC_USAC) { if (flags & AC_USAC) {
for (int _ch = 0; _ch < flushChannels; _ch++) { for (int _ch = 0; _ch < flushChannels; _ch++) {
ch = aacChannelsOffset + _ch; ch = aacChannelsOffset + _ch;
if (self->pTimeDataFlush[ch] == NULL) { if (self->pTimeDataFlush[ch] == NULL) {
@ -2207,7 +2233,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
} }
} }
if (self->flags[streamIndex] & (AC_USAC | AC_RSV603DA)) { if (flags & (AC_USAC | AC_RSV603DA)) {
int complexStereoPredPossible = 0; int complexStereoPredPossible = 0;
ch = aacChannelsOffset; ch = aacChannelsOffset;
chIdx = aacChannelsOffsetIdx; chIdx = aacChannelsOffsetIdx;
@ -2223,7 +2249,7 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
elCh = 1; elCh = 1;
} }
if (self->elFlags[el2] & AC_EL_USAC_CP_POSSIBLE) { if (elFlags[el2] & AC_EL_USAC_CP_POSSIBLE) {
complexStereoPredPossible = 1; complexStereoPredPossible = 1;
if (self->cpeStaticData[el2] == NULL) { if (self->cpeStaticData[el2] == NULL) {
self->cpeStaticData[el2] = GetCpePersistentData(); self->cpeStaticData[el2] = GetCpePersistentData();
@ -2360,9 +2386,6 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
} }
} }
/* Update externally visible copy of flags */
self->streamInfo.flags = self->flags[0];
if (*configChanged) { if (*configChanged) {
int drcDecSampleRate, drcDecFrameSize; int drcDecSampleRate, drcDecFrameSize;
@ -2393,6 +2416,12 @@ CAacDecoder_Init(HANDLE_AACDECODER self, const CSAudioSpecificConfig *asc,
pcmLimiter_SetThreshold(self->hLimiter, FL2FXCONST_DBL(0.89125094f)); pcmLimiter_SetThreshold(self->hLimiter, FL2FXCONST_DBL(0.89125094f));
} }
CAacDecoder_AcceptFlags(self, asc, flags, elFlags, streamIndex,
elementOffset);
/* Update externally visible copy of flags */
self->streamInfo.flags = self->flags[0];
return err; return err;
bail: bail: