mm-video-v4l2: venc: Clamp 601 -> 709 if requested by camera

Read colorspace hint from gralloc handle and request
conversion to 709

bug 17785855

Change-Id: I7f6289363910db42677eb8a1be78a4d0bcdc8f48
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 976498f..b427cdf 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
@@ -1,5 +1,5 @@
 /*--------------------------------------------------------------------------
-Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
+Copyright (c) 2010-2015, The Linux Foundation. All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:
@@ -44,6 +44,7 @@
 #ifdef _ANDROID_
 #include <media/hardware/HardwareAPI.h>
 #include <gralloc_priv.h>
+#include <qdMetaData.h>
 #endif
 
 #define ALIGN(x, to_align) ((((unsigned long) x) + (to_align - 1)) & ~(to_align - 1))
@@ -2414,6 +2415,18 @@
                     plane.data_offset = 0;
                     plane.length = handle->size;
                     plane.bytesused = handle->size;
+                    if (handle->base_metadata) {
+                        MetaData_t *pMeta =
+                                reinterpret_cast<MetaData_t*>(handle->base_metadata);
+                        ColorSpace_t csc = pMeta->operation & UPDATE_COLOR_SPACE ?
+                                pMeta->colorSpace : (ColorSpace_t)-1;
+                        if (csc == ITU_R_709) {
+                            buf.flags |= V4L2_MSM_BUF_FLAG_YUV_601_709_CLAMP;
+                            DEBUG_PRINT_LOW("venc_empty_buf: force 601 -> 709 clamping");
+                        }
+                    } else {
+                        DEBUG_PRINT_LOW("venc_empty_buf: gralloc metadata is NULL");
+                    }
                         DEBUG_PRINT_LOW("venc_empty_buf: Opaque camera buf: fd = %d "
                                 ": filled %d of %d", fd, plane.bytesused, plane.length);
                 }