Add skeleton implementation of a fake v2 camera device.

Change-Id: Idd2485064548a6036ea318680065b7429463d9cd
This commit is contained in:
Eino-Ville Talvala
2012-03-28 19:44:38 -07:00
parent 3cd661a616
commit 0819e42a0b
9 changed files with 1158 additions and 10 deletions

View File

@@ -35,9 +35,10 @@ LOCAL_SHARED_LIBRARIES += \
libandroid_runtime \
LOCAL_C_INCLUDES += external/jpeg \
external/skia/include/core/ \
frameworks/native/include/media/hardware \
frameworks/base/core/jni/android/graphics
external/skia/include/core/ \
frameworks/native/include/media/hardware \
frameworks/base/core/jni/android/graphics \
$(call include-path-for, camera)
LOCAL_SRC_FILES := \
EmulatedCameraHal.cpp \
@@ -53,7 +54,10 @@ LOCAL_SRC_FILES := \
PreviewWindow.cpp \
CallbackNotifier.cpp \
QemuClient.cpp \
JpegCompressor.cpp
JpegCompressor.cpp \
EmulatedCamera2.cpp \
EmulatedFakeCamera2.cpp \
EmulatedQemuCamera2.cpp
ifeq ($(TARGET_PRODUCT),vbox_x86)
LOCAL_MODULE := camera.vbox_x86

View File

