Merge "mm-video-v4l2: Disable integer overflow sanitization on lito"
diff --git a/conf_files/kona/media_codecs.xml b/conf_files/kona/media_codecs.xml
index ffb158e..50233a0 100644
--- a/conf_files/kona/media_codecs.xml
+++ b/conf_files/kona/media_codecs.xml
@@ -172,6 +172,7 @@
  |          | 3840    2160    120     220     3888000             |
  |          | 4096    2160    60      220     2073600             |
  |          | 8192    4320    24      220     3317760             |
+ | hevc.cq  | 512     512     3825    220     3916800     3916800 |
  | mpeg4-sw | 1280    720     30      4       108000      108000  |
  | vp8      | 1280    720     60      70      216000      2073600 |
  |          | 1920    1088    60      70      489600              |
@@ -252,6 +253,7 @@
             <Limit name="concurrent-instances" max="16" />
             <Limit name="quality" range="0-100" default="80" />
             <Feature name="bitrate-modes" value="CQ" />
+            <Limit name="performance-point-512x512" value="3825" />
         </MediaCodec>
         <MediaCodec name="OMX.qcom.video.encoder.heic" type="image/vnd.android.heic" >
             <Quirk name="requires-allocate-on-input-ports" />
@@ -335,7 +337,6 @@
             <Feature name="secure-playback" required="true" />
             <Limit name="concurrent-instances" max="3" />
             <Limit name="performance-point-3840x2160" value="60" />
-            <Limit name="performance-point-4096x2160" value="60" />
             <Limit name="performance-point-4096x2304" value="60" />
         </MediaCodec>
         <MediaCodec name="OMX.qcom.video.decoder.mpeg2" type="video/mpeg2" >
@@ -416,7 +417,6 @@
             <Feature name="secure-playback" required="true" />
             <Limit name="concurrent-instances" max="3" />
             <Limit name="performance-point-3840x2160" value="60" />
-            <Limit name="performance-point-4096x2160" value="60" />
             <Limit name="performance-point-4096x2304" value="60" />
         </MediaCodec>
         <MediaCodec name="OMX.qcom.video.decoder.hevc" type="video/hevc" >
@@ -452,7 +452,6 @@
             <Feature name="secure-playback" required="true" />
             <Limit name="concurrent-instances" max="3" />
             <Limit name="performance-point-3840x2160" value="60" />
-            <Limit name="performance-point-4096x2160" value="60" />
             <Limit name="performance-point-4096x2304" value="60" />
         </MediaCodec>
         <!-- Video Software -->
diff --git a/conf_files/kona/media_codecs_performance.xml b/conf_files/kona/media_codecs_performance.xml
index 4072536..29ecd0b 100644
--- a/conf_files/kona/media_codecs_performance.xml
+++ b/conf_files/kona/media_codecs_performance.xml
@@ -127,11 +127,11 @@
             <Limit name="measured-frame-rate-1920x1080" range="248-248" />
         </MediaCodec>
         <MediaCodec name="OMX.qcom.video.decoder.vp9" type="video/x-vnd.on2.vp9" update="true">
-            <Limit name="measured-frame-rate-320x240" range="1103-1262" />
-            <Limit name="measured-frame-rate-640x360" range="1055-1163" />
-            <Limit name="measured-frame-rate-1280x720" range="579-594" />
-            <Limit name="measured-frame-rate-1920x1080" range="496-518" />
-            <Limit name="measured-frame-rate-3840x2160" range="139-139" />
+            <Limit name="measured-frame-rate-320x240" range="330-450" />
+            <Limit name="measured-frame-rate-640x360" range="300-390" />
+            <Limit name="measured-frame-rate-1280x720" range="238-253" />
+            <Limit name="measured-frame-rate-1920x1080" range="175-225" />
+            <Limit name="measured-frame-rate-3840x2160" range="83-98" />
         </MediaCodec>
         <MediaCodec name="OMX.google.h264.decoder" type="video/avc" update="true">
             <Limit name="measured-frame-rate-320x240" range="122-370" />
diff --git a/conf_files/kona/media_codecs_vendor.xml b/conf_files/kona/media_codecs_vendor.xml
index 496c906..52c55fa 100644
--- a/conf_files/kona/media_codecs_vendor.xml
+++ b/conf_files/kona/media_codecs_vendor.xml
@@ -172,6 +172,7 @@
  |          | 3840    2160    120     220     3888000             |
  |          | 4096    2160    60      220     2073600             |
  |          | 8192    4320    24      220     3317760             |
+ | hevc.cq  | 512     512     3825    220     3916800     3916800 |
  | mpeg4-sw | 1280    720     30      4       108000      108000  |
  | vp8      | 1280    720     60      70      216000      2073600 |
  |          | 1920    1088    60      70      489600              |
@@ -253,6 +254,7 @@
             <Limit name="concurrent-instances" max="16" />
             <Limit name="quality" range="0-100" default="80" />
             <Feature name="bitrate-modes" value="CQ" />
+            <Limit name="performance-point-512x512" value="3825" />
         </MediaCodec>
         <MediaCodec name="OMX.qcom.video.encoder.heic" type="image/vnd.android.heic" >
             <Quirk name="requires-allocate-on-input-ports" />
@@ -336,7 +338,6 @@
             <Feature name="secure-playback" required="true" />
             <Limit name="concurrent-instances" max="3" />
             <Limit name="performance-point-3840x2160" value="60" />
-            <Limit name="performance-point-4096x2160" value="60" />
             <Limit name="performance-point-4096x2304" value="60" />
         </MediaCodec>
         <MediaCodec name="OMX.qcom.video.decoder.mpeg2" type="video/mpeg2" >
@@ -417,7 +418,6 @@
             <Feature name="secure-playback" required="true" />
             <Limit name="concurrent-instances" max="3" />
             <Limit name="performance-point-3840x2160" value="60" />
-            <Limit name="performance-point-4096x2160" value="60" />
             <Limit name="performance-point-4096x2304" value="60" />
         </MediaCodec>
         <MediaCodec name="OMX.qcom.video.decoder.hevc" type="video/hevc" >
@@ -453,7 +453,6 @@
             <Feature name="secure-playback" required="true" />
             <Limit name="concurrent-instances" max="3" />
             <Limit name="performance-point-3840x2160" value="60" />
-            <Limit name="performance-point-4096x2160" value="60" />
             <Limit name="performance-point-4096x2304" value="60" />
         </MediaCodec>
         <!-- Video Software -->
diff --git a/conf_files/kona/mediacodec-seccomp.policy b/conf_files/kona/mediacodec-seccomp.policy
index 3bf11a3..0b75b84 100644
--- a/conf_files/kona/mediacodec-seccomp.policy
+++ b/conf_files/kona/mediacodec-seccomp.policy
@@ -17,3 +17,5 @@
 timer_create: 1
 timer_settime: 1
 rt_sigtimedwait: 1
+readlink: 1
+open: 1
diff --git a/conf_files/lito/media_codecs_vendor.xml b/conf_files/lito/media_codecs_vendor.xml
index 48b7848..7da517d 100644
--- a/conf_files/lito/media_codecs_vendor.xml
+++ b/conf_files/lito/media_codecs_vendor.xml
@@ -181,6 +181,17 @@
             <Limit name="quality" range="0-100" default="80" />
             <Feature name="bitrate-modes" value="VBR,CBR" />
         </MediaCodec>
+        <MediaCodec name="OMX.qcom.video.encoder.hevc.cq" type="video/hevc" >
+            <Quirk name="requires-allocate-on-input-ports" />
+            <Quirk name="requires-allocate-on-input-ports" />
+            <Quirk name="requires-allocate-on-output-ports" />
+            <Quirk name="requires-loaded-to-idle-after-allocation" />
+            <Limit name="size" min="512x512" max="512x512" />
+            <Limit name="frame-rate" range="1-20" />
+            <Limit name="concurrent-instances" max="6" />
+            <Limit name="quality" range="0-100" default="80" />
+            <Feature name="bitrate-modes" value="CQ" />
+        </MediaCodec>
         <MediaCodec name="OMX.qcom.video.encoder.heic" type="image/vnd.android.heic" >
             <Quirk name="requires-allocate-on-input-ports" />
             <Quirk name="requires-allocate-on-input-ports" />
diff --git a/conf_files/lito/media_codecs_vendor_v1.xml b/conf_files/lito/media_codecs_vendor_v1.xml
index d2ba141..b4e4f62 100644
--- a/conf_files/lito/media_codecs_vendor_v1.xml
+++ b/conf_files/lito/media_codecs_vendor_v1.xml
@@ -178,6 +178,17 @@
             <Limit name="quality" range="0-100" default="80" />
             <Feature name="bitrate-modes" value="VBR,CBR" />
         </MediaCodec>
+        <MediaCodec name="OMX.qcom.video.encoder.hevc.cq" type="video/hevc" >
+            <Quirk name="requires-allocate-on-input-ports" />
+            <Quirk name="requires-allocate-on-input-ports" />
+            <Quirk name="requires-allocate-on-output-ports" />
+            <Quirk name="requires-loaded-to-idle-after-allocation" />
+            <Limit name="size" min="512x512" max="512x512" />
+            <Limit name="frame-rate" range="1-20" />
+            <Limit name="concurrent-instances" max="6" />
+            <Limit name="quality" range="0-100" default="80" />
+            <Feature name="bitrate-modes" value="CQ" />
+        </MediaCodec>
         <MediaCodec name="OMX.qcom.video.encoder.heic" type="image/vnd.android.heic" >
             <Quirk name="requires-allocate-on-input-ports" />
             <Quirk name="requires-allocate-on-input-ports" />
