mm-video-v4l2: venc: Fix interpretation of nBFrames on Android

Android specifies nBFrames as number of Bs between I OR P;
while the OMX spec says nBFrames = number of Bs between I.
Convert to spec version of nBFrames since the codec relies
on this convention.

Bug: 28930897
Change-Id: I196db4595703d93ec35f88e81b99756d4d3e4e09
diff --git a/msm8996/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h b/msm8996/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h
index 0a874d8..d1c41f7 100644
--- a/msm8996/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h
+++ b/msm8996/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h
@@ -474,6 +474,7 @@
         msm_venc_temporal_layers            temporal_layers_config;
 
         bool venc_set_profile_level(OMX_U32 eProfile,OMX_U32 eLevel);
+        bool venc_set_intra_period_config(OMX_U32 nPFrames, OMX_U32 nBFrames);
         bool venc_set_intra_period(OMX_U32 nPFrames, OMX_U32 nBFrames);
         bool venc_set_target_bitrate(OMX_U32 nTargetBitrate, OMX_U32 config);
         bool venc_set_ratectrl_cfg(OMX_VIDEO_CONTROLRATETYPE eControlRate);
diff --git a/msm8996/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp b/msm8996/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
index 1e2a2dc..cd909e7 100644
--- a/msm8996/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
+++ b/msm8996/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
@@ -1763,7 +1763,7 @@
                         }
                     }
 
-                    if (!venc_set_intra_period (pParam->nPFrames,bFrames)) {
+                    if (!venc_set_intra_period_config (pParam->nPFrames,bFrames)) {
                         DEBUG_PRINT_ERROR("ERROR: Request for setting intra period failed");
                         return false;
                     }
@@ -1796,7 +1796,7 @@
                     if (pParam->nBFrames)
                         DEBUG_PRINT_ERROR("WARNING: B frame not supported for H.263");
 
-                    if (venc_set_intra_period (pParam->nPFrames, bFrames) == false) {
+                    if (venc_set_intra_period_config (pParam->nPFrames, bFrames) == false) {
                         DEBUG_PRINT_ERROR("ERROR: Request for setting intra period failed");
                         return false;
                     }
@@ -1837,7 +1837,7 @@
                         }
                     }
 
-                    if (!venc_set_intra_period (pParam->nPFrames, bFrames)) {
+                    if (!venc_set_intra_period_config (pParam->nPFrames, bFrames)) {
                         DEBUG_PRINT_ERROR("ERROR: Request for setting intra period failed");
                         return false;
                     }
@@ -4489,6 +4489,17 @@
     return true;
 }
 
+bool venc_dev::venc_set_intra_period_config(OMX_U32 nPFrames, OMX_U32 nBFrames) {
+#if _ANDROID_
+    // Android defines nBFrames as number of Bs between I OR P
+    // Per the spec, nBFrames is number of Bs between I
+    OMX_U32 nBs = nBFrames * (nPFrames + 1);
+    DEBUG_PRINT_INFO("Updating Bframes from %u to %u", nBFrames, nBs);
+    nBFrames = nBs;
+#endif //_ANDROID_
+   return venc_set_intra_period(nPFrames, nBFrames);
+}
+
 bool venc_dev::venc_set_intra_period(OMX_U32 nPFrames, OMX_U32 nBFrames)
 {