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
This commit is contained in:
Eino-Ville Talvala
2012-03-23 12:12:58 -07:00
parent a85a93fdb0
commit d6a3832650
8 changed files with 220 additions and 67 deletions

View File

@@ -42,6 +42,7 @@ LOCAL_C_INCLUDES += external/jpeg \
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
EmulatedCameraHal.cpp \ EmulatedCameraHal.cpp \
EmulatedCameraFactory.cpp \ EmulatedCameraFactory.cpp \
EmulatedBaseCamera.cpp \
EmulatedCamera.cpp \ EmulatedCamera.cpp \
EmulatedCameraDevice.cpp \ EmulatedCameraDevice.cpp \
EmulatedQemuCamera.cpp \ EmulatedQemuCamera.cpp \

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -58,22 +58,17 @@ static void PrintParamDiff(const CameraParameters& current, const char* new_par)
*/ */
static char* AddValue(const char* param, const char* val); static char* AddValue(const char* param, const char* val);
EmulatedCamera::EmulatedCamera(int cameraId, struct hw_module_t* module) EmulatedCamera::EmulatedCamera(int cameraId,
: mPreviewWindow(), struct hw_module_t* module)
mCallbackNotifier(), : EmulatedBaseCamera(cameraId,
mCameraID(cameraId) HARDWARE_DEVICE_API_VERSION(1, 0),
&common,
module),
mPreviewWindow(),
mCallbackNotifier()
{ {
/* /* camera_device v1 fields. */
* Initialize camera_device descriptor for this object.
*/
/* Common header */
common.tag = HARDWARE_DEVICE_TAG;
common.version = 0;
common.module = module;
common.close = EmulatedCamera::close; common.close = EmulatedCamera::close;
/* camera_device fields. */
ops = &mDeviceOps; ops = &mDeviceOps;
priv = this; priv = this;
} }
@@ -243,7 +238,7 @@ status_t EmulatedCamera::getCameraInfo(struct camera_info* info)
info->orientation = 0; info->orientation = 0;
} }
return NO_ERROR; return EmulatedBaseCamera::getCameraInfo(info);
} }
status_t EmulatedCamera::setPreviewWindow(struct preview_stream_ops* window) status_t EmulatedCamera::setPreviewWindow(struct preview_stream_ops* window)

View File