diff --git a/libc2dcolorconvert/C2DColorConverter.cpp b/libc2dcolorconvert/C2DColorConverter.cpp
index b7ca088..ca3674f 100644
--- a/libc2dcolorconvert/C2DColorConverter.cpp
+++ b/libc2dcolorconvert/C2DColorConverter.cpp
@@ -303,7 +303,6 @@
         case YCbCr420P:
         case YCrCb420P:
         case NV12_2K:
-        case NV12_512:
         case NV12_128m:
         case NV12_UBWC:
         case TP10_UBWC:
@@ -486,7 +485,6 @@
             return (C2D_COLOR_FORMAT_420_NV12 | C2D_FORMAT_MACROTILED);
         case YCbCr420SP:
         case NV12_2K:
-        case NV12_512:
         case NV12_128m:
             return C2D_COLOR_FORMAT_420_NV12;
         case YCbCr420P:
@@ -519,10 +517,8 @@
             return ALIGN(width, ALIGN16);
         case NV12_2K:
             return ALIGN(width, ALIGN16);
-        case NV12_512:
-            return ALIGN(width, ALIGN512);
         case NV12_128m:
-            return ALIGN(width, ALIGN128);
+            return ALIGN(width, ALIGN512);
         case YCbCr420P:
             return ALIGN(width, ALIGN16);
         case YCrCb420P:
@@ -553,10 +549,8 @@
             size_t lumaSize = ALIGN(alignedw * height, ALIGN2K);
             return lumaSize;
         }
-        case NV12_512:
-            return ALIGN(width, ALIGN512) * ALIGN(height, ALIGN512);
         case NV12_128m:
-            return ALIGN(width, ALIGN128) * ALIGN(height, ALIGN32);
+            return ALIGN(width, ALIGN512) * ALIGN(height, ALIGN512);
         case NV12_UBWC:
             return ALIGN( VENUS_Y_STRIDE(COLOR_FMT_NV12_UBWC, width) *
                     VENUS_Y_SCANLINES(COLOR_FMT_NV12_UBWC, height), ALIGN4K) +
@@ -635,16 +629,11 @@
                                                    __FUNCTION__, width, height, size);
             }
             break;
-        case NV12_512:
+        case NV12_128m:
             alignedw = ALIGN(width, ALIGN512);
             alignedh = ALIGN(height, ALIGN512);
             size = ALIGN(alignedw * alignedh + (alignedw * ALIGN((height+1)/2, ALIGN256)), ALIGN4K);
             break;
-        case NV12_128m:
-            alignedw = ALIGN(width, ALIGN128);
-            alignedh = ALIGN(height, ALIGN32);
-            size = ALIGN(alignedw * alignedh + (alignedw * ALIGN((height+1)/2, ALIGN16)), ALIGN4K);
-            break;
         case NV12_UBWC:
             size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12_UBWC, width, height);
             break;