@@ -0,0 +1,528 @@
/*
* 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 EmulatedCamera that encapsulates
* functionality common to all version 2.0 emulated camera devices. 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 camera2_device_ops_t API.
*/
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera2_Camera"
#include <cutils/log.h>
#include "EmulatedCamera2.h"
#include "system/camera_metadata.h"
namespace android {
/* Constructs EmulatedCamera2 instance.
* Param:
* cameraId - Zero based camera identifier, which is an index of the camera
* instance in camera factory's array.
* module - Emulated camera HAL module descriptor.
*/
EmulatedCamera2::EmulatedCamera2(int cameraId,
struct hw_module_t* module):
EmulatedBaseCamera(cameraId,
CAMERA_DEVICE_API_VERSION_2_0,
&common,
module)
{
common.close = EmulatedCamera2::close;
ops = &sDeviceOps;
priv = this;
mRequestQueueDstOps.notify_queue_not_empty =
EmulatedCamera2::request_queue_notify_queue_not_empty;
mRequestQueueDstOps.parent = this;
mRequestQueueDstOps.notify_queue_not_empty =
EmulatedCamera2::reprocess_queue_notify_queue_not_empty;
mReprocessQueueDstOps.parent = this;
mFrameQueueSrcOps.buffer_count = EmulatedCamera2::frame_queue_buffer_count;
mFrameQueueSrcOps.dequeue = EmulatedCamera2::frame_queue_dequeue;
mFrameQueueSrcOps.free = EmulatedCamera2::frame_queue_free;
mFrameQueueSrcOps.parent = this;
mReprocessStreamOps.dequeue_buffer =
EmulatedCamera2::reprocess_stream_dequeue_buffer;
mReprocessStreamOps.enqueue_buffer =
EmulatedCamera2::reprocess_stream_enqueue_buffer;
mReprocessStreamOps.cancel_buffer =
EmulatedCamera2::reprocess_stream_cancel_buffer;
mReprocessStreamOps.set_buffer_count =
EmulatedCamera2::reprocess_stream_set_buffer_count;
mReprocessStreamOps.set_crop = EmulatedCamera2::reprocess_stream_set_crop;
mReprocessStreamOps.set_timestamp =
EmulatedCamera2::reprocess_stream_set_timestamp;
mReprocessStreamOps.set_usage = EmulatedCamera2::reprocess_stream_set_usage;
mReprocessStreamOps.get_min_undequeued_buffer_count =
EmulatedCamera2::reprocess_stream_get_min_undequeued_buffer_count;
mReprocessStreamOps.lock_buffer =
EmulatedCamera2::reprocess_stream_lock_buffer;
mReprocessStreamOps.parent = this;
mVendorTagOps.get_camera_vendor_section_name =
EmulatedCamera2::get_camera_vendor_section_name;
mVendorTagOps.get_camera_vendor_tag_name =
EmulatedCamera2::get_camera_vendor_tag_name;
mVendorTagOps.get_camera_vendor_tag_type =
EmulatedCamera2::get_camera_vendor_tag_type;
mVendorTagOps.parent = this;
}
/* Destructs EmulatedCamera2 instance. */
EmulatedCamera2::~EmulatedCamera2() {
}
/****************************************************************************
* Abstract API
***************************************************************************/
/****************************************************************************
* Public API
***************************************************************************/
status_t EmulatedCamera2::Initialize() {
return NO_ERROR;
}
/****************************************************************************
* Camera API implementation
***************************************************************************/
status_t EmulatedCamera2::connectCamera(hw_device_t** device) {
return NO_ERROR;
}
status_t EmulatedCamera2::closeCamera() {
return NO_ERROR;
}
status_t EmulatedCamera2::getCameraInfo(struct camera_info* info) {
return EmulatedBaseCamera::getCameraInfo(info);
}
/****************************************************************************
* Camera API implementation.
* These methods are called from the camera API callback routines.
***************************************************************************/
/** Request input queue */
int EmulatedCamera2::setRequestQueueSrcOps(
camera2_metadata_queue_src_ops *request_queue_src_ops) {
return NO_ERROR;
}
int EmulatedCamera2::requestQueueNotifyNotEmpty() {
return NO_ERROR;
}
/** Reprocessing input queue */
int EmulatedCamera2::setReprocessQueueSrcOps(
camera2_metadata_queue_src_ops *reprocess_queue_src_ops) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessQueueNotifyNotEmpty() {
return NO_ERROR;
}
/** Frame output queue */
int EmulatedCamera2::setFrameQueueDstOps(camera2_metadata_queue_dst_ops *frame_queue_dst_ops) {
return NO_ERROR;
}
int EmulatedCamera2::frameQueueBufferCount() {
return NO_ERROR;
}
int EmulatedCamera2::frameQueueDequeue(camera_metadata_t **buffer) {
return NO_ERROR;
}
int EmulatedCamera2::frameQueueFree(camera_metadata_t *old_buffer) {
return NO_ERROR;
}
/** Notifications to application */
int EmulatedCamera2::setNotifyCallback(camera2_notify_callback notify_cb) {
return NO_ERROR;
}
/** Count of requests in flight */
int EmulatedCamera2::getInProgressCount() {
return NO_ERROR;
}
/** Cancel all captures in flight */
int EmulatedCamera2::flushCapturesInProgress() {
return NO_ERROR;
}
/** Reprocessing input stream management */
int EmulatedCamera2::reprocessStreamDequeueBuffer(buffer_handle_t** buffer,
int *stride) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessStreamEnqueueBuffer(buffer_handle_t* buffer) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessStreamCancelBuffer(buffer_handle_t* buffer) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessStreamSetBufferCount(int count) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessStreamSetCrop(int left, int top, int right, int bottom) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessStreamSetTimestamp(int64_t timestamp) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessStreamSetUsage(int usage) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessStreamSetSwapInterval(int interval) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessStreamGetMinUndequeuedBufferCount(int *count) {
return NO_ERROR;
}
int EmulatedCamera2::reprocessStreamLockBuffer(buffer_handle_t *buffer) {
return NO_ERROR;
}
/** Output stream creation and management */
int EmulatedCamera2::getStreamSlotCount() {
return NO_ERROR;
}
int EmulatedCamera2::allocateStream(uint32_t stream_slot,
uint32_t width,
uint32_t height,
int format,
camera2_stream_ops_t *stream_ops) {
return NO_ERROR;
}
int EmulatedCamera2::releaseStream(uint32_t stream_slot) {
return NO_ERROR;
}
/** Custom tag query methods */
const char* EmulatedCamera2::getVendorSectionName(uint32_t tag) {
return NULL;
}
const char* EmulatedCamera2::getVendorTagName(uint32_t tag) {
return NULL;
}
int EmulatedCamera2::getVendorTagType(uint32_t tag) {
return -1;
}
/** Shutdown and debug methods */
int EmulatedCamera2::release() {
return NO_ERROR;
}
int EmulatedCamera2::dump(int fd) {
return NO_ERROR;
}
/****************************************************************************
* Private API.
***************************************************************************/
/****************************************************************************
* Camera API callbacks as defined by camera2_device_ops structure. See
* hardware/libhardware/include/hardware/camera2.h for information on each
* of these callbacks. Implemented in this class, these callbacks simply
* dispatch the call into an instance of EmulatedCamera2 class defined by the
* 'camera_device2' parameter.
***************************************************************************/
int EmulatedCamera2::set_request_queue_src_ops(struct camera2_device *d,
camera2_metadata_queue_src_ops *queue_src_ops) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
return ec->setRequestQueueSrcOps(queue_src_ops);
}
int EmulatedCamera2::get_request_queue_dst_ops(struct camera2_device *d,
camera2_metadata_queue_dst_ops **queue_dst_ops) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
*queue_dst_ops = static_cast<camera2_metadata_queue_dst_ops*>(
&ec->mRequestQueueDstOps);
return NO_ERROR;
}
int EmulatedCamera2::request_queue_notify_queue_not_empty(
camera2_metadata_queue_dst_ops *q) {
EmulatedCamera2* ec = static_cast<QueueDstOps*>(q)->parent;
return ec->requestQueueNotifyNotEmpty();
}
int EmulatedCamera2::set_reprocess_queue_src_ops(struct camera2_device *d,
camera2_metadata_queue_src_ops *queue_src_ops) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
return ec->setReprocessQueueSrcOps(queue_src_ops);
}
int EmulatedCamera2::get_reprocess_queue_dst_ops(struct camera2_device *d,
camera2_metadata_queue_dst_ops **queue_dst_ops) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
*queue_dst_ops = static_cast<camera2_metadata_queue_dst_ops*>(
&ec->mReprocessQueueDstOps);
return NO_ERROR;
}
int EmulatedCamera2::reprocess_queue_notify_queue_not_empty(
camera2_metadata_queue_dst_ops *q) {
EmulatedCamera2* ec = static_cast<QueueDstOps*>(q)->parent;
return ec->reprocessQueueNotifyNotEmpty();
}
int EmulatedCamera2::set_frame_queue_dst_ops(struct camera2_device *d,
camera2_metadata_queue_dst_ops *queue_dst_ops) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
return ec->setFrameQueueDstOps(queue_dst_ops);
}
int EmulatedCamera2::get_frame_queue_src_ops(struct camera2_device *d,
camera2_metadata_queue_src_ops **queue_src_ops) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
*queue_src_ops = static_cast<camera2_metadata_queue_src_ops*>(
&ec->mFrameQueueSrcOps);
return NO_ERROR;
}
int EmulatedCamera2::frame_queue_buffer_count(camera2_metadata_queue_src_ops *q) {
EmulatedCamera2 *ec = static_cast<QueueSrcOps*>(q)->parent;
return ec->frameQueueBufferCount();
}
int EmulatedCamera2::frame_queue_dequeue(camera2_metadata_queue_src_ops *q,
camera_metadata_t **buffer) {
EmulatedCamera2 *ec = static_cast<QueueSrcOps*>(q)->parent;
return ec->frameQueueDequeue(buffer);
}
int EmulatedCamera2::frame_queue_free(camera2_metadata_queue_src_ops *q,
camera_metadata_t *old_buffer) {
EmulatedCamera2 *ec = static_cast<QueueSrcOps*>(q)->parent;
return ec->frameQueueFree(old_buffer);
}
int EmulatedCamera2::set_notify_callback(struct camera2_device *d,
camera2_notify_callback notify_cb) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
return ec->setNotifyCallback(notify_cb);
}
int EmulatedCamera2::get_in_progress_count(struct camera2_device *d) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
return ec->getInProgressCount();
}
int EmulatedCamera2::flush_captures_in_progress(struct camera2_device *d) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
return ec->flushCapturesInProgress();
}
int EmulatedCamera2::get_reprocess_stream_ops(camera2_device_t *d,
camera2_stream_ops **stream) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
*stream = static_cast<camera2_stream_ops*>(&ec->mReprocessStreamOps);
return NO_ERROR;
}
int EmulatedCamera2::reprocess_stream_dequeue_buffer(camera2_stream_ops *s,
buffer_handle_t** buffer, int *stride) {
EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
return ec->reprocessStreamDequeueBuffer(buffer, stride);
}
int EmulatedCamera2::reprocess_stream_enqueue_buffer(camera2_stream_ops *s,
buffer_handle_t* buffer) {
EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
return ec->reprocessStreamEnqueueBuffer(buffer);
}
int EmulatedCamera2::reprocess_stream_cancel_buffer(camera2_stream_ops *s,
buffer_handle_t* buffer) {
EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
return ec->reprocessStreamCancelBuffer(buffer);
}
int EmulatedCamera2::reprocess_stream_set_buffer_count(camera2_stream_ops *s,
int count) {
EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
return ec->reprocessStreamSetBufferCount(count);
}
int EmulatedCamera2::reprocess_stream_set_crop(camera2_stream_ops *s,
int left, int top, int right, int bottom) {
EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
return ec->reprocessStreamSetCrop(left, top, right, bottom);
}
int EmulatedCamera2::reprocess_stream_set_timestamp(camera2_stream_ops *s,
int64_t timestamp) {
EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
return ec->reprocessStreamSetTimestamp(timestamp);
}
int EmulatedCamera2::reprocess_stream_set_usage(camera2_stream_ops *s,
int usage) {
EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
return ec->reprocessStreamSetUsage(usage);
}
int EmulatedCamera2::reprocess_stream_set_swap_interval(camera2_stream_ops *s,
int interval) {
EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
return ec->reprocessStreamSetSwapInterval(interval);
}
int EmulatedCamera2::reprocess_stream_get_min_undequeued_buffer_count(
const camera2_stream_ops *s,
int *count) {
EmulatedCamera2* ec = static_cast<const StreamOps*>(s)->parent;
return ec->reprocessStreamGetMinUndequeuedBufferCount(count);
}
int EmulatedCamera2::reprocess_stream_lock_buffer(camera2_stream_ops *s,
buffer_handle_t* buffer) {
EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
return ec->reprocessStreamLockBuffer(buffer);
}
int EmulatedCamera2::get_stream_slot_count(struct camera2_device *d) {
EmulatedCamera2* ec =
static_cast<EmulatedCamera2*>(d);
return ec->getStreamSlotCount();
}
int EmulatedCamera2::allocate_stream(struct camera2_device *d,
uint32_t stream_slot,
uint32_t width,
uint32_t height,
uint32_t format,
camera2_stream_ops_t *stream_ops) {
EmulatedCamera2* ec =
static_cast<EmulatedCamera2*>(d);
return ec->allocateStream(stream_slot, width, height, format, stream_ops);
}
int EmulatedCamera2::release_stream(struct camera2_device *d,
uint32_t stream_slot) {
EmulatedCamera2* ec =
static_cast<EmulatedCamera2*>(d);
return ec->releaseStream(stream_slot);
}
void EmulatedCamera2::release(struct camera2_device *d) {
EmulatedCamera2* ec =
static_cast<EmulatedCamera2*>(d);
ec->release();
}
int EmulatedCamera2::dump(struct camera2_device *d, int fd) {
EmulatedCamera2* ec =
static_cast<EmulatedCamera2*>(d);
return ec->dump(fd);
}
int EmulatedCamera2::close(struct hw_device_t* device) {
EmulatedCamera2* ec =
static_cast<EmulatedCamera2*>(
reinterpret_cast<struct camera2_device*>(device) );
if (ec == NULL) {
ALOGE("%s: Unexpected NULL camera2 device", __FUNCTION__);
return -EINVAL;
}
return ec->closeCamera();
}
int EmulatedCamera2::get_metadata_vendor_tag_ops(struct camera2_device *d,
vendor_tag_query_ops_t **ops) {
EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
*ops = static_cast<vendor_tag_query_ops_t*>(
&ec->mVendorTagOps);
return NO_ERROR;
}
const char* EmulatedCamera2::get_camera_vendor_section_name(
const vendor_tag_query_ops_t *v,
uint32_t tag) {
EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
return ec->getVendorSectionName(tag);
}
const char* EmulatedCamera2::get_camera_vendor_tag_name(
const vendor_tag_query_ops_t *v,
uint32_t tag) {
EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
return ec->getVendorTagName(tag);
}
int EmulatedCamera2::get_camera_vendor_tag_type(
const vendor_tag_query_ops_t *v,
uint32_t tag) {
EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
return ec->getVendorTagType(tag);
}
camera2_device_ops_t EmulatedCamera2::sDeviceOps = {
EmulatedCamera2::set_request_queue_src_ops,
EmulatedCamera2::get_request_queue_dst_ops,
EmulatedCamera2::set_reprocess_queue_src_ops,
EmulatedCamera2::get_reprocess_queue_dst_ops,
EmulatedCamera2::set_frame_queue_dst_ops,
EmulatedCamera2::get_frame_queue_src_ops,
EmulatedCamera2::set_notify_callback,
EmulatedCamera2::get_in_progress_count,
EmulatedCamera2::flush_captures_in_progress,
EmulatedCamera2::get_reprocess_stream_ops,
EmulatedCamera2::get_stream_slot_count,
EmulatedCamera2::allocate_stream,
EmulatedCamera2::release_stream,
EmulatedCamera2::get_metadata_vendor_tag_ops,
EmulatedCamera2::release,
EmulatedCamera2::dump
};
}; /* namespace android */

