diff options
Diffstat (limited to 'media/libstagefright/codecs/mp3dec/SoftMP3.cpp')
-rw-r--r-- | media/libstagefright/codecs/mp3dec/SoftMP3.cpp | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/media/libstagefright/codecs/mp3dec/SoftMP3.cpp b/media/libstagefright/codecs/mp3dec/SoftMP3.cpp index f743b1c..4c4da60 100644 --- a/media/libstagefright/codecs/mp3dec/SoftMP3.cpp +++ b/media/libstagefright/codecs/mp3dec/SoftMP3.cpp @@ -51,7 +51,9 @@ SoftMP3::SoftMP3( mSignalledError(false), mSawInputEos(false), mSignalledOutputEos(false), - mOutputPortSettingsChange(NONE) { + mOutputPortSettingsChange(NONE), + mLastAnchorTimeUs(-1), + mNextOutBufferTimeUs(0) { initPorts(); initDecoder(); } @@ -112,7 +114,7 @@ void SoftMP3::initPorts() { void SoftMP3::initDecoder() { mConfig->equalizerType = flat; mConfig->crcEnabled = false; - + mConfig->samplingRate = mSamplingRate; uint32_t memRequirements = pvmp3_decoderMemRequirements(); mDecoderBuf = malloc(memRequirements); @@ -212,7 +214,7 @@ void SoftMP3::onQueueFilled(OMX_U32 /* portIndex */) { List<BufferInfo *> &inQueue = getPortQueue(0); List<BufferInfo *> &outQueue = getPortQueue(1); - + int64_t tmpTime = 0; while ((!inQueue.empty() || (mSawInputEos && !mSignalledOutputEos)) && !outQueue.empty()) { BufferInfo *inInfo = NULL; OMX_BUFFERHEADERTYPE *inHeader = NULL; @@ -227,7 +229,20 @@ void SoftMP3::onQueueFilled(OMX_U32 /* portIndex */) { if (inHeader) { if (inHeader->nOffset == 0 && inHeader->nFilledLen) { - mAnchorTimeUs = inHeader->nTimeStamp; + // use new input buffer timestamp as Anchor Time if its + // a) first buffer or + // b) first buffer post seek or + // c) different from last buffer timestamp + //If input buffer timestamp is same as last input buffer timestamp then + //treat this as a erroneous timestamp and ignore new input buffer + //timestamp and use last output buffer timestamp as Anchor Time. + if ((mLastAnchorTimeUs != inHeader->nTimeStamp)) { + mAnchorTimeUs = inHeader->nTimeStamp; + mLastAnchorTimeUs = inHeader->nTimeStamp; + } else { + mAnchorTimeUs = mNextOutBufferTimeUs; + } + mNumFramesOutput = 0; } @@ -259,10 +274,13 @@ void SoftMP3::onQueueFilled(OMX_U32 /* portIndex */) { if (decoderErr != NO_ENOUGH_MAIN_DATA_ERROR && decoderErr != SIDE_INFO_ERROR) { ALOGE("mp3 decoder returned error %d", decoderErr); - - notify(OMX_EventError, OMX_ErrorUndefined, decoderErr, NULL); - mSignalledError = true; - return; + if(decoderErr == SYNCH_LOST_ERROR) { + mConfig->outputFrameSize = kOutputBufferSize / sizeof(int16_t); + } else { + notify(OMX_EventError, OMX_ErrorUndefined, decoderErr, NULL); + mSignalledError = true; + return; + } } if (mConfig->outputFrameSize == 0) { @@ -323,7 +341,7 @@ void SoftMP3::onQueueFilled(OMX_U32 /* portIndex */) { outHeader->nTimeStamp = mAnchorTimeUs + (mNumFramesOutput * 1000000ll) / mSamplingRate; - + tmpTime = outHeader->nTimeStamp; if (inHeader) { CHECK_GE(inHeader->nFilledLen, mConfig->inputBufferUsedLength); @@ -348,6 +366,10 @@ void SoftMP3::onQueueFilled(OMX_U32 /* portIndex */) { notifyFillBufferDone(outHeader); outHeader = NULL; } + + if (tmpTime > 0) { + mNextOutBufferTimeUs = tmpTime; + } } void SoftMP3::onPortFlushCompleted(OMX_U32 portIndex) { @@ -359,6 +381,8 @@ void SoftMP3::onPortFlushCompleted(OMX_U32 portIndex) { mSignalledError = false; mSawInputEos = false; mSignalledOutputEos = false; + mLastAnchorTimeUs = -1; + mNextOutBufferTimeUs = 0; } } @@ -395,6 +419,8 @@ void SoftMP3::onReset() { mSawInputEos = false; mSignalledOutputEos = false; mOutputPortSettingsChange = NONE; + mLastAnchorTimeUs = -1; + mNextOutBufferTimeUs = 0; } } // namespace android |