@@ -750,10 +739,8 @@
     switch (format) {
         case NV12_2K:
           return ALIGN2K;
-        case NV12_512:
-          return ALIGN512;
         case NV12_128m:
-          return 1;
+          return ALIGN512;
         case NV12_UBWC:
         case TP10_UBWC:
           return ALIGN4K;
@@ -771,7 +758,6 @@
         case YCbCr420SP: //OR NV12
         case YCbCr420P:
         case NV12_2K:
-        case NV12_512:
         case NV12_128m:
         case NV12_UBWC:
         case TP10_UBWC:
@@ -801,7 +787,6 @@
         case YCrCb420P:
         case YCbCr420Tile:
         case NV12_2K:
-        case NV12_512:
         case NV12_128m:
         case NV12_UBWC:
         case TP10_UBWC:
diff --git a/libc2dcolorconvert/C2DColorConverter.h b/libc2dcolorconvert/C2DColorConverter.h
index f677deb..d23c780 100644
--- a/libc2dcolorconvert/C2DColorConverter.h
+++ b/libc2dcolorconvert/C2DColorConverter.h
@@ -108,7 +108,6 @@
     RGBA8888,
     RGBA8888_UBWC,
     NV12_2K,
-    NV12_512,
     NV12_128m,
     NV12_UBWC,
     TP10_UBWC,
diff --git a/mm-core/src/registry_table_android.c b/mm-core/src/registry_table_android.c
index 5e6488a..1ad8796 100644
--- a/mm-core/src/registry_table_android.c
+++ b/mm-core/src/registry_table_android.c
@@ -57,11 +57,9 @@
     OMX_REGISTRY_ENTRY("OMX.qcom.video.encoder.mpeg4sw", "libOmxSwVencMpeg4.so", "video_encoder.mpeg4"),
     OMX_REGISTRY_ENTRY("OMX.qcom.video.encoder.h263sw", "libOmxSwVencMpeg4.so", "video_encoder.h263"),
     OMX_REGISTRY_ENTRY("OMX.qcom.video.encoder.avc", "libOmxVenc.so", "video_encoder.avc"),
-    OMX_REGISTRY_ENTRY("OMX.qcom.video.encoder.avc.secure", "libOmxVenc.so", "video_encoder.avc"),
     OMX_REGISTRY_ENTRY("OMX.qcom.video.encoder.vp8", "libOmxVenc.so", "video_encoder.vp8"),
     OMX_REGISTRY_ENTRY("OMX.qcom.video.encoder.hevc", "libOmxVenc.so", "video_encoder.hevc"),
     OMX_REGISTRY_ENTRY("OMX.qcom.video.encoder.hevc.cq", "libOmxVenc.so", "video_encoder.hevc"),
-    OMX_REGISTRY_ENTRY("OMX.qcom.video.encoder.hevc.secure", "libOmxVenc.so", "video_encoder.hevc"),
     OMX_REGISTRY_ENTRY("OMX.qcom.video.encoder.heic", "libOmxVenc.so", "image_encoder.heic"),
     OMX_REGISTRY_ENTRY("OMX.qti.vdec.vpp", "libOmxVpp.so", "iv_processor.yuv"),
 #endif // VIDC_STUB_HAL
diff --git a/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h b/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h
index 42d1ec6..b666cd6 100644
--- a/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h
+++ b/mm-video-v4l2/vidc/vdec/inc/omx_vdec.h
@@ -181,7 +181,8 @@
 #define MAX_NUM_INPUT_OUTPUT_BUFFERS VIDEO_MAX_FRAME
 #endif
 
-#define MIN_NUM_INPUT_OUTPUT_EXTRADATA_BUFFERS 32 // 32 (max cap when VPP enabled)
+// Aligning to MAX NUM INPUT & OUTPUT
+#define MIN_NUM_INPUT_OUTPUT_EXTRADATA_BUFFERS MAX_NUM_INPUT_OUTPUT_BUFFERS
 
 /* STATUS CODES */
 /* Base value for status codes */
@@ -324,7 +325,7 @@
 	size_t offset;
 	size_t len;
 	uint32_t flags;
-	int64_t time_stamp;
+	uint64_t time_stamp;
 	enum vdec_picture pic_type;
 	void *client_data;
 	struct vdec_picsize picsize;
diff --git a/mm-video-v4l2/vidc/venc/inc/omx_video_common.h b/mm-video-v4l2/vidc/venc/inc/omx_video_common.h
index 80f473b..8660248 100644
--- a/mm-video-v4l2/vidc/venc/inc/omx_video_common.h
+++ b/mm-video-v4l2/vidc/venc/inc/omx_video_common.h
@@ -52,6 +52,11 @@
 #define OMX_VIDEO_DEC_NUM_INPUT_BUFFERS   2
 #define OMX_VIDEO_DEC_NUM_OUTPUT_BUFFERS  2
 
+/* Based on 1080p resolution */
+#define DEFAULT_TILE_ROWS 3
+#define DEFAULT_TILE_COLS 4
+#define DEFAULT_TILE_DIMENSION 512
+
 #ifdef FEATURE_QTV_WVGA_ENABLE
 #define OMX_VIDEO_DEC_INPUT_BUFFER_SIZE   (256*1024)
 #else
diff --git a/mm-video-v4l2/vidc/venc/inc/omx_video_encoder.h b/mm-video-v4l2/vidc/venc/inc/omx_video_encoder.h
index 7567720..707c466 100644
--- a/mm-video-v4l2/vidc/venc/inc/omx_video_encoder.h
+++ b/mm-video-v4l2/vidc/venc/inc/omx_video_encoder.h
@@ -38,9 +38,6 @@
     OMX_API void * get_omx_component_factory_fn(void);
 }
 