View File

@@ -0,0 +1,305 @@
/*
* 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_CAMERA2_H
#define HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H
/*
* Contains declaration of a class EmulatedCamera that encapsulates
* functionality common to all version 2.0 emulated camera devices. 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 camera2_device_ops_t API.
*/
#include "hardware/camera2.h"
#include "system/camera_metadata.h"
#include "EmulatedBaseCamera.h"
namespace android {
/* Encapsulates functionality common to all version 2.0 emulated camera devices
*
* 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 invoked in
* response to hw_module_methods_t::open, and camera_device::close callbacks.
*/
class EmulatedCamera2 : public camera2_device, public EmulatedBaseCamera {
public:
/* Constructs EmulatedCamera2 instance.
* Param:
* cameraId - Zero based camera identifier, which is an index of the camera
* instance in camera factory's array.
* module - Emulated camera HAL module descriptor.
*/
EmulatedCamera2(int cameraId,
struct hw_module_t* module);
/* Destructs EmulatedCamera2 instance. */
virtual ~EmulatedCamera2();
/****************************************************************************
* Abstract API
***************************************************************************/
public:
/****************************************************************************
* Public API
***************************************************************************/
public:
virtual status_t Initialize();
/****************************************************************************
* Camera API implementation
***************************************************************************/
public:
virtual status_t connectCamera(hw_device_t** device);
virtual status_t closeCamera();
virtual status_t getCameraInfo(struct camera_info* info);
/****************************************************************************
* Camera API implementation.
* These methods are called from the camera API callback routines.
***************************************************************************/
protected:
/** Request input queue */
int setRequestQueueSrcOps(
camera2_metadata_queue_src_ops *request_queue_src_ops);
int requestQueueNotifyNotEmpty();
/** Reprocessing input queue */
int setReprocessQueueSrcOps(
camera2_metadata_queue_src_ops *reprocess_queue_src_ops);
int reprocessQueueNotifyNotEmpty();
/** Frame output queue */
int setFrameQueueDstOps(camera2_metadata_queue_dst_ops *frame_queue_dst_ops);
int frameQueueBufferCount();
int frameQueueDequeue(camera_metadata_t **buffer);
int frameQueueFree(camera_metadata_t *old_buffer);
/** Notifications to application */
int setNotifyCallback(camera2_notify_callback notify_cb);
/** Count of requests in flight */
int getInProgressCount();
/** Cancel all captures in flight */
int flushCapturesInProgress();
/** Reprocessing input stream management */
int reprocessStreamDequeueBuffer(buffer_handle_t** buffer,
int *stride);
int reprocessStreamEnqueueBuffer(buffer_handle_t* buffer);
int reprocessStreamCancelBuffer(buffer_handle_t* buffer);
int reprocessStreamSetBufferCount(int count);
int reprocessStreamSetCrop(int left, int top, int right, int bottom);
int reprocessStreamSetTimestamp(int64_t timestamp);
int reprocessStreamSetUsage(int usage);
int reprocessStreamSetSwapInterval(int interval);
int reprocessStreamGetMinUndequeuedBufferCount(int *count);
int reprocessStreamLockBuffer(buffer_handle_t *buffer);
/** Output stream creation and management */
int getStreamSlotCount();
int allocateStream(uint32_t stream_slot,
uint32_t width,
uint32_t height,
int format,
camera2_stream_ops_t *stream_ops);
int releaseStream(uint32_t stream_slot);
/** Custom tag definitions */
const char* getVendorSectionName(uint32_t tag);
const char* getVendorTagName(uint32_t tag);
int getVendorTagType(uint32_t tag);
/** Shutdown and debug methods */
int release();
int dump(int fd);
int close();
/****************************************************************************
* Camera API callbacks as defined by camera2_device_ops structure. See
* hardware/libhardware/include/hardware/camera2.h for information on each
* of these callbacks. Implemented in this class, these callbacks simply
* dispatch the call into an instance of EmulatedCamera2 class defined in the
* 'camera_device2' parameter.
***************************************************************************/
private:
/** Input request queue */
static int set_request_queue_src_ops(camera2_device_t *,
camera2_metadata_queue_src_ops *queue_src_ops);
static int get_request_queue_dst_ops(camera2_device_t *,
camera2_metadata_queue_dst_ops **queue_dst_ops);
// for get_request_queue_dst_ops
static int request_queue_notify_queue_not_empty(
camera2_metadata_queue_dst_ops *);
/** Input reprocess queue */
static int set_reprocess_queue_src_ops(camera2_device_t *,
camera2_metadata_queue_src_ops *reprocess_queue_src_ops);
static int get_reprocess_queue_dst_ops(camera2_device_t *,
camera2_metadata_queue_dst_ops **queue_dst_ops);
// for reprocess_queue_dst_ops
static int reprocess_queue_notify_queue_not_empty(
camera2_metadata_queue_dst_ops *);
/** Output frame queue */
static int set_frame_queue_dst_ops(camera2_device_t *,
camera2_metadata_queue_dst_ops *queue_dst_ops);
static int get_frame_queue_src_ops(camera2_device_t *,
camera2_metadata_queue_src_ops **queue_src_ops);
// for get_frame_queue_src_ops
static int frame_queue_buffer_count(camera2_metadata_queue_src_ops *);
static int frame_queue_dequeue(camera2_metadata_queue_src_ops *,
camera_metadata_t **buffer);
static int frame_queue_free(camera2_metadata_queue_src_ops *,
camera_metadata_t *old_buffer);
/** Notifications to application */
static int set_notify_callback(camera2_device_t *,
camera2_notify_callback notify_cb);
/** In-progress request management */
static int get_in_progress_count(camera2_device_t *);
static int flush_captures_in_progress(camera2_device_t *);
/** Input reprocessing stream */
static int get_reprocess_stream_ops(camera2_device_t *,
camera2_stream_ops_t **stream);
// for get_reprocess_stream_ops
static int reprocess_stream_dequeue_buffer(camera2_stream_ops *,
buffer_handle_t** buffer, int *stride);
static int reprocess_stream_enqueue_buffer(camera2_stream_ops *,
buffer_handle_t* buffer);
static int reprocess_stream_cancel_buffer(camera2_stream_ops *,
buffer_handle_t* buffer);
static int reprocess_stream_set_buffer_count(camera2_stream_ops *,
int count);
static int reprocess_stream_set_crop(camera2_stream_ops *,
int left, int top, int right, int bottom);
static int reprocess_stream_set_timestamp(camera2_stream_ops *,
int64_t timestamp);
static int reprocess_stream_set_usage(camera2_stream_ops *,
int usage);
static int reprocess_stream_set_swap_interval(camera2_stream_ops *,
int interval);
static int reprocess_stream_get_min_undequeued_buffer_count(
const camera2_stream_ops *,
int *count);
static int reprocess_stream_lock_buffer(camera2_stream_ops *,
buffer_handle_t* buffer);
/** Output stream allocation and management */
static int get_stream_slot_count(camera2_device_t *);
static int allocate_stream(camera2_device_t *,
uint32_t stream_slot,
uint32_t width,
uint32_t height,
uint32_t format,
camera2_stream_ops_t *stream_ops);
static int release_stream(camera2_device_t *,
uint32_t stream_slot);
static void release(camera2_device_t *);
/** Vendor metadata registration */
static int get_metadata_vendor_tag_ops(camera2_device_t *,
vendor_tag_query_ops_t **ops);
// for get_metadata_vendor_tag_ops
static const char* get_camera_vendor_section_name(
const vendor_tag_query_ops_t *,
uint32_t tag);
static const char* get_camera_vendor_tag_name(
const vendor_tag_query_ops_t *,
uint32_t tag);
static int get_camera_vendor_tag_type(
const vendor_tag_query_ops_t *,
uint32_t tag);
static int dump(camera2_device_t *, int fd);
static int close(struct hw_device_t* device);
/****************************************************************************
* Data members
***************************************************************************/
private:
static camera2_device_ops_t sDeviceOps;
struct QueueDstOps : public camera2_metadata_queue_dst_ops {
EmulatedCamera2 *parent;
};
struct QueueSrcOps : public camera2_metadata_queue_src_ops {
EmulatedCamera2 *parent;
};
struct StreamOps : public camera2_stream_ops {
EmulatedCamera2 *parent;
};
struct TagOps : public vendor_tag_query_ops {
EmulatedCamera2 *parent;
};
QueueDstOps mRequestQueueDstOps;
QueueDstOps mReprocessQueueDstOps;
QueueSrcOps mFrameQueueSrcOps;
StreamOps mReprocessStreamOps;
TagOps mVendorTagOps;
};
}; /* namespace android */
#endif /* HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H */

