Update emulated camera to support HAL v2.0 modules and devices.
- Update camera HAL module to version 2
- Break out common camera HAL device functionality into
EmulatedBaseCamera
- EmulatedCamera is now the base class for all version 1 camera
devices.
- No camera device version 2 implementation included.
No change to supported functionality.
Change-Id: Iabb0b9a4e41f3c01dfd921256fa8fb1d40d71834
diff --git a/tools/emulator/system/camera/Android.mk b/tools/emulator/system/camera/Android.mk
index 9596f7e..61e1e83 100755
--- a/tools/emulator/system/camera/Android.mk
+++ b/tools/emulator/system/camera/Android.mk
@@ -42,6 +42,7 @@
LOCAL_SRC_FILES := \
EmulatedCameraHal.cpp \
EmulatedCameraFactory.cpp \
+ EmulatedBaseCamera.cpp \
EmulatedCamera.cpp \
EmulatedCameraDevice.cpp \
EmulatedQemuCamera.cpp \
diff --git a/tools/emulator/system/camera/EmulatedBaseCamera.cpp b/tools/emulator/system/camera/EmulatedBaseCamera.cpp
new file mode 100644
index 0000000..19d398e
--- /dev/null
+++ b/tools/emulator/system/camera/EmulatedBaseCamera.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Contains implementation of a class EmulatedBaseCamera that encapsulates
+ * functionality common to all emulated camera device versions ("fake",
+ * "webcam", "video file", "cam2.0" etc.). Instances of this class (for each
+ * emulated camera) are created during the construction of the
+ * EmulatedCameraFactory instance. This class serves as an entry point for all
+ * camera API calls that are common across all versions of the
+ * camera_device_t/camera_module_t structures.
+ */
+
+#define LOG_NDEBUG 0
+#define LOG_TAG "EmulatedCamera_BaseCamera"
+#include <cutils/log.h>
+
+#include "EmulatedBaseCamera.h"
+
+namespace android {
+
+EmulatedBaseCamera::EmulatedBaseCamera(int cameraId,
+ uint32_t cameraVersion,
+ struct hw_device_t* device,
+ struct hw_module_t* module)
+ : mCameraInfo(NULL),
+ mCameraID(cameraId),
+ mCameraDeviceVersion(cameraVersion)
+{
+ /*
+ * Initialize camera_device descriptor for this object.
+ */
+
+ /* Common header */
+ device->tag = HARDWARE_DEVICE_TAG;
+ device->version = cameraVersion;
+ device->module = module;
+ device->close = NULL; // Must be filled in by child implementation
+}
+
+EmulatedBaseCamera::~EmulatedBaseCamera()
+{
+}
+
+status_t EmulatedBaseCamera::getCameraInfo(struct camera_info* info)
+{
+ ALOGV("%s", __FUNCTION__);
+
+ info->device_version = mCameraDeviceVersion;
+ if (mCameraDeviceVersion >= HARDWARE_DEVICE_API_VERSION(2, 0)) {
+ info->static_camera_characteristics = mCameraInfo;
+ } else {
+ info->static_camera_characteristics = (camera_metadata_t*)0xcafef00d;
+ }
+
+ return NO_ERROR;
+}
+
+
+} /* namespace android */
diff --git a/tools/emulator/system/camera/EmulatedBaseCamera.h b/tools/emulator/system/camera/EmulatedBaseCamera.h
new file mode 100644
index 0000000..5888ca0
--- /dev/null
+++ b/tools/emulator/system/camera/EmulatedBaseCamera.h
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H
+#define HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H
+
+#include <hardware/camera_common.h>
+#include <utils/Errors.h>
+
+namespace android {
+
+/*
+ * Contains declaration of a class EmulatedBaseCamera that encapsulates
+ * functionality common to all emulated camera device versions ("fake",
+ * "webcam", "video file", etc.). Instances of this class (for each emulated
+ * camera) are created during the construction of the EmulatedCameraFactory
+ * instance. This class serves as an entry point for all camera API calls that
+ * are common across all versions of the camera_device_t/camera_module_t
+ * structures.
+ */
+
+class EmulatedBaseCamera {
+ public:
+ EmulatedBaseCamera(int cameraId,
+ uint32_t cameraVersion,
+ struct hw_device_t* device,
+ struct hw_module_t* module);
+
+ virtual ~EmulatedBaseCamera();
+
+ /****************************************************************************
+ * Public API
+ ***************************************************************************/
+
+ public:
+ /* Initializes EmulatedCamera instance.
+ * Return:
+ * NO_ERROR on success, or an appropriate error status on failure.
+ */
+ virtual status_t Initialize() = 0;
+
+ /****************************************************************************
+ * Camera API implementation
+ ***************************************************************************/
+
+ public:
+ /* Creates connection to the emulated camera device.
+ * This method is called in response to hw_module_methods_t::open callback.
+ * NOTE: When this method is called the object is locked.
+ * Note that failures in this method are reported as negative EXXX statuses.
+ */
+ virtual status_t connectCamera(hw_device_t** device) = 0;
+
+ /* Closes connection to the emulated camera.
+ * This method is called in response to camera_device::close callback.
+ * NOTE: When this method is called the object is locked.
+ * Note that failures in this method are reported as negative EXXX statuses.
+ */
+ virtual status_t closeCamera() = 0;
+
+ /* Gets camera information.
+ * This method is called in response to camera_module_t::get_camera_info
+ * callback.
+ * NOTE: When this method is called the object is locked.
+ * Note that failures in this method are reported as negative EXXX statuses.
+ */
+ virtual status_t getCameraInfo(struct camera_info* info) = 0;
+
+ /****************************************************************************
+ * Data members
+ ***************************************************************************/
+
+ protected:
+ /* Fixed camera information for camera2 devices. Must be valid to access if
+ * mCameraDeviceVersion is >= HARDWARE_DEVICE_API_VERSION(2,0) */
+ camera_metadata_t *mCameraInfo;
+
+ private:
+ /* Zero-based ID assigned to this camera. */
+ int mCameraID;
+
+ /* Version of the camera device HAL implemented by this camera */
+ int mCameraDeviceVersion;
+};
+
+} /* namespace android */
+
+#endif /* HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H */
diff --git a/tools/emulator/system/camera/EmulatedCamera.cpp b/tools/emulator/system/camera/EmulatedCamera.cpp
index d54d7b4..28aede1 100755
--- a/tools/emulator/system/camera/EmulatedCamera.cpp
+++ b/tools/emulator/system/camera/EmulatedCamera.cpp
@@ -58,22 +58,17 @@
*/
static char* AddValue(const char* param, const char* val);
-EmulatedCamera::EmulatedCamera(int cameraId, struct hw_module_t* module)
- : mPreviewWindow(),
- mCallbackNotifier(),
- mCameraID(cameraId)
+EmulatedCamera::EmulatedCamera(int cameraId,
+ struct hw_module_t* module)
+ : EmulatedBaseCamera(cameraId,
+ HARDWARE_DEVICE_API_VERSION(1, 0),
+ &common,
+ module),
+ mPreviewWindow(),
+ mCallbackNotifier()
{
- /*
- * Initialize camera_device descriptor for this object.
- */
-
- /* Common header */
- common.tag = HARDWARE_DEVICE_TAG;
- common.version = 0;
- common.module = module;
+ /* camera_device v1 fields. */
common.close = EmulatedCamera::close;
-
- /* camera_device fields. */
ops = &mDeviceOps;
priv = this;
}
@@ -243,7 +238,7 @@
info->orientation = 0;
}
- return NO_ERROR;
+ return EmulatedBaseCamera::getCameraInfo(info);
}
status_t EmulatedCamera::setPreviewWindow(struct preview_stream_ops* window)
diff --git a/tools/emulator/system/camera/EmulatedCamera.h b/tools/emulator/system/camera/EmulatedCamera.h
index 0a7584e..9825d5d 100755
--- a/tools/emulator/system/camera/EmulatedCamera.h
+++ b/tools/emulator/system/camera/EmulatedCamera.h
@@ -18,31 +18,32 @@
#define HW_EMULATOR_CAMERA_EMULATED_CAMERA_H
/*
- * Contains declaration of a class EmulatedCamera that encapsulates functionality
- * common to all emulated cameras ("fake", "webcam", "video file", etc.).
- * Instances of this class (for each emulated camera) are created during the
- * construction of the EmulatedCameraFactory instance.
- * This class serves as an entry point for all camera API calls that defined
- * by camera_device_ops_t API.
+ * Contains declaration of a class EmulatedCamera that encapsulates
+ * functionality common to all version 1.0 emulated camera devices ("fake",
+ * "webcam", "video file", etc.). Instances of this class (for each emulated
+ * camera) are created during the construction of the EmulatedCameraFactory
+ * instance. This class serves as an entry point for all camera API calls that
+ * defined by camera_device_ops_t API.
*/
#include <camera/CameraParameters.h>
+#include "EmulatedBaseCamera.h"
#include "EmulatedCameraDevice.h"
#include "PreviewWindow.h"
#include "CallbackNotifier.h"
namespace android {
-/* Encapsulates functionality common to all emulated cameras ("fake", "webcam",
- * "file stream", etc.).
+/* Encapsulates functionality common to all version 1.0 emulated camera devices
+ * ("fake", "webcam", "file stream", etc.).
*
* Note that EmulatedCameraFactory instantiates object of this class just once,
* when EmulatedCameraFactory instance gets constructed. Connection to /
- * disconnection from the actual camera device is handled by calls to connectDevice(),
- * and closeCamera() methods of this class that are ivoked in response to
- * hw_module_methods_t::open, and camera_device::close callbacks.
+ * disconnection from the actual camera device is handled by calls to
+ * connectDevice(), and closeCamera() methods of this class that are ivoked in
+ * response to hw_module_methods_t::open, and camera_device::close callbacks.
*/
-class EmulatedCamera : public camera_device {
+class EmulatedCamera : public camera_device, public EmulatedBaseCamera {
public:
/* Constructs EmulatedCamera instance.
* Param:
@@ -50,7 +51,8 @@
* instance in camera factory's array.
* module - Emulated camera HAL module descriptor.
*/
- EmulatedCamera(int cameraId, struct hw_module_t* module);
+ EmulatedCamera(int cameraId,
+ struct hw_module_t* module);
/* Destructs EmulatedCamera instance. */
virtual ~EmulatedCamera();
@@ -69,10 +71,7 @@
***************************************************************************/
public:
- /* Initializes EmulatedCamera instance.
- * Return:
- * NO_ERROR on success, or an appropriate error status on failure.
- */
+ /** Override of base class method */
virtual status_t Initialize();
/* Next frame is available in the camera device.
@@ -105,26 +104,13 @@
***************************************************************************/
public:
- /* Creates connection to the emulated camera device.
- * This method is called in response to hw_module_methods_t::open callback.
- * NOTE: When this method is called the object is locked.
- * Note that failures in this method are reported as negave EXXX statuses.
- */
+ /** Override of base class method */
virtual status_t connectCamera(hw_device_t** device);
- /* Closes connection to the emulated camera.
- * This method is called in response to camera_device::close callback.
- * NOTE: When this method is called the object is locked.
- * Note that failures in this method are reported as negave EXXX statuses.
- */
+ /** Override of base class method */
virtual status_t closeCamera();
- /* Gets camera information.
- * This method is called in response to camera_module_t::get_camera_info
- * callback.
- * NOTE: When this method is called the object is locked.
- * Note that failures in this method are reported as negave EXXX statuses.
- */
+ /** Override of base class method */
virtual status_t getCameraInfo(struct camera_info* info);
/****************************************************************************
@@ -388,9 +374,6 @@
/* Callback notifier. */
CallbackNotifier mCallbackNotifier;
- /* Zero-based ID assigned to this camera. */
- int mCameraID;
-
private:
/* Registered callbacks implementing camera API. */
static camera_device_ops_t mDeviceOps;
diff --git a/tools/emulator/system/camera/EmulatedCameraFactory.cpp b/tools/emulator/system/camera/EmulatedCameraFactory.cpp
index 35e4e5c..fbb05b5 100755
--- a/tools/emulator/system/camera/EmulatedCameraFactory.cpp
+++ b/tools/emulator/system/camera/EmulatedCameraFactory.cpp
@@ -60,7 +60,7 @@
* cameras created. Note that we preallocate the array so it may contain
* two fake cameras: one facing back, and another facing front. */
if (mEmulatedCameras == NULL) {
- mEmulatedCameras = new EmulatedCamera*[mEmulatedCameraNum + 1];
+ mEmulatedCameras = new EmulatedBaseCamera*[mEmulatedCameraNum + 1];
if (mEmulatedCameras == NULL) {
ALOGE("%s: Unable to allocate emulated camera array for %d entries",
__FUNCTION__, mEmulatedCameraNum);
@@ -92,7 +92,7 @@
/* Make sure that array is allocated (in case there were no 'qemu'
* cameras created. */
if (mEmulatedCameras == NULL) {
- mEmulatedCameras = new EmulatedCamera*[mEmulatedCameraNum];
+ mEmulatedCameras = new EmulatedBaseCamera*[mEmulatedCameraNum];
if (mEmulatedCameras == NULL) {
ALOGE("%s: Unable to allocate emulated camera array for %d entries",
__FUNCTION__, mEmulatedCameraNum);
@@ -136,7 +136,7 @@
/****************************************************************************
* Camera HAL API handlers.
*
- * Each handler simply verifies existence of an appropriate EmulatedCamera
+ * Each handler simply verifies existence of an appropriate EmulatedBaseCamera
* instance, and dispatches the call to that instance.
*
***************************************************************************/
@@ -260,14 +260,14 @@
/* Allocate the array for emulated camera instances. Note that we allocate
* two more entries for back and front fake camera emulation. */
- mEmulatedCameras = new EmulatedCamera*[num + 2];
+ mEmulatedCameras = new EmulatedBaseCamera*[num + 2];
if (mEmulatedCameras == NULL) {
ALOGE("%s: Unable to allocate emulated camera array for %d entries",
__FUNCTION__, num + 1);
free(camera_list);
return;
}
- memset(mEmulatedCameras, 0, sizeof(EmulatedCamera*) * (num + 1));
+ memset(mEmulatedCameras, 0, sizeof(EmulatedBaseCamera*) * (num + 1));
/*
* Iterate the list, creating, and initializin emulated qemu cameras for each
diff --git a/tools/emulator/system/camera/EmulatedCameraFactory.h b/tools/emulator/system/camera/EmulatedCameraFactory.h
index 0aa4a32..7e3d4b2 100755
--- a/tools/emulator/system/camera/EmulatedCameraFactory.h
+++ b/tools/emulator/system/camera/EmulatedCameraFactory.h
@@ -17,7 +17,7 @@
#ifndef HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H
#define HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H
-#include "EmulatedCamera.h"
+#include "EmulatedBaseCamera.h"
#include "QemuClient.h"
namespace android {
@@ -146,7 +146,7 @@
FactoryQemuClient mQemuClient;
/* Array of cameras available for the emulation. */
- EmulatedCamera** mEmulatedCameras;
+ EmulatedBaseCamera** mEmulatedCameras;
/* Number of emulated cameras (including the fake ones). */
int mEmulatedCameraNum;
diff --git a/tools/emulator/system/camera/EmulatedCameraHal.cpp b/tools/emulator/system/camera/EmulatedCameraHal.cpp
index 7f3f7b8..aa0cb00 100755
--- a/tools/emulator/system/camera/EmulatedCameraHal.cpp
+++ b/tools/emulator/system/camera/EmulatedCameraHal.cpp
@@ -30,15 +30,15 @@
*/
camera_module_t HAL_MODULE_INFO_SYM = {
common: {
- tag: HARDWARE_MODULE_TAG,
- version_major: 1,
- version_minor: 0,
- id: CAMERA_HARDWARE_MODULE_ID,
- name: "Emulated Camera Module",
- author: "The Android Open Source Project",
- methods: &android::EmulatedCameraFactory::mCameraModuleMethods,
- dso: NULL,
- reserved: {0},
+ tag: HARDWARE_MODULE_TAG,
+ module_api_version: CAMERA_MODULE_API_VERSION_2_0,
+ hal_api_version: HARDWARE_HAL_API_VERSION,
+ id: CAMERA_HARDWARE_MODULE_ID,
+ name: "Emulated Camera Module",
+ author: "The Android Open Source Project",
+ methods: &android::EmulatedCameraFactory::mCameraModuleMethods,
+ dso: NULL,
+ reserved: {0},
},
get_number_of_cameras: android::EmulatedCameraFactory::get_number_of_cameras,
get_camera_info: android::EmulatedCameraFactory::get_camera_info,