-#define DEFAULT_TILE_DIMENSION 512
-#define DEFAULT_TILE_COUNT 40
-
 class omx_venc: public omx_video
 {
     public:
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 18b87f7..569d53d 100644
--- a/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h
+++ b/mm-video-v4l2/vidc/venc/inc/video_encoder_device_v4l2.h
@@ -265,7 +265,7 @@
 struct statistics {
     struct timeval prev_tv;
     int prev_fbd;
-    int bytes_generated;
+    OMX_U32 bytes_generated;
 };
 
 enum rc_modes {
@@ -460,7 +460,7 @@
         bool venc_set_extradata_hdr10metadata(OMX_U32 omx_profile);
         bool venc_store_dynamic_config(OMX_INDEXTYPE type, OMX_PTR config);
         bool venc_cvp_enable(private_handle_t *handle);
-        bool venc_get_cvp_metadata(private_handle_t *handle);
+        bool venc_get_cvp_metadata(private_handle_t *handle, struct v4l2_buffer *buf);
         bool venc_superframe_enable(private_handle_t *handle);
 
         OMX_U32 pmem_free();
diff --git a/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp b/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
index 7ea0ad0..40ed324 100644
--- a/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
+++ b/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
@@ -291,7 +291,6 @@
     mMapPixelFormat2Converter.insert({
             {HAL_PIXEL_FORMAT_RGBA_8888, RGBA8888},
             {HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC, NV12_UBWC},
-            {HAL_PIXEL_FORMAT_NV12_HEIF, NV12_512},
                 });
 
     pthread_mutex_init(&m_lock, NULL);
@@ -1676,6 +1675,17 @@
                 OMX_VIDEO_PARAM_ANDROID_IMAGEGRIDTYPE* pParam =
                     (OMX_VIDEO_PARAM_ANDROID_IMAGEGRIDTYPE*)paramData;
                 DEBUG_PRINT_LOW("get_parameter: OMX_IndexParamVideoAndroidImageGrid");
+                m_sParamAndroidImageGrid.bEnabled = OMX_TRUE;
+                m_sParamAndroidImageGrid.nTileWidth = DEFAULT_TILE_DIMENSION;
+                m_sParamAndroidImageGrid.nTileHeight = DEFAULT_TILE_DIMENSION;
+                m_sParamAndroidImageGrid.nGridRows =
+                    m_sInPortDef.format.video.nFrameHeight > 0 ?
+                    ((m_sInPortDef.format.video.nFrameHeight - 1) / DEFAULT_TILE_DIMENSION + 1) :
+                    DEFAULT_TILE_ROWS;
+                m_sParamAndroidImageGrid.nGridCols =
+                    m_sInPortDef.format.video.nFrameWidth > 0 ?
+                    ((m_sInPortDef.format.video.nFrameWidth - 1) / DEFAULT_TILE_DIMENSION + 1) :
+                    DEFAULT_TILE_COLS;
                 memcpy(pParam, &m_sParamAndroidImageGrid, sizeof(m_sParamAndroidImageGrid));
                 break;
             }
@@ -5116,7 +5126,7 @@
                                private_handle_t::PRIV_FLAGS_ITU_R_601_FR : 0;
 
         if (m_sOutPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingImageHEIC)
-            c2dDestFmt = NV12_512;
+            c2dDestFmt = NV12_128m;
 
         if (c2dcc.getConversionNeeded() &&
             c2dcc.isPropChanged(m_sInPortDef.format.video.nFrameWidth,
diff --git a/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp b/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
index 0717d5d..138530f 100644
--- a/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
+++ b/mm-video-v4l2/vidc/venc/src/omx_video_encoder.cpp
@@ -231,11 +231,6 @@
                 OMX_MAX_STRINGNAME_SIZE)) {
         strlcpy((char *)m_cRole, "video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
         codec_type = OMX_VIDEO_CodingAVC;
-    } else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc.secure",\
-                OMX_MAX_STRINGNAME_SIZE)) {
-        strlcpy((char *)m_cRole, "video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
-        codec_type = OMX_VIDEO_CodingAVC;
-        secure_session = true;
     } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.vp8",    \
                 OMX_MAX_STRINGNAME_SIZE)) {
         strlcpy((char *)m_cRole, "video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE);
@@ -250,11 +245,6 @@
                 OMX_MAX_STRINGNAME_SIZE)) {
         strlcpy((char *)m_cRole, "video_encoder.hevc", OMX_MAX_STRINGNAME_SIZE);
         codec_type = OMX_VIDEO_CodingImageHEIC;
-    } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.hevc.secure",    \
-                OMX_MAX_STRINGNAME_SIZE)) {
-        strlcpy((char *)m_cRole, "video_encoder.hevc", OMX_MAX_STRINGNAME_SIZE);
-        codec_type = OMX_VIDEO_CodingHEVC;
-        secure_session = true;
     } else {
         DEBUG_PRINT_ERROR("ERROR: Unknown Component");
         eRet = OMX_ErrorInvalidComponentName;
@@ -543,8 +533,8 @@
     m_sParamAndroidImageGrid.bEnabled = OMX_FALSE;
     m_sParamAndroidImageGrid.nTileWidth = DEFAULT_TILE_DIMENSION;
     m_sParamAndroidImageGrid.nTileHeight = DEFAULT_TILE_DIMENSION;
-    m_sParamAndroidImageGrid.nGridRows = DEFAULT_TILE_COUNT;
-    m_sParamAndroidImageGrid.nGridCols = DEFAULT_TILE_COUNT;
+    m_sParamAndroidImageGrid.nGridRows = DEFAULT_TILE_ROWS;
+    m_sParamAndroidImageGrid.nGridCols = DEFAULT_TILE_COLS;
 
     OMX_INIT_STRUCT(&m_sParamLTRCount, QOMX_VIDEO_PARAM_LTRCOUNT_TYPE);
     m_sParamLTRCount.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
@@ -942,15 +932,7 @@
             }
         case OMX_IndexParamVideoAndroidImageGrid:
             {
-                VALIDATE_OMX_PARAM_DATA(paramData, OMX_VIDEO_PARAM_ANDROID_IMAGEGRIDTYPE);
-                DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAndroidImageGrid");
-                OMX_VIDEO_PARAM_ANDROID_IMAGEGRIDTYPE* pParam =
-                    (OMX_VIDEO_PARAM_ANDROID_IMAGEGRIDTYPE*)paramData;
-                if (!handle->venc_set_param(paramData, (OMX_INDEXTYPE)OMX_IndexParamVideoAndroidImageGrid)) {
-                    DEBUG_PRINT_ERROR("ERROR: Request for setting image grid enable failed");
-                    return OMX_ErrorUnsupportedSetting;
-                }
-                memcpy(&m_sParamAndroidImageGrid, pParam, sizeof(m_sParamAndroidImageGrid));
+                DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAndroidImageGrid. Ignore!");
                 break;
             }
         case OMX_IndexParamVideoProfileLevelCurrent:
