mm-video-legacy: vdec: add YUV420SP output format support

Add YUV420SP support and advertize this ahead of YUV420P.
Clients which need linear YUVs for editing can use this format
rather than YUV420P.
TILE -> 420SP conversion fairs better in performance and quality
as compared to 420P

Bug: 17188136
Change-Id: I4085d2e9c268e839d78f9bf4ff444de68278d272
diff --git a/mm-video-legacy/vidc/vdec/src/omx_vdec.cpp b/mm-video-legacy/vidc/vdec/src/omx_vdec.cpp
index fb66cb0..6634634 100644
--- a/mm-video-legacy/vidc/vdec/src/omx_vdec.cpp
+++ b/mm-video-legacy/vidc/vdec/src/omx_vdec.cpp
@@ -2759,6 +2759,8 @@
             QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka;
 #endif
         else if (1 == portFmt->nIndex) {
+          portFmt->eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar;
+        } else if (2 == portFmt->nIndex) {
           portFmt->eColorFormat = OMX_COLOR_FormatYUV420Planar;
         }
         else
@@ -2767,6 +2769,7 @@
                   " NoMore Color formats\n");
            eRet =  OMX_ErrorNoMore;
         }
+        ALOGI("get_parameter: color-format=%x @ index=%d", portFmt->eColorFormat, portFmt->nIndex);
       }
       else
       {
@@ -7985,6 +7988,11 @@
   portDefn->format.video.nFrameWidth  =  drv_ctx.video_resolution.frame_width;
   portDefn->format.video.nStride = drv_ctx.video_resolution.stride;
   portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.scan_lines;
+  if ((portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) ||
+      (portDefn->format.video.eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) {
+      portDefn->format.video.nStride = drv_ctx.video_resolution.frame_width;
+      portDefn->format.video.nSliceHeight = drv_ctx.video_resolution.frame_height;
+  }
   DEBUG_PRINT_LOW("update_portdef Width = %d Height = %d Stride = %u"
     "SliceHeight = %u \n", portDefn->format.video.nFrameHeight,
     portDefn->format.video.nFrameWidth,
@@ -9033,6 +9041,7 @@
   omx = NULL;
   init_members();
   ColorFormat = OMX_COLOR_FormatMax;
+  dest_format = YCbCr420P;
 }
 
 void omx_vdec::allocate_color_convert_buf::set_vdec_client(void *client)
@@ -9079,7 +9088,7 @@
   c2d.close();
   status = c2d.open(omx->drv_ctx.video_resolution.frame_height,
                     omx->drv_ctx.video_resolution.frame_width,
-                    YCbCr420Tile,YCbCr420P);
+                    YCbCr420Tile, dest_format);
   if (status) {
     status = c2d.get_buffer_size(C2D_INPUT,src_size);
     if (status)
@@ -9124,12 +9133,16 @@
   }
   pthread_mutex_lock(&omx->c_lock);
   if (status && (drv_color_format != dest_color_format)) {
-    if (dest_color_format != OMX_COLOR_FormatYUV420Planar) {
+    if ((dest_color_format != OMX_COLOR_FormatYUV420Planar) &&
+        (dest_color_format != OMX_COLOR_FormatYUV420SemiPlanar)) {
       DEBUG_PRINT_ERROR("\n Unsupported color format for c2d");
       status = false;
     } else {
       DEBUG_PRINT_HIGH("\n Planar color format set");
-      ColorFormat = OMX_COLOR_FormatYUV420Planar;
+      ColorFormat = dest_color_format;
+      dest_format = (dest_color_format == OMX_COLOR_FormatYUV420Planar) ?
+              YCbCr420P : YCbCr420SP;
+      ALOGI("C2D o/p color format = %x", dest_color_format);
       if (enabled)
         c2d.destroy();
       enabled = false;
@@ -9366,10 +9379,12 @@
     else
       status = false;
   } else {
-    if (ColorFormat != OMX_COLOR_FormatYUV420Planar) {
-      status = false;
-    } else
-      dest_color_format = OMX_COLOR_FormatYUV420Planar;
+    if ((ColorFormat == OMX_COLOR_FormatYUV420Planar) ||
+       (ColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)) {
+        dest_color_format = ColorFormat;
+    } else {
+        status = false;
+    }
   }
   return status;
 }
@@ -9420,11 +9435,10 @@
    struct vdec_ioctl_msg ioctl_msg = {NULL,NULL};
    OMX_ERRORTYPE eRet = OMX_ErrorNone;
    enum vdec_output_fromat op_format;
-   if(eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)
-     op_format = VDEC_YUV_FORMAT_NV12;
-   else if(eColorFormat ==
+   if(eColorFormat ==
            QOMX_COLOR_FormatYUV420PackedSemiPlanar64x32Tile2m8ka ||
-           eColorFormat == OMX_COLOR_FormatYUV420Planar)
+           eColorFormat == OMX_COLOR_FormatYUV420Planar ||
+           eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar)
       op_format = VDEC_YUV_FORMAT_TILE_4x2;
    else
       eRet = OMX_ErrorBadParameter;