View File

@@ -25,6 +25,7 @@
#include <cutils/properties.h>
#include "EmulatedQemuCamera.h"
#include "EmulatedFakeCamera.h"
#include "EmulatedFakeCamera2.h"
#include "EmulatedCameraFactory.h"
extern camera_module_t HAL_MODULE_INFO_SYM;
@@ -66,13 +67,27 @@ EmulatedCameraFactory::EmulatedCameraFactory()
__FUNCTION__, mEmulatedCameraNum);
return;
}
memset(mEmulatedCameras, 0, (mEmulatedCameraNum + 1) * sizeof(EmulatedCamera*));
memset(mEmulatedCameras, 0,
(mEmulatedCameraNum + 1) * sizeof(EmulatedBaseCamera*));
}
/* Create, and initialize the fake camera */
mEmulatedCameras[camera_id] =
new EmulatedFakeCamera(camera_id, true, &HAL_MODULE_INFO_SYM.common);
switch (getBackCameraHalVersion()) {
case 1:
mEmulatedCameras[camera_id] =
new EmulatedFakeCamera(camera_id, false, &HAL_MODULE_INFO_SYM.common);
break;
case 2:
mEmulatedCameras[camera_id] =
new EmulatedFakeCamera2(camera_id, false, &HAL_MODULE_INFO_SYM.common);
break;
default:
ALOGE("%s: Unknown back camera hal version requested: %d", __FUNCTION__,
getBackCameraHalVersion());
}
if (mEmulatedCameras[camera_id] != NULL) {
ALOGV("%s: Back camera device version is %d", __FUNCTION__,
getBackCameraHalVersion());
if (mEmulatedCameras[camera_id]->Initialize() != NO_ERROR) {
delete mEmulatedCameras[camera_id];
mEmulatedCameras--;
@@ -98,13 +113,27 @@ EmulatedCameraFactory::EmulatedCameraFactory()
__FUNCTION__, mEmulatedCameraNum);
return;
}
memset(mEmulatedCameras, 0, mEmulatedCameraNum * sizeof(EmulatedCamera*));
memset(mEmulatedCameras, 0,
mEmulatedCameraNum * sizeof(EmulatedBaseCamera*));
}
/* Create, and initialize the fake camera */
mEmulatedCameras[camera_id] =
new EmulatedFakeCamera(camera_id, false, &HAL_MODULE_INFO_SYM.common);
switch (getFrontCameraHalVersion()) {
case 1:
mEmulatedCameras[camera_id] =
new EmulatedFakeCamera(camera_id, false, &HAL_MODULE_INFO_SYM.common);
break;
case 2:
mEmulatedCameras[camera_id] =
new EmulatedFakeCamera2(camera_id, false, &HAL_MODULE_INFO_SYM.common);
break;
default:
ALOGE("%s: Unknown front camera hal version requested: %d", __FUNCTION__,
getFrontCameraHalVersion());
}
if (mEmulatedCameras[camera_id] != NULL) {
ALOGV("%s: Front camera device version is %d", __FUNCTION__,
getFrontCameraHalVersion());
if (mEmulatedCameras[camera_id]->Initialize() != NO_ERROR) {
delete mEmulatedCameras[camera_id];
mEmulatedCameras--;
@@ -348,6 +377,23 @@ bool EmulatedCameraFactory::isBackFakeCameraEmulationOn()
}
}
int EmulatedCameraFactory::getBackCameraHalVersion()
{
/* Defined by 'qemu.sf.back_camera_hal_version' boot property: if the
* property doesn't exist, it is assumed to be 1. */
char prop[PROPERTY_VALUE_MAX];
if (property_get("qemu.sf.back_camera_hal", prop, NULL) > 0) {
char *prop_end = prop;
int val = strtol(prop, &prop_end, 10);
if (*prop_end == '\0') {
return val;
}
// Badly formatted property, should just be a number
ALOGE("qemu.sf.back_camera_hal is not a number: %s", prop);
}
return 1;
}
bool EmulatedCameraFactory::isFrontFakeCameraEmulationOn()
{
/* Defined by 'qemu.sf.fake_camera' boot property: if property exist, and
@@ -362,6 +408,23 @@ bool EmulatedCameraFactory::isFrontFakeCameraEmulationOn()
}
}
int EmulatedCameraFactory::getFrontCameraHalVersion()
{
/* Defined by 'qemu.sf.front_camera_hal_version' boot property: if the
* property doesn't exist, it is assumed to be 1. */
char prop[PROPERTY_VALUE_MAX];
if (property_get("qemu.sf.front_camera_hal", prop, NULL) > 0) {
char *prop_end = prop;
int val = strtol(prop, &prop_end, 10);
if (*prop_end == '\0') {
return val;
}
// Badly formatted property, should just be a number
ALOGE("qemu.sf.front_camera_hal is not a number: %s", prop);
}
return 1;
}
/********************************************************************************
* Initializer for the static member structure.
*******************************************************************************/

