[Movie Studio] make transition complete when play the exported video

BZ: 61850

root cause: the async encode mode can't get the last encoded frame by
default, we need special method, that is push the last raw data to
encoder twice and get the last encoded frame.

Change-Id: I93540d33aa315301bdaf3f23ed908c83fa9c2d93
Signed-off-by: Gu, Wangyi <wangyi.gu@intel.com>
Reviewed-on: http://android.intel.com:8080/70522
Reviewed-by: Tang, Richard <richard.tang@intel.com>
Reviewed-by: Zhao, Leo <leo.zhao@intel.com>
Reviewed-by: Jiang, Fei <fei.jiang@intel.com>
Reviewed-by: Shi, PingX <pingx.shi@intel.com>
Tested-by: Shi, PingX <pingx.shi@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
diff --git a/frameworks/videoedit/stagefrightshells/IntelVideoEditorAVCEncoder.cpp b/frameworks/videoedit/stagefrightshells/IntelVideoEditorAVCEncoder.cpp
index a63dfd5..3e55e52 100644
--- a/frameworks/videoedit/stagefrightshells/IntelVideoEditorAVCEncoder.cpp
+++ b/frameworks/videoedit/stagefrightshells/IntelVideoEditorAVCEncoder.cpp
@@ -345,7 +345,7 @@
 
 status_t IntelVideoEditorAVCEncoder::read(MediaBuffer **out, const ReadOptions *options) {
 
-    status_t err;
+    status_t err = OK;
     Encode_Status encRet;
     MediaBuffer *tmpIn;
     int64_t timestamp = 0;
@@ -364,7 +364,11 @@
     } while (err == INFO_FORMAT_CHANGED);
 
     if (err == ERROR_END_OF_STREAM) {
-        return err;
+        if (mLastInputBuffer != NULL) {
+            tmpIn = mLastInputBuffer;
+        } else {
+            return err;
+        }
     }
     else if (err != OK) {
         LOGE("Failed to read input video frame: %d", err);
@@ -387,9 +391,12 @@
         return UNKNOWN_ERROR;
     }
 
-    if (mLastInputBuffer != NULL) {
+    if (mLastInputBuffer != NULL && err != ERROR_END_OF_STREAM) {
+        mLastInputBuffer->meta_data()->findInt64(kKeyTime, &timestamp);
         mLastInputBuffer->release();
         mLastInputBuffer = NULL;
+    } else {
+        timestamp = vaInBuf.timeStamp;
     }
     mLastInputBuffer = tmpIn;
 
@@ -427,7 +434,6 @@
             outputBuffer->meta_data()->setInt32(kKeyIsSyncFrame,true);
         }
     }
-    timestamp = vaInBuf.timeStamp;
 
     LOGV("Got it! data= %p, ts=%llu size =%d", vaOutBuf.data, timestamp, vaOutBuf.dataSize);
 
@@ -436,7 +442,7 @@
     *out = outputBuffer;
 
     LOGV("IntelVideoEditorAVCEncoder::read end");
-    return OK;
+    return err;
 }
 
 status_t IntelVideoEditorAVCEncoder::getSharedBuffers() {
diff --git a/frameworks/videoedit/stagefrightshells/MediaBufferPuller.cpp b/frameworks/videoedit/stagefrightshells/MediaBufferPuller.cpp
index acc8268..6d826e9 100644
--- a/frameworks/videoedit/stagefrightshells/MediaBufferPuller.cpp
+++ b/frameworks/videoedit/stagefrightshells/MediaBufferPuller.cpp
@@ -134,7 +134,9 @@
         status_t result = mSource->read(&pBuffer, NULL);
         mLock.lock();
         mSourceError = result;
-        if (result != OK) {
+        if (result == ERROR_END_OF_STREAM && pBuffer != NULL) {
+            mAskToStop = true;
+        } else if (result != OK) {
             break;
         }
         mBuffers.push(pBuffer);