mm-video: venc: switch between executing and loaded.

when the v4l2 modules stopped, it will free all output
and input buffers. So when it is re-started again,
re-do the VIDIOC_REQBUFS command again.

b/11051201
Signed-off: Kim Zhang<xiazhang@codeaurora.org>
Change-Id: I7c6de237fdd7476ca4ebc7d1f1016e86f3af9d95
diff --git a/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h b/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h
index 7b4b250..557ba2c 100755
--- a/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h
+++ b/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h
@@ -251,6 +251,7 @@
         };
 
         int stopped;
+        int resume_in_stopped;
         bool m_max_allowed_bitrate_check;
         pthread_t m_tid;
         bool async_thread_created;
@@ -300,6 +301,8 @@
         bool venc_set_slice_delivery_mode(OMX_U32 enable);
         bool venc_set_extradata(OMX_U32 extra_data);
         bool venc_set_idr_period(OMX_U32 nPFrames, OMX_U32 nIDRPeriod);
+        bool venc_reconfig_reqbufs();
+
 #ifdef MAX_RES_1080P
         OMX_U32 pmem_free();
         OMX_U32 pmem_allocate(OMX_U32 size, OMX_U32 alignment, OMX_U32 count);
diff --git a/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp b/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
index 98443b7..7dcfcb4 100755
--- a/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
+++ b/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
@@ -677,6 +677,7 @@
     m_sOutput_buff_property.mincount = m_sOutput_buff_property.actualcount = bufreq.count;
 
 
+    resume_in_stopped = 0;
     metadatamode = 0;
 
     control.id = V4L2_CID_MPEG_VIDEO_HEADER_MODE;
@@ -1491,6 +1492,9 @@
         if (!rc && !ret) {
             venc_stop_done();
             stopped = 1;
+            /*set flag to re-configure when started again*/
+            resume_in_stopped = 1;
+
         }
     }
 
@@ -1558,6 +1562,12 @@
 
     venc_config_print();
 
+    if(resume_in_stopped){
+        /*set buffercount when restarted*/
+        venc_reconfig_reqbufs();
+        resume_in_stopped = 0;
+    }
+
     /* Check if slice_delivery mode is enabled & max slices is sufficient for encoding complete frame */
     if (slice_mode.enable && multislice.mslice_size &&
             (m_sVenc_cfg.input_width *  m_sVenc_cfg.input_height)/(256 * multislice.mslice_size) >= MAX_SUPPORTED_SLICES_PER_FRAME) {
@@ -1611,6 +1621,29 @@
 
 }
 
+bool venc_dev::venc_reconfig_reqbufs()
+{
+    struct v4l2_requestbuffers bufreq;
+
+    bufreq.memory = V4L2_MEMORY_USERPTR;
+    bufreq.count = m_sInput_buff_property.actualcount;
+    bufreq.type=V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
+    if(ioctl(m_nDriver_fd,VIDIOC_REQBUFS, &bufreq)) {
+            DEBUG_PRINT_ERROR("\n VIDIOC_REQBUFS OUTPUT_MPLANE Failed when resume\n");
+            return false;
+    }
+
+    bufreq.memory = V4L2_MEMORY_USERPTR;
+    bufreq.count = m_sOutput_buff_property.actualcount;
+    bufreq.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
+    if(ioctl(m_nDriver_fd,VIDIOC_REQBUFS, &bufreq))
+    {
+            DEBUG_PRINT_ERROR("\nERROR: Request for setting o/p buffer count failed when resume\n");
+            return false;
+    }
+    return true;
+}
+
 unsigned venc_dev::venc_flush( unsigned port)
 {
     struct v4l2_encoder_cmd enc;
@@ -2544,7 +2577,7 @@
         }
 
         DEBUG_PRINT_LOW("Success IOCTL set control for id=%d, value=%d\n", control.id, control.value);
-        entropy.longentropysel=control.value;
+        entropy.cabacmodel=control.value;
     } else if (!enable) {
         control.value =  V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC;
         control.id = V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE;