am 4c85e16c: am d2dc1ea3: am 88574352: am 7725022e: Merge "SoftMPEG2: start output at first I-frame"

* commit '4c85e16c9f7cbd9e9fa4713d62ed2c7f4da2f7d3':
  SoftMPEG2: start output at first I-frame
diff --git a/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.cpp b/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.cpp
index e382f4c..78b3ab4 100644
--- a/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.cpp
+++ b/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.cpp
@@ -245,6 +245,7 @@
         return UNKNOWN_ERROR;
     }
 
+    mWaitForI = true;
     mIsInFlush = true;
     return OK;
 }
@@ -257,6 +258,7 @@
     UWORD32 u4_share_disp_buf;
 
     mNumCores = GetCPUCoreCount();
+    mWaitForI = true;
 
     /* Initialize number of ref and reorder modes (for MPEG2) */
     u4_num_reorder_frames = 16;
@@ -448,6 +450,8 @@
 void SoftMPEG2::onReset() {
     SoftVideoDecoderOMXComponent::onReset();
 
+    mWaitForI = true;
+
     resetDecoder();
     resetPlugin();
 }
@@ -710,11 +714,22 @@
                 outHeader->nTimeStamp = mTimeStamps[timeStampIdx];
                 mTimeStampsValid[timeStampIdx] = false;
 
-                outInfo->mOwnedByUs = false;
-                outQueue.erase(outQueue.begin());
-                outInfo = NULL;
-                notifyFillBufferDone(outHeader);
-                outHeader = NULL;
+                /* mWaitForI waits for the first I picture. Once made FALSE, it
+                   has to remain false till explicitly set to TRUE. */
+                mWaitForI = mWaitForI && !(IV_I_FRAME == s_dec_op.e_pic_type);
+
+                if (mWaitForI) {
+                    s_dec_op.u4_output_present = false;
+                } else {
+                    ALOGV("Output timestamp: %lld, res: %ux%u",
+                            (long long)outHeader->nTimeStamp, mWidth, mHeight);
+                    DUMP_TO_FILE(mOutFile, outHeader->pBuffer, outHeader->nFilledLen);
+                    outInfo->mOwnedByUs = false;
+                    outQueue.erase(outQueue.begin());
+                    outInfo = NULL;
+                    notifyFillBufferDone(outHeader);
+                    outHeader = NULL;
+                }
             } else {
                 /* If in flush mode and no output is returned by the codec,
                  * then come out of flush mode */
diff --git a/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.h b/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.h
index f7b1961..a625e08 100644
--- a/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.h
+++ b/media/libstagefright/codecs/mpeg2dec/SoftMPEG2.h
@@ -105,6 +105,7 @@
     // codec. So the codec is switching to decode the new resolution.
     bool mChangingResolution;
     bool mFlushNeeded;
+    bool mWaitForI;
 
     status_t initDecoder();
     status_t deInitDecoder();