View File

@@ -134,9 +134,15 @@ private:
/* Checks if fake camera emulation is on for the camera facing back. */
bool isBackFakeCameraEmulationOn();
/* Gets camera device version number to use for back camera emulation */
int getBackCameraHalVersion();
/* Checks if fake camera emulation is on for the camera facing front. */
bool isFrontFakeCameraEmulationOn();
/* Gets camera device version number to use for front camera emulation */
int getFrontCameraHalVersion();
/****************************************************************************
* Data members.
***************************************************************************/

View File

@@ -0,0 +1,54 @@
/*
* 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 EmulatedFakeCamera2 that encapsulates
* functionality of an advanced fake camera.
*/
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_FakeCamera2"
#include <cutils/log.h>
#include <cutils/properties.h>
#include "EmulatedFakeCamera2.h"
#include "EmulatedCameraFactory.h"
namespace android {
EmulatedFakeCamera2::EmulatedFakeCamera2(int cameraId,
bool facingBack,
struct hw_module_t* module)
: EmulatedCamera2(cameraId,module),
mFacingBack(facingBack)
{
ALOGD("Constructing emulated fake camera 2 facing %s",
facingBack ? "back" : "front");
}
EmulatedFakeCamera2::~EmulatedFakeCamera2()
{
}
/****************************************************************************
* Public API overrides
***************************************************************************/
status_t EmulatedFakeCamera2::Initialize()
{
return NO_ERROR;
}
}; /* namespace android */

