Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2013 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 3.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 camera3_device_ops_t API.
     23  */
     24 
     25 //#define LOG_NDEBUG 0
     26 #define LOG_TAG "EmulatedCamera3_Camera"
     27 #include <cutils/log.h>
     28 
     29 #include "EmulatedCamera3.h"
     30 #include "system/camera_metadata.h"
     31 
     32 namespace android {
     33 
     34 /**
     35  * Constructs EmulatedCamera3 instance.
     36  * Param:
     37  *  cameraId - Zero based camera identifier, which is an index of the camera
     38  *      instance in camera factory's array.
     39  *  module - Emulated camera HAL module descriptor.
     40  */
     41 EmulatedCamera3::EmulatedCamera3(int cameraId,
     42         struct hw_module_t* module):
     43         EmulatedBaseCamera(cameraId,
     44                 CAMERA_DEVICE_API_VERSION_3_0,
     45                 &common,
     46                 module),
     47         mStatus(STATUS_ERROR)
     48 {
     49     common.close = EmulatedCamera3::close;
     50     ops = &sDeviceOps;
     51 
     52     mCallbackOps = NULL;
     53 
     54     mVendorTagOps.get_camera_vendor_section_name =
     55             EmulatedCamera3::get_camera_vendor_section_name;
     56     mVendorTagOps.get_camera_vendor_tag_name =
     57             EmulatedCamera3::get_camera_vendor_tag_name;
     58     mVendorTagOps.get_camera_vendor_tag_type =
     59             EmulatedCamera3::get_camera_vendor_tag_type;
     60     mVendorTagOps.parent = this;
     61 }
     62 
     63 /* Destructs EmulatedCamera3 instance. */
     64 EmulatedCamera3::~EmulatedCamera3() {
     65 }
     66 
     67 /****************************************************************************
     68  * Abstract API
     69  ***************************************************************************/
     70 
     71 /****************************************************************************
     72  * Public API
     73  ***************************************************************************/
     74 
     75 status_t EmulatedCamera3::Initialize() {
     76     ALOGV("%s", __FUNCTION__);
     77 
     78     mStatus = STATUS_CLOSED;
     79     return NO_ERROR;
     80 }
     81 
     82 /****************************************************************************
     83  * Camera API implementation
     84  ***************************************************************************/
     85 
     86 status_t EmulatedCamera3::connectCamera(hw_device_t** device) {
     87     ALOGV("%s", __FUNCTION__);
     88     if (device == NULL) return BAD_VALUE;
     89 
     90     if (mStatus != STATUS_CLOSED) {
     91         ALOGE("%s: Trying to open a camera in state %d!",
     92                 __FUNCTION__, mStatus);
     93         return INVALID_OPERATION;
     94     }
     95 
     96     *device = &common;
     97     mStatus = STATUS_OPEN;
     98     return NO_ERROR;
     99 }
    100 
    101 status_t EmulatedCamera3::closeCamera() {
    102     mStatus = STATUS_CLOSED;
    103     return NO_ERROR;
    104 }
    105 
    106 status_t EmulatedCamera3::getCameraInfo(struct camera_info* info) {
    107     return EmulatedBaseCamera::getCameraInfo(info);
    108 }
    109 
    110 /****************************************************************************
    111  * Camera Device API implementation.
    112  * These methods are called from the camera API callback routines.
    113  ***************************************************************************/
    114 
    115 status_t EmulatedCamera3::initializeDevice(
    116         const camera3_callback_ops *callbackOps) {
    117     if (callbackOps == NULL) {
    118         ALOGE("%s: NULL callback ops provided to HAL!",
    119                 __FUNCTION__);
    120         return BAD_VALUE;
    121     }
    122 
    123     if (mStatus != STATUS_OPEN) {
    124         ALOGE("%s: Trying to initialize a camera in state %d!",
    125                 __FUNCTION__, mStatus);
    126         return INVALID_OPERATION;
    127     }
    128 
    129     mCallbackOps = callbackOps;
    130     mStatus = STATUS_READY;
    131 
    132     return NO_ERROR;
    133 }
    134 
    135 status_t EmulatedCamera3::configureStreams(
    136         camera3_stream_configuration *streamList) {
    137     ALOGE("%s: Not implemented", __FUNCTION__);
    138     return INVALID_OPERATION;
    139 }
    140 
    141 status_t EmulatedCamera3::registerStreamBuffers(
    142         const camera3_stream_buffer_set *bufferSet) {
    143     ALOGE("%s: Not implemented", __FUNCTION__);
    144     return INVALID_OPERATION;
    145 }
    146 
    147 const camera_metadata_t* EmulatedCamera3::constructDefaultRequestSettings(
    148         int type) {
    149     ALOGE("%s: Not implemented", __FUNCTION__);
    150     return NULL;
    151 }
    152 
    153 status_t EmulatedCamera3::processCaptureRequest(
    154         camera3_capture_request *request) {
    155     ALOGE("%s: Not implemented", __FUNCTION__);
    156     return INVALID_OPERATION;
    157 }
    158 
    159 /** Custom tag query methods */
    160 
    161 const char* EmulatedCamera3::getVendorSectionName(uint32_t tag) {
    162     ALOGE("%s: Not implemented", __FUNCTION__);
    163     return NULL;
    164 }
    165 
    166 const char* EmulatedCamera3::getVendorTagName(uint32_t tag) {
    167     ALOGE("%s: Not implemented", __FUNCTION__);
    168     return NULL;
    169 }
    170 
    171 int EmulatedCamera3::getVendorTagType(uint32_t tag) {
    172     ALOGE("%s: Not implemented", __FUNCTION__);
    173     return -1;
    174 }
    175 
    176 /** Debug methods */
    177 
    178 void EmulatedCamera3::dump(int fd) {
    179     ALOGE("%s: Not implemented", __FUNCTION__);
    180     return;
    181 }
    182 
    183 /****************************************************************************
    184  * Protected API. Callbacks to the framework.
    185  ***************************************************************************/
    186 
    187 void EmulatedCamera3::sendCaptureResult(camera3_capture_result_t *result) {
    188     mCallbackOps->process_capture_result(mCallbackOps, result);
    189 }
    190 
    191 void EmulatedCamera3::sendNotify(camera3_notify_msg_t *msg) {
    192     mCallbackOps->notify(mCallbackOps, msg);
    193 }
    194 
    195 /****************************************************************************
    196  * Private API.
    197  ***************************************************************************/
    198 
    199 /****************************************************************************
    200  * Camera API callbacks as defined by camera3_device_ops structure.  See
    201  * hardware/libhardware/include/hardware/camera3.h for information on each
    202  * of these callbacks. Implemented in this class, these callbacks simply
    203  * dispatch the call into an instance of EmulatedCamera3 class defined by the
    204  * 'camera_device3' parameter, or set a member value in the same.
    205  ***************************************************************************/
    206 
    207 EmulatedCamera3* getInstance(const camera3_device_t *d) {
    208     const EmulatedCamera3* cec = static_cast<const EmulatedCamera3*>(d);
    209     return const_cast<EmulatedCamera3*>(cec);
    210 }
    211 
    212 int EmulatedCamera3::initialize(const struct camera3_device *d,
    213         const camera3_callback_ops_t *callback_ops) {
    214     EmulatedCamera3* ec = getInstance(d);
    215     return ec->initializeDevice(callback_ops);
    216 }
    217 
    218 int EmulatedCamera3::configure_streams(const struct camera3_device *d,
    219         camera3_stream_configuration_t *stream_list) {
    220     EmulatedCamera3* ec = getInstance(d);
    221     return ec->configureStreams(stream_list);
    222 }
    223 
    224 int EmulatedCamera3::register_stream_buffers(
    225         const struct camera3_device *d,
    226         const camera3_stream_buffer_set_t *buffer_set) {
    227     EmulatedCamera3* ec = getInstance(d);
    228     return ec->registerStreamBuffers(buffer_set);
    229 }
    230 
    231 int EmulatedCamera3::process_capture_request(
    232         const struct camera3_device *d,
    233         camera3_capture_request_t *request) {
    234     EmulatedCamera3* ec = getInstance(d);
    235     return ec->processCaptureRequest(request);
    236 }
    237 
    238 const camera_metadata_t* EmulatedCamera3::construct_default_request_settings(
    239         const camera3_device_t *d, int type) {
    240     EmulatedCamera3* ec = getInstance(d);
    241     return ec->constructDefaultRequestSettings(type);
    242 }
    243 
    244 void EmulatedCamera3::get_metadata_vendor_tag_ops(const camera3_device_t *d,
    245         vendor_tag_query_ops_t *ops) {
    246     ops->get_camera_vendor_section_name = get_camera_vendor_section_name;
    247     ops->get_camera_vendor_tag_name = get_camera_vendor_tag_name;
    248     ops->get_camera_vendor_tag_type = get_camera_vendor_tag_type;
    249 }
    250 
    251 const char* EmulatedCamera3::get_camera_vendor_section_name(
    252         const vendor_tag_query_ops_t *v,
    253         uint32_t tag) {
    254     EmulatedCamera3* ec = static_cast<const TagOps*>(v)->parent;
    255     return ec->getVendorSectionName(tag);
    256 }
    257 
    258 const char* EmulatedCamera3::get_camera_vendor_tag_name(
    259         const vendor_tag_query_ops_t *v,
    260         uint32_t tag) {
    261     EmulatedCamera3* ec = static_cast<const TagOps*>(v)->parent;
    262     return ec->getVendorTagName(tag);
    263 }
    264 
    265 int EmulatedCamera3::get_camera_vendor_tag_type(
    266         const vendor_tag_query_ops_t *v,
    267         uint32_t tag)  {
    268     EmulatedCamera3* ec = static_cast<const TagOps*>(v)->parent;
    269     return ec->getVendorTagType(tag);
    270 }
    271 
    272 void EmulatedCamera3::dump(const camera3_device_t *d, int fd) {
    273     EmulatedCamera3* ec = getInstance(d);
    274     ec->dump(fd);
    275 }
    276 
    277 int EmulatedCamera3::close(struct hw_device_t* device) {
    278     EmulatedCamera3* ec =
    279             static_cast<EmulatedCamera3*>(
    280                 reinterpret_cast<camera3_device_t*>(device) );
    281     if (ec == NULL) {
    282         ALOGE("%s: Unexpected NULL camera3 device", __FUNCTION__);
    283         return BAD_VALUE;
    284     }
    285     return ec->closeCamera();
    286 }
    287 
    288 camera3_device_ops_t EmulatedCamera3::sDeviceOps = {
    289     EmulatedCamera3::initialize,
    290     EmulatedCamera3::configure_streams,
    291     EmulatedCamera3::register_stream_buffers,
    292     EmulatedCamera3::construct_default_request_settings,
    293     EmulatedCamera3::process_capture_request,
    294     EmulatedCamera3::get_metadata_vendor_tag_ops,
    295     EmulatedCamera3::dump
    296 };
    297 
    298 }; /* namespace android */
    299