@@ -972,12 +954,6 @@
                     m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)m_sParamProfileLevel.eLevel;
                     DEBUG_PRINT_LOW("AVC profile = %d, level = %d", m_sParamAVC.eProfile,
                             m_sParamAVC.eLevel);
-                } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc.secure",\
-                            OMX_MAX_STRINGNAME_SIZE)) {
-                    m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)m_sParamProfileLevel.eProfile;
-                    m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)m_sParamProfileLevel.eLevel;
-                    DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
-                            m_sParamAVC.eLevel);
                 }
                 else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.vp8",\
                             OMX_MAX_STRINGNAME_SIZE)) {
@@ -1023,13 +999,6 @@
                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
                         eRet =OMX_ErrorUnsupportedSetting;
                     }
-                } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) {
-                    if (!strncmp((char*)comp_role->cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
-                        strlcpy((char*)m_cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
-                    } else {
-                        DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
-                        eRet =OMX_ErrorUnsupportedSetting;
-                    }
                 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
                     if (!strncmp((const char*)comp_role->cRole,"video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
                         strlcpy((char*)m_cRole,"video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE);
@@ -1045,13 +1014,6 @@
                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
                         eRet = OMX_ErrorUnsupportedSetting;
                     }
-                } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.hevc.secure",OMX_MAX_STRINGNAME_SIZE)) {
-                    if (!strncmp((const char*)comp_role->cRole,"video_encoder.hevc",OMX_MAX_STRINGNAME_SIZE)) {
-                        strlcpy((char*)m_cRole,"video_encoder.hevc",OMX_MAX_STRINGNAME_SIZE);
-                    } else {
-                        DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
-                        eRet = OMX_ErrorUnsupportedSetting;
-                    }
                 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.heic",OMX_MAX_STRINGNAME_SIZE)) {
                     if (!strncmp((const char*)comp_role->cRole,"image_encoder.heic",OMX_MAX_STRINGNAME_SIZE)) {
                         strlcpy((char*)m_cRole,"video_encoder.hevc",OMX_MAX_STRINGNAME_SIZE);
@@ -1605,12 +1567,6 @@
         m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)eLevel;
         DEBUG_PRINT_LOW("AVC profile = %d, level = %d", m_sParamAVC.eProfile,
                 m_sParamAVC.eLevel);
-    } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc.secure",\
-                OMX_MAX_STRINGNAME_SIZE)) {
-        m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)eProfile;
-        m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)eLevel;
-        DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
-                m_sParamAVC.eLevel);
     }
     else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.vp8",\
                 OMX_MAX_STRINGNAME_SIZE)) {
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
old mode 100755
new mode 100644
index 9335666..ab2f301
--- a/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
+++ b/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2.cpp
@@ -440,14 +440,14 @@
         /* calc avg. fps, bitrate */
         struct timeval tv;
         gettimeofday(&tv,NULL);