View File

@@ -0,0 +1,67 @@
/*
* 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_FAKE_CAMERA2_H
#define HW_EMULATOR_CAMERA_EMULATED_FAKE_CAMERA2_H
/*
* Contains declaration of a class EmulatedFakeCamera2 that encapsulates
* functionality of a fake camera that implements version 2 of the camera device
* interface.
*/
#include "EmulatedCamera2.h"
namespace android {
/* Encapsulates functionality of an advanced fake camera. This camera contains
* a simple simulation of a scene, sensor, and image processing pipeline.
*/
class EmulatedFakeCamera2 : public EmulatedCamera2 {
public:
/* Constructs EmulatedFakeCamera instance. */
EmulatedFakeCamera2(int cameraId, bool facingBack, struct hw_module_t* module);
/* Destructs EmulatedFakeCamera instance. */
~EmulatedFakeCamera2();
/****************************************************************************
* EmulatedCamera2 virtual overrides.
***************************************************************************/
public:
/* Initializes EmulatedFakeCamera2 instance. */
status_t Initialize();
/****************************************************************************
* EmulatedCamera abstract API implementation.
***************************************************************************/
protected:
/****************************************************************************
* Data memebers.
***************************************************************************/
protected:
/* Facing back (true) or front (false) switch. */
bool mFacingBack;
};
}; /* namespace android */
#endif /* HW_EMULATOR_CAMERA_EMULATED_FAKE_CAMERA2_H */

