Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*
     18  * Contains implementation of a class EmulatedCamera that encapsulates
     19  * functionality common to all version 2.0 emulated camera devices.  Instances
     20  * of this class (for each emulated camera) are created during the construction
     21  * of the EmulatedCameraFactory instance.  This class serves as an entry point
     22  * for all camera API calls that defined by camera2_device_ops_t API.
     23  */
     24 
     25 #define LOG_NDEBUG 0
     26 #define LOG_TAG "EmulatedCamera2_Camera"
     27 #include <cutils/log.h>
     28 
     29 #include "EmulatedCamera2.h"
     30 #include "system/camera_metadata.h"
     31 
     32 namespace android {
     33 
     34 /* Constructs EmulatedCamera2 instance.
     35  * Param:
     36  *  cameraId - Zero based camera identifier, which is an index of the camera
     37  *      instance in camera factory's array.
     38  *  module - Emulated camera HAL module descriptor.
     39  */
     40 EmulatedCamera2::EmulatedCamera2(int cameraId,
     41         struct hw_module_t* module):
     42         EmulatedBaseCamera(cameraId,
     43                 CAMERA_DEVICE_API_VERSION_2_0,
     44                 &common,
     45                 module)
     46 {
     47     common.close = EmulatedCamera2::close;
     48     ops = &sDeviceOps;
     49     priv = this;
     50 
     51     mRequestQueueDstOps.notify_queue_not_empty =
     52             EmulatedCamera2::request_queue_notify_queue_not_empty;
     53     mRequestQueueDstOps.parent                 = this;
     54 
     55     mRequestQueueDstOps.notify_queue_not_empty =
     56             EmulatedCamera2::reprocess_queue_notify_queue_not_empty;
     57     mReprocessQueueDstOps.parent               = this;
     58 
     59     mFrameQueueSrcOps.buffer_count = EmulatedCamera2::frame_queue_buffer_count;
     60     mFrameQueueSrcOps.dequeue      = EmulatedCamera2::frame_queue_dequeue;
     61     mFrameQueueSrcOps.free         = EmulatedCamera2::frame_queue_free;
     62     mFrameQueueSrcOps.parent       = this;
     63 
     64     mReprocessStreamOps.dequeue_buffer =
     65             EmulatedCamera2::reprocess_stream_dequeue_buffer;
     66     mReprocessStreamOps.enqueue_buffer =
     67             EmulatedCamera2::reprocess_stream_enqueue_buffer;
     68     mReprocessStreamOps.cancel_buffer =
     69             EmulatedCamera2::reprocess_stream_cancel_buffer;
     70     mReprocessStreamOps.set_buffer_count =
     71             EmulatedCamera2::reprocess_stream_set_buffer_count;
     72     mReprocessStreamOps.set_crop = EmulatedCamera2::reprocess_stream_set_crop;
     73     mReprocessStreamOps.set_timestamp =
     74             EmulatedCamera2::reprocess_stream_set_timestamp;
     75     mReprocessStreamOps.set_usage = EmulatedCamera2::reprocess_stream_set_usage;
     76     mReprocessStreamOps.get_min_undequeued_buffer_count =
     77             EmulatedCamera2::reprocess_stream_get_min_undequeued_buffer_count;
     78     mReprocessStreamOps.lock_buffer =
     79             EmulatedCamera2::reprocess_stream_lock_buffer;
     80     mReprocessStreamOps.parent   = this;
     81 
     82     mVendorTagOps.get_camera_vendor_section_name =
     83             EmulatedCamera2::get_camera_vendor_section_name;
     84     mVendorTagOps.get_camera_vendor_tag_name =
     85             EmulatedCamera2::get_camera_vendor_tag_name;
     86     mVendorTagOps.get_camera_vendor_tag_type =
     87             EmulatedCamera2::get_camera_vendor_tag_type;
     88     mVendorTagOps.parent = this;
     89 }
     90 
     91 /* Destructs EmulatedCamera2 instance. */
     92 EmulatedCamera2::~EmulatedCamera2() {
     93 }
     94 
     95 /****************************************************************************
     96  * Abstract API
     97  ***************************************************************************/
     98 
     99 /****************************************************************************
    100  * Public API
    101  ***************************************************************************/
    102 
    103 status_t EmulatedCamera2::Initialize() {
    104     return NO_ERROR;
    105 }
    106 
    107 /****************************************************************************
    108  * Camera API implementation
    109  ***************************************************************************/
    110 
    111 status_t EmulatedCamera2::connectCamera(hw_device_t** device) {
    112     return NO_ERROR;
    113 }
    114 
    115 status_t EmulatedCamera2::closeCamera() {
    116     return NO_ERROR;
    117 }
    118 
    119 status_t EmulatedCamera2::getCameraInfo(struct camera_info* info) {
    120 
    121     return EmulatedBaseCamera::getCameraInfo(info);
    122 }
    123 
    124 /****************************************************************************
    125  * Camera API implementation.
    126  * These methods are called from the camera API callback routines.
    127  ***************************************************************************/
    128 
    129 /** Request input queue */
    130 
    131 int EmulatedCamera2::setRequestQueueSrcOps(
    132     camera2_metadata_queue_src_ops *request_queue_src_ops) {
    133     return NO_ERROR;
    134 }
    135 
    136 int EmulatedCamera2::requestQueueNotifyNotEmpty() {
    137     return NO_ERROR;
    138 }
    139 
    140 /** Reprocessing input queue */
    141 
    142 int EmulatedCamera2::setReprocessQueueSrcOps(
    143     camera2_metadata_queue_src_ops *reprocess_queue_src_ops) {
    144     return NO_ERROR;
    145 }
    146 
    147 int EmulatedCamera2::reprocessQueueNotifyNotEmpty() {
    148     return NO_ERROR;
    149 }
    150 
    151 /** Frame output queue */
    152 
    153 int EmulatedCamera2::setFrameQueueDstOps(camera2_metadata_queue_dst_ops *frame_queue_dst_ops) {
    154     return NO_ERROR;
    155 }
    156 
    157 int EmulatedCamera2::frameQueueBufferCount() {
    158     return NO_ERROR;
    159 }
    160 int EmulatedCamera2::frameQueueDequeue(camera_metadata_t **buffer) {
    161     return NO_ERROR;
    162 }
    163 int EmulatedCamera2::frameQueueFree(camera_metadata_t *old_buffer) {
    164     return NO_ERROR;
    165 }
    166 
    167 /** Notifications to application */
    168 int EmulatedCamera2::setNotifyCallback(camera2_notify_callback notify_cb) {
    169     return NO_ERROR;
    170 }
    171 
    172 /** Count of requests in flight */
    173 int EmulatedCamera2::getInProgressCount() {
    174     return NO_ERROR;
    175 }
    176 
    177 /** Cancel all captures in flight */
    178 int EmulatedCamera2::flushCapturesInProgress() {
    179     return NO_ERROR;
    180 }
    181 
    182 /** Reprocessing input stream management */
    183 int EmulatedCamera2::reprocessStreamDequeueBuffer(buffer_handle_t** buffer,
    184         int *stride) {
    185     return NO_ERROR;
    186 }
    187 
    188 int EmulatedCamera2::reprocessStreamEnqueueBuffer(buffer_handle_t* buffer) {
    189     return NO_ERROR;
    190 }
    191 
    192 int EmulatedCamera2::reprocessStreamCancelBuffer(buffer_handle_t* buffer) {
    193     return NO_ERROR;
    194 }
    195 
    196 int EmulatedCamera2::reprocessStreamSetBufferCount(int count) {
    197     return NO_ERROR;
    198 }
    199 
    200 int EmulatedCamera2::reprocessStreamSetCrop(int left, int top, int right, int bottom) {
    201     return NO_ERROR;
    202 }
    203 
    204 int EmulatedCamera2::reprocessStreamSetTimestamp(int64_t timestamp) {
    205     return NO_ERROR;
    206 }
    207 
    208 int EmulatedCamera2::reprocessStreamSetUsage(int usage) {
    209     return NO_ERROR;
    210 }
    211 
    212 int EmulatedCamera2::reprocessStreamSetSwapInterval(int interval) {
    213     return NO_ERROR;
    214 }
    215 
    216 int EmulatedCamera2::reprocessStreamGetMinUndequeuedBufferCount(int *count) {
    217     return NO_ERROR;
    218 }
    219 
    220 int EmulatedCamera2::reprocessStreamLockBuffer(buffer_handle_t *buffer) {
    221     return NO_ERROR;
    222 }
    223 
    224 /** Output stream creation and management */
    225 
    226 int EmulatedCamera2::getStreamSlotCount() {
    227     return NO_ERROR;
    228 }
    229 
    230 int EmulatedCamera2::allocateStream(uint32_t stream_slot,
    231         uint32_t width,
    232         uint32_t height,
    233         int format,
    234         camera2_stream_ops_t *stream_ops) {
    235     return NO_ERROR;
    236 }
    237 
    238 int EmulatedCamera2::releaseStream(uint32_t stream_slot) {
    239     return NO_ERROR;
    240 }
    241 
    242 /** Custom tag query methods */
    243 
    244 const char* EmulatedCamera2::getVendorSectionName(uint32_t tag) {
    245     return NULL;
    246 }
    247 
    248 const char* EmulatedCamera2::getVendorTagName(uint32_t tag) {
    249     return NULL;
    250 }
    251 
    252 int EmulatedCamera2::getVendorTagType(uint32_t tag) {
    253     return -1;
    254 }
    255 
    256 /** Shutdown and debug methods */
    257 
    258 int EmulatedCamera2::release() {
    259     return NO_ERROR;
    260 }
    261 
    262 int EmulatedCamera2::dump(int fd) {
    263     return NO_ERROR;
    264 }
    265 
    266 /****************************************************************************
    267  * Private API.
    268  ***************************************************************************/
    269 
    270 /****************************************************************************
    271  * Camera API callbacks as defined by camera2_device_ops structure.  See
    272  * hardware/libhardware/include/hardware/camera2.h for information on each
    273  * of these callbacks. Implemented in this class, these callbacks simply
    274  * dispatch the call into an instance of EmulatedCamera2 class defined by the
    275  * 'camera_device2' parameter.
    276  ***************************************************************************/
    277 
    278 int EmulatedCamera2::set_request_queue_src_ops(struct camera2_device *d,
    279         camera2_metadata_queue_src_ops *queue_src_ops) {
    280     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    281     return ec->setRequestQueueSrcOps(queue_src_ops);
    282 }
    283 
    284 int EmulatedCamera2::get_request_queue_dst_ops(struct camera2_device *d,
    285         camera2_metadata_queue_dst_ops **queue_dst_ops) {
    286     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    287     *queue_dst_ops = static_cast<camera2_metadata_queue_dst_ops*>(
    288         &ec->mRequestQueueDstOps);
    289     return NO_ERROR;
    290 }
    291 
    292 int EmulatedCamera2::request_queue_notify_queue_not_empty(
    293         camera2_metadata_queue_dst_ops *q) {
    294     EmulatedCamera2* ec = static_cast<QueueDstOps*>(q)->parent;
    295     return ec->requestQueueNotifyNotEmpty();
    296 }
    297 
    298 int EmulatedCamera2::set_reprocess_queue_src_ops(struct camera2_device *d,
    299         camera2_metadata_queue_src_ops *queue_src_ops) {
    300     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    301     return ec->setReprocessQueueSrcOps(queue_src_ops);
    302 }
    303 
    304 int EmulatedCamera2::get_reprocess_queue_dst_ops(struct camera2_device *d,
    305         camera2_metadata_queue_dst_ops **queue_dst_ops) {
    306     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    307     *queue_dst_ops = static_cast<camera2_metadata_queue_dst_ops*>(
    308         &ec->mReprocessQueueDstOps);
    309     return NO_ERROR;
    310 }
    311 
    312 int EmulatedCamera2::reprocess_queue_notify_queue_not_empty(
    313         camera2_metadata_queue_dst_ops *q) {
    314     EmulatedCamera2* ec = static_cast<QueueDstOps*>(q)->parent;
    315     return ec->reprocessQueueNotifyNotEmpty();
    316 }
    317 
    318 int EmulatedCamera2::set_frame_queue_dst_ops(struct camera2_device *d,
    319         camera2_metadata_queue_dst_ops *queue_dst_ops) {
    320     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    321     return ec->setFrameQueueDstOps(queue_dst_ops);
    322 }
    323 
    324 int EmulatedCamera2::get_frame_queue_src_ops(struct camera2_device *d,
    325         camera2_metadata_queue_src_ops **queue_src_ops) {
    326     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    327     *queue_src_ops = static_cast<camera2_metadata_queue_src_ops*>(
    328         &ec->mFrameQueueSrcOps);
    329     return NO_ERROR;
    330 }
    331 
    332 int EmulatedCamera2::frame_queue_buffer_count(camera2_metadata_queue_src_ops *q) {
    333     EmulatedCamera2 *ec = static_cast<QueueSrcOps*>(q)->parent;
    334     return ec->frameQueueBufferCount();
    335 }
    336 
    337 int EmulatedCamera2::frame_queue_dequeue(camera2_metadata_queue_src_ops *q,
    338         camera_metadata_t **buffer) {
    339     EmulatedCamera2 *ec = static_cast<QueueSrcOps*>(q)->parent;
    340     return ec->frameQueueDequeue(buffer);
    341 }
    342 
    343 int EmulatedCamera2::frame_queue_free(camera2_metadata_queue_src_ops *q,
    344         camera_metadata_t *old_buffer) {
    345     EmulatedCamera2 *ec = static_cast<QueueSrcOps*>(q)->parent;
    346     return ec->frameQueueFree(old_buffer);
    347 }
    348 
    349 int EmulatedCamera2::set_notify_callback(struct camera2_device *d,
    350         camera2_notify_callback notify_cb) {
    351     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    352     return ec->setNotifyCallback(notify_cb);
    353 }
    354 
    355 int EmulatedCamera2::get_in_progress_count(struct camera2_device *d) {
    356     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    357     return ec->getInProgressCount();
    358 }
    359 
    360 int EmulatedCamera2::flush_captures_in_progress(struct camera2_device *d) {
    361     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    362     return ec->flushCapturesInProgress();
    363 }
    364 
    365 int EmulatedCamera2::get_reprocess_stream_ops(camera2_device_t *d,
    366         camera2_stream_ops **stream) {
    367     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    368     *stream = static_cast<camera2_stream_ops*>(&ec->mReprocessStreamOps);
    369     return NO_ERROR;
    370 }
    371 
    372 int EmulatedCamera2::reprocess_stream_dequeue_buffer(camera2_stream_ops *s,
    373         buffer_handle_t** buffer, int *stride) {
    374     EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
    375     return ec->reprocessStreamDequeueBuffer(buffer, stride);
    376 }
    377 
    378 int EmulatedCamera2::reprocess_stream_enqueue_buffer(camera2_stream_ops *s,
    379         buffer_handle_t* buffer) {
    380     EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
    381     return ec->reprocessStreamEnqueueBuffer(buffer);
    382 }
    383 
    384 int EmulatedCamera2::reprocess_stream_cancel_buffer(camera2_stream_ops *s,
    385         buffer_handle_t* buffer) {
    386     EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
    387     return ec->reprocessStreamCancelBuffer(buffer);
    388 }
    389 
    390 int EmulatedCamera2::reprocess_stream_set_buffer_count(camera2_stream_ops *s,
    391         int count) {
    392     EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
    393     return ec->reprocessStreamSetBufferCount(count);
    394 }
    395 
    396 int EmulatedCamera2::reprocess_stream_set_crop(camera2_stream_ops *s,
    397         int left, int top, int right, int bottom) {
    398     EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
    399     return ec->reprocessStreamSetCrop(left, top, right, bottom);
    400 }
    401 
    402 int EmulatedCamera2::reprocess_stream_set_timestamp(camera2_stream_ops *s,
    403         int64_t timestamp) {
    404     EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
    405     return ec->reprocessStreamSetTimestamp(timestamp);
    406 }
    407 
    408 int EmulatedCamera2::reprocess_stream_set_usage(camera2_stream_ops *s,
    409         int usage) {
    410     EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
    411     return ec->reprocessStreamSetUsage(usage);
    412 }
    413 
    414 int EmulatedCamera2::reprocess_stream_set_swap_interval(camera2_stream_ops *s,
    415         int interval) {
    416     EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
    417     return ec->reprocessStreamSetSwapInterval(interval);
    418 }
    419 
    420 int EmulatedCamera2::reprocess_stream_get_min_undequeued_buffer_count(
    421         const camera2_stream_ops *s,
    422         int *count) {
    423     EmulatedCamera2* ec = static_cast<const StreamOps*>(s)->parent;
    424     return ec->reprocessStreamGetMinUndequeuedBufferCount(count);
    425 }
    426 
    427 int EmulatedCamera2::reprocess_stream_lock_buffer(camera2_stream_ops *s,
    428         buffer_handle_t* buffer) {
    429     EmulatedCamera2* ec = static_cast<StreamOps*>(s)->parent;
    430     return ec->reprocessStreamLockBuffer(buffer);
    431 }
    432 
    433 int EmulatedCamera2::get_stream_slot_count(struct camera2_device *d) {
    434     EmulatedCamera2* ec =
    435             static_cast<EmulatedCamera2*>(d);
    436     return ec->getStreamSlotCount();
    437 }
    438 
    439 int EmulatedCamera2::allocate_stream(struct camera2_device *d,
    440         uint32_t stream_slot,
    441         uint32_t width,
    442         uint32_t height,
    443         uint32_t format,
    444         camera2_stream_ops_t *stream_ops) {
    445     EmulatedCamera2* ec =
    446             static_cast<EmulatedCamera2*>(d);
    447     return ec->allocateStream(stream_slot, width, height, format, stream_ops);
    448 }
    449 
    450 int EmulatedCamera2::release_stream(struct camera2_device *d,
    451         uint32_t stream_slot) {
    452     EmulatedCamera2* ec =
    453             static_cast<EmulatedCamera2*>(d);
    454     return ec->releaseStream(stream_slot);
    455 }
    456 
    457 void EmulatedCamera2::release(struct camera2_device *d) {
    458     EmulatedCamera2* ec =
    459             static_cast<EmulatedCamera2*>(d);
    460     ec->release();
    461 }
    462 
    463 int EmulatedCamera2::dump(struct camera2_device *d, int fd) {
    464     EmulatedCamera2* ec =
    465             static_cast<EmulatedCamera2*>(d);
    466     return ec->dump(fd);
    467 }
    468 
    469 int EmulatedCamera2::close(struct hw_device_t* device) {
    470     EmulatedCamera2* ec =
    471             static_cast<EmulatedCamera2*>(
    472                 reinterpret_cast<struct camera2_device*>(device) );
    473     if (ec == NULL) {
    474         ALOGE("%s: Unexpected NULL camera2 device", __FUNCTION__);
    475         return -EINVAL;
    476     }
    477     return ec->closeCamera();
    478 }
    479 
    480 int EmulatedCamera2::get_metadata_vendor_tag_ops(struct camera2_device *d,
    481         vendor_tag_query_ops_t **ops) {
    482     EmulatedCamera2* ec = static_cast<EmulatedCamera2*>(d);
    483     *ops = static_cast<vendor_tag_query_ops_t*>(
    484             &ec->mVendorTagOps);
    485     return NO_ERROR;
    486 }
    487 
    488 const char* EmulatedCamera2::get_camera_vendor_section_name(
    489         const vendor_tag_query_ops_t *v,
    490         uint32_t tag) {
    491     EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
    492     return ec->getVendorSectionName(tag);
    493 }
    494 
    495 const char* EmulatedCamera2::get_camera_vendor_tag_name(
    496         const vendor_tag_query_ops_t *v,
    497         uint32_t tag) {
    498     EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
    499     return ec->getVendorTagName(tag);
    500 }
    501 
    502 int EmulatedCamera2::get_camera_vendor_tag_type(
    503         const vendor_tag_query_ops_t *v,
    504         uint32_t tag)  {
    505     EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
    506     return ec->getVendorTagType(tag);
    507 }
    508 
    509 camera2_device_ops_t EmulatedCamera2::sDeviceOps = {
    510     EmulatedCamera2::set_request_queue_src_ops,
    511     EmulatedCamera2::get_request_queue_dst_ops,
    512     EmulatedCamera2::set_reprocess_queue_src_ops,
    513     EmulatedCamera2::get_reprocess_queue_dst_ops,
    514     EmulatedCamera2::set_frame_queue_dst_ops,
    515     EmulatedCamera2::get_frame_queue_src_ops,
    516     EmulatedCamera2::set_notify_callback,
    517     EmulatedCamera2::get_in_progress_count,
    518     EmulatedCamera2::flush_captures_in_progress,
    519     EmulatedCamera2::get_reprocess_stream_ops,
    520     EmulatedCamera2::get_stream_slot_count,
    521     EmulatedCamera2::allocate_stream,
    522     EmulatedCamera2::release_stream,
    523     EmulatedCamera2::get_metadata_vendor_tag_ops,
    524     EmulatedCamera2::release,
    525     EmulatedCamera2::dump
    526 };
    527 
    528 }; /* namespace android */
    529