diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-03-04 15:52:49 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-03-04 15:52:49 +0100 |
commit | c7f9c2d1d996ac8f67927e9c86b907196ca6a72d (patch) | |
tree | a2dcc8e8cd3df5628f43242243fd475562ea4082 /libSACdec | |
parent | f665ac21b355ebc74c951c09b4774936a74fdca0 (diff) | |
parent | 95858d7bd36f19bde4a9595e2bd68f195215b164 (diff) | |
download | fdk-aac-c7f9c2d1d996ac8f67927e9c86b907196ca6a72d.tar.gz fdk-aac-c7f9c2d1d996ac8f67927e9c86b907196ca6a72d.tar.bz2 fdk-aac-c7f9c2d1d996ac8f67927e9c86b907196ca6a72d.zip |
Merge remote-tracking branch 'mstorjo/master' into dabplus2
Diffstat (limited to 'libSACdec')
-rw-r--r-- | libSACdec/include/sac_dec_lib.h | 6 | ||||
-rw-r--r-- | libSACdec/src/sac_bitdec.cpp | 36 | ||||
-rw-r--r-- | libSACdec/src/sac_dec_lib.cpp | 148 |
3 files changed, 141 insertions, 49 deletions
diff --git a/libSACdec/include/sac_dec_lib.h b/libSACdec/include/sac_dec_lib.h index 2797a10..9913279 100644 --- a/libSACdec/include/sac_dec_lib.h +++ b/libSACdec/include/sac_dec_lib.h @@ -315,9 +315,9 @@ SACDEC_ERROR mpegSurroundDecoder_Init( */ SACDEC_ERROR mpegSurroundDecoder_Config( CMpegSurroundDecoder *pMpegSurroundDecoder, HANDLE_FDK_BITSTREAM hBs, - AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT stereoConfigIndex, - INT coreSbrFrameLengthIndex, INT configBytes, const UCHAR configMode, - UCHAR *configChanged); + AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT frameSize, + INT stereoConfigIndex, INT coreSbrFrameLengthIndex, INT configBytes, + const UCHAR configMode, UCHAR *configChanged); SACDEC_ERROR mpegSurroundDecoder_ConfigureQmfDomain( diff --git a/libSACdec/src/sac_bitdec.cpp b/libSACdec/src/sac_bitdec.cpp index 37e0cf2..883e1e8 100644 --- a/libSACdec/src/sac_bitdec.cpp +++ b/libSACdec/src/sac_bitdec.cpp @@ -291,13 +291,13 @@ SACDEC_ERROR SpatialDecParseSpecificConfigHeader( if (sacHeaderLen == 127) { sacHeaderLen += FDKreadBits(bitstream, 16); } - numFillBits = FDKgetValidBits(bitstream); + numFillBits = (INT)FDKgetValidBits(bitstream); err = SpatialDecParseSpecificConfig(bitstream, pSpatialSpecificConfig, sacHeaderLen, coreCodec); numFillBits -= - FDKgetValidBits(bitstream); /* the number of read bits (tmpBits) */ + (INT)FDKgetValidBits(bitstream); /* the number of read bits (tmpBits) */ numFillBits = (8 * sacHeaderLen) - numFillBits; if (numFillBits < 0) { /* Parsing went wrong */ @@ -325,6 +325,8 @@ SACDEC_ERROR SpatialDecParseMps212Config( INT coreSbrFrameLengthIndex) { int i; + FDKmemclear(pSpatialSpecificConfig, sizeof(SPATIAL_SPECIFIC_CONFIG)); + pSpatialSpecificConfig->stereoConfigIndex = stereoConfigIndex; pSpatialSpecificConfig->coreSbrFrameLengthIndex = coreSbrFrameLengthIndex; pSpatialSpecificConfig->freqRes = @@ -447,6 +449,8 @@ SACDEC_ERROR SpatialDecParseSpecificConfig( int numHeaderBits; int cfgStartPos, bitsAvailable; + FDKmemclear(pSpatialSpecificConfig, sizeof(SPATIAL_SPECIFIC_CONFIG)); + cfgStartPos = FDKgetValidBits(bitstream); /* It might be that we do not know the SSC length beforehand. */ if (sacHeaderLen == 0) { @@ -513,6 +517,10 @@ SACDEC_ERROR SpatialDecParseSpecificConfig( pSpatialSpecificConfig->tempShapeConfig = (SPATIALDEC_TS_CONF)FDKreadBits(bitstream, 2); + if (pSpatialSpecificConfig->tempShapeConfig > 2) { + return MPS_PARSE_ERROR; /* reserved value */ + } + pSpatialSpecificConfig->decorrConfig = (SPATIALDEC_DECORR_CONF)FDKreadBits(bitstream, 2); if (pSpatialSpecificConfig->decorrConfig > 2) { @@ -568,16 +576,18 @@ SACDEC_ERROR SpatialDecParseSpecificConfig( numHeaderBits = cfgStartPos - (INT)FDKgetValidBits(bitstream); bitsAvailable -= numHeaderBits; + if (bitsAvailable < 0) { + err = MPS_PARSE_ERROR; + goto bail; + } pSpatialSpecificConfig->sacExtCnt = 0; pSpatialSpecificConfig->bResidualCoding = 0; - if ((err == MPS_OK) && (bitsAvailable > 0)) { - err = SpatialDecParseExtensionConfig( - bitstream, pSpatialSpecificConfig, pSpatialSpecificConfig->nOttBoxes, - pSpatialSpecificConfig->nTttBoxes, - pSpatialSpecificConfig->nOutputChannels, bitsAvailable); - } + err = SpatialDecParseExtensionConfig( + bitstream, pSpatialSpecificConfig, pSpatialSpecificConfig->nOttBoxes, + pSpatialSpecificConfig->nTttBoxes, + pSpatialSpecificConfig->nOutputChannels, bitsAvailable); FDKbyteAlign( bitstream, @@ -1864,6 +1874,16 @@ SACDEC_ERROR SpatialDecDecodeFrame(spatialDec *self, SPATIAL_BS_FRAME *frame) { frame->numParameterSets = fixMin(MAX_PARAMETER_SETS, frame->numParameterSets + 1); frame->paramSlot[frame->numParameterSets - 1] = self->timeSlots - 1; + + for (int p = 0; p < frame->numParameterSets; p++) { + if (frame->paramSlot[p] > self->timeSlots - 1) { + frame->paramSlot[p] = self->timeSlots - 1; + err = MPS_PARSE_ERROR; + } + } + if (err != MPS_OK) { + goto bail; + } } bail: diff --git a/libSACdec/src/sac_dec_lib.cpp b/libSACdec/src/sac_dec_lib.cpp index ebf9bee..5792858 100644 --- a/libSACdec/src/sac_dec_lib.cpp +++ b/libSACdec/src/sac_dec_lib.cpp @@ -237,6 +237,11 @@ struct MpegSurroundDecoder { SPATIAL_DEC_CONFIG decConfig; }; +SACDEC_ERROR +static sscCheckOutOfBand(const SPATIAL_SPECIFIC_CONFIG *pSsc, + const INT coreCodec, const INT sampleRate, + const INT frameSize); + static SACDEC_ERROR sscParseCheck(const SPATIAL_SPECIFIC_CONFIG *pSsc); /** @@ -694,11 +699,13 @@ bail: **/ SACDEC_ERROR mpegSurroundDecoder_Config( CMpegSurroundDecoder *pMpegSurroundDecoder, HANDLE_FDK_BITSTREAM hBs, - AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT stereoConfigIndex, - INT coreSbrFrameLengthIndex, INT configBytes, const UCHAR configMode, - UCHAR *configChanged) { + AUDIO_OBJECT_TYPE coreCodec, INT samplingRate, INT frameSize, + INT stereoConfigIndex, INT coreSbrFrameLengthIndex, INT configBytes, + const UCHAR configMode, UCHAR *configChanged) { SACDEC_ERROR err = MPS_OK; SPATIAL_SPECIFIC_CONFIG spatialSpecificConfig; + SPATIAL_SPECIFIC_CONFIG *pSsc = + &pMpegSurroundDecoder->spatialSpecificConfigBackup; switch (coreCodec) { case AOT_DRM_USAC: @@ -709,6 +716,7 @@ SACDEC_ERROR mpegSurroundDecoder_Config( err = SpatialDecParseMps212Config( hBs, &spatialSpecificConfig, samplingRate, coreCodec, stereoConfigIndex, coreSbrFrameLengthIndex); + pSsc = &spatialSpecificConfig; } else { err = SpatialDecParseMps212Config( hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup, @@ -723,6 +731,7 @@ SACDEC_ERROR mpegSurroundDecoder_Config( * into temporarily allocated structure */ err = SpatialDecParseSpecificConfig(hBs, &spatialSpecificConfig, configBytes, coreCodec); + pSsc = &spatialSpecificConfig; } else { err = SpatialDecParseSpecificConfig( hBs, &pMpegSurroundDecoder->spatialSpecificConfigBackup, @@ -738,14 +747,21 @@ SACDEC_ERROR mpegSurroundDecoder_Config( goto bail; } + err = sscCheckOutOfBand(pSsc, coreCodec, samplingRate, frameSize); + + if (err != MPS_OK) { + goto bail; + } + if (configMode & AC_CM_DET_CFG_CHANGE) { return err; } if (configMode & AC_CM_ALLOC_MEM) { if (*configChanged) { - if ((err = mpegSurroundDecoder_Open(&pMpegSurroundDecoder, - stereoConfigIndex, NULL))) { + err = mpegSurroundDecoder_Open(&pMpegSurroundDecoder, stereoConfigIndex, + NULL); + if (err) { return err; } } @@ -815,29 +831,9 @@ static MPEGS_OPMODE mpegSurroundOperationMode( * \return MPS_OK on sucess, and else on parse error. */ static SACDEC_ERROR sscParseCheck(const SPATIAL_SPECIFIC_CONFIG *pSsc) { - SACDEC_ERROR err = MPS_OK; - if (pSsc->samplingFreq > 96000) return MPS_PARSE_ERROR; if (pSsc->samplingFreq < 8000) return MPS_PARSE_ERROR; - switch (pSsc->freqRes) { - case SPATIALDEC_FREQ_RES_28: - case SPATIALDEC_FREQ_RES_20: - case SPATIALDEC_FREQ_RES_14: - case SPATIALDEC_FREQ_RES_10: - case SPATIALDEC_FREQ_RES_23: - case SPATIALDEC_FREQ_RES_15: - case SPATIALDEC_FREQ_RES_12: - case SPATIALDEC_FREQ_RES_9: - case SPATIALDEC_FREQ_RES_7: - case SPATIALDEC_FREQ_RES_5: - case SPATIALDEC_FREQ_RES_4: - break; - case SPATIALDEC_FREQ_RES_40: /* 40 doesn't exist in ISO/IEC 23003-1 */ - default: - return MPS_PARSE_ERROR; - } - if ((pSsc->treeConfig < 0) || (pSsc->treeConfig > 7)) { return MPS_PARSE_ERROR; } @@ -846,17 +842,9 @@ static SACDEC_ERROR sscParseCheck(const SPATIAL_SPECIFIC_CONFIG *pSsc) { return MPS_PARSE_ERROR; } - if (pSsc->tempShapeConfig == 3) { - return MPS_PARSE_ERROR; - } - - if (pSsc->decorrConfig == 3) { - return MPS_PARSE_ERROR; - } - /* now we are sure there were no parsing errors */ - return err; + return MPS_OK; } /** @@ -1024,6 +1012,11 @@ static SACDEC_ERROR sscCheckInBand(SPATIAL_SPECIFIC_CONFIG *pSsc, FDK_ASSERT(pSsc != NULL); + /* check ssc for parse errors */ + if (sscParseCheck(pSsc) != MPS_OK) { + err = MPS_PARSE_ERROR; + } + /* core fs and mps fs must match */ if (pSsc->samplingFreq != sampleRate) { err = MPS_PARSE_ERROR /* MPEGSDEC_SSC_PARSE_ERROR */; @@ -1087,12 +1080,90 @@ mpegSurroundDecoder_ConfigureQmfDomain( if (coreCodec == AOT_ER_AAC_ELD) { pGC->flags_requested |= QMF_FLAG_MPSLDFB; + pGC->flags_requested &= ~QMF_FLAG_CLDFB; } return err; } /** + * \brief Check out-of-band config + * + * \param pSsc spatial specific config handle. + * \param coreCodec core codec. + * \param sampleRate sampling frequency. + * + * \return errorStatus + */ +SACDEC_ERROR +sscCheckOutOfBand(const SPATIAL_SPECIFIC_CONFIG *pSsc, const INT coreCodec, + const INT sampleRate, const INT frameSize) { + FDK_ASSERT(pSsc != NULL); + int qmfBands = 0; + + /* check ssc for parse errors */ + if (sscParseCheck(pSsc) != MPS_OK) { + return MPS_PARSE_ERROR; + } + + switch (coreCodec) { + case AOT_USAC: + case AOT_DRM_USAC: + /* ISO/IEC 23003-1:2007(E), Chapter 6.3.3, Support for lower and higher + * sampling frequencies */ + if (pSsc->samplingFreq >= 55426) { + return MPS_PARSE_ERROR; + } + break; + case AOT_ER_AAC_LD: + case AOT_ER_AAC_ELD: + /* core fs and mps fs must match */ + if (pSsc->samplingFreq != sampleRate) { + return MPS_PARSE_ERROR; + } + + /* ISO/IEC 14496-3:2009 FDAM 3: Chapter 1.5.2.3, Levels for the Low Delay + * AAC v2 profile */ + if (pSsc->samplingFreq > 48000) { + return MPS_PARSE_ERROR; + } + + qmfBands = mpegSurroundDecoder_GetNrOfQmfBands(pSsc, pSsc->samplingFreq); + switch (frameSize) { + case 480: + if (!((qmfBands == 32) && (pSsc->nTimeSlots == 15))) { + return MPS_PARSE_ERROR; + } + break; + case 960: + if (!((qmfBands == 64) && (pSsc->nTimeSlots == 15))) { + return MPS_PARSE_ERROR; + } + break; + case 512: + if (!(((qmfBands == 32) && (pSsc->nTimeSlots == 16)) || + ((qmfBands == 64) && (pSsc->nTimeSlots == 8)))) { + return MPS_PARSE_ERROR; + } + break; + case 1024: + if (!((qmfBands == 64) && (pSsc->nTimeSlots == 16))) { + return MPS_PARSE_ERROR; + } + break; + default: + return MPS_PARSE_ERROR; + } + break; + default: + return MPS_PARSE_ERROR; + break; + } + + return MPS_OK; +} + +/** * \brief Decode MPEG Surround frame. **/ int mpegSurroundDecoder_ParseNoHeader( @@ -1232,7 +1303,7 @@ int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder, FDK_ASSERT(pMpegSurroundDecoder->pSpatialDec); - mpsBsBits = FDKgetValidBits(hBs); + mpsBsBits = (INT)FDKgetValidBits(hBs); sscParse = &pMpegSurroundDecoder ->spatialSpecificConfig[pMpegSurroundDecoder->bsFrameParse]; @@ -1308,14 +1379,14 @@ int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder, pMpegSurroundDecoder->spatialSpecificConfigBackup; /* Parse spatial specific config */ - bitsRead = FDKgetValidBits(hMpsBsData); + bitsRead = (INT)FDKgetValidBits(hMpsBsData); err = SpatialDecParseSpecificConfigHeader( hMpsBsData, &pMpegSurroundDecoder->spatialSpecificConfigBackup, coreCodec, pMpegSurroundDecoder->upmixType); - bitsRead = (bitsRead - FDKgetValidBits(hMpsBsData)); + bitsRead = (bitsRead - (INT)FDKgetValidBits(hMpsBsData)); parseResult = ((err == MPS_OK) ? bitsRead : -bitsRead); if (parseResult < 0) { @@ -1349,6 +1420,7 @@ int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder, pMpegSurroundDecoder->mpegSurroundSscIsGlobalCfg = 0; } } + FDK_FALLTHROUGH; case MPEGS_ANCTYPE_FRAME: if (pMpegSurroundDecoder @@ -1429,7 +1501,7 @@ int mpegSurroundDecoder_Parse(CMpegSurroundDecoder *pMpegSurroundDecoder, bail: - *pMpsDataBits -= (mpsBsBits - FDKgetValidBits(hBs)); + *pMpsDataBits -= (mpsBsBits - (INT)FDKgetValidBits(hBs)); return err; } |