Add control for video subsampling

Add '-s' to assign jpeg subsampling.
  0: 444, 1: 420

Using 420 will make video lack of detail compared to 444, but cut
amount of video data by half. This could be useful for some cases.

Change-Id: I48836a7117f7e3b9986e3f5c6a92974c9268525e
Signed-off-by: Jammy Huang <jammy_huang@aspeedtech.com>
diff --git a/ikvm_video.cpp b/ikvm_video.cpp
index 8303170..5159b25 100644
--- a/ikvm_video.cpp
+++ b/ikvm_video.cpp
@@ -30,9 +30,10 @@
 using namespace sdbusplus::xyz::openbmc_project::Common::File::Error;
 using namespace sdbusplus::xyz::openbmc_project::Common::Device::Error;
 
-Video::Video(const std::string& p, Input& input, int fr) :
+Video::Video(const std::string& p, Input& input, int fr, int sub) :
     resizeAfterOpen(false), timingsError(false), fd(-1), frameRate(fr),
-    lastFrameIndex(-1), height(600), width(800), input(input), path(p)
+    lastFrameIndex(-1), height(600), width(800), subSampling(sub),
+	input(input), path(p)
 {
 }
 
@@ -378,6 +379,7 @@
     v4l2_capability cap;
     v4l2_format fmt;
     v4l2_streamparm sparm;
+    v4l2_control ctrl;
 
     if (fd >= 0)
     {
@@ -444,6 +446,16 @@
                             entry("ERROR=%s", strerror(errno)));
     }
 
+    ctrl.id = V4L2_CID_JPEG_CHROMA_SUBSAMPLING;
+    ctrl.value = subSampling
+	       ? V4L2_JPEG_CHROMA_SUBSAMPLING_420 : V4L2_JPEG_CHROMA_SUBSAMPLING_444;
+    rc = ioctl(fd, VIDIOC_S_CTRL, &ctrl);
+    if (rc < 0)
+    {
+        log<level::WARNING>("Failed to set video jpeg subsampling",
+                            entry("ERROR=%s", strerror(errno)));
+    }
+
     height = fmt.fmt.pix.height;
     width = fmt.fmt.pix.width;