Fix video format

Apparently, video pixel format expected by the camera framework is YU12, and not YV12
as it was implemented.

Change-Id: Id33d8aa7f62f6e68276774ca2a7d25c04acd71cc
diff --git a/tools/emulator/system/camera/Converters.cpp b/tools/emulator/system/camera/Converters.cpp
index 22c4bd3..f63f67f 100755
--- a/tools/emulator/system/camera/Converters.cpp
+++ b/tools/emulator/system/camera/Converters.cpp
@@ -98,6 +98,15 @@
 {
     const int pix_total = width * height;
     const uint8_t* Y = reinterpret_cast<const uint8_t*>(yv12);
+    const uint8_t* V = Y + pix_total;
+    const uint8_t* U = V + pix_total / 4;
+    _YUV420SToRGB32(Y, U, V, 1, reinterpret_cast<uint32_t*>(rgb), width, height);
+}
+
+void YU12ToRGB32(const void* yu12, void* rgb, int width, int height)
+{
+    const int pix_total = width * height;
+    const uint8_t* Y = reinterpret_cast<const uint8_t*>(yu12);
     const uint8_t* U = Y + pix_total;
     const uint8_t* V = U + pix_total / 4;
     _YUV420SToRGB32(Y, U, V, 1, reinterpret_cast<uint32_t*>(rgb), width, height);
@@ -113,20 +122,7 @@
                           int width,
                           int height)
 {
-#if 1
     _YUV420SToRGB565(Y, U, V, 2, rgb, width, height);
-#else
-    for (int y = 0; y < height; y++) {
-        for (int x = 0; x < width; x += 2, U += 2, V += 2) {
-            const uint8_t nU = *U;
-            const uint8_t nV = *V;
-            *rgb = YUVToRGB565(*Y, nU, nV);
-            Y++; rgb++;
-            *rgb = YUVToRGB565(*Y, nU, nV);
-            Y++; rgb++;
-        }
-    }
-#endif
 }
 
 /* Common converter for YUV 4:2:0 interleaved to RGB32.
@@ -139,20 +135,7 @@
                          int width,
                          int height)
 {
-#if 1
     _YUV420SToRGB32(Y, U, V, 2, rgb, width, height);
-#else
-    for (int y = 0; y < height; y++) {
-        for (int x = 0; x < width; x += 2, U += 2, V += 2) {
-            const uint8_t nU = *U;
-            const uint8_t nV = *V;
-            *rgb = YUVToRGB32(*Y, nU, nV);
-            Y++; rgb++;
-            *rgb = YUVToRGB32(*Y, nU, nV);
-            Y++; rgb++;
-        }
-    }
-#endif
 }
 
 void NV12ToRGB565(const void* nv12, void* rgb, int width, int height)
diff --git a/tools/emulator/system/camera/Converters.h b/tools/emulator/system/camera/Converters.h
index 5001948..ab00711 100755
--- a/tools/emulator/system/camera/Converters.h
+++ b/tools/emulator/system/camera/Converters.h
@@ -269,6 +269,14 @@
  */
 void YV12ToRGB32(const void* yv12, void* rgb, int width, int height);
 
+/* Converts an YU12 framebuffer to RGB32 framebuffer.
+ * Param:
+ *  yu12 - YU12 framebuffer.
+ *  rgb - RGB32 framebuffer.
+ *  width, height - Dimensions for both framebuffers.
+ */
+void YU12ToRGB32(const void* yu12, void* rgb, int width, int height);
+
 /* Converts an NV12 framebuffer to RGB565 framebuffer.
  * Param:
  *  nv12 - NV12 framebuffer.
diff --git a/tools/emulator/system/camera/EmulatedCamera.cpp b/tools/emulator/system/camera/EmulatedCamera.cpp
index 8f50eb8..d050413 100755
--- a/tools/emulator/system/camera/EmulatedCamera.cpp
+++ b/tools/emulator/system/camera/EmulatedCamera.cpp
@@ -543,7 +543,7 @@
     }
     uint32_t org_fmt;
     if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420P) == 0) {
-        org_fmt = V4L2_PIX_FMT_YVU420;
+        org_fmt = V4L2_PIX_FMT_YUV420;
     } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_RGBA8888) == 0) {
         org_fmt = V4L2_PIX_FMT_RGB32;
     } else if (strcmp(pix_fmt, CameraParameters::PIXEL_FORMAT_YUV420SP) == 0) {
diff --git a/tools/emulator/system/camera/EmulatedCameraDevice.cpp b/tools/emulator/system/camera/EmulatedCameraDevice.cpp
index bfb2c34..e09bead 100755
--- a/tools/emulator/system/camera/EmulatedCameraDevice.cpp
+++ b/tools/emulator/system/camera/EmulatedCameraDevice.cpp
@@ -117,6 +117,9 @@
         case V4L2_PIX_FMT_YVU420:
             YV12ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight);
             return NO_ERROR;
+        case V4L2_PIX_FMT_YUV420:
+            YU12ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight);
+            return NO_ERROR;
         case V4L2_PIX_FMT_NV21:
             NV21ToRGB32(mCurrentFrame, buffer, mFrameWidth, mFrameHeight);
             return NO_ERROR;
@@ -142,6 +145,7 @@
     /* Validate pixel format, and calculate framebuffer size at the same time. */
     switch (pix_fmt) {
         case V4L2_PIX_FMT_YVU420:
+        case V4L2_PIX_FMT_YUV420:
         case V4L2_PIX_FMT_NV21:
         case V4L2_PIX_FMT_NV12:
             mFrameBufferSize = (width * height * 12) / 8;
diff --git a/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp b/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp
index 1aac442..53a5b1b 100755
--- a/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp
+++ b/tools/emulator/system/camera/EmulatedFakeCameraDevice.cpp
@@ -117,6 +117,13 @@
         /* Calculate U/V panes inside the framebuffer. */
         switch (mPixelFormat) {
             case V4L2_PIX_FMT_YVU420:
+                mFrameV = mCurrentFrame + mTotalPixels;
+                mFrameU = mFrameU + mTotalPixels / 4;
+                mUVStep = 1;
+                mUVTotalNum = mTotalPixels / 4;
+                break;
+
+            case V4L2_PIX_FMT_YUV420:
                 mFrameU = mCurrentFrame + mTotalPixels;
                 mFrameV = mFrameU + mTotalPixels / 4;
                 mUVStep = 1;