View File

@@ -0,0 +1,55 @@
/*
* 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 EmulatedQemuCamera2 that encapsulates
* functionality of a host webcam with further processing to simulate the
* capabilities of a v2 camera device.
*/
#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera_QemuCamera2"
#include <cutils/log.h>
#include <cutils/properties.h>
#include "EmulatedQemuCamera2.h"
#include "EmulatedCameraFactory.h"
namespace android {
EmulatedQemuCamera2::EmulatedQemuCamera2(int cameraId,
bool facingBack,
struct hw_module_t* module)
: EmulatedCamera2(cameraId,module),
mFacingBack(facingBack)
{
ALOGD("Constructing emulated qemu camera 2 facing %s",
facingBack ? "back" : "front");
}
EmulatedQemuCamera2::~EmulatedQemuCamera2()
{
}
/****************************************************************************
* Public API overrides
***************************************************************************/
status_t EmulatedQemuCamera2::Initialize()
{
return NO_ERROR;
}
}; /* namespace android */

View File

@@ -0,0 +1,66 @@
/*
* 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_QEMU_CAMERA2_H
#define HW_EMULATOR_CAMERA_EMULATED_QEMU_CAMERA2_H
/*
* Contains declaration of a class EmulatedQemuCamera2 that encapsulates
* functionality of a host webcam with added processing to implement version 2
* of the camera device interface.
*/
#include "EmulatedCamera2.h"
namespace android {
/* Encapsulates functionality of an advanced fake camera based on real host camera data.
*/
class EmulatedQemuCamera2 : public EmulatedCamera2 {
public:
/* Constructs EmulatedFakeCamera instance. */
EmulatedQemuCamera2(int cameraId, bool facingBack, struct hw_module_t* module);
/* Destructs EmulatedFakeCamera instance. */
~EmulatedQemuCamera2();
/****************************************************************************
* EmulatedCamera2 virtual overrides.
***************************************************************************/
public:
/* Initializes EmulatedQemuCamera2 instance. */
status_t Initialize();
/****************************************************************************
* EmulatedCamera abstract API implementation.
***************************************************************************/
protected:
/****************************************************************************
* Data memebers.
***************************************************************************/
protected:
/* Facing back (true) or front (false) switch. */
bool mFacingBack;
};
}; /* namespace android */
#endif /* HW_EMULATOR_CAMERA_EMULATED_QEMU_CAMERA2_H */