[PORT FROM R3]Change the frame skip query

BZ: 47812 44763

For better performance, in async mode, libmix need to know
if frame N is skipped before frame N-1 is completely encoded.
So video driver store the skip flag in frame N-2 instead of
frame N-1. See video driver patch 47812. In sync mode, libmix
also need to query last frame to check if its next frame is
skipped.
Signed-off-by: Elaine Wang <elaine.wang@intel.com>

Change-Id: If3e163cbb47bf482e7e5a447d76398aaa1b68433
Reviewed-on: http://android.intel.com:8080/61656
Reviewed-by: Wang, Elaine <elaine.wang@intel.com>
Reviewed-by: Ding, Haitao <haitao.ding@intel.com>
Tested-by: Ding, Haitao <haitao.ding@intel.com>
Reviewed-by: buildbot <buildbot@intel.com>
Tested-by: buildbot <buildbot@intel.com>
diff --git a/videoencoder/VideoEncoderBase.cpp b/videoencoder/VideoEncoderBase.cpp
index f4df5e2..72b4778 100644
--- a/videoencoder/VideoEncoderBase.cpp
+++ b/videoencoder/VideoEncoderBase.cpp
@@ -402,7 +402,7 @@
         mKeyFrame = true;
     }
 
-    // Query the status of current surface
+    // Query the status of last surface to check if its next frame is skipped
     VASurfaceStatus vaSurfaceStatus;
     vaStatus = vaQuerySurfaceStatus(mVADisplay, mLastSurface, &vaSurfaceStatus);
     CHECK_VA_STATUS_RETURN("vaQuerySurfaceStatus");
@@ -467,14 +467,17 @@
     vaStatus = vaMapBuffer (mVADisplay, mOutCodedBuffer, (void **)&buf);
     vaStatus = vaUnmapBuffer(mVADisplay, mOutCodedBuffer);
 
-    // Query the status of current surface
-    VASurfaceStatus vaSurfaceStatus;
-    vaStatus = vaQuerySurfaceStatus(mVADisplay, mCurSurface,  &vaSurfaceStatus);
-    CHECK_VA_STATUS_RETURN("vaQuerySurfaceStatus");
+    mPicSkipped = false;
+    if (!mFirstFrame) {
+        // Query the status of last surface to check if its next frame is skipped
+        VASurfaceStatus vaSurfaceStatus;
+        vaStatus = vaQuerySurfaceStatus(mVADisplay, mLastSurface,  &vaSurfaceStatus);
+        CHECK_VA_STATUS_RETURN("vaQuerySurfaceStatus");
+        mPicSkipped = vaSurfaceStatus & VASurfaceSkipped;
+    }
 
-    mPicSkipped = vaSurfaceStatus & VASurfaceSkipped;
-
-    mCurSurface = 0;
+    mLastSurface = mCurSurface;
+    mCurSurface = VA_INVALID_SURFACE;
 
     mEncodedFrames ++;
     mFrameNum ++;