summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2012-08-07 14:24:00 -0700
committerAndreas Huber <andih@google.com>2012-08-07 14:24:00 -0700
commit51d7547944967d1157b7fe18e1fb8f7ee6810412 (patch)
tree5c5d6cb884a163c7ea1f23899776f856fefbd1fa
parente671207115fac3914134c61b336d5fa0242c68ca (diff)
downloadframeworks_av-51d7547944967d1157b7fe18e1fb8f7ee6810412.zip
frameworks_av-51d7547944967d1157b7fe18e1fb8f7ee6810412.tar.gz
frameworks_av-51d7547944967d1157b7fe18e1fb8f7ee6810412.tar.bz2
Only emit padding at the end of the stream in the aac and mp3 decoders
if we actually discarded content at the beginning of the stream. Change-Id: I1e79835bb3a02350060a137b94f85f2c90f4a12b
-rw-r--r--media/libstagefright/codecs/aacdec/SoftAAC2.cpp52
-rw-r--r--media/libstagefright/codecs/mp3dec/SoftMP3.cpp24
-rw-r--r--media/libstagefright/omx/tests/OMXHarness.cpp17
3 files changed, 68 insertions, 25 deletions
diff --git a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
index ff95f9f..566b1db 100644
--- a/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
+++ b/media/libstagefright/codecs/aacdec/SoftAAC2.cpp
@@ -320,22 +320,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 +421,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 +512,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;
}
diff --git a/media/libstagefright/codecs/mp3dec/SoftMP3.cpp b/media/libstagefright/codecs/mp3dec/SoftMP3.cpp
index 8f2a3aa..fb1135c 100644
--- a/media/libstagefright/codecs/mp3dec/SoftMP3.cpp
+++ b/media/libstagefright/codecs/mp3dec/SoftMP3.cpp
@@ -191,10 +191,19 @@ void SoftMP3::onQueueFilled(OMX_U32 portIndex) {
inInfo->mOwnedByUs = false;
notifyEmptyBufferDone(inHeader);
- // pad the end of the stream with 529 samples, since that many samples
- // were trimmed off the beginning when decoding started
- outHeader->nFilledLen = kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t);
- memset(outHeader->pBuffer, 0, outHeader->nFilledLen);
+ if (!mIsFirst) {
+ // pad the end of the stream with 529 samples, since that many samples
+ // were trimmed off the beginning when decoding started
+ outHeader->nFilledLen =
+ kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t);
+
+ memset(outHeader->pBuffer, 0, outHeader->nFilledLen);
+ } 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->nFlags = OMX_BUFFERFLAG_EOS;
outQueue.erase(outQueue.begin());
@@ -260,8 +269,11 @@ void SoftMP3::onQueueFilled(OMX_U32 portIndex) {
// The decoder delay is 529 samples, so trim that many samples off
// the start of the first output buffer. This essentially makes this
// decoder have zero delay, which the rest of the pipeline assumes.
- outHeader->nOffset = kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t);
- outHeader->nFilledLen = mConfig->outputFrameSize * sizeof(int16_t) - outHeader->nOffset;
+ outHeader->nOffset =
+ kPVMP3DecoderDelay * mNumChannels * sizeof(int16_t);
+
+ outHeader->nFilledLen =
+ mConfig->outputFrameSize * sizeof(int16_t) - outHeader->nOffset;
} else {
outHeader->nOffset = 0;
outHeader->nFilledLen = mConfig->outputFrameSize * sizeof(int16_t);
diff --git a/media/libstagefright/omx/tests/OMXHarness.cpp b/media/libstagefright/omx/tests/OMXHarness.cpp
index fab1771..4b369ed 100644
--- a/media/libstagefright/omx/tests/OMXHarness.cpp
+++ b/media/libstagefright/omx/tests/OMXHarness.cpp
@@ -515,7 +515,10 @@ static const char *GetURLForMime(const char *mime) {
static sp<MediaSource> CreateSourceForMime(const char *mime) {
const char *url = GetURLForMime(mime);
- CHECK(url != NULL);
+
+ if (url == NULL) {
+ return NULL;
+ }
sp<MediaExtractor> extractor = CreateExtractorFromURI(url);
@@ -571,14 +574,22 @@ status_t Harness::testSeek(
const char *mime = GetMimeFromComponentRole(componentRole);
if (!mime) {
- ALOGI("Cannot perform seek test with this componentRole (%s)",
- componentRole);
+ printf(" * Cannot perform seek test with this componentRole (%s)\n",
+ componentRole);
return OK;
}
sp<MediaSource> source = CreateSourceForMime(mime);
+ if (source == NULL) {
+ printf(" * Unable to open test content for type '%s', "
+ "skipping test of componentRole %s\n",
+ mime, componentRole);
+
+ return OK;
+ }
+
sp<MediaSource> seekSource = CreateSourceForMime(mime);
if (source == NULL || seekSource == NULL) {
return UNKNOWN_ERROR;