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