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 <log/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 */
EmulatedCamera3(int cameraId,struct hw_module_t * module)41 EmulatedCamera3::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. */
~EmulatedCamera3()57 EmulatedCamera3::~EmulatedCamera3() {
58 }
59
60 /****************************************************************************
61 * Abstract API
62 ***************************************************************************/
63
64 /****************************************************************************
65 * Public API
66 ***************************************************************************/
67
Initialize()68 status_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
connectCamera(hw_device_t ** device)79 status_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
closeCamera()94 status_t EmulatedCamera3::closeCamera() {
95 mStatus = STATUS_CLOSED;
96 return NO_ERROR;
97 }
98
getCameraInfo(struct camera_info * info)99 status_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
initializeDevice(const camera3_callback_ops * callbackOps)108 status_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
configureStreams(camera3_stream_configuration * streamList)128 status_t EmulatedCamera3::configureStreams(
129 camera3_stream_configuration *streamList) {
130 ALOGE("%s: Not implemented", __FUNCTION__);
131 return INVALID_OPERATION;
132 }
133
registerStreamBuffers(const camera3_stream_buffer_set * bufferSet)134 status_t EmulatedCamera3::registerStreamBuffers(
135 const camera3_stream_buffer_set *bufferSet) {
136 ALOGE("%s: Not implemented", __FUNCTION__);
137 return INVALID_OPERATION;
138 }
139
constructDefaultRequestSettings(int type)140 const camera_metadata_t* EmulatedCamera3::constructDefaultRequestSettings(
141 int type) {
142 ALOGE("%s: Not implemented", __FUNCTION__);
143 return NULL;
144 }
145
processCaptureRequest(camera3_capture_request * request)146 status_t EmulatedCamera3::processCaptureRequest(
147 camera3_capture_request *request) {
148 ALOGE("%s: Not implemented", __FUNCTION__);
149 return INVALID_OPERATION;
150 }
151
flush()152 status_t EmulatedCamera3::flush() {
153 ALOGE("%s: Not implemented", __FUNCTION__);
154 return INVALID_OPERATION;
155 }
156
157 /** Debug methods */
158
dump(int fd)159 void EmulatedCamera3::dump(int fd) {
160 ALOGE("%s: Not implemented", __FUNCTION__);
161 return;
162 }
163
164 /****************************************************************************
165 * Protected API. Callbacks to the framework.
166 ***************************************************************************/
167
sendCaptureResult(camera3_capture_result_t * result)168 void EmulatedCamera3::sendCaptureResult(camera3_capture_result_t *result) {
169 mCallbackOps->process_capture_result(mCallbackOps, result);
170 }
171
sendNotify(camera3_notify_msg_t * msg)172 void 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
getInstance(const camera3_device_t * d)188 EmulatedCamera3* getInstance(const camera3_device_t *d) {
189 const EmulatedCamera3* cec = static_cast<const EmulatedCamera3*>(d);
190 return const_cast<EmulatedCamera3*>(cec);
191 }
192
initialize(const struct camera3_device * d,const camera3_callback_ops_t * callback_ops)193 int 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
configure_streams(const struct camera3_device * d,camera3_stream_configuration_t * stream_list)199 int 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
register_stream_buffers(const struct camera3_device * d,const camera3_stream_buffer_set_t * buffer_set)205 int 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
process_capture_request(const struct camera3_device * d,camera3_capture_request_t * request)212 int 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
construct_default_request_settings(const camera3_device_t * d,int type)219 const 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
dump(const camera3_device_t * d,int fd)225 void EmulatedCamera3::dump(const camera3_device_t *d, int fd) {
226 EmulatedCamera3* ec = getInstance(d);
227 ec->dump(fd);
228 }
229
flush(const camera3_device_t * d)230 int EmulatedCamera3::flush(const camera3_device_t *d) {
231 EmulatedCamera3* ec = getInstance(d);
232 return ec->flush();
233 }
234
close(struct hw_device_t * device)235 int 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
246 camera3_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 /* UNUSED: signal_stream_flush */ nullptr,
256 /* UNUSED: is_reconfiguration_required */ nullptr,
257 /* RESERVED */ { nullptr },
258 };
259
260 const char* EmulatedCamera3::sAvailableCapabilitiesStrings[NUM_CAPABILITIES] = {
261 "BACKWARD_COMPATIBLE",
262 "MANUAL_SENSOR",
263 "MANUAL_POST_PROCESSING",
264 "RAW",
265 "PRIVATE_REPROCESSING",
266 "READ_SENSOR_SETTINGS",
267 "BURST_CAPTURE",
268 "YUV_REPROCESSING",
269 "DEPTH_OUTPUT",
270 "CONSTRAINED_HIGH_SPEED_VIDEO",
271 "FULL_LEVEL"
272 };
273
274 }; /* namespace android */
275