2 /* -----------------------------------------------------------------------------------------------------------
3 Software License for The Fraunhofer FDK AAC Codec Library for Android
5 © Copyright 1995 - 2013 Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16 of the MPEG specifications.
18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20 individually for the purpose of encoding or decoding bit streams in products that are compliant with
21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23 software may already be covered under those patent licenses when it is used for those licensed purposes only.
25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27 applications information and documentation.
31 Redistribution and use in source and binary forms, with or without modification, are permitted without
32 payment of copyright license fees provided that you satisfy the following conditions:
34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35 your modifications thereto in source code form.
37 You must retain the complete text of this software license in the documentation and/or other materials
38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40 modifications thereto to recipients of copies in binary form.
42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43 prior written permission.
45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46 software or your modifications thereto.
48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49 and the date of any change. For modified versions of the FDK AAC Codec, the term
50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57 respect to this software.
59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60 by appropriate patent licenses.
64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69 or business interruption, however caused and on any theory of liability, whether in contract, strict
70 liability, or tort (including negligence), arising in any way out of the use of this software, even if
71 advised of the possibility of such damage.
73 5. CONTACT INFORMATION
75 Fraunhofer Institute for Integrated Circuits IIS
76 Attention: Audio and Multimedia Departments - FDK AAC LL
78 91058 Erlangen, Germany
80 www.iis.fraunhofer.de/amm
81 amm-info@iis.fraunhofer.de
82 ----------------------------------------------------------------------------------------------------------- */
84 /***************************** MPEG-4 AAC Decoder **************************
86 Author(s): Manuel Jander
89 ******************************************************************************/
91 #include "aacdecoder_lib.h"
94 #include "aacdecoder.h"
95 #include "tpdec_lib.h"
96 #include "FDK_core.h" /* FDK_tools version info */
99 #include "sbrdecoder.h"
106 #include "aacdec_drc.h"
110 /* Decoder library info */
111 #define AACDECODER_LIB_VL0 2
112 #define AACDECODER_LIB_VL1 5
113 #define AACDECODER_LIB_VL2 5
114 #define AACDECODER_LIB_TITLE "AAC Decoder Lib"
115 #define AACDECODER_LIB_BUILD_DATE __DATE__
116 #define AACDECODER_LIB_BUILD_TIME __TIME__
118 static AAC_DECODER_ERROR
119 setConcealMethod ( const HANDLE_AACDECODER self
,
123 LINKSPEC_CPP AAC_DECODER_ERROR
aacDecoder_GetFreeBytes ( const HANDLE_AACDECODER self
, UINT
*pFreeBytes
){
125 /* reset free bytes */
130 return AAC_DEC_INVALID_HANDLE
;
132 /* return nr of free bytes */
133 HANDLE_FDK_BITSTREAM hBs
= transportDec_GetBitstream(self
->hInput
, 0);
134 *pFreeBytes
= FDKgetFreeBits(hBs
) >> 3;
141 * Config Decoder using a CSAudioSpecificConfig struct.
144 LINKSPEC_CPP AAC_DECODER_ERROR
aacDecoder_Config(HANDLE_AACDECODER self
, const CSAudioSpecificConfig
*pAscStruct
)
146 AAC_DECODER_ERROR err
;
148 /* Initialize AAC core decoder, and update self->streaminfo */
149 err
= CAacDecoder_Init(self
, pAscStruct
);
154 LINKSPEC_CPP AAC_DECODER_ERROR
aacDecoder_ConfigRaw (
155 HANDLE_AACDECODER self
,
157 const UINT length
[] )
159 AAC_DECODER_ERROR err
= AAC_DEC_OK
;
160 TRANSPORTDEC_ERROR errTp
;
161 UINT layer
, nrOfLayers
= self
->nrOfLayers
;
163 for(layer
= 0; layer
< nrOfLayers
; layer
++){
164 if(length
[layer
] > 0){
165 errTp
= transportDec_OutOfBandConfig(self
->hInput
, conf
[layer
], length
[layer
], layer
);
166 if (errTp
!= TRANSPORTDEC_OK
) {
168 case TRANSPORTDEC_NEED_TO_RESTART
:
169 err
= AAC_DEC_NEED_TO_RESTART
;
171 case TRANSPORTDEC_UNSUPPORTED_FORMAT
:
172 err
= AAC_DEC_UNSUPPORTED_FORMAT
;
175 err
= AAC_DEC_UNKNOWN
;
178 /* if baselayer is OK we continue decoding */
180 self
->nrOfLayers
= layer
;
192 static INT
aacDecoder_ConfigCallback(void *handle
, const CSAudioSpecificConfig
*pAscStruct
)
194 HANDLE_AACDECODER self
= (HANDLE_AACDECODER
)handle
;
195 AAC_DECODER_ERROR err
= AAC_DEC_OK
;
196 TRANSPORTDEC_ERROR errTp
;
200 err
= aacDecoder_Config(self
, pAscStruct
);
203 if (err
== AAC_DEC_OK
) {
204 if ( self
->flags
& (AC_USAC
|AC_RSVD50
|AC_LD
|AC_ELD
)
205 && CConcealment_GetDelay(&self
->concealCommonData
) > 0 )
207 /* Revert to error concealment method Noise Substitution.
208 Because interpolation is not implemented for USAC/RSVD50 or
209 the additional delay is unwanted for low delay codecs. */
210 setConcealMethod(self
, 1);
212 FDKprintf(" Concealment method was reverted to 1 !\n");
215 errTp
= TRANSPORTDEC_OK
;
217 if (IS_INIT_ERROR(err
)) {
218 errTp
= TRANSPORTDEC_UNSUPPORTED_FORMAT
;
220 else if (err
== AAC_DEC_NEED_TO_RESTART
) {
221 errTp
= TRANSPORTDEC_NEED_TO_RESTART
;
223 errTp
= TRANSPORTDEC_UNKOWN_ERROR
;
232 LINKSPEC_CPP AAC_DECODER_ERROR
233 aacDecoder_AncDataInit ( HANDLE_AACDECODER self
,
237 CAncData
*ancData
= &self
->ancData
;
239 return CAacDecoder_AncDataInit(ancData
, buffer
, size
);
243 LINKSPEC_CPP AAC_DECODER_ERROR
244 aacDecoder_AncDataGet ( HANDLE_AACDECODER self
,
249 CAncData
*ancData
= &self
->ancData
;
251 return CAacDecoder_AncDataGet(ancData
, index
, ptr
, size
);
255 static AAC_DECODER_ERROR
256 setConcealMethod ( const HANDLE_AACDECODER self
, /*!< Handle of the decoder instance */
259 AAC_DECODER_ERROR errorStatus
= AAC_DEC_OK
;
260 CConcealParams
*pConcealData
= NULL
;
261 HANDLE_SBRDECODER hSbrDec
= NULL
;
262 HANDLE_AAC_DRC hDrcInfo
= NULL
;
263 HANDLE_PCM_DOWNMIX hPcmDmx
= NULL
;
264 CConcealmentMethod backupMethod
= ConcealMethodNone
;
268 /* check decoder handle */
270 pConcealData
= &self
->concealCommonData
;
271 hSbrDec
= self
->hSbrDecoder
;
272 hDrcInfo
= self
->hDrcInfo
;
273 hPcmDmx
= self
->hPcmUtils
;
277 /* Get current method/delay */
278 backupMethod
= CConcealment_GetMethod(pConcealData
);
279 backupDelay
= CConcealment_GetDelay(pConcealData
);
281 /* Be sure to set AAC and SBR concealment method simultaneously! */
283 CConcealment_SetParams(
285 (int)method
, // concealMethod
286 AACDEC_CONCEAL_PARAM_NOT_SPECIFIED
, // concealFadeOutSlope
287 AACDEC_CONCEAL_PARAM_NOT_SPECIFIED
, // concealFadeInSlope
288 AACDEC_CONCEAL_PARAM_NOT_SPECIFIED
, // concealMuteRelease
289 AACDEC_CONCEAL_PARAM_NOT_SPECIFIED
// concealComfNoiseLevel
291 if ( (errorStatus
!= AAC_DEC_OK
)
292 && (errorStatus
!= AAC_DEC_INVALID_HANDLE
) ) {
297 bsDelay
= CConcealment_GetDelay(pConcealData
);
300 SBR_ERROR sbrErr
= SBRDEC_OK
;
302 /* set SBR bitstream delay */
303 sbrErr
= sbrDecoder_SetParam (
305 SBR_SYSTEM_BITSTREAM_DELAY
,
311 case SBRDEC_NOT_INITIALIZED
:
313 /* save the param value and set later
314 (when SBR has been initialized) */
315 self
->sbrParams
.bsDelay
= bsDelay
;
319 errorStatus
= AAC_DEC_SET_PARAM_FAIL
;
325 aacDecoder_drcSetParam (
330 if ( (errorStatus
!= AAC_DEC_OK
)
331 && (errorStatus
!= AAC_DEC_INVALID_HANDLE
) ) {
335 if (errorStatus
== AAC_DEC_OK
) {
343 case PCMDMX_INVALID_HANDLE
:
344 errorStatus
= AAC_DEC_INVALID_HANDLE
;
348 errorStatus
= AAC_DEC_SET_PARAM_FAIL
;
355 if ( (errorStatus
!= AAC_DEC_OK
)
356 && (errorStatus
!= AAC_DEC_INVALID_HANDLE
) )
358 /* Revert to the initial state */
359 CConcealment_SetParams (
362 AACDEC_CONCEAL_PARAM_NOT_SPECIFIED
,
363 AACDEC_CONCEAL_PARAM_NOT_SPECIFIED
,
364 AACDEC_CONCEAL_PARAM_NOT_SPECIFIED
,
365 AACDEC_CONCEAL_PARAM_NOT_SPECIFIED
367 /* Revert SBR bitstream delay */
368 sbrDecoder_SetParam (
370 SBR_SYSTEM_BITSTREAM_DELAY
,
373 /* Revert DRC bitstream delay */
374 aacDecoder_drcSetParam (
379 /* Revert PCM mixdown bitstream delay */
391 LINKSPEC_CPP AAC_DECODER_ERROR
392 aacDecoder_SetParam ( const HANDLE_AACDECODER self
, /*!< Handle of the decoder instance */
393 const AACDEC_PARAM param
, /*!< Parameter to set */
394 const INT value
) /*!< Parameter valued */
396 AAC_DECODER_ERROR errorStatus
= AAC_DEC_OK
;
397 CConcealParams
*pConcealData
= NULL
;
398 HANDLE_AAC_DRC hDrcInfo
= NULL
;
399 HANDLE_PCM_DOWNMIX hPcmDmx
= NULL
;
401 /* check decoder handle */
403 pConcealData
= &self
->concealCommonData
;
404 hDrcInfo
= self
->hDrcInfo
;
405 hPcmDmx
= self
->hPcmUtils
;
407 errorStatus
= AAC_DEC_INVALID_HANDLE
;
410 /* configure the subsystems */
413 case AAC_PCM_OUTPUT_INTERLEAVED
:
414 if (value
< 0 || value
> 1) {
415 return AAC_DEC_SET_PARAM_FAIL
;
418 return AAC_DEC_INVALID_HANDLE
;
420 self
->outputInterleaved
= value
;
423 case AAC_PCM_OUTPUT_CHANNELS
:
424 if (value
< -1 || value
> (6)) {
425 return AAC_DEC_SET_PARAM_FAIL
;
430 err
= pcmDmx_SetParam (
432 NUMBER_OF_OUTPUT_CHANNELS
,
438 case PCMDMX_INVALID_HANDLE
:
439 return AAC_DEC_INVALID_HANDLE
;
441 return AAC_DEC_SET_PARAM_FAIL
;
446 case AAC_PCM_DUAL_CHANNEL_OUTPUT_MODE
:
450 err
= pcmDmx_SetParam (
452 DUAL_CHANNEL_DOWNMIX_MODE
,
458 case PCMDMX_INVALID_HANDLE
:
459 return AAC_DEC_INVALID_HANDLE
;
461 return AAC_DEC_SET_PARAM_FAIL
;
466 case AAC_PCM_OUTPUT_CHANNEL_MAPPING
:
470 self
->channelOutputMapping
= channelMappingTablePassthrough
;
475 self
->channelOutputMapping
= channelMappingTableWAV
;
479 errorStatus
= AAC_DEC_SET_PARAM_FAIL
;
485 case AAC_QMF_LOWPOWER
:
486 if (value
< -1 || value
> 1) {
487 return AAC_DEC_SET_PARAM_FAIL
;
490 return AAC_DEC_INVALID_HANDLE
;
494 * Set QMF mode (might be overriden)
496 * 1:LP (partially complex)
498 self
->qmfModeUser
= (QMF_MODE
)value
;
502 case AAC_DRC_ATTENUATION_FACTOR
:
503 /* DRC compression factor (where 0 is no and 127 is max compression) */
505 aacDecoder_drcSetParam (
512 case AAC_DRC_BOOST_FACTOR
:
513 /* DRC boost factor (where 0 is no and 127 is max boost) */
515 aacDecoder_drcSetParam (
522 case AAC_DRC_REFERENCE_LEVEL
:
523 /* DRC reference level quantized in 0.25dB steps using values [0..127] it is '-' for analog scaling */
525 aacDecoder_drcSetParam (
532 case AAC_DRC_HEAVY_COMPRESSION
:
533 /* Don't need to overwrite cut/boost values */
535 aacDecoder_drcSetParam (
537 APPLY_HEAVY_COMPRESSION
,
543 case AAC_TPDEC_CLEAR_BUFFER
:
544 transportDec_SetParam(self
->hInput
, TPDEC_PARAM_RESET
, 1);
545 self
->streamInfo
.numLostAccessUnits
= 0;
546 self
->streamInfo
.numBadBytes
= 0;
547 self
->streamInfo
.numTotalBytes
= 0;
548 /* aacDecoder_SignalInterruption(self); */
551 case AAC_CONCEAL_METHOD
:
552 /* Changing the concealment method can introduce additional bitstream delay. And
553 that in turn affects sub libraries and modules which makes the whole thing quite
554 complex. So the complete changing routine is packed into a helper function which
555 keeps all modules and libs in a consistent state even in the case an error occures. */
556 errorStatus
= setConcealMethod ( self
, value
);
560 return AAC_DEC_SET_PARAM_FAIL
;
561 } /* switch(param) */
563 return (errorStatus
);
567 LINKSPEC_CPP HANDLE_AACDECODER
aacDecoder_Open(TRANSPORT_TYPE transportFmt
, UINT nrOfLayers
)
569 AAC_DECODER_INSTANCE
*aacDec
= NULL
;
570 HANDLE_TRANSPORTDEC pIn
;
573 /* Allocate transport layer struct. */
574 pIn
= transportDec_Open(transportFmt
, TP_FLAG_MPEG4
);
579 transportDec_SetParam(pIn
, TPDEC_PARAM_IGNORE_BUFFERFULLNESS
, 1);
581 /* Allocate AAC decoder core struct. */
582 aacDec
= CAacDecoder_Open(transportFmt
);
584 if (aacDec
== NULL
) {
585 transportDec_Close(&pIn
);
588 aacDec
->hInput
= pIn
;
590 aacDec
->nrOfLayers
= nrOfLayers
;
592 aacDec
->channelOutputMapping
= channelMappingTableWAV
;
594 /* Register Config Update callback. */
595 transportDec_RegisterAscCallback(pIn
, aacDecoder_ConfigCallback
, (void*)aacDec
);
597 /* open SBR decoder */
598 if ( SBRDEC_OK
!= sbrDecoder_Open ( &aacDec
->hSbrDecoder
)) {
602 aacDec
->qmfModeUser
= NOT_DEFINED
;
603 transportDec_RegisterSbrCallback(aacDec
->hInput
, (cbSbr_t
)sbrDecoder_Header
, (void*)aacDec
->hSbrDecoder
);
606 pcmDmx_Open( &aacDec
->hPcmUtils
);
607 if (aacDec
->hPcmUtils
== NULL
) {
614 /* Assure that all modules have same delay */
615 if ( setConcealMethod(aacDec
, CConcealment_GetMethod(&aacDec
->concealCommonData
)) ) {
622 aacDecoder_Close(aacDec
);
628 LINKSPEC_CPP AAC_DECODER_ERROR
aacDecoder_Fill(
629 HANDLE_AACDECODER self
,
631 const UINT bufferSize
[],
635 TRANSPORTDEC_ERROR tpErr
;
636 /* loop counter for layers; if not TT_MP4_RAWPACKETS used as index for only
639 INT nrOfLayers
= self
->nrOfLayers
;
642 for (layer
= 0; layer
< nrOfLayers
; layer
++){
644 tpErr
= transportDec_FillData( self
->hInput
, pBuffer
[layer
], bufferSize
[layer
], &pBytesValid
[layer
], layer
);
645 if (tpErr
!= TRANSPORTDEC_OK
) {
646 return AAC_DEC_UNKNOWN
; /* Must be an internal error */
656 static void aacDecoder_SignalInterruption(HANDLE_AACDECODER self
)
658 CAacDecoder_SignalInterruption(self
);
660 if ( self
->hSbrDecoder
!= NULL
) {
661 sbrDecoder_SetParam(self
->hSbrDecoder
, SBR_BS_INTERRUPTION
, 0);
665 static void aacDecoder_UpdateBitStreamCounters(CStreamInfo
*pSi
, HANDLE_FDK_BITSTREAM hBs
, int nBits
, AAC_DECODER_ERROR ErrorStatus
)
667 /* calculate bit difference (amount of bits moved forward) */
668 nBits
= nBits
- FDKgetValidBits(hBs
);
670 /* Note: The amount of bits consumed might become negative when parsing a
671 bit stream with several sub frames, and we find out at the last sub frame
672 that the total frame length does not match the sum of sub frame length.
673 If this happens, the transport decoder might want to rewind to the supposed
674 ending of the transport frame, and this position might be before the last
675 access unit beginning. */
678 if (pSi
->frameSize
> 0) {
679 pSi
->bitRate
= (nBits
* pSi
->sampleRate
)/pSi
->frameSize
;
682 /* bit/byte counters */
687 pSi
->numTotalBytes
+= nBytes
;
688 if (IS_OUTPUT_VALID(ErrorStatus
)) {
689 pSi
->numTotalAccessUnits
++;
691 if (IS_DECODE_ERROR(ErrorStatus
)) {
692 pSi
->numBadBytes
+= nBytes
;
693 pSi
->numBadAccessUnits
++;
698 static INT
aacDecoder_EstimateNumberOfLostFrames(HANDLE_AACDECODER self
)
702 transportDec_GetMissingAccessUnitCount( &n
, self
->hInput
);
707 LINKSPEC_CPP AAC_DECODER_ERROR
aacDecoder_DecodeFrame(
708 HANDLE_AACDECODER self
,
710 const INT timeDataSize
,
713 AAC_DECODER_ERROR ErrorStatus
;
716 INT interleaved
= self
->outputInterleaved
;
717 HANDLE_FDK_BITSTREAM hBs
;
718 int fTpInterruption
= 0; /* Transport originated interruption detection. */
719 int fTpConceal
= 0; /* Transport originated concealment. */
723 return AAC_DEC_INVALID_HANDLE
;
726 if (flags
& AACDEC_INTR
) {
727 self
->streamInfo
.numLostAccessUnits
= 0;
730 hBs
= transportDec_GetBitstream(self
->hInput
, 0);
732 /* Get current bits position for bitrate calculation. */
733 nBits
= FDKgetValidBits(hBs
);
734 if (! (flags
& (AACDEC_CONCEAL
| AACDEC_FLUSH
) ) )
736 TRANSPORTDEC_ERROR err
;
738 for(layer
= 0; layer
< self
->nrOfLayers
; layer
++)
740 err
= transportDec_ReadAccessUnit(self
->hInput
, layer
);
741 if (err
!= TRANSPORTDEC_OK
) {
743 case TRANSPORTDEC_NOT_ENOUGH_BITS
:
744 ErrorStatus
= AAC_DEC_NOT_ENOUGH_BITS
;
746 case TRANSPORTDEC_SYNC_ERROR
:
747 self
->streamInfo
.numLostAccessUnits
= aacDecoder_EstimateNumberOfLostFrames(self
);
750 case TRANSPORTDEC_NEED_TO_RESTART
:
751 ErrorStatus
= AAC_DEC_NEED_TO_RESTART
;
753 case TRANSPORTDEC_CRC_ERROR
:
757 ErrorStatus
= AAC_DEC_UNKNOWN
;
763 if (self
->streamInfo
.numLostAccessUnits
> 0) {
764 self
->streamInfo
.numLostAccessUnits
--;
768 /* Signal bit stream interruption to other modules if required. */
769 if ( fTpInterruption
|| (flags
& (AACDEC_INTR
|AACDEC_CLRHIST
)) )
771 aacDecoder_SignalInterruption(self
);
772 if ( ! (flags
& AACDEC_INTR
) ) {
773 ErrorStatus
= AAC_DEC_TRANSPORT_SYNC_ERROR
;
778 /* Empty bit buffer in case of flush request. */
779 if (flags
& AACDEC_FLUSH
)
781 transportDec_SetParam(self
->hInput
, TPDEC_PARAM_RESET
, 1);
782 self
->streamInfo
.numLostAccessUnits
= 0;
783 self
->streamInfo
.numBadBytes
= 0;
784 self
->streamInfo
.numTotalBytes
= 0;
788 ErrorStatus
= CAacDecoder_DecodeFrame(self
,
789 flags
| (fTpConceal
? AACDEC_CONCEAL
: 0),
794 if (!(flags
& (AACDEC_CONCEAL
|AACDEC_FLUSH
))) {
795 TRANSPORTDEC_ERROR tpErr
;
796 tpErr
= transportDec_EndAccessUnit(self
->hInput
);
797 if (tpErr
!= TRANSPORTDEC_OK
) {
802 /* If the current pTimeData does not contain a valid signal, there nothing else we can do, so bail. */
803 if ( ! IS_OUTPUT_VALID(ErrorStatus
) ) {
808 /* Export data into streaminfo structure */
809 self
->streamInfo
.sampleRate
= self
->streamInfo
.aacSampleRate
;
810 self
->streamInfo
.frameSize
= self
->streamInfo
.aacSamplesPerFrame
;
812 self
->streamInfo
.numChannels
= self
->streamInfo
.aacNumChannels
;
816 CAacDecoder_SyncQmfMode(self
);
820 if (ErrorStatus
|| (flags
& AACDEC_CONCEAL
) || self
->pAacDecoderStaticChannelInfo
[0]->concealmentInfo
.concealState
> ConcealState_FadeIn
)
822 self
->frameOK
= 0; /* if an error has occured do concealment in the SBR decoder too */
825 if (self
->sbrEnabled
)
827 SBR_ERROR sbrError
= SBRDEC_OK
;
830 sbrDecoder_SetParam ( self
->hSbrDecoder
,
831 SBR_SYSTEM_BITSTREAM_DELAY
,
832 self
->sbrParams
.bsDelay
);
834 if ( self
->streamInfo
.aot
== AOT_ER_AAC_ELD
) {
836 sbrDecoder_SetParam ( self
->hSbrDecoder
,
837 SBR_LD_QMF_TIME_ALIGN
,
838 (self
->flags
& AC_LD_MPS
) ? 1 : 0 );
844 /* apply SBR processing */
845 sbrError
= sbrDecoder_Apply ( self
->hSbrDecoder
,
847 &self
->streamInfo
.numChannels
,
848 &self
->streamInfo
.sampleRate
,
849 self
->channelOutputMapping
[self
->streamInfo
.numChannels
-1],
855 if (sbrError
== SBRDEC_OK
) {
857 /* Update data in streaminfo structure. Assume that the SBR upsampling factor is either 1 or 2 */
858 self
->flags
|= AC_SBR_PRESENT
;
859 if (self
->streamInfo
.aacSampleRate
!= self
->streamInfo
.sampleRate
) {
860 if (self
->streamInfo
.frameSize
== 768) {
861 self
->streamInfo
.frameSize
= (self
->streamInfo
.aacSamplesPerFrame
* 8) / 3;
863 self
->streamInfo
.frameSize
= self
->streamInfo
.aacSamplesPerFrame
<< 1;
867 if (self
->psPossible
) {
868 self
->flags
|= AC_PS_PRESENT
;
869 self
->channelType
[0] = ACT_FRONT
;
870 self
->channelType
[1] = ACT_FRONT
;
871 self
->channelIndices
[0] = 0;
872 self
->channelIndices
[1] = 1;
874 self
->flags
&= ~AC_PS_PRESENT
;
880 if ( flags
& (AACDEC_INTR
| AACDEC_CLRHIST
) ) {
881 /* delete data from the past (e.g. mixdown coeficients) */
882 pcmDmx_Reset( self
->hPcmUtils
, PCMDMX_RESET_BS_DATA
);
884 /* do PCM post processing */
888 self
->streamInfo
.frameSize
,
889 &self
->streamInfo
.numChannels
,
892 self
->channelIndices
,
893 self
->channelOutputMapping
898 /* Signal interruption to take effect in next frame. */
899 if ( flags
& AACDEC_FLUSH
) {
900 aacDecoder_SignalInterruption(self
);
903 /* Update externally visible copy of flags */
904 self
->streamInfo
.flags
= self
->flags
;
908 /* Update Statistics */
909 aacDecoder_UpdateBitStreamCounters(&self
->streamInfo
, hBs
, nBits
, ErrorStatus
);
914 LINKSPEC_CPP
void aacDecoder_Close ( HANDLE_AACDECODER self
)
921 if (self
->hPcmUtils
!= NULL
) {
922 pcmDmx_Close( &self
->hPcmUtils
);
927 if (self
->hSbrDecoder
!= NULL
) {
928 sbrDecoder_Close(&self
->hSbrDecoder
);
931 if (self
->hInput
!= NULL
) {
932 transportDec_Close(&self
->hInput
);
935 CAacDecoder_Close(self
);
939 LINKSPEC_CPP CStreamInfo
* aacDecoder_GetStreamInfo ( HANDLE_AACDECODER self
)
941 return CAacDecoder_GetStreamInfo(self
);
944 LINKSPEC_CPP INT
aacDecoder_GetLibInfo ( LIB_INFO
*info
)
952 sbrDecoder_GetLibInfo( info
);
953 transportDec_GetLibInfo( info
);
954 FDK_toolsGetLibInfo( info
);
955 pcmDmx_GetLibInfo( info
);
957 /* search for next free tab */
958 for (i
= 0; i
< FDK_MODULE_LAST
; i
++) {
959 if (info
[i
].module_id
== FDK_NONE
) break;
961 if (i
== FDK_MODULE_LAST
) {
966 info
->module_id
= FDK_AACDEC
;
967 /* build own library info */
968 info
->version
= LIB_VERSION(AACDECODER_LIB_VL0
, AACDECODER_LIB_VL1
, AACDECODER_LIB_VL2
);
969 LIB_VERSION_STRING(info
);
970 info
->build_date
= AACDECODER_LIB_BUILD_DATE
;
971 info
->build_time
= AACDECODER_LIB_BUILD_TIME
;
972 info
->title
= AACDECODER_LIB_TITLE
;
982 | CAPF_AAC_CONCEALMENT