[Camera Revamp] Emulator camera test

Test: compile and run test binary
Change-Id: I9178cef783b4af1ef49c1f13ac772eb85f3743bb
diff --git a/camera/Android.mk b/camera/Android.mk
index 59102e2..e5a1b04 100644
--- a/camera/Android.mk
+++ b/camera/Android.mk
@@ -126,6 +126,23 @@
 LOCAL_POST_INSTALL_CMD := ln -sf /data/vendor/etc/media_codecs_google_video.xml $(PRODUCT_OUT)/vendor/etc/media_codecs_google_video.xml
 include $(BUILD_SHARED_LIBRARY)
 
+# Emulator camera - test binary################################################
+
+include ${CLEAR_VARS}
+
+LOCAL_MODULE_RELATIVE_PATH := ${emulator_camera_module_relative_path}
+LOCAL_CFLAGS := ${emulator_camera_cflags}
+LOCAL_CLANG_CFLAGS += ${emulator_camera_clang_flags}
+
+LOCAL_SHARED_LIBRARIES := ${emulator_camera_shared_libraries}
+LOCAL_STATIC_LIBRARIES := ${emulator_camera_static_libraries}
+LOCAL_C_INCLUDES += ${emulator_camera_c_includes}
+LOCAL_SRC_FILES := ${emulator_camera_src}
+LOCAL_SRC_FILES += EmulatorCameraTest.cpp
+
+LOCAL_MODULE := emulatorcameratest
+include $(BUILD_EXECUTABLE)
+
 # Build all subdirectories #####################################################
 include $(call all-makefiles-under,$(LOCAL_PATH))
 
diff --git a/camera/EmulatorCameraTest.cpp b/camera/EmulatorCameraTest.cpp
new file mode 100644
index 0000000..684e6d7
--- /dev/null
+++ b/camera/EmulatorCameraTest.cpp
@@ -0,0 +1,91 @@
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include "fake-pipeline2/Base.h"
+#include "QemuClient.h"
+
+#include <linux/videodev2.h>
+#include <utils/Timers.h>
+
+using namespace android;
+
+// Test the capture speed of qemu camera, e.g., webcam and virtual scene
+int main(int argc, char* argv[]) {
+    uint32_t pixFmt;
+    if (!strncmp(argv[1], "RGB", 3)) {
+        pixFmt = V4L2_PIX_FMT_RGB32;
+    } else if (!strncmp(argv[1], "NV21", 3)) {
+        pixFmt = V4L2_PIX_FMT_NV21;
+    } else if (!strncmp(argv[1], "YV12", 3)) {
+        pixFmt = V4L2_PIX_FMT_YVU420;
+    } else {
+        printf("format error, use RGB, NV21 or YV12");
+        return -1;
+    }
+    uint32_t width = atoi(argv[2]);
+    uint32_t height = atoi(argv[3]);
+    std::string deviceName;
+    if (!strncmp(argv[4], "web", 3)) {
+        deviceName = "name=/dev/video0";
+    } else if (!strncmp(argv[4], "vir", 3)) {
+        deviceName = "name=virtualscene";
+    } else {
+        printf("device error, use web or virtual");
+        return -1;
+    }
+
+    // Open qemu pipe
+    CameraQemuClient client;
+    int ret = client.connectClient(deviceName.c_str());
+    if (ret != NO_ERROR) {
+        printf("Failed to connect device\n");
+        return -1;
+    }
+    ret = client.queryConnect();
+    if (ret == NO_ERROR) {
+        printf("Connected to device\n");
+    } else {
+        printf("Failed to connect device\n");
+        return -1;
+    }
+
+    // Caputre ASAP
+    ret = client.queryStart(pixFmt, width, height);
+    if (ret != NO_ERROR) {
+        printf("Failed to configure device for query\n");
+        return -1;
+    }
+    size_t bufferSize;
+    if (pixFmt == V4L2_PIX_FMT_RGB32) {
+        bufferSize = width * height * 4;
+    } else {
+        bufferSize = width * height * 12 / 8;
+    }
+    std::vector<char> buffer(bufferSize, 0);
+    float whiteBalance[] = {1.0f, 1.0f, 1.0f};
+    float exposureCompensation = 1.0f;
+    std::vector<nsecs_t> report;
+    size_t repeated = 100;
+    for (int i = 0 ; i < repeated; i++) {
+        nsecs_t start = systemTime();
+        client.queryFrame(buffer.data(), nullptr, 0, bufferSize,
+                          whiteBalance[0], whiteBalance[1], whiteBalance[2],
+                          exposureCompensation, nullptr);
+        nsecs_t end = systemTime();
+        report.push_back(end - start);
+    }
+
+    // Report
+    nsecs_t average, sum = 0;
+    for (int i = 0; i < repeated; i++) {
+        sum += report[i];
+    }
+    average = sum / repeated;
+    printf("Report for reading %d frames\n", repeated);
+    printf("\ttime total: %lld\n", sum);
+    printf("\tframe average: %lld\n", average);
+
+    return 0;
+}
+