aboutsummaryrefslogtreecommitdiffstats
path: root/libSBRdec/src/sbrdecoder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libSBRdec/src/sbrdecoder.cpp')
-rw-r--r--libSBRdec/src/sbrdecoder.cpp133
1 files changed, 60 insertions, 73 deletions
diff --git a/libSBRdec/src/sbrdecoder.cpp b/libSBRdec/src/sbrdecoder.cpp
index c827ced..b101a4a 100644
--- a/libSBRdec/src/sbrdecoder.cpp
+++ b/libSBRdec/src/sbrdecoder.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 - 2020 Fraunhofer-Gesellschaft zur Förderung der angewandten
Forschung e.V. All rights reserved.
1. INTRODUCTION
@@ -143,24 +143,22 @@ amm-info@iis.fraunhofer.de
#include "env_extr.h"
#include "sbr_dec.h"
#include "env_dec.h"
-#include "sbr_crc.h"
+#include "FDK_crc.h"
#include "sbr_ram.h"
#include "sbr_rom.h"
#include "lpp_tran.h"
#include "transcendent.h"
-#include "FDK_crc.h"
-
#include "sbrdec_drc.h"
#include "psbitdec.h"
/* Decoder library info */
#define SBRDECODER_LIB_VL0 3
-#define SBRDECODER_LIB_VL1 0
+#define SBRDECODER_LIB_VL1 1
#define SBRDECODER_LIB_VL2 0
#define SBRDECODER_LIB_TITLE "SBR Decoder"
-#ifdef __ANDROID__
+#ifdef SUPPRESS_BUILD_DATE_INFO
#define SBRDECODER_LIB_BUILD_DATE ""
#define SBRDECODER_LIB_BUILD_TIME ""
#else
@@ -619,10 +617,6 @@ SBR_ERROR sbrDecoder_InitElement(
self->numSbrChannels -= self->pSbrElement[elementIndex]->nChannels;
}
- /* Save element ID for sanity checks and to have a fallback for concealment.
- */
- self->pSbrElement[elementIndex]->elementID = elementID;
-
/* Determine amount of channels for this element */
switch (elementID) {
case ID_NONE:
@@ -655,12 +649,16 @@ SBR_ERROR sbrDecoder_InitElement(
}
/* Sanity check to avoid memory leaks */
- if (elChannels < self->pSbrElement[elementIndex]->nChannels) {
+ if (elChannels < self->pSbrElement[elementIndex]->nChannels ||
+ (self->numSbrChannels + elChannels) > (8) + (1)) {
self->numSbrChannels += self->pSbrElement[elementIndex]->nChannels;
sbrError = SBRDEC_PARSE_ERROR;
goto bail;
}
+ /* Save element ID for sanity checks and to have a fallback for concealment.
+ */
+ self->pSbrElement[elementIndex]->elementID = elementID;
self->pSbrElement[elementIndex]->nChannels = elChannels;
for (ch = 0; ch < elChannels; ch++) {
@@ -1134,18 +1132,22 @@ SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
SBR_HEADER_STATUS headerStatus = HEADER_NOT_PRESENT;
INT startPos = FDKgetValidBits(hBs);
- INT CRCLen = 0;
+ FDK_CRCINFO crcInfo;
+ INT crcReg = 0;
+ USHORT sbrCrc = 0;
+ UINT crcPoly;
+ UINT crcStartValue = 0;
+ UINT crcLen;
+
HANDLE_FDK_BITSTREAM hBsOriginal = hBs;
FDK_BITSTREAM bsBwd;
- FDK_CRCINFO crcInfo;
- INT crcReg = 0;
- USHORT drmSbrCrc = 0;
const int fGlobalIndependencyFlag = acFlags & AC_INDEP;
const int bs_pvc = acElFlags[elementIndex] & AC_EL_USAC_PVC;
const int bs_interTes = acElFlags[elementIndex] & AC_EL_USAC_ITES;
int stereo;
int fDoDecodeSbrData = 1;
+ int alignBits = 0;
int lastSlot, lastHdrSlot = 0, thisHdrSlot = 0;
@@ -1277,27 +1279,23 @@ SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
if (fDoDecodeSbrData) {
if (crcFlag) {
switch (self->coreCodec) {
- case AOT_ER_AAC_ELD:
- FDKpushFor(hBs, 10);
- /* check sbrcrc later: we don't know the payload length now */
- break;
case AOT_DRM_AAC:
case AOT_DRM_SURROUND:
- drmSbrCrc = (USHORT)FDKreadBits(hBs, 8);
- /* Setup CRC decoder */
- FDKcrcInit(&crcInfo, 0x001d, 0xFFFF, 8);
- /* Start CRC region */
- crcReg = FDKcrcStartReg(&crcInfo, hBs, 0);
+ crcPoly = 0x001d;
+ crcLen = 8;
+ crcStartValue = 0x000000ff;
break;
default:
- CRCLen = bsPayLen - 10; /* change: 0 => i */
- if (CRCLen < 0) {
- fDoDecodeSbrData = 0;
- } else {
- fDoDecodeSbrData = SbrCrcCheck(hBs, CRCLen);
- }
+ crcPoly = 0x0633;
+ crcLen = 10;
+ crcStartValue = 0x00000000;
break;
}
+ sbrCrc = (USHORT)FDKreadBits(hBs, crcLen);
+ /* Setup CRC decoder */
+ FDKcrcInit(&crcInfo, crcPoly, crcStartValue, crcLen);
+ /* Start CRC region */
+ crcReg = FDKcrcStartReg(&crcInfo, hBs, 0);
}
} /* if (fDoDecodeSbrData) */
@@ -1450,35 +1448,6 @@ SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
valBits = (INT)FDKgetValidBits(hBs);
}
- if (crcFlag) {
- switch (self->coreCodec) {
- case AOT_ER_AAC_ELD: {
- /* late crc check for eld */
- INT payloadbits =
- (INT)startPos - (INT)FDKgetValidBits(hBs) - startPos;
- INT crcLen = payloadbits - 10;
- FDKpushBack(hBs, payloadbits);
- fDoDecodeSbrData = SbrCrcCheck(hBs, crcLen);
- FDKpushFor(hBs, crcLen);
- } break;
- case AOT_DRM_AAC:
- case AOT_DRM_SURROUND:
- /* End CRC region */
- FDKcrcEndReg(&crcInfo, hBs, crcReg);
- /* Check CRC */
- if ((FDKcrcGetCRC(&crcInfo) ^ 0xFF) != drmSbrCrc) {
- fDoDecodeSbrData = 0;
- if (headerStatus != HEADER_NOT_PRESENT) {
- headerStatus = HEADER_ERROR;
- hSbrHeader->syncState = SBR_NOT_INITIALIZED;
- }
- }
- break;
- default:
- break;
- }
- }
-
/* sanity check of remaining bits */
if (valBits < 0) {
fDoDecodeSbrData = 0;
@@ -1489,7 +1458,7 @@ SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
case AOT_AAC_LC: {
/* This sanity check is only meaningful with General Audio
* bitstreams */
- int alignBits = valBits & 0x7;
+ alignBits = valBits & 0x7;
if (valBits > alignBits) {
fDoDecodeSbrData = 0;
@@ -1508,6 +1477,20 @@ SBR_ERROR sbrDecoder_Parse(HANDLE_SBRDECODER self, HANDLE_FDK_BITSTREAM hBs,
errorStatus = SBRDEC_PARSE_ERROR;
}
+ if (crcFlag && (hSbrHeader->syncState >= SBR_HEADER) && fDoDecodeSbrData) {
+ FDKpushFor(hBs, alignBits);
+ FDKcrcEndReg(&crcInfo, hBs, crcReg); /* End CRC region */
+ FDKpushBack(hBs, alignBits);
+ /* Check CRC */
+ if ((FDKcrcGetCRC(&crcInfo) ^ crcStartValue) != sbrCrc) {
+ fDoDecodeSbrData = 0;
+ if (headerStatus != HEADER_NOT_PRESENT) {
+ headerStatus = HEADER_ERROR;
+ hSbrHeader->syncState = SBR_NOT_INITIALIZED;
+ }
+ }
+ }
+
if (!fDoDecodeSbrData) {
/* Set error flag for this slot to trigger concealment */
setFrameErrorFlag(self->pSbrElement[elementIndex], FRAME_ERROR);
@@ -1587,10 +1570,10 @@ bail:
* \return SBRDEC_OK if successfull, else error code
*/
static SBR_ERROR sbrDecoder_DecodeElement(
- HANDLE_SBRDECODER self, QDOM_PCM *input, INT_PCM *timeData,
- const int timeDataSize, const FDK_channelMapDescr *const mapDescr,
- const int mapIdx, int channelIndex, const int elementIndex,
- const int numInChannels, int *numOutChannels, const int psPossible) {
+ HANDLE_SBRDECODER self, LONG *input, LONG *timeData, const int timeDataSize,
+ const FDK_channelMapDescr *const mapDescr, const int mapIdx,
+ int channelIndex, const int elementIndex, const int numInChannels,
+ int *numOutChannels, const int psPossible) {
SBR_DECODER_ELEMENT *hSbrElement = self->pSbrElement[elementIndex];
HANDLE_SBR_CHANNEL *pSbrChannel =
self->pSbrElement[elementIndex]->pSbrChannel;
@@ -1760,7 +1743,7 @@ static SBR_ERROR sbrDecoder_DecodeElement(
timeData + offset1, strideOut, hSbrHeader, hFrameDataLeft,
&pSbrChannel[0]->prevFrameData,
(hSbrHeader->syncState == SBR_ACTIVE), h_ps_d, self->flags,
- codecFrameSize);
+ codecFrameSize, self->sbrInDataHeadroom);
if (stereo) {
/* Process right channel */
@@ -1768,7 +1751,7 @@ static SBR_ERROR sbrDecoder_DecodeElement(
timeData + offset1, NULL, NULL, strideOut, hSbrHeader,
hFrameDataRight, &pSbrChannel[1]->prevFrameData,
(hSbrHeader->syncState == SBR_ACTIVE), NULL, self->flags,
- codecFrameSize);
+ codecFrameSize, self->sbrInDataHeadroom);
}
C_ALLOC_SCRATCH_END(pPsScratch, struct PS_DEC_COEFFICIENTS, 1)
@@ -1788,14 +1771,14 @@ static SBR_ERROR sbrDecoder_DecodeElement(
int copyFrameSize =
codecFrameSize * self->pQmfDomain->QmfDomainOut->fb.no_channels;
copyFrameSize /= self->pQmfDomain->QmfDomainIn->fb.no_channels;
- INT_PCM *ptr;
+ LONG *ptr;
INT i;
FDK_ASSERT(strideOut == 2);
ptr = timeData;
for (i = copyFrameSize >> 1; i--;) {
- INT_PCM tmp; /* This temporal variable is required because some
- compilers can't do *ptr++ = *ptr++ correctly. */
+ LONG tmp; /* This temporal variable is required because some compilers
+ can't do *ptr++ = *ptr++ correctly. */
tmp = *ptr++;
*ptr++ = tmp;
tmp = *ptr++;
@@ -1808,12 +1791,13 @@ static SBR_ERROR sbrDecoder_DecodeElement(
return errorStatus;
}
-SBR_ERROR sbrDecoder_Apply(HANDLE_SBRDECODER self, INT_PCM *input,
- INT_PCM *timeData, const int timeDataSize,
- int *numChannels, int *sampleRate,
+SBR_ERROR sbrDecoder_Apply(HANDLE_SBRDECODER self, LONG *input, LONG *timeData,
+ const int timeDataSize, int *numChannels,
+ int *sampleRate,
const FDK_channelMapDescr *const mapDescr,
const int mapIdx, const int coreDecodedOk,
- UCHAR *psDecoded) {
+ UCHAR *psDecoded, const INT inDataHeadroom,
+ INT *outDataHeadroom) {
SBR_ERROR errorStatus = SBRDEC_OK;
int psPossible;
@@ -1850,6 +1834,9 @@ SBR_ERROR sbrDecoder_Apply(HANDLE_SBRDECODER self, INT_PCM *input,
psPossible = 0;
}
+ self->sbrInDataHeadroom = inDataHeadroom;
+ *outDataHeadroom = (INT)(8);
+
/* Make sure that even if no SBR data was found/parsed *psDecoded is returned
* 1 if psPossible was 0. */
if (psPossible == 0) {