OSDN Git Service

We were accidentally sending out an output buffer before the final port settings...
authorAndreas Huber <andih@google.com>
Tue, 23 Aug 2011 17:21:34 +0000 (10:21 -0700)
committerAndreas Huber <andih@google.com>
Tue, 23 Aug 2011 17:22:49 +0000 (10:22 -0700)
Change-Id: I4de0d3c377bb12e59524ed370ab3ed0b9a9b70a6
related-to-bug: 5122512

media/libstagefright/codecs/aacdec/SoftAAC.cpp

index f0a330f..2abdb56 100644 (file)
@@ -378,23 +378,35 @@ void SoftAAC::onQueueFilled(OMX_U32 portIndex) {
             // fall through
         }
 
-        if (mUpsamplingFactor == 2) {
-            if (mConfig->desiredChannels == 1) {
-                memcpy(&mConfig->pOutputBuffer[1024],
-                       &mConfig->pOutputBuffer[2048],
-                       numOutBytes * 2);
+        if (decoderErr == MP4AUDEC_SUCCESS || mNumSamplesOutput > 0) {
+            // We'll only output data if we successfully decoded it or
+            // we've previously decoded valid data, in the latter case
+            // (decode failed) we'll output a silent frame.
+
+            if (mUpsamplingFactor == 2) {
+                if (mConfig->desiredChannels == 1) {
+                    memcpy(&mConfig->pOutputBuffer[1024],
+                           &mConfig->pOutputBuffer[2048],
+                           numOutBytes * 2);
+                }
+                numOutBytes *= 2;
             }
-            numOutBytes *= 2;
-        }
 
-        outHeader->nFilledLen = numOutBytes;
-        outHeader->nFlags = 0;
+            outHeader->nFilledLen = numOutBytes;
+            outHeader->nFlags = 0;
 
-        outHeader->nTimeStamp =
-            mAnchorTimeUs
-                + (mNumSamplesOutput * 1000000ll) / mConfig->samplingRate;
+            outHeader->nTimeStamp =
+                mAnchorTimeUs
+                    + (mNumSamplesOutput * 1000000ll) / mConfig->samplingRate;
 
-        mNumSamplesOutput += mConfig->frameLength * mUpsamplingFactor;
+            mNumSamplesOutput += mConfig->frameLength * mUpsamplingFactor;
+
+            outInfo->mOwnedByUs = false;
+            outQueue.erase(outQueue.begin());
+            outInfo = NULL;
+            notifyFillBufferDone(outHeader);
+            outHeader = NULL;
+        }
 
         if (inHeader->nFilledLen == 0) {
             inInfo->mOwnedByUs = false;
@@ -404,12 +416,6 @@ void SoftAAC::onQueueFilled(OMX_U32 portIndex) {
             inHeader = NULL;
         }
 
-        outInfo->mOwnedByUs = false;
-        outQueue.erase(outQueue.begin());
-        outInfo = NULL;
-        notifyFillBufferDone(outHeader);
-        outHeader = NULL;
-
         if (decoderErr == MP4AUDEC_SUCCESS) {
             ++mInputBufferCount;
         }