@@ -18,31 +18,32 @@
#define HW_EMULATOR_CAMERA_EMULATED_CAMERA_H #define HW_EMULATOR_CAMERA_EMULATED_CAMERA_H
/* /*
* Contains declaration of a class EmulatedCamera that encapsulates functionality * Contains declaration of a class EmulatedCamera that encapsulates
* common to all emulated cameras ("fake", "webcam", "video file", etc.). * functionality common to all version 1.0 emulated camera devices ("fake",
* Instances of this class (for each emulated camera) are created during the * "webcam", "video file", etc.). Instances of this class (for each emulated
* construction of the EmulatedCameraFactory instance. * camera) are created during the construction of the EmulatedCameraFactory
* This class serves as an entry point for all camera API calls that defined * instance. This class serves as an entry point for all camera API calls that
* by camera_device_ops_t API. * defined by camera_device_ops_t API.
*/ */
#include <camera/CameraParameters.h> #include <camera/CameraParameters.h>
#include "EmulatedBaseCamera.h"
#include "EmulatedCameraDevice.h" #include "EmulatedCameraDevice.h"
#include "PreviewWindow.h" #include "PreviewWindow.h"
#include "CallbackNotifier.h" #include "CallbackNotifier.h"
namespace android { namespace android {
/* Encapsulates functionality common to all emulated cameras ("fake", "webcam", /* Encapsulates functionality common to all version 1.0 emulated camera devices
* "file stream", etc.). * ("fake", "webcam", "file stream", etc.).
* *
* Note that EmulatedCameraFactory instantiates object of this class just once, * Note that EmulatedCameraFactory instantiates object of this class just once,
* when EmulatedCameraFactory instance gets constructed. Connection to / * when EmulatedCameraFactory instance gets constructed. Connection to /
* disconnection from the actual camera device is handled by calls to connectDevice(), * disconnection from the actual camera device is handled by calls to
* and closeCamera() methods of this class that are ivoked in response to * connectDevice(), and closeCamera() methods of this class that are ivoked in
* hw_module_methods_t::open, and camera_device::close callbacks. * 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: public:
/* Constructs EmulatedCamera instance. /* Constructs EmulatedCamera instance.
* Param: * Param:
@@ -50,7 +51,8 @@ public:
* instance in camera factory's array. * instance in camera factory's array.
* module - Emulated camera HAL module descriptor. * 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. */ /* Destructs EmulatedCamera instance. */
virtual ~EmulatedCamera(); virtual ~EmulatedCamera();
@@ -69,10 +71,7 @@ public:
***************************************************************************/ ***************************************************************************/
public: public:
/* Initializes EmulatedCamera instance. /** Override of base class method */
* Return:
* NO_ERROR on success, or an appropriate error status on failure.
*/
virtual status_t Initialize(); virtual status_t Initialize();
/* Next frame is available in the camera device. /* Next frame is available in the camera device.
@@ -105,26 +104,13 @@ public:
***************************************************************************/ ***************************************************************************/
public: public:
/* Creates connection to the emulated camera device. /** Override of base class method */
* 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.
*/
virtual status_t connectCamera(hw_device_t** device); virtual status_t connectCamera(hw_device_t** device);
/* Closes connection to the emulated camera. /** Override of base class method */
* 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.
*/
virtual status_t closeCamera(); virtual status_t closeCamera();
/* Gets camera information. /** Override of base class method */
* 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.
*/
virtual status_t getCameraInfo(struct camera_info* info); virtual status_t getCameraInfo(struct camera_info* info);
/**************************************************************************** /****************************************************************************
@@ -388,9 +374,6 @@ protected:
/* Callback notifier. */ /* Callback notifier. */
CallbackNotifier mCallbackNotifier; CallbackNotifier mCallbackNotifier;
/* Zero-based ID assigned to this camera. */
int mCameraID;
private: private:
/* Registered callbacks implementing camera API. */ /* Registered callbacks implementing camera API. */
static camera_device_ops_t mDeviceOps; static camera_device_ops_t mDeviceOps;

View File

@@ -60,7 +60,7 @@ EmulatedCameraFactory::EmulatedCameraFactory()
* cameras created. Note that we preallocate the array so it may contain * cameras created. Note that we preallocate the array so it may contain
* two fake cameras: one facing back, and another facing front. */ * two fake cameras: one facing back, and another facing front. */
if (mEmulatedCameras == NULL) { if (mEmulatedCameras == NULL) {
mEmulatedCameras = new EmulatedCamera*[mEmulatedCameraNum + 1]; mEmulatedCameras = new EmulatedBaseCamera*[mEmulatedCameraNum + 1];
if (mEmulatedCameras == NULL) { if (mEmulatedCameras == NULL) {
ALOGE("%s: Unable to allocate emulated camera array for %d entries", ALOGE("%s: Unable to allocate emulated camera array for %d entries",
__FUNCTION__, mEmulatedCameraNum); __FUNCTION__, mEmulatedCameraNum);
@@ -92,7 +92,7 @@ EmulatedCameraFactory::EmulatedCameraFactory()
/* Make sure that array is allocated (in case there were no 'qemu' /* Make sure that array is allocated (in case there were no 'qemu'
* cameras created. */ * cameras created. */
if (mEmulatedCameras == NULL) { if (mEmulatedCameras == NULL) {
mEmulatedCameras = new EmulatedCamera*[mEmulatedCameraNum]; mEmulatedCameras = new EmulatedBaseCamera*[mEmulatedCameraNum];
if (mEmulatedCameras == NULL) { if (mEmulatedCameras == NULL) {
ALOGE("%s: Unable to allocate emulated camera array for %d entries", ALOGE("%s: Unable to allocate emulated camera array for %d entries",
__FUNCTION__, mEmulatedCameraNum); __FUNCTION__, mEmulatedCameraNum);
@@ -136,7 +136,7 @@ EmulatedCameraFactory::~EmulatedCameraFactory()
/**************************************************************************** /****************************************************************************
* Camera HAL API handlers. * 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. * instance, and dispatches the call to that instance.
* *
***************************************************************************/ ***************************************************************************/
@@ -260,14 +260,14 @@ void EmulatedCameraFactory::createQemuCameras()
/* Allocate the array for emulated camera instances. Note that we allocate /* Allocate the array for emulated camera instances. Note that we allocate
* two more entries for back and front fake camera emulation. */ * two more entries for back and front fake camera emulation. */
mEmulatedCameras = new EmulatedCamera*[num + 2]; mEmulatedCameras = new EmulatedBaseCamera*[num + 2];
if (mEmulatedCameras == NULL) { if (mEmulatedCameras == NULL) {
ALOGE("%s: Unable to allocate emulated camera array for %d entries", ALOGE("%s: Unable to allocate emulated camera array for %d entries",
__FUNCTION__, num + 1); __FUNCTION__, num + 1);
free(camera_list); free(camera_list);
return; 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 * Iterate the list, creating, and initializin emulated qemu cameras for each

View File

@@ -17,7 +17,7 @@
#ifndef HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H #ifndef HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H
#define HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H #define HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H
#include "EmulatedCamera.h" #include "EmulatedBaseCamera.h"
#include "QemuClient.h" #include "QemuClient.h"
namespace android { namespace android {
@@ -146,7 +146,7 @@ private:
FactoryQemuClient mQemuClient; FactoryQemuClient mQemuClient;
/* Array of cameras available for the emulation. */ /* Array of cameras available for the emulation. */
EmulatedCamera** mEmulatedCameras; EmulatedBaseCamera** mEmulatedCameras;
/* Number of emulated cameras (including the fake ones). */ /* Number of emulated cameras (including the fake ones). */
int mEmulatedCameraNum; int mEmulatedCameraNum;

View File

@@ -30,15 +30,15 @@
*/ */
camera_module_t HAL_MODULE_INFO_SYM = { camera_module_t HAL_MODULE_INFO_SYM = {
common: { common: {
tag: HARDWARE_MODULE_TAG, tag: HARDWARE_MODULE_TAG,
version_major: 1, module_api_version: CAMERA_MODULE_API_VERSION_2_0,
version_minor: 0, hal_api_version: HARDWARE_HAL_API_VERSION,
id: CAMERA_HARDWARE_MODULE_ID, id: CAMERA_HARDWARE_MODULE_ID,
name: "Emulated Camera Module", name: "Emulated Camera Module",
author: "The Android Open Source Project", author: "The Android Open Source Project",
methods: &android::EmulatedCameraFactory::mCameraModuleMethods, methods: &android::EmulatedCameraFactory::mCameraModuleMethods,
dso: NULL, dso: NULL,
reserved: {0}, reserved: {0},
}, },
get_number_of_cameras: android::EmulatedCameraFactory::get_number_of_cameras, get_number_of_cameras: android::EmulatedCameraFactory::get_number_of_cameras,
get_camera_info: android::EmulatedCameraFactory::get_camera_info, get_camera_info: android::EmulatedCameraFactory::get_camera_info,