mm-video-v4l2: venc: Check private handle->flags changed in empty_this_buffer_opaque
am: 5c3f5e0a91

Change-Id: I2800b653de2fe643860ff7932281c6ea4b9fff8c
diff --git a/msm8996/libc2dcolorconvert/Android.mk b/msm8996/libc2dcolorconvert/Android.mk
index ec30280..f549450 100644
--- a/msm8996/libc2dcolorconvert/Android.mk
+++ b/msm8996/libc2dcolorconvert/Android.mk
@@ -15,7 +15,7 @@
 endif
 
 LOCAL_SHARED_LIBRARIES := liblog libdl
-LOCAL_HEADER_LIBRARIES := copybit_headers
+LOCAL_HEADER_LIBRARIES := copybit_headers gralloc_headers
 
 LOCAL_MODULE_TAGS := optional
 
diff --git a/msm8996/libc2dcolorconvert/C2DColorConverter.cpp b/msm8996/libc2dcolorconvert/C2DColorConverter.cpp
index a976171..5cafc10 100644
--- a/msm8996/libc2dcolorconvert/C2DColorConverter.cpp
+++ b/msm8996/libc2dcolorconvert/C2DColorConverter.cpp
@@ -38,6 +38,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <media/msm_media_info.h>
+#include <gralloc_priv.h>
 
 #undef LOG_TAG
 #define LOG_TAG "C2DColorConvert"
@@ -337,6 +338,8 @@
     } else {
         C2D_RGB_SURFACE_DEF * surfaceDef = new C2D_RGB_SURFACE_DEF;
         surfaceDef->format = getC2DFormat(format);
+        if (mFlags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED)
+            surfaceDef->format |= C2D_FORMAT_UBWC_COMPRESSED;
         surfaceDef->width = width;
         surfaceDef->height = height;
         surfaceDef->buffer = (void *)0xaaaaaaaa;
diff --git a/msm8996/mm-video-v4l2/vidc/venc/inc/omx_video_base.h b/msm8996/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
index 61aee80..58f1ba4 100644
--- a/msm8996/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
+++ b/msm8996/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
@@ -176,13 +176,14 @@
                 ~omx_c2d_conv();
                 bool init();
                 bool open(unsigned int height,unsigned int width,
-                        ColorConvertFormat src,
-                        ColorConvertFormat dest,unsigned int src_stride);
+                        ColorConvertFormat src, ColorConvertFormat dest,
+                        unsigned int src_stride, unsigned int flags);
                 bool convert(int src_fd, void *src_base, void *src_viraddr,
                         int dest_fd, void *dest_base, void *dest_viraddr);
                 bool get_buffer_size(int port,unsigned int &buf_size);
                 int get_src_format();
                 void close();
+                bool isUBWCChanged(unsigned int flags);
             private:
                 C2DColorConverterBase *c2dcc;
                 pthread_mutex_t c_lock;
@@ -190,6 +191,7 @@
                 ColorConvertFormat src_format;
                 createC2DColorConverter_t *mConvertOpen;
                 destroyC2DColorConverter_t *mConvertClose;
+                unsigned int mFlags = 0;
         };
         omx_c2d_conv c2d_conv;
 #endif
@@ -564,7 +566,7 @@
         }
 
         void complete_pending_buffer_done_cbs();
-        bool is_conv_needed(int, int);
+        bool is_conv_needed(int);
         void print_debug_color_aspects(ColorAspects *aspects, const char *prefix);
 
         OMX_ERRORTYPE get_vendor_extension_config(
diff --git a/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp b/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
index 62fd5d8..8cffada 100644
--- a/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
+++ b/msm8996/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
@@ -4908,16 +4908,18 @@
 }
 
 bool omx_video::omx_c2d_conv::open(unsigned int height,unsigned int width,
-        ColorConvertFormat src, ColorConvertFormat dest,unsigned int src_stride)
+        ColorConvertFormat src, ColorConvertFormat dest,unsigned int src_stride,
+        unsigned int flags)
 {
     bool status = false;
     pthread_mutex_lock(&c_lock);
     if (!c2dcc) {
         c2dcc = mConvertOpen(width, height, width, height,
-                src,dest,0,src_stride);
+                src, dest, flags, src_stride);
         if (c2dcc) {
             src_format = src;
             status = true;
+            mFlags = flags;
         } else
             DEBUG_PRINT_ERROR("mConvertOpen failed");
     }
@@ -4980,11 +4982,16 @@
     }
     return ret;
 }