-        OMX_U64 time_diff = (tv.tv_sec * 1000000ULL + tv.tv_usec) -
-                (stats.prev_tv.tv_sec * 1000000ULL + stats.prev_tv.tv_usec);
+        OMX_U64 time_diff = ((uint64_t) tv.tv_sec * (uint64_t) 1000000ULL + (uint64_t) tv.tv_usec) -
+                ((uint64_t) stats.prev_tv.tv_sec * (uint64_t) 1000000ULL + (uint64_t) stats.prev_tv.tv_usec);
         if (time_diff >= 1000000) {
             OMX_U32 num_fbd = omx->handle->fbd - stats.prev_fbd;
             if (stats.prev_tv.tv_sec && num_fbd && time_diff) {
                 float framerate = num_fbd * 1000000/(float)time_diff;
-                OMX_U32 bitrate = (stats.bytes_generated * 8 / num_fbd) * framerate;
-                DEBUG_PRINT_INFO("stats: avg. fps %0.2f, bitrate %d",
+                OMX_U64 bitrate = (stats.bytes_generated * 8 / num_fbd) * framerate;
+                DEBUG_PRINT_INFO("stats: avg. fps %0.2f, bitrate %llu",
                     framerate, bitrate);
             }
             stats.prev_tv = tv;
@@ -935,7 +935,6 @@
 
         switch (color_format) {
         case NV12_128m:
-        case NV12_512:
             return venc_set_color_format((OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m);
         case NV12_UBWC:
             return venc_set_color_format((OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed);
@@ -1369,23 +1368,6 @@
                 fwrite(ptemp, m_sVenc_cfg.input_width, 1, m_debug.infile);
                 ptemp += stride;
             }
-        } else if (color_format == COLOR_FMT_NV12_512) {
-            stride = VENUS_Y_STRIDE(color_format, m_sVenc_cfg.input_width);
-            scanlines = VENUS_Y_SCANLINES(color_format, m_sVenc_cfg.input_height);
-
-            for (i = 0; i < scanlines; i++) {
-                fwrite(ptemp, stride, 1, m_debug.infile);
-                ptemp += stride;
-            }
-            if (metadatamode == 1) {
-                ptemp = pvirt + (stride * scanlines);
-            } else {
-                ptemp = (unsigned char *)pbuffer->pBuffer + (stride * scanlines);
-            }
-            for (i = 0; i < scanlines/2; i++) {
-                fwrite(ptemp, stride, 1, m_debug.infile);
-                ptemp += stride;
-            }
         } else if (color_format == COLOR_FMT_RGBA8888) {
             stride = VENUS_RGB_STRIDE(color_format, m_sVenc_cfg.input_width);
             scanlines = VENUS_RGB_SCANLINES(color_format, m_sVenc_cfg.input_height);
@@ -2686,8 +2668,8 @@
                             m_sVenc_cfg.inputformat = isUBWC ? V4L2_PIX_FMT_NV12_UBWC : V4L2_PIX_FMT_NV12;
                             DEBUG_PRINT_INFO("ENC_CONFIG: Input Color = NV12 %s", isUBWC ? "UBWC" : "Linear");
                         } else if (handle->format == HAL_PIXEL_FORMAT_NV12_HEIF) {
-                            m_sVenc_cfg.inputformat = V4L2_PIX_FMT_NV12_512;
-                            DEBUG_PRINT_INFO("ENC_CONFIG: Input Color = NV12_512");
+                            m_sVenc_cfg.inputformat = V4L2_PIX_FMT_NV12;
+                            DEBUG_PRINT_INFO("ENC_CONFIG: Input Color = NV12");
                         } else if (handle->format == HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC) {
                             m_sVenc_cfg.inputformat = V4L2_PIX_FMT_NV12_UBWC;
                             DEBUG_PRINT_INFO("ENC_CONFIG: Input Color = NV12_UBWC");
@@ -2801,7 +2783,7 @@
                         }
                     } // Check OUTPUT Streaming
 
-                    venc_get_cvp_metadata(handle);
+                    venc_get_cvp_metadata(handle, &buf);
 
                     struct UBWCStats cam_ubwc_stats[2];
                     unsigned long long int compression_ratio = 1 << 16;
@@ -3018,9 +3000,6 @@
         case V4L2_PIX_FMT_NV12:
             color_format = COLOR_FMT_NV12;
             break;
-        case V4L2_PIX_FMT_NV12_512:
-            color_format = COLOR_FMT_NV12_512;
-            break;
         case V4L2_PIX_FMT_NV12_UBWC:
             color_format = COLOR_FMT_NV12_UBWC;
             break;
@@ -3595,10 +3574,7 @@
     }
 
     if (m_codec == OMX_VIDEO_CodingImageHEIC)
-        format = V4L2_PIX_FMT_NV12_512;
-
-    if (m_codec == OMX_VIDEO_CodingImageHEIC)
-        format = V4L2_PIX_FMT_NV12_512;
+        format = V4L2_PIX_FMT_NV12;
 
     return format;
 }
@@ -3644,10 +3620,7 @@
     }
 
     if (m_codec == OMX_VIDEO_CodingImageHEIC)
-        m_sVenc_cfg.inputformat = V4L2_PIX_FMT_NV12_512;
-
-    if (m_codec == OMX_VIDEO_CodingImageHEIC)
-        m_sVenc_cfg.inputformat = V4L2_PIX_FMT_NV12_512;
+        m_sVenc_cfg.inputformat = V4L2_PIX_FMT_NV12;
 
     memset(&fmt, 0, sizeof(fmt));
     fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
