summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/codecs/mp3dec/SoftMP3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/codecs/mp3dec/SoftMP3.cpp')
-rw-r--r--media/libstagefright/codecs/mp3dec/SoftMP3.cpp46
1 files changed, 36 insertions, 10 deletions
diff --git a/media/libstagefright/codecs/mp3dec/SoftMP3.cpp b/media/libstagefright/codecs/mp3dec/SoftMP3.cpp
index 9f7dd59..005956d 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);
@@ -239,7 +241,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;
@@ -254,7 +256,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;
}
@@ -275,7 +290,7 @@ void SoftMP3::onQueueFilled(OMX_U32 /* portIndex */) {
mConfig->outputFrameSize = kOutputBufferSize / sizeof(int16_t);
if ((int32)outHeader->nAllocLen < mConfig->outputFrameSize) {
- ALOGE("input buffer too small: got %lu, expected %u",
+ ALOGE("input buffer too small: got %u, expected %u",
outHeader->nAllocLen, mConfig->outputFrameSize);
android_errorWriteLog(0x534e4554, "27793371");
notify(OMX_EventError, OMX_ErrorUndefined, OUTPUT_BUFFER_TOO_SMALL, NULL);
@@ -294,10 +309,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) {
@@ -361,7 +379,7 @@ void SoftMP3::onQueueFilled(OMX_U32 /* portIndex */) {
outHeader->nTimeStamp =
mAnchorTimeUs + (mNumFramesOutput * 1000000ll) / mSamplingRate;
-
+ tmpTime = outHeader->nTimeStamp;
if (inHeader) {
CHECK_GE(inHeader->nFilledLen, mConfig->inputBufferUsedLength);
@@ -386,6 +404,10 @@ void SoftMP3::onQueueFilled(OMX_U32 /* portIndex */) {
notifyFillBufferDone(outHeader);
outHeader = NULL;
}
+
+ if (tmpTime > 0) {
+ mNextOutBufferTimeUs = tmpTime;
+ }
}
void SoftMP3::onPortFlushCompleted(OMX_U32 portIndex) {
@@ -397,6 +419,8 @@ void SoftMP3::onPortFlushCompleted(OMX_U32 portIndex) {
mSignalledError = false;
mSawInputEos = false;
mSignalledOutputEos = false;
+ mLastAnchorTimeUs = -1;
+ mNextOutBufferTimeUs = 0;
}
}
@@ -433,6 +457,8 @@ void SoftMP3::onReset() {
mSawInputEos = false;
mSignalledOutputEos = false;
mOutputPortSettingsChange = NONE;
+ mLastAnchorTimeUs = -1;
+ mNextOutBufferTimeUs = 0;
}
} // namespace android