Support vaQuerySurfaceAttributes API in libmix

BZ: 129308

Change-Id: Icaa30baea7e13ce250d629f5f43b56881b8efa79
Signed-off-by: Zhao Liang <leo.zhao@intel.com>
Reviewed-on: http://android.intel.com:8080/124674
Reviewed-by: Shi, PingX <pingx.shi@intel.com>
Tested-by: Shi, PingX <pingx.shi@intel.com>
Reviewed-by: cactus <cactus@intel.com>
Tested-by: cactus <cactus@intel.com>
diff --git a/videoencoder/VideoEncoderBase.cpp b/videoencoder/VideoEncoderBase.cpp
index 7a04da2..ca66b70 100644
--- a/videoencoder/VideoEncoderBase.cpp
+++ b/videoencoder/VideoEncoderBase.cpp
@@ -67,7 +67,8 @@
     ,mOffsetInSeg(0)
     ,mTotalSize(0)
     ,mTotalSizeCopied(0)
-    ,mFrameSkipped(false){
+    ,mFrameSkipped(false)
+    ,mSupportedSurfaceMemType(0){
 
     VAStatus vaStatus = VA_STATUS_SUCCESS;
     // here the display can be any value, use following one
@@ -160,6 +161,8 @@
 //            &vaAttrib[0], 3, &(mVAConfig));  //uncomment this after psb_video supports
     CHECK_VA_STATUS_RETURN("vaCreateConfig");
 
+    querySupportedSurfaceMemTypes();
+
     if (mComParams.rcMode == VA_RC_VCM) {
         // Following three features are only enabled in VCM mode
         mRenderMaxSliceSize = true;
@@ -627,6 +630,7 @@
     mTotalSize = 0;
     mTotalSizeCopied = 0;
     mFrameSkipped = false;
+    mSupportedSurfaceMemType = 0;
 
     LOG_V( "end\n");
     return ret;
@@ -792,6 +796,40 @@
     return ENCODE_SUCCESS;
 }
 
+Encode_Status VideoEncoderBase::querySupportedSurfaceMemTypes() {
+
+    VAStatus vaStatus = VA_STATUS_SUCCESS;
+
+    unsigned int num = 0;
+
+    VASurfaceAttrib* attribs = NULL;
+
+    //get attribs number
+    vaStatus = vaQuerySurfaceAttributes(mVADisplay, mVAConfig, attribs, &num);
+    CHECK_VA_STATUS_RETURN("vaGetSurfaceAttributes");
+
+    if (num == 0)
+        return ENCODE_SUCCESS;
+
+    attribs = new VASurfaceAttrib[num];
+
+    vaStatus = vaQuerySurfaceAttributes(mVADisplay, mVAConfig, attribs, &num);
+    CHECK_VA_STATUS_RETURN("vaGetSurfaceAttributes");
+
+    for(int i = 0; i < num; i ++) {
+        if (attribs[i].type == VASurfaceAttribMemoryType) {
+            mSupportedSurfaceMemType = attribs[i].value.value.i;
+            break;
+        }
+        else
+            continue;
+    }
+
+    delete attribs;
+
+    return ENCODE_SUCCESS;
+}
+
 Encode_Status VideoEncoderBase::outputAllData(VideoEncOutputBuffer *outBuffer) {
 
     // Data size been copied for every single call
@@ -2163,6 +2201,9 @@
             return VA_INVALID_SURFACE;
     }
 
+    if (mSupportedSurfaceMemType & type == 0)
+        return VA_INVALID_SURFACE;
+
     attribs[0].type = (VASurfaceAttribType)VASurfaceAttribMemoryType;
     attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
     attribs[0].value.type = VAGenericValueTypeInteger;
diff --git a/videoencoder/VideoEncoderBase.h b/videoencoder/VideoEncoderBase.h
index 4354e16..d43878b 100644
--- a/videoencoder/VideoEncoderBase.h
+++ b/videoencoder/VideoEncoderBase.h
@@ -97,6 +97,7 @@
     Encode_Status cleanupForOutput();
     Encode_Status outputAllData(VideoEncOutputBuffer *outBuffer);
     Encode_Status queryAutoReferenceConfig(VAProfile profile);
+    Encode_Status querySupportedSurfaceMemTypes();
     Encode_Status copySurfaces(VASurfaceID srcId, VASurfaceID destId);
     VASurfaceID CreateSurfaceFromExternalBuf(int32_t value, ValueInfo& vinfo);
 
@@ -159,5 +160,8 @@
     android::Condition           mCodedBuffer_Cond, mEncodeTask_Cond;
 
     bool mFrameSkipped;
+
+    //supported surface memory types
+    int mSupportedSurfaceMemType;
 };
 #endif /* __VIDEO_ENCODER_BASE_H__ */