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 */
EmulatedCamera2(int cameraId,struct hw_module_t * module)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 mNotifyCb = NULL;
52
53 mRequestQueueSrc = NULL;
54 mFrameQueueDst = NULL;
55
56 mVendorTagOps.get_camera_vendor_section_name =
57 EmulatedCamera2::get_camera_vendor_section_name;
58 mVendorTagOps.get_camera_vendor_tag_name =
59 EmulatedCamera2::get_camera_vendor_tag_name;
60 mVendorTagOps.get_camera_vendor_tag_type =
61 EmulatedCamera2::get_camera_vendor_tag_type;
62 mVendorTagOps.parent = this;
63 }
64
65 /* Destructs EmulatedCamera2 instance. */
~EmulatedCamera2()66 EmulatedCamera2::~EmulatedCamera2() {
67 }
68
69 /****************************************************************************
70 * Abstract API
71 ***************************************************************************/
72
73 /****************************************************************************
74 * Public API
75 ***************************************************************************/
76
Initialize()77 status_t EmulatedCamera2::Initialize() {
78 return NO_ERROR;
79 }
80
81 /****************************************************************************
82 * Camera API implementation
83 ***************************************************************************/
84
connectCamera(hw_device_t ** device)85 status_t EmulatedCamera2::connectCamera(hw_device_t** device) {
86 *device = &common;
87 return NO_ERROR;
88 }
89
closeCamera()90 status_t EmulatedCamera2::closeCamera() {
91 return NO_ERROR;
92 }
93
getCameraInfo(struct camera_info * info)94 status_t EmulatedCamera2::getCameraInfo(struct camera_info* info) {
95 return EmulatedBaseCamera::getCameraInfo(info);
96 }
97
98 /****************************************************************************
99 * Camera Device API implementation.
100 * These methods are called from the camera API callback routines.
101 ***************************************************************************/
102
103 /** Request input queue */
104
requestQueueNotify()105 int EmulatedCamera2::requestQueueNotify() {
106 return INVALID_OPERATION;
107 }
108
109 /** Count of requests in flight */
getInProgressCount()110 int EmulatedCamera2::getInProgressCount() {
111 return INVALID_OPERATION;
112 }
113
114 /** Cancel all captures in flight */
flushCapturesInProgress()115 int EmulatedCamera2::flushCapturesInProgress() {
116 return INVALID_OPERATION;
117 }
118
119 /** Construct a default request for a given use case */
constructDefaultRequest(int request_template,camera_metadata_t ** request)120 int EmulatedCamera2::constructDefaultRequest(
121 int request_template,
122 camera_metadata_t **request) {
123 return INVALID_OPERATION;
124 }
125
126 /** Output stream creation and management */
127
allocateStream(uint32_t width,uint32_t height,int format,const camera2_stream_ops_t * stream_ops,uint32_t * stream_id,uint32_t * format_actual,uint32_t * usage,uint32_t * max_buffers)128 int EmulatedCamera2::allocateStream(
129 uint32_t width,
130 uint32_t height,
131 int format,
132 const camera2_stream_ops_t *stream_ops,
133 uint32_t *stream_id,
134 uint32_t *format_actual,
135 uint32_t *usage,
136 uint32_t *max_buffers) {
137 return INVALID_OPERATION;
138 }
139
registerStreamBuffers(uint32_t stream_id,int num_buffers,buffer_handle_t * buffers)140 int EmulatedCamera2::registerStreamBuffers(
141 uint32_t stream_id,
142 int num_buffers,
143 buffer_handle_t *buffers) {
144 return INVALID_OPERATION;
145 }
146
147
releaseStream(uint32_t stream_id)148 int EmulatedCamera2::releaseStream(uint32_t stream_id) {
149 return INVALID_OPERATION;
150 }
151
152 /** Reprocessing input stream management */
153
allocateReprocessStream(uint32_t width,uint32_t height,uint32_t format,const camera2_stream_in_ops_t * reprocess_stream_ops,uint32_t * stream_id,uint32_t * consumer_usage,uint32_t * max_buffers)154 int EmulatedCamera2::allocateReprocessStream(
155 uint32_t width,
156 uint32_t height,
157 uint32_t format,
158 const camera2_stream_in_ops_t *reprocess_stream_ops,
159 uint32_t *stream_id,
160 uint32_t *consumer_usage,
161 uint32_t *max_buffers) {
162 return INVALID_OPERATION;
163 }
164
allocateReprocessStreamFromStream(uint32_t output_stream_id,const camera2_stream_in_ops_t * reprocess_stream_ops,uint32_t * stream_id)165 int EmulatedCamera2::allocateReprocessStreamFromStream(
166 uint32_t output_stream_id,
167 const camera2_stream_in_ops_t *reprocess_stream_ops,
168 uint32_t *stream_id) {
169 return INVALID_OPERATION;
170 }
171
releaseReprocessStream(uint32_t stream_id)172 int EmulatedCamera2::releaseReprocessStream(uint32_t stream_id) {
173 return INVALID_OPERATION;
174 }
175
176 /** 3A triggering */
177
triggerAction(uint32_t trigger_id,int ext1,int ext2)178 int EmulatedCamera2::triggerAction(uint32_t trigger_id,
179 int ext1, int ext2) {
180 return INVALID_OPERATION;
181 }
182
183 /** Custom tag query methods */
184
getVendorSectionName(uint32_t tag)185 const char* EmulatedCamera2::getVendorSectionName(uint32_t tag) {
186 return NULL;
187 }
188
getVendorTagName(uint32_t tag)189 const char* EmulatedCamera2::getVendorTagName(uint32_t tag) {
190 return NULL;
191 }
192
getVendorTagType(uint32_t tag)193 int EmulatedCamera2::getVendorTagType(uint32_t tag) {
194 return -1;
195 }
196
197 /** Debug methods */
198
dump(int fd)199 int EmulatedCamera2::dump(int fd) {
200 return INVALID_OPERATION;
201 }
202
203 /****************************************************************************
204 * Private API.
205 ***************************************************************************/
206
207 /****************************************************************************
208 * Camera API callbacks as defined by camera2_device_ops structure. See
209 * hardware/libhardware/include/hardware/camera2.h for information on each
210 * of these callbacks. Implemented in this class, these callbacks simply
211 * dispatch the call into an instance of EmulatedCamera2 class defined by the
212 * 'camera_device2' parameter, or set a member value in the same.
213 ***************************************************************************/
214
getInstance(const camera2_device_t * d)215 EmulatedCamera2* getInstance(const camera2_device_t *d) {
216 const EmulatedCamera2* cec = static_cast<const EmulatedCamera2*>(d);
217 return const_cast<EmulatedCamera2*>(cec);
218 }
219
set_request_queue_src_ops(const camera2_device_t * d,const camera2_request_queue_src_ops * queue_src_ops)220 int EmulatedCamera2::set_request_queue_src_ops(const camera2_device_t *d,
221 const camera2_request_queue_src_ops *queue_src_ops) {
222 EmulatedCamera2* ec = getInstance(d);
223 ec->mRequestQueueSrc = queue_src_ops;
224 return NO_ERROR;
225 }
226
notify_request_queue_not_empty(const camera2_device_t * d)227 int EmulatedCamera2::notify_request_queue_not_empty(const camera2_device_t *d) {
228 EmulatedCamera2* ec = getInstance(d);
229 return ec->requestQueueNotify();
230 }
231
set_frame_queue_dst_ops(const camera2_device_t * d,const camera2_frame_queue_dst_ops * queue_dst_ops)232 int EmulatedCamera2::set_frame_queue_dst_ops(const camera2_device_t *d,
233 const camera2_frame_queue_dst_ops *queue_dst_ops) {
234 EmulatedCamera2* ec = getInstance(d);
235 ec->mFrameQueueDst = queue_dst_ops;
236 return NO_ERROR;
237 }
238
get_in_progress_count(const camera2_device_t * d)239 int EmulatedCamera2::get_in_progress_count(const camera2_device_t *d) {
240 EmulatedCamera2* ec = getInstance(d);
241 return ec->getInProgressCount();
242 }
243
flush_captures_in_progress(const camera2_device_t * d)244 int EmulatedCamera2::flush_captures_in_progress(const camera2_device_t *d) {
245 EmulatedCamera2* ec = getInstance(d);
246 return ec->flushCapturesInProgress();
247 }
248
construct_default_request(const camera2_device_t * d,int request_template,camera_metadata_t ** request)249 int EmulatedCamera2::construct_default_request(const camera2_device_t *d,
250 int request_template,
251 camera_metadata_t **request) {
252 EmulatedCamera2* ec = getInstance(d);
253 return ec->constructDefaultRequest(request_template, request);
254 }
255
allocate_stream(const camera2_device_t * d,uint32_t width,uint32_t height,int format,const camera2_stream_ops_t * stream_ops,uint32_t * stream_id,uint32_t * format_actual,uint32_t * usage,uint32_t * max_buffers)256 int EmulatedCamera2::allocate_stream(const camera2_device_t *d,
257 uint32_t width,
258 uint32_t height,
259 int format,
260 const camera2_stream_ops_t *stream_ops,
261 uint32_t *stream_id,
262 uint32_t *format_actual,
263 uint32_t *usage,
264 uint32_t *max_buffers) {
265 EmulatedCamera2* ec = getInstance(d);
266 return ec->allocateStream(width, height, format, stream_ops,
267 stream_id, format_actual, usage, max_buffers);
268 }
269
register_stream_buffers(const camera2_device_t * d,uint32_t stream_id,int num_buffers,buffer_handle_t * buffers)270 int EmulatedCamera2::register_stream_buffers(const camera2_device_t *d,
271 uint32_t stream_id,
272 int num_buffers,
273 buffer_handle_t *buffers) {
274 EmulatedCamera2* ec = getInstance(d);
275 return ec->registerStreamBuffers(stream_id,
276 num_buffers,
277 buffers);
278 }
release_stream(const camera2_device_t * d,uint32_t stream_id)279 int EmulatedCamera2::release_stream(const camera2_device_t *d,
280 uint32_t stream_id) {
281 EmulatedCamera2* ec = getInstance(d);
282 return ec->releaseStream(stream_id);
283 }
284
allocate_reprocess_stream(const camera2_device_t * d,uint32_t width,uint32_t height,uint32_t format,const camera2_stream_in_ops_t * reprocess_stream_ops,uint32_t * stream_id,uint32_t * consumer_usage,uint32_t * max_buffers)285 int EmulatedCamera2::allocate_reprocess_stream(const camera2_device_t *d,
286 uint32_t width,
287 uint32_t height,
288 uint32_t format,
289 const camera2_stream_in_ops_t *reprocess_stream_ops,
290 uint32_t *stream_id,
291 uint32_t *consumer_usage,
292 uint32_t *max_buffers) {
293 EmulatedCamera2* ec = getInstance(d);
294 return ec->allocateReprocessStream(width, height, format,
295 reprocess_stream_ops, stream_id, consumer_usage, max_buffers);
296 }
297
allocate_reprocess_stream_from_stream(const camera2_device_t * d,uint32_t output_stream_id,const camera2_stream_in_ops_t * reprocess_stream_ops,uint32_t * stream_id)298 int EmulatedCamera2::allocate_reprocess_stream_from_stream(
299 const camera2_device_t *d,
300 uint32_t output_stream_id,
301 const camera2_stream_in_ops_t *reprocess_stream_ops,
302 uint32_t *stream_id) {
303 EmulatedCamera2* ec = getInstance(d);
304 return ec->allocateReprocessStreamFromStream(output_stream_id,
305 reprocess_stream_ops, stream_id);
306 }
307
308
release_reprocess_stream(const camera2_device_t * d,uint32_t stream_id)309 int EmulatedCamera2::release_reprocess_stream(const camera2_device_t *d,
310 uint32_t stream_id) {
311 EmulatedCamera2* ec = getInstance(d);
312 return ec->releaseReprocessStream(stream_id);
313 }
314
trigger_action(const camera2_device_t * d,uint32_t trigger_id,int ext1,int ext2)315 int EmulatedCamera2::trigger_action(const camera2_device_t *d,
316 uint32_t trigger_id,
317 int ext1,
318 int ext2) {
319 EmulatedCamera2* ec = getInstance(d);
320 return ec->triggerAction(trigger_id, ext1, ext2);
321 }
322
set_notify_callback(const camera2_device_t * d,camera2_notify_callback notify_cb,void * user)323 int EmulatedCamera2::set_notify_callback(const camera2_device_t *d,
324 camera2_notify_callback notify_cb, void* user) {
325 EmulatedCamera2* ec = getInstance(d);
326 Mutex::Autolock l(ec->mMutex);
327 ec->mNotifyCb = notify_cb;
328 ec->mNotifyUserPtr = user;
329 return NO_ERROR;
330 }
331
get_metadata_vendor_tag_ops(const camera2_device_t * d,vendor_tag_query_ops_t ** ops)332 int EmulatedCamera2::get_metadata_vendor_tag_ops(const camera2_device_t *d,
333 vendor_tag_query_ops_t **ops) {
334 EmulatedCamera2* ec = getInstance(d);
335 *ops = static_cast<vendor_tag_query_ops_t*>(
336 &ec->mVendorTagOps);
337 return NO_ERROR;
338 }
339
get_camera_vendor_section_name(const vendor_tag_query_ops_t * v,uint32_t tag)340 const char* EmulatedCamera2::get_camera_vendor_section_name(
341 const vendor_tag_query_ops_t *v,
342 uint32_t tag) {
343 EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
344 return ec->getVendorSectionName(tag);
345 }
346
get_camera_vendor_tag_name(const vendor_tag_query_ops_t * v,uint32_t tag)347 const char* EmulatedCamera2::get_camera_vendor_tag_name(
348 const vendor_tag_query_ops_t *v,
349 uint32_t tag) {
350 EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
351 return ec->getVendorTagName(tag);
352 }
353
get_camera_vendor_tag_type(const vendor_tag_query_ops_t * v,uint32_t tag)354 int EmulatedCamera2::get_camera_vendor_tag_type(
355 const vendor_tag_query_ops_t *v,
356 uint32_t tag) {
357 EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
358 return ec->getVendorTagType(tag);
359 }
360
dump(const camera2_device_t * d,int fd)361 int EmulatedCamera2::dump(const camera2_device_t *d, int fd) {
362 EmulatedCamera2* ec = getInstance(d);
363 return ec->dump(fd);
364 }
365
close(struct hw_device_t * device)366 int EmulatedCamera2::close(struct hw_device_t* device) {
367 EmulatedCamera2* ec =
368 static_cast<EmulatedCamera2*>(
369 reinterpret_cast<camera2_device_t*>(device) );
370 if (ec == NULL) {
371 ALOGE("%s: Unexpected NULL camera2 device", __FUNCTION__);
372 return -EINVAL;
373 }
374 return ec->closeCamera();
375 }
376
sendNotification(int32_t msgType,int32_t ext1,int32_t ext2,int32_t ext3)377 void EmulatedCamera2::sendNotification(int32_t msgType,
378 int32_t ext1, int32_t ext2, int32_t ext3) {
379 camera2_notify_callback notifyCb;
380 {
381 Mutex::Autolock l(mMutex);
382 notifyCb = mNotifyCb;
383 }
384 if (notifyCb != NULL) {
385 notifyCb(msgType, ext1, ext2, ext3, mNotifyUserPtr);
386 }
387 }
388
389 camera2_device_ops_t EmulatedCamera2::sDeviceOps = {
390 EmulatedCamera2::set_request_queue_src_ops,
391 EmulatedCamera2::notify_request_queue_not_empty,
392 EmulatedCamera2::set_frame_queue_dst_ops,
393 EmulatedCamera2::get_in_progress_count,
394 EmulatedCamera2::flush_captures_in_progress,
395 EmulatedCamera2::construct_default_request,
396 EmulatedCamera2::allocate_stream,
397 EmulatedCamera2::register_stream_buffers,
398 EmulatedCamera2::release_stream,
399 EmulatedCamera2::allocate_reprocess_stream,
400 EmulatedCamera2::allocate_reprocess_stream_from_stream,
401 EmulatedCamera2::release_reprocess_stream,
402 EmulatedCamera2::trigger_action,
403 EmulatedCamera2::set_notify_callback,
404 EmulatedCamera2::get_metadata_vendor_tag_ops,
405 EmulatedCamera2::dump
406 };
407
408 }; /* namespace android */
409