diff options
Diffstat (limited to 'media/libstagefright/codecs/aacdec/SoftAAC2.cpp')
-rw-r--r-- | media/libstagefright/codecs/aacdec/SoftAAC2.cpp | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp index ff95f9f..a7eec57 100644 --- a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp +++ b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp @@ -26,6 +26,9 @@ #define FILEREAD_MAX_LAYERS 2 +#define DRC_DEFAULT_REF_LEVEL 108 /* 108*0.25dB = -27 dB below full scale (typical for movies) */ +#define MAX_CHANNEL_COUNT 6 /* maximum number of audio channels that can be decoded */ + namespace android { template<class T> @@ -85,7 +88,7 @@ void SoftAAC2::initPorts() { def.eDir = OMX_DirOutput; def.nBufferCountMin = kNumOutputBuffers; def.nBufferCountActual = def.nBufferCountMin; - def.nBufferSize = 8192 * 2; + def.nBufferSize = 4096 * MAX_CHANNEL_COUNT; def.bEnabled = OMX_TRUE; def.bPopulated = OMX_FALSE; def.eDomain = OMX_PortDomainAudio; @@ -110,6 +113,9 @@ status_t SoftAAC2::initDecoder() { } } mIsFirst = true; + // the decoder will bypass all DRC processing during decode unless any of the DRC parameters + // is set, so here we just reset the DRC reference level to its default value. + aacDecoder_SetParam(mAACDecoder, AAC_DRC_REFERENCE_LEVEL, DRC_DEFAULT_REF_LEVEL); return status; } @@ -320,22 +326,39 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) { inInfo->mOwnedByUs = false; notifyEmptyBufferDone(inHeader); - // flush out the decoder's delayed data by calling DecodeFrame one more time, with - // the AACDEC_FLUSH flag set - INT_PCM *outBuffer = - reinterpret_cast<INT_PCM *>(outHeader->pBuffer + outHeader->nOffset); - AAC_DECODER_ERROR decoderErr = aacDecoder_DecodeFrame(mAACDecoder, - outBuffer, - outHeader->nAllocLen, - AACDEC_FLUSH); - if (decoderErr != AAC_DEC_OK) { - mSignalledError = true; - notify(OMX_EventError, OMX_ErrorUndefined, decoderErr, NULL); - return; + if (!mIsFirst) { + // flush out the decoder's delayed data by calling DecodeFrame + // one more time, with the AACDEC_FLUSH flag set + INT_PCM *outBuffer = + reinterpret_cast<INT_PCM *>( + outHeader->pBuffer + outHeader->nOffset); + + AAC_DECODER_ERROR decoderErr = + aacDecoder_DecodeFrame(mAACDecoder, + outBuffer, + outHeader->nAllocLen, + AACDEC_FLUSH); + + if (decoderErr != AAC_DEC_OK) { + mSignalledError = true; + + notify(OMX_EventError, OMX_ErrorUndefined, decoderErr, + NULL); + + return; + } + + outHeader->nFilledLen = + mStreamInfo->frameSize + * sizeof(int16_t) + * mStreamInfo->numChannels; + } else { + // Since we never discarded frames from the start, we won't have + // to add any padding at the end either. + + outHeader->nFilledLen = 0; } - outHeader->nFilledLen = - mStreamInfo->frameSize * sizeof(int16_t) * mStreamInfo->numChannels; outHeader->nFlags = OMX_BUFFERFLAG_EOS; outQueue.erase(outQueue.begin()); @@ -404,7 +427,9 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) { } // Fill and decode - INT_PCM *outBuffer = reinterpret_cast<INT_PCM *>(outHeader->pBuffer + outHeader->nOffset); + INT_PCM *outBuffer = reinterpret_cast<INT_PCM *>( + outHeader->pBuffer + outHeader->nOffset); + bytesValid[0] = inBufferLength[0]; int prevSampleRate = mStreamInfo->sampleRate; @@ -493,7 +518,8 @@ void SoftAAC2::onQueueFilled(OMX_U32 portIndex) { // (decode failed) we'll output a silent frame. if (mIsFirst) { mIsFirst = false; - // the first decoded frame should be discarded to account for decoder delay + // the first decoded frame should be discarded to account + // for decoder delay numOutBytes = 0; } |