@@ -4322,19 +4295,19 @@
             m_cvp_meta_enabled = true;
             DEBUG_PRINT_HIGH("CVP metadata enabled");
         } else {
-            DEBUG_PRINT_ERROR("ERROR: invalid CVP metadata, size %d",
-                    cvpMetadata.size);
+            DEBUG_PRINT_ERROR("ERROR: External CVP mode disabled for this session and continue!");
             clearMetaData(handle, SET_CVP_METADATA);
         }
     }
     return true;
 }
 
-bool venc_dev::venc_get_cvp_metadata(private_handle_t *handle)
+bool venc_dev::venc_get_cvp_metadata(private_handle_t *handle, struct v4l2_buffer *buf)
 {
     if (!m_cvp_meta_enabled)
         return true;
 
+    buf->flags &= ~V4L2_BUF_FLAG_CVPMETADATA_SKIP;
     cvpMetadata.size = 0;
     if (getMetaData(handle, GET_CVP_METADATA, &cvpMetadata) == 0) {
         clearMetaData(handle, SET_CVP_METADATA);
@@ -4342,10 +4315,14 @@
             DEBUG_PRINT_ERROR("ERROR: Invalid CVP metadata size %d",
                 cvpMetadata.size);
             cvpMetadata.size = 0;
+            /* If camera sends metadata of size not matching to CVP_METADATA_SIZE,
+               it is considered as an error case. So, do not add skip flag */
             return false;
         }
         DEBUG_PRINT_LOW("CVP metadata size %d", cvpMetadata.size);
     } else {
+        buf->flags |= V4L2_BUF_FLAG_CVPMETADATA_SKIP;
+        DEBUG_PRINT_LOW("venc_empty_buf: V4L2_BUF_FLAG_CVPMETADATA_SKIP is set");
         DEBUG_PRINT_LOW("CVP metadata not available");
     }
     return true;
diff --git a/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2_params.cpp b/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2_params.cpp
index e6710da..561cf05 100755
--- a/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2_params.cpp
+++ b/mm-video-v4l2/vidc/venc/src/video_encoder_device_v4l2_params.cpp
@@ -55,17 +55,12 @@
             *usage &= ~GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
             DEBUG_PRINT_INFO("Clear UBWC consumer usage bits as 10-bit linear color requested");
         }
-    } else if (mUseLinearColorFormat & REQUEST_LINEAR_COLOR_8_BIT) {
+    } else if (mUseLinearColorFormat & REQUEST_LINEAR_COLOR_8_BIT ||
+            m_codec == OMX_VIDEO_CodingImageHEIC) {
         *usage &= ~GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
         DEBUG_PRINT_INFO("Clear UBWC consumer usage bits as 8-bit linear color requested");
     }
 
-    if (m_codec == OMX_VIDEO_CodingImageHEIC) {
-        DEBUG_PRINT_INFO("Clear UBWC and set HEIF consumer usage bit");
-        *usage &= ~GRALLOC_USAGE_PRIVATE_ALLOC_UBWC;
-        *usage |= GRALLOC_USAGE_PRIVATE_HEIF_VIDEO;
-    }
-
     DEBUG_PRINT_INFO("venc_get_consumer_usage 0x%x", *usage);
 }
 
@@ -787,17 +782,7 @@
             }
         case (OMX_INDEXTYPE)OMX_IndexParamVideoAndroidImageGrid:
             {
-                DEBUG_PRINT_LOW("venc_set_param: OMX_IndexParamVideoAndroidImageGrid");
-
-                if (m_codec != OMX_VIDEO_CodingImageHEIC) {
-                    DEBUG_PRINT_ERROR("OMX_IndexParamVideoAndroidImageGrid is only set for HEIC (HW tiling)");
-                    return true;
-                }
-
-                if (!venc_set_grid_enable()) {
-                    DEBUG_PRINT_ERROR("ERROR: Failed to set grid-enable");
-                    return false;
-                }
+                DEBUG_PRINT_LOW("venc_set_param: OMX_IndexParamVideoAndroidImageGrid. Ignore!");
                 break;
             }
         case OMX_IndexParamVideoIntraRefresh:
diff --git a/product.mk b/product.mk
index 8072deb..f809485 100644
--- a/product.mk
+++ b/product.mk
@@ -25,3 +25,6 @@
 include hardware/qcom/media/conf_files/$(TARGET_BOARD_PLATFORM)/$(TARGET_BOARD_PLATFORM).mk
 
 endif
+
+#Vendor property to enable Codec2 for audio and OMX for Video
+PRODUCT_PROPERTY_OVERRIDES += debug.stagefright.ccodec=1