Enable Max Frame Size setting for VP8 encode

BZ: 162278

Add related config code in libmix layer and passing down to driver.

Change-Id: Idad5ecb0a3bf942f75b7e28c7bf1431265931c96
Signed-off-by: Liu Bolun <bolun.liu@intel.com>
diff --git a/videoencoder/VideoEncoderBase.cpp b/videoencoder/VideoEncoderBase.cpp
index c758d3a..d35aca1 100644
--- a/videoencoder/VideoEncoderBase.cpp
+++ b/videoencoder/VideoEncoderBase.cpp
@@ -1199,7 +1199,8 @@
         case VideoConfigTypeIDRRequest:
         case VideoConfigTypeSliceNum:
         case VideoConfigTypeVP8:
-        case VideoConfigTypeVP8ReferenceFrame: {
+        case VideoConfigTypeVP8ReferenceFrame:
+        case VideoConfigTypeVP8MaxFrameSize:{
             ret = derivedSetConfig(videoEncConfig);
             break;
         }
diff --git a/videoencoder/VideoEncoderBase.h b/videoencoder/VideoEncoderBase.h
index 10f8141..692162f 100644
--- a/videoencoder/VideoEncoderBase.h
+++ b/videoencoder/VideoEncoderBase.h
@@ -120,6 +120,7 @@
     bool mRenderFrameRate;
     bool mRenderBitRate;
     bool mRenderHrd;
+    bool mRenderMaxFrameSize;
 
     VABufferID mSeqParamBuf;
     VABufferID mRcParamBuf;
diff --git a/videoencoder/VideoEncoderDef.h b/videoencoder/VideoEncoderDef.h
index 4ff90fa..d65f50d 100644
--- a/videoencoder/VideoEncoderDef.h
+++ b/videoencoder/VideoEncoderDef.h
@@ -329,6 +329,7 @@
     VideoConfigTypeVP8,
     VideoConfigTypeVP8ReferenceFrame,
     VideoConfigTypeCIR,
+    VideoConfigTypeVP8MaxFrameSize,
 
     VideoParamsConfigExtension
 };
@@ -637,6 +638,7 @@
         uint32_t hrd_buf_size;
         uint32_t hrd_buf_initial_fullness;
         uint32_t hrd_buf_optimal_fullness;
+        uint32_t max_frame_size;
 
         VideoParamsVP8() {
                 type = VideoParamsTypeVP8;
@@ -672,5 +674,16 @@
         }
 };
 
+struct VideoConfigVP8MaxFrameSize : VideoParamConfigSet {
+
+    VideoConfigVP8MaxFrameSize() {
+        type = VideoConfigTypeVP8MaxFrameSize;
+        size = sizeof(VideoConfigVP8MaxFrameSize);
+    }
+
+    uint32_t max_frame_size;
+};
+
+
 
 #endif /*  __VIDEO_ENCODER_DEF_H__ */
diff --git a/videoencoder/VideoEncoderVP8.cpp b/videoencoder/VideoEncoderVP8.cpp
index 3539bdd..d9785e4 100644
--- a/videoencoder/VideoEncoderVP8.cpp
+++ b/videoencoder/VideoEncoderVP8.cpp
@@ -30,6 +30,7 @@
         mVideoParamsVP8.hrd_buf_size = 1000;
         mVideoParamsVP8.hrd_buf_initial_fullness = 500;
         mVideoParamsVP8.hrd_buf_optimal_fullness = 600;
+        mVideoParamsVP8.max_frame_size = 0;
 
         mVideoConfigVP8.force_kf = 0;
         mVideoConfigVP8.refresh_entropy_probs = 0;
