diff options
author | Alex Ray <aray@google.com> | 2013-02-25 15:02:16 -0800 |
---|---|---|
committer | Alex Ray <aray@google.com> | 2013-02-27 00:02:37 -0800 |
commit | a0ed4bead4d7a9b9031f7cefe0ef49a951443461 (patch) | |
tree | b02ec06826a5358c28b86010902ea684a7ff7fe4 /modules | |
parent | 819cfd87bad560fbd89747371088ad35aaef8d43 (diff) | |
download | hardware_libhardware-a0ed4bead4d7a9b9031f7cefe0ef49a951443461.zip hardware_libhardware-a0ed4bead4d7a9b9031f7cefe0ef49a951443461.tar.gz hardware_libhardware-a0ed4bead4d7a9b9031f7cefe0ef49a951443461.tar.bz2 |
modules: camera: Camera v3 Devices
Default camera HAL statically allocates camera devices. Update camera
device to API v3.
Change-Id: Ic53ffcf3b746b9b4011b932e26dbb0f533cba554
Diffstat (limited to 'modules')
-rw-r--r-- | modules/camera/Camera.cpp | 155 | ||||
-rw-r--r-- | modules/camera/Camera.h | 38 | ||||
-rw-r--r-- | modules/camera/CameraHAL.cpp | 18 | ||||
-rw-r--r-- | modules/camera/CameraHAL.h | 4 |
4 files changed, 163 insertions, 52 deletions
diff --git a/modules/camera/Camera.cpp b/modules/camera/Camera.cpp index 6ae0a5d..203b772 100644 --- a/modules/camera/Camera.cpp +++ b/modules/camera/Camera.cpp @@ -16,6 +16,8 @@ #include <cstdlib> #include <pthread.h> +#include <hardware/camera3.h> +#include "CameraHAL.h" //#define LOG_NDEBUG 0 #define LOG_TAG "Camera" @@ -32,24 +34,24 @@ extern "C" { // Shim passed to the framework to close an opened device. static int close_device(hw_device_t* dev) { - camera2_device_t* cam_dev = reinterpret_cast<camera2_device_t*>(dev); + camera3_device_t* cam_dev = reinterpret_cast<camera3_device_t*>(dev); Camera* cam = static_cast<Camera*>(cam_dev->priv); return cam->close(); } } // extern "C" -Camera::Camera(int id, const hw_module_t* module) - : mId(id), - mBusy(false), - mMetadata(NULL) +Camera::Camera(int id) + : mId(id), + mBusy(false), + mCallbackOps(NULL) { pthread_mutex_init(&mMutex, NULL); // No pthread mutex attributes. - // TODO: fill in device operations function pointers + memset(&mDevice, 0, sizeof(mDevice)); mDevice.common.tag = HARDWARE_DEVICE_TAG; - mDevice.common.module = const_cast<hw_module_t*>(module); mDevice.common.close = close_device; + mDevice.ops = const_cast<camera3_device_ops_t*>(&sOps); mDevice.priv = this; } @@ -57,20 +59,22 @@ Camera::~Camera() { } -int Camera::open() +int Camera::open(const hw_module_t *module, hw_device_t **device) { - ALOGV("%s: camera id %d", __func__, mId); - ATRACE_BEGIN("open"); + ALOGI("%s:%d: Opening camera device", __func__, mId); + ATRACE_BEGIN(__func__); pthread_mutex_lock(&mMutex); if (mBusy) { pthread_mutex_unlock(&mMutex); ATRACE_END(); - ALOGE("%s:id%d: Error, device already in use.", __func__, mId); + ALOGE("%s:%d: Error! Camera device already opened", __func__, mId); return -EBUSY; } // TODO: open camera dev nodes, etc mBusy = true; + mDevice.common.module = const_cast<hw_module_t*>(module); + *device = &mDevice.common; pthread_mutex_unlock(&mMutex); ATRACE_END(); @@ -79,13 +83,13 @@ int Camera::open() int Camera::close() { - ALOGV("%s: camera id %d", __func__, mId); - ATRACE_BEGIN("close"); + ALOGI("%s:%d: Closing camera device", __func__, mId); + ATRACE_BEGIN(__func__); pthread_mutex_lock(&mMutex); if (!mBusy) { pthread_mutex_unlock(&mMutex); ATRACE_END(); - ALOGE("%s:id%d: Error, close() on not open device.", __func__, mId); + ALOGE("%s:%d: Error! Camera device not open", __func__, mId); return -EINVAL; } @@ -97,36 +101,121 @@ int Camera::close() return 0; } -int Camera::getCameraInfo(struct camera_info* info) +int Camera::initialize(const camera3_callback_ops_t *callback_ops) { - ALOGV("%s: camera id %d: info=%p", __func__, mId, info); - init(); - if (mMetadata == NULL) { - ALOGE("%s:id%d: unable to initialize metadata.", __func__, mId); - return -ENOENT; - } + ALOGV("%s:%d: callback_ops=%p", __func__, mId, callback_ops); + mCallbackOps = callback_ops; + return 0; +} - // TODO: fill remainder of info struct - info->static_camera_characteristics = mMetadata; +int Camera::configureStreams(camera3_stream_configuration_t *stream_list) +{ + ALOGV("%s:%d: stream_list=%p", __func__, mId, stream_list); + // TODO: validate input, create internal stream representations + return 0; +} +int Camera::registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set) +{ + ALOGV("%s:%d: buffer_set=%p", __func__, mId, buf_set); + // TODO: register buffers with hardware return 0; } -void Camera::init() +const camera_metadata_t* Camera::constructDefaultRequestSettings(int type) { - ATRACE_BEGIN("init"); - pthread_mutex_lock(&mMutex); - if (mMetadata != NULL) { - pthread_mutex_unlock(&mMutex); + ALOGV("%s:%d: type=%d", __func__, mId, type); + // TODO: return statically built default request + return NULL; +} + +int Camera::processCaptureRequest(camera3_capture_request_t *request) +{ + ALOGV("%s:%d: request=%p", __func__, mId, request); + ATRACE_BEGIN(__func__); + + if (request == NULL) { + ALOGE("%s:%d: NULL request recieved", __func__, mId); ATRACE_END(); - return; + return -EINVAL; } - // TODO: init metadata, dummy value for now - mMetadata = allocate_camera_metadata(1,1); - - pthread_mutex_unlock(&mMutex); + // TODO: verify request; submit request to hardware ATRACE_END(); + return 0; +} + +void Camera::getMetadataVendorTagOps(vendor_tag_query_ops_t *ops) +{ + ALOGV("%s:%d: ops=%p", __func__, mId, ops); + // TODO: return vendor tag ops +} + +void Camera::dump(int fd) +{ + ALOGV("%s:%d: Dumping to fd %d", fd); + // TODO: dprintf all relevant state to fd +} + +extern "C" { +// Get handle to camera from device priv data +static Camera *camdev_to_camera(const camera3_device_t *dev) +{ + return reinterpret_cast<Camera*>(dev->priv); +} + +static int initialize(const camera3_device_t *dev, + const camera3_callback_ops_t *callback_ops) +{ + return camdev_to_camera(dev)->initialize(callback_ops); +} + +static int configure_streams(const camera3_device_t *dev, + camera3_stream_configuration_t *stream_list) +{ + return camdev_to_camera(dev)->configureStreams(stream_list); +} + +static int register_stream_buffers(const camera3_device_t *dev, + const camera3_stream_buffer_set_t *buffer_set) +{ + return camdev_to_camera(dev)->registerStreamBuffers(buffer_set); +} + +static const camera_metadata_t *construct_default_request_settings( + const camera3_device_t *dev, int type) +{ + return camdev_to_camera(dev)->constructDefaultRequestSettings(type); } +static int process_capture_request(const camera3_device_t *dev, + camera3_capture_request_t *request) +{ + return camdev_to_camera(dev)->processCaptureRequest(request); +} + +static void get_metadata_vendor_tag_ops(const camera3_device_t *dev, + vendor_tag_query_ops_t *ops) +{ + camdev_to_camera(dev)->getMetadataVendorTagOps(ops); +} + +static void dump(const camera3_device_t *dev, int fd) +{ + camdev_to_camera(dev)->dump(fd); +} +} // extern "C" + +const camera3_device_ops_t Camera::sOps = { + .initialize = default_camera_hal::initialize, + .configure_streams = default_camera_hal::configure_streams, + .register_stream_buffers = default_camera_hal::register_stream_buffers, + .construct_default_request_settings = + default_camera_hal::construct_default_request_settings, + .process_capture_request = default_camera_hal::process_capture_request, + .get_metadata_vendor_tag_ops = + default_camera_hal::get_metadata_vendor_tag_ops, + .dump = default_camera_hal::dump +}; + } // namespace default_camera_hal diff --git a/modules/camera/Camera.h b/modules/camera/Camera.h index ca66406..f38b461 100644 --- a/modules/camera/Camera.h +++ b/modules/camera/Camera.h @@ -18,42 +18,46 @@ #define CAMERA_H_ #include <pthread.h> -#include <hardware/camera_common.h> -#include <hardware/camera2.h> +#include <hardware/hardware.h> +#include <hardware/camera3.h> namespace default_camera_hal { // Camera represents a physical camera on a device. // This is constructed when the HAL module is loaded, one per physical camera. // It is opened by the framework, and must be closed before it can be opened // again. -// Also, the framework can query for camera metadata with getCameraInfo. -// For the first query, the metadata must first be allocated and initialized, -// but once done it is used for all future calls. -// It is protected by @mMutex, and functions that modify the Camera object hold -// this lock when performing modifications. Currently these functions are: -// @open, @close, and @init. class Camera { public: // id is used to distinguish cameras. 0 <= id < NUM_CAMERAS. // module is a handle to the HAL module, used when the device is opened. - Camera(int id, const hw_module_t* module); + Camera(int id); ~Camera(); // Common Camera Device Operations (see <hardware/camera_common.h>) - camera2_device_t mDevice; - int open(); + int open(const hw_module_t *module, hw_device_t **device); int close(); - int getCameraInfo(struct camera_info* info); + + // Camera v3 Device Operations (see <hardware/camera3.h>) + int initialize(const camera3_callback_ops_t *callback_ops); + int configureStreams(camera3_stream_configuration_t *stream_list); + int registerStreamBuffers(const camera3_stream_buffer_set_t *buf_set); + const camera_metadata_t *constructDefaultRequestSettings(int type); + int processCaptureRequest(camera3_capture_request_t *request); + void getMetadataVendorTagOps(vendor_tag_query_ops_t *ops); + void dump(int fd); + + // Camera device handle returned to framework for use + camera3_device_t mDevice; private: - // One-time initialization of camera metadata. - void init(); // Identifier used by framework to distinguish cameras int mId; - // True indicates camera is already open. + // Busy flag indicates camera is in use bool mBusy; - // Camera characteristics. NULL means it has not been allocated yet. - camera_metadata_t* mMetadata; + // Camera device operations handle shared by all devices + const static camera3_device_ops_t sOps; + // Methods used to call back into the framework + const camera3_callback_ops_t *mCallbackOps; // Lock protecting the Camera object for modifications pthread_mutex_t mMutex; }; diff --git a/modules/camera/CameraHAL.cpp b/modules/camera/CameraHAL.cpp index 9880908..6cae7d2 100644 --- a/modules/camera/CameraHAL.cpp +++ b/modules/camera/CameraHAL.cpp @@ -17,6 +17,7 @@ #include <cstdlib> #include <hardware/camera_common.h> #include <hardware/hardware.h> +#include "Camera.h" //#define LOG_NDEBUG 0 #define LOG_TAG "DefaultCameraHAL" @@ -42,10 +43,23 @@ CameraHAL::CameraHAL(int num_cameras) : mNumberOfCameras(num_cameras), mCallbacks(NULL) { + int i; + + // Allocate camera array and instantiate camera devices + mCameras = new Camera*[mNumberOfCameras]; + for (i = 0; i < mNumberOfCameras; i++) { + mCameras[i] = new Camera(i); + } } CameraHAL::~CameraHAL() { + int i; + + for (i = 0; i < mNumberOfCameras; i++) { + delete mCameras[i]; + } + delete [] mCameras; } int CameraHAL::getNumberOfCameras() @@ -76,6 +90,7 @@ int CameraHAL::open(const hw_module_t* mod, const char* name, hw_device_t** dev) { int id; char *nameEnd; + Camera *cam; ALOGV("%s: module=%p, name=%s, device=%p", __func__, mod, name, dev); id = strtol(name, &nameEnd, 10); @@ -86,8 +101,7 @@ int CameraHAL::open(const hw_module_t* mod, const char* name, hw_device_t** dev) ALOGE("%s: Invalid camera id %d", __func__, id); return -ENODEV; } - // TODO: check for existing use; allocate and return new camera device - return 0; + return mCameras[id]->open(mod, dev); } extern "C" { diff --git a/modules/camera/CameraHAL.h b/modules/camera/CameraHAL.h index b53ab31..ba0db4e 100644 --- a/modules/camera/CameraHAL.h +++ b/modules/camera/CameraHAL.h @@ -17,8 +17,10 @@ #ifndef CAMERA_HAL_H_ #define CAMERA_HAL_H_ +#include <cutils/bitops.h> #include <hardware/hardware.h> #include <hardware/camera_common.h> +#include "Camera.h" namespace default_camera_hal { // CameraHAL contains all module state that isn't specific to an individual @@ -41,6 +43,8 @@ class CameraHAL { const int mNumberOfCameras; // Callback handle const camera_module_callbacks_t *mCallbacks; + // Array of camera devices, contains mNumberOfCameras device pointers + Camera **mCameras; }; } // namespace default_camera_hal |