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, struct hw_module_t* module) 42 : EmulatedBaseCamera(cameraId, CAMERA_DEVICE_API_VERSION_3_3, &common, 43 module), 44 mStatus(STATUS_ERROR) { 45 common.close = EmulatedCamera3::close; 46 ops = &sDeviceOps; 47 48 mCallbackOps = NULL; 49 } 50 51 /* Destructs EmulatedCamera3 instance. */ 52 EmulatedCamera3::~EmulatedCamera3() {} 53 54 /**************************************************************************** 55 * Abstract API 56 ***************************************************************************/ 57 58 /**************************************************************************** 59 * Public API 60 ***************************************************************************/ 61 62 status_t EmulatedCamera3::Initialize(const cvd::CameraDefinition& /*params*/) { 63 ALOGV("%s", __FUNCTION__); 64 65 mStatus = STATUS_CLOSED; 66 return NO_ERROR; 67 } 68 69 /**************************************************************************** 70 * Camera API implementation 71 ***************************************************************************/ 72 73 status_t EmulatedCamera3::connectCamera(hw_device_t** device) { 74 ALOGV("%s", __FUNCTION__); 75 if (device == NULL) return BAD_VALUE; 76 77 if (mStatus != STATUS_CLOSED) { 78 ALOGE("%s: Trying to open a camera in state %d!", __FUNCTION__, mStatus); 79 return INVALID_OPERATION; 80 } 81 82 *device = &common; 83 mStatus = STATUS_OPEN; 84 return NO_ERROR; 85 } 86 87 status_t EmulatedCamera3::closeCamera() { 88 mStatus = STATUS_CLOSED; 89 return NO_ERROR; 90 } 91 92 status_t EmulatedCamera3::getCameraInfo(struct camera_info* info) { 93 return EmulatedBaseCamera::getCameraInfo(info); 94 } 95 96 /**************************************************************************** 97 * Camera Device API implementation. 98 * These methods are called from the camera API callback routines. 99 ***************************************************************************/ 100 101 status_t EmulatedCamera3::initializeDevice( 102 const camera3_callback_ops* callbackOps) { 103 if (callbackOps == NULL) { 104 ALOGE("%s: NULL callback ops provided to HAL!", __FUNCTION__); 105 return BAD_VALUE; 106 } 107 108 if (mStatus != STATUS_OPEN) { 109 ALOGE("%s: Trying to initialize a camera in state %d!", __FUNCTION__, 110 mStatus); 111 return INVALID_OPERATION; 112 } 113 114 mCallbackOps = callbackOps; 115 mStatus = STATUS_READY; 116 117 return NO_ERROR; 118 } 119 120 status_t EmulatedCamera3::configureStreams( 121 camera3_stream_configuration* /*streamList*/) { 122 ALOGE("%s: Not implemented", __FUNCTION__); 123 return INVALID_OPERATION; 124 } 125 126 status_t EmulatedCamera3::registerStreamBuffers( 127 const camera3_stream_buffer_set* /*bufferSet*/) { 128 ALOGE("%s: Not implemented", __FUNCTION__); 129 return INVALID_OPERATION; 130 } 131 132 const camera_metadata_t* EmulatedCamera3::constructDefaultRequestSettings( 133 int /*type*/) { 134 ALOGE("%s: Not implemented", __FUNCTION__); 135 return NULL; 136 } 137 138 status_t EmulatedCamera3::processCaptureRequest( 139 camera3_capture_request* /*request*/) { 140 ALOGE("%s: Not implemented", __FUNCTION__); 141 return INVALID_OPERATION; 142 } 143 144 status_t EmulatedCamera3::flush() { 145 ALOGE("%s: Not implemented", __FUNCTION__); 146 return INVALID_OPERATION; 147 } 148 149 /** Debug methods */ 150 151 void EmulatedCamera3::dump(int /*fd*/) { 152 ALOGE("%s: Not implemented", __FUNCTION__); 153 return; 154 } 155 156 /**************************************************************************** 157 * Protected API. Callbacks to the framework. 158 ***************************************************************************/ 159 160 void EmulatedCamera3::sendCaptureResult(camera3_capture_result_t* result) { 161 mCallbackOps->process_capture_result(mCallbackOps, result); 162 } 163 164 void EmulatedCamera3::sendNotify(camera3_notify_msg_t* msg) { 165 mCallbackOps->notify(mCallbackOps, msg); 166 } 167 168 /**************************************************************************** 169 * Private API. 170 ***************************************************************************/ 171 172 /**************************************************************************** 173 * Camera API callbacks as defined by camera3_device_ops structure. See 174 * hardware/libhardware/include/hardware/camera3.h for information on each 175 * of these callbacks. Implemented in this class, these callbacks simply 176 * dispatch the call into an instance of EmulatedCamera3 class defined by the 177 * 'camera_device3' parameter, or set a member value in the same. 178 ***************************************************************************/ 179 180 EmulatedCamera3* getInstance(const camera3_device_t* d) { 181 const EmulatedCamera3* cec = static_cast<const EmulatedCamera3*>(d); 182 return const_cast<EmulatedCamera3*>(cec); 183 } 184 185 int EmulatedCamera3::initialize(const struct camera3_device* d, 186 const camera3_callback_ops_t* callback_ops) { 187 EmulatedCamera3* ec = getInstance(d); 188 return ec->initializeDevice(callback_ops); 189 } 190 191 int EmulatedCamera3::configure_streams( 192 const struct camera3_device* d, 193 camera3_stream_configuration_t* stream_list) { 194 EmulatedCamera3* ec = getInstance(d); 195 return ec->configureStreams(stream_list); 196 } 197 198 int EmulatedCamera3::register_stream_buffers( 199 const struct camera3_device* d, 200 const camera3_stream_buffer_set_t* buffer_set) { 201 EmulatedCamera3* ec = getInstance(d); 202 return ec->registerStreamBuffers(buffer_set); 203 } 204 205 int EmulatedCamera3::process_capture_request( 206 const struct camera3_device* d, camera3_capture_request_t* request) { 207 EmulatedCamera3* ec = getInstance(d); 208 return ec->processCaptureRequest(request); 209 } 210 211 const camera_metadata_t* EmulatedCamera3::construct_default_request_settings( 212 const camera3_device_t* d, int type) { 213 EmulatedCamera3* ec = getInstance(d); 214 return ec->constructDefaultRequestSettings(type); 215 } 216 217 void EmulatedCamera3::dump(const camera3_device_t* d, int fd) { 218 EmulatedCamera3* ec = getInstance(d); 219 ec->dump(fd); 220 } 221 222 int EmulatedCamera3::flush(const camera3_device_t* d) { 223 EmulatedCamera3* ec = getInstance(d); 224 return ec->flush(); 225 } 226 227 int EmulatedCamera3::close(struct hw_device_t* device) { 228 EmulatedCamera3* ec = static_cast<EmulatedCamera3*>( 229 reinterpret_cast<camera3_device_t*>(device)); 230 if (ec == NULL) { 231 ALOGE("%s: Unexpected NULL camera3 device", __FUNCTION__); 232 return BAD_VALUE; 233 } 234 return ec->closeCamera(); 235 } 236 237 camera3_device_ops_t EmulatedCamera3::sDeviceOps = { 238 EmulatedCamera3::initialize, 239 EmulatedCamera3::configure_streams, 240 /* DEPRECATED: register_stream_buffers */ nullptr, 241 EmulatedCamera3::construct_default_request_settings, 242 EmulatedCamera3::process_capture_request, 243 /* DEPRECATED: get_metadata_vendor_tag_ops */ nullptr, 244 EmulatedCamera3::dump, 245 EmulatedCamera3::flush, 246 {0}}; 247 248 const char* EmulatedCamera3::sAvailableCapabilitiesStrings[NUM_CAPABILITIES] = { 249 "BACKWARD_COMPATIBLE", 250 "MANUAL_SENSOR", 251 "MANUAL_POST_PROCESSING", 252 "RAW", 253 "PRIVATE_REPROCESSING", 254 "READ_SENSOR_SETTINGS", 255 "BURST_CAPTURE", 256 "YUV_REPROCESSING", 257 "DEPTH_OUTPUT", 258 "CONSTRAINED_HIGH_SPEED_VIDEO", 259 "FULL_LEVEL"}; 260 261 }; /* namespace android */ 262