OSDN Git Service

stagefright-plugins: Fix audio trimmed when reaching eos
authorKeith Mok <kmok@cyngn.com>
Wed, 23 Dec 2015 20:54:37 +0000 (12:54 -0800)
committerSteve Kondik <shade@chemlab.org>
Mon, 28 Dec 2015 15:55:00 +0000 (07:55 -0800)
When received eos, SoftFFmpegAudio will drop that buffer
without decoding it. This makes the following cts test case failed:
android.media.cts.DecoderTest/testDecodeWithEOSOnLastBuffer

Change-Id: I51e670ac4348dc5bfb8bae267a1801209e509fd7

omx/SoftFFmpegAudio.cpp

index a860843..aca6aa1 100644 (file)
@@ -1067,7 +1067,7 @@ int32_t SoftFFmpegAudio::decodeAudio() {
     int gotFrm = false;
     int32_t ret = ERR_OK;
     int32_t inputBufferUsedLength = 0;
-    bool is_flush = (mEOSStatus != INPUT_DATA_AVAILABLE);
+    bool is_flush = (mEOSStatus == OUTPUT_FRAMES_FLUSHED);
     List<BufferInfo *> &inQueue = getPortQueue(kInputPortIndex);
     BufferInfo *inInfo = NULL;
     OMX_BUFFERHEADERTYPE *inHeader = NULL;
@@ -1076,15 +1076,21 @@ int32_t SoftFFmpegAudio::decodeAudio() {
 
     if (!is_flush) {
         inInfo = *inQueue.begin();
-        CHECK(inInfo != NULL);
-        inHeader = inInfo->mHeader;
+        if (inInfo != NULL)  {
+            inHeader = inInfo->mHeader;
 
-        if (mInputBufferSize == 0) {
-            updateTimeStamp(inHeader);
-            mInputBufferSize = inHeader->nFilledLen;
+            if (mInputBufferSize == 0) {
+                updateTimeStamp(inHeader);
+                mInputBufferSize = inHeader->nFilledLen;
+            }
         }
     }
 
+    if (mEOSStatus == INPUT_EOS_SEEN && (!inHeader || inHeader->nFilledLen == 0)
+        && !(mCtx->codec->capabilities & CODEC_CAP_DELAY)) {
+        return ERR_FLUSHED;
+    }
+
     AVPacket pkt;
     initPacket(&pkt, inHeader);
     av_frame_unref(mFrame);
@@ -1331,12 +1337,6 @@ void SoftFFmpegAudio::drainAllOutputBuffers() {
         return;
     }
 
-    if(!(mCtx->codec->capabilities & CODEC_CAP_DELAY)) {
-        drainEOSOutputBuffer();
-        mEOSStatus = OUTPUT_FRAMES_FLUSHED;
-        return;
-    }
-
     while (!outQueue.empty()) {
         if (mResampledDataSize == 0) {
             int32_t err = decodeAudio();
@@ -1385,10 +1385,7 @@ void SoftFFmpegAudio::onQueueFilled(OMX_U32 /* portIndex */) {
         inHeader = inInfo->mHeader;
 
         if (inHeader->nFlags & OMX_BUFFERFLAG_EOS) {
-            ALOGD("ffmpeg audio decoder empty eos inbuf");
-            inQueue.erase(inQueue.begin());
-            inInfo->mOwnedByUs = false;
-            notifyEmptyBufferDone(inHeader);
+            ALOGD("ffmpeg audio decoder eos");
             mEOSStatus = INPUT_EOS_SEEN;
             continue;
         }
@@ -1495,6 +1492,7 @@ void SoftFFmpegAudio::onReset() {
     initDecoder(codecID);
     mSignalledError = false;
     mOutputPortSettingsChange = NONE;
+    mEOSStatus = INPUT_DATA_AVAILABLE;
 }
 
 SoftOMXComponent* SoftFFmpegAudio::createSoftOMXComponent(