@@ -122,7 +123,7 @@
 {
     VABufferID rc_param_buf;
 	VAStatus vaStatus = VA_STATUS_SUCCESS;
-    VAEncMiscParameterBuffer *misc_param, *misc_param_tmp;
+    VAEncMiscParameterBuffer *misc_param;
     VAEncMiscParameterRateControl *misc_rate_ctrl;
 
     vaStatus = vaCreateBuffer(mVADisplay, mVAContext,
@@ -155,7 +156,7 @@
 {
     VABufferID framerate_param_buf;
     VAStatus vaStatus = VA_STATUS_SUCCESS;
-    VAEncMiscParameterBuffer *misc_param, *misc_param_tmp;
+    VAEncMiscParameterBuffer *misc_param;
     VAEncMiscParameterFrameRate * misc_framerate;
     uint32_t frameRateNum = mComParams.frameRate.frameRateNum;
     uint32_t frameRateDenom = mComParams.frameRate.frameRateDenom;
@@ -183,8 +184,8 @@
 {
     VABufferID hrd_param_buf;
     VAStatus vaStatus = VA_STATUS_SUCCESS;
-    VAEncMiscParameterBuffer *misc_param, *misc_param_tmp;
-    VAEncMiscParameterHRD * misc_hrd; //*misc_rate_ctrl;
+    VAEncMiscParameterBuffer *misc_param;
+    VAEncMiscParameterHRD * misc_hrd;
     vaStatus = vaCreateBuffer(mVADisplay, mVAContext,
                               VAEncMiscParameterBufferType,
                               sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterHRD),
@@ -206,6 +207,30 @@
     return 0;
 }
 
+Encode_Status VideoEncoderVP8::renderMaxFrameSizeParams(void)
+{
+    VABufferID max_frame_size_param_buf;
+    VAStatus vaStatus = VA_STATUS_SUCCESS;
+    VAEncMiscParameterBuffer *misc_param;
+    VAEncMiscParameterBufferMaxFrameSize * misc_maxframesize;
+    vaStatus = vaCreateBuffer(mVADisplay, mVAContext,
+                              VAEncMiscParameterBufferType,
+                              sizeof(VAEncMiscParameterBuffer) + sizeof(VAEncMiscParameterHRD),
+                              1,NULL,&max_frame_size_param_buf);
+    CHECK_VA_STATUS_RETURN("vaCreateBuffer");
+
+    vaMapBuffer(mVADisplay, max_frame_size_param_buf,(void **)&misc_param);
+    misc_param->type = VAEncMiscParameterTypeMaxFrameSize;
+    misc_maxframesize = (VAEncMiscParameterBufferMaxFrameSize *)misc_param->data;
+    memset(misc_maxframesize, 0, sizeof(*misc_maxframesize));
+    misc_maxframesize->max_frame_size = mVideoParamsVP8.max_frame_size;
+    vaUnmapBuffer(mVADisplay, max_frame_size_param_buf);
+
+    vaStatus = vaRenderPicture(mVADisplay,mVAContext, &max_frame_size_param_buf, 1);
+    CHECK_VA_STATUS_RETURN("vaRenderPicture");;
+
+    return 0;
+}
 
 Encode_Status VideoEncoderVP8::sendEncodeCommand(EncodeTask *task) {
 
@@ -217,6 +242,7 @@
         ret = renderRCParams();
         ret = renderHRDParams();
         ret = renderSequenceParams();
+        ret = renderMaxFrameSizeParams();
         CHECK_ENCODE_STATUS_RETURN("renderSequenceParams");
     }
 
@@ -234,6 +260,13 @@
         mRenderFrameRate = false;
     }
 
+    if (mRenderMaxFrameSize) {
+        ret = renderMaxFrameSizeParams();
+        CHECK_ENCODE_STATUS_RETURN("renderMaxFrameSizeParams");
+
+        mRenderMaxFrameSize = false;
+    }
+
     ret = renderPictureParams(task);
     CHECK_ENCODE_STATUS_RETURN("renderPictureParams");
 
@@ -300,9 +333,22 @@
                 }
                 break;
 
+                case VideoConfigTypeVP8MaxFrameSize:{
+
+                        VideoConfigVP8MaxFrameSize *encConfigVP8MaxFrameSize =
+                                reinterpret_cast<VideoConfigVP8MaxFrameSize*> (videoEncConfig);
+
+                        if (encConfigVP8MaxFrameSize->size != sizeof(VideoConfigVP8MaxFrameSize)) {
+                                return ENCODE_INVALID_PARAMS;
+                        }
+
+                        encConfigVP8MaxFrameSize->max_frame_size = mVideoParamsVP8.max_frame_size;
+                }
+                break;
+
                 default: {
-            LOG_E ("Invalid Config Type");
-            break;
+                   LOG_E ("Invalid Config Type");
+                   break;
                 }
        }
 
@@ -342,6 +388,19 @@
                 }
                 break;
 
+                case VideoConfigTypeVP8MaxFrameSize:{
+                        VideoConfigVP8MaxFrameSize *encConfigVP8MaxFrameSize =
+                                reinterpret_cast<VideoConfigVP8MaxFrameSize*> (videoEncConfig);
+
+                        if (encConfigVP8MaxFrameSize->size != sizeof(VideoConfigVP8MaxFrameSize)) {
+                                return ENCODE_INVALID_PARAMS;
+                        }
+
+                        mVideoParamsVP8.max_frame_size = encConfigVP8MaxFrameSize->max_frame_size;
+                        mRenderMaxFrameSize = true;
+		}
+                break;
+
                 default: {
             LOG_E ("Invalid Config Type");
             break;
diff --git a/videoencoder/VideoEncoderVP8.h b/videoencoder/VideoEncoderVP8.h
index cacb7c1..60ddca8 100644
--- a/videoencoder/VideoEncoderVP8.h
+++ b/videoencoder/VideoEncoderVP8.h
@@ -38,6 +38,7 @@
 	Encode_Status renderRCParams(void);
 	Encode_Status renderHRDParams(void);
 	Encode_Status renderFrameRateParams(void);
+	Encode_Status renderMaxFrameSizeParams(void);
 
 
 	VideoConfigVP8 mVideoConfigVP8;