-
-bool omx_video::is_conv_needed(int hal_fmt, int hal_flags)
+bool omx_video::omx_c2d_conv::isUBWCChanged(unsigned int flags)
 {
-    bool bRet = hal_fmt == HAL_PIXEL_FORMAT_RGBA_8888 &&
-        !(hal_flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED);
+    return (mFlags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) !=
+           (flags  & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED);
+}
+
+bool omx_video::is_conv_needed(int hal_fmt)
+{
+    bool bRet = hal_fmt == HAL_PIXEL_FORMAT_RGBA_8888;
+
 #ifdef _HW_RGBA
     bRet = false;
 #endif
@@ -5036,20 +5043,21 @@
       updated correctly*/
 
     if (buffer->nFilledLen > 0 && handle) {
-        if (c2d_opened && handle->format != c2d_conv.get_src_format()) {
+        if (c2d_opened && (handle->format != c2d_conv.get_src_format() ||
+                           c2d_conv.isUBWCChanged(handle->flags))) {
             c2d_conv.close();
             c2d_opened = false;
         }
 
         if (!c2d_opened) {
-            mUsesColorConversion = is_conv_needed(handle->format, handle->flags);
+            mUsesColorConversion = is_conv_needed(handle->format);
             if (mUsesColorConversion) {
                 DEBUG_PRINT_INFO("open Color conv forW: %u, H: %u",
                         (unsigned int)m_sInPortDef.format.video.nFrameWidth,
                         (unsigned int)m_sInPortDef.format.video.nFrameHeight);
                 if (!c2d_conv.open(m_sInPortDef.format.video.nFrameHeight,
                             m_sInPortDef.format.video.nFrameWidth,
-                            RGBA8888, NV12_128m, handle->width)) {
+                            RGBA8888, NV12_128m, handle->width, handle->flags)) {
                     m_pCallbacks.EmptyBufferDone(hComp,m_app_data,buffer);
                     DEBUG_PRINT_ERROR("Color conv open failed");
                     return OMX_ErrorBadParameter;
@@ -5255,7 +5263,7 @@
             Input_pmem_info.offset = 0;
             Input_pmem_info.size = handle->size;
             m_graphicBufferSize = handle->size;
-            if (is_conv_needed(handle->format, handle->flags))
+            if (is_conv_needed(handle->format))
                 ret = convert_queue_buffer(hComp,Input_pmem_info,index);
             else if (handle->format == HAL_PIXEL_FORMAT_NV12_ENCODEABLE ||
                     handle->format == QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m ||
diff --git a/msm8998/mm-video-v4l2/vidc/venc/inc/omx_video_base.h b/msm8998/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
index 7ea8fd7..c15a1b1 100644
--- a/msm8998/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
+++ b/msm8998/mm-video-v4l2/vidc/venc/inc/omx_video_base.h
@@ -195,6 +195,7 @@
                 bool get_buffer_size(int port,unsigned int &buf_size);
                 int get_src_format();
                 void close();
+                bool isUBWCChanged(unsigned int flags);
             private:
                 C2DColorConverterBase *c2dcc;
                 pthread_mutex_t c_lock;
@@ -202,6 +203,7 @@
                 ColorConvertFormat src_format;
                 createC2DColorConverter_t *mConvertOpen;
                 destroyC2DColorConverter_t *mConvertClose;
+                unsigned int mFlags = 0;
         };
         omx_c2d_conv c2d_conv;
 #endif
diff --git a/msm8998/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp b/msm8998/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
index d1c8d97..8756c09 100644
--- a/msm8998/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
+++ b/msm8998/mm-video-v4l2/vidc/venc/src/omx_video_base.cpp
@@ -5069,6 +5069,7 @@
         if (c2dcc) {
             src_format = src;
             status = true;
+            mFlags = flags;
         } else
             DEBUG_PRINT_ERROR("mConvertOpen failed");
     }
@@ -5131,6 +5132,11 @@
     }
     return ret;
 }
+bool omx_video::omx_c2d_conv::isUBWCChanged(unsigned int flags)
+{
+    return (mFlags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) !=
+           (flags  & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED);
+}
 
 bool omx_video::is_conv_needed(int hal_fmt, int hal_flags)
 {
@@ -5212,7 +5218,8 @@
       updated correctly*/
 
     if (buffer->nFilledLen > 0 && handle) {
-        if (c2d_opened && handle->format != c2d_conv.get_src_format()) {
+        if (c2d_opened && (handle->format != c2d_conv.get_src_format() ||
+                           c2d_conv.isUBWCChanged(handle->flags))) {
             c2d_conv.close();
             c2d_opened = false;
         }