2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
25 //#define LOG_NDEBUG 0
26 #define LOG_TAG "EmulatedCamera2_Camera"
27 #include <cutils/log.h>
29 #include "EmulatedCamera2.h"
30 #include "system/camera_metadata.h"
34 /* Constructs EmulatedCamera2 instance.
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.
40 EmulatedCamera2::EmulatedCamera2(int cameraId,
41 struct hw_module_t* module):
42 EmulatedBaseCamera(cameraId,
43 CAMERA_DEVICE_API_VERSION_2_0,
47 common.close = EmulatedCamera2::close;
53 mRequestQueueSrc = NULL;
54 mFrameQueueDst = NULL;
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;
64 mStatusPresent = true;
67 /* Destructs EmulatedCamera2 instance. */
68 EmulatedCamera2::~EmulatedCamera2() {
71 /****************************************************************************
73 ***************************************************************************/
75 /****************************************************************************
77 ***************************************************************************/
79 status_t EmulatedCamera2::Initialize() {
83 /****************************************************************************
84 * Camera API implementation
85 ***************************************************************************/
87 status_t EmulatedCamera2::connectCamera(hw_device_t** device) {
92 status_t EmulatedCamera2::closeCamera() {
96 status_t EmulatedCamera2::getCameraInfo(struct camera_info* info) {
97 return EmulatedBaseCamera::getCameraInfo(info);
100 /****************************************************************************
101 * Camera Device API implementation.
102 * These methods are called from the camera API callback routines.
103 ***************************************************************************/
105 /** Request input queue */
107 int EmulatedCamera2::requestQueueNotify() {
108 return INVALID_OPERATION;
111 /** Count of requests in flight */
112 int EmulatedCamera2::getInProgressCount() {
113 return INVALID_OPERATION;
116 /** Cancel all captures in flight */
117 int EmulatedCamera2::flushCapturesInProgress() {
118 return INVALID_OPERATION;
121 /** Construct a default request for a given use case */
122 int EmulatedCamera2::constructDefaultRequest(
123 int request_template,
124 camera_metadata_t **request) {
125 return INVALID_OPERATION;
128 /** Output stream creation and management */
130 int EmulatedCamera2::allocateStream(
134 const camera2_stream_ops_t *stream_ops,
136 uint32_t *format_actual,
138 uint32_t *max_buffers) {
139 return INVALID_OPERATION;
142 int EmulatedCamera2::registerStreamBuffers(
145 buffer_handle_t *buffers) {
146 return INVALID_OPERATION;
150 int EmulatedCamera2::releaseStream(uint32_t stream_id) {
151 return INVALID_OPERATION;
154 /** Reprocessing input stream management */
156 int EmulatedCamera2::allocateReprocessStream(
160 const camera2_stream_in_ops_t *reprocess_stream_ops,
162 uint32_t *consumer_usage,
163 uint32_t *max_buffers) {
164 return INVALID_OPERATION;
167 int EmulatedCamera2::allocateReprocessStreamFromStream(
168 uint32_t output_stream_id,
169 const camera2_stream_in_ops_t *reprocess_stream_ops,
170 uint32_t *stream_id) {
171 return INVALID_OPERATION;
174 int EmulatedCamera2::releaseReprocessStream(uint32_t stream_id) {
175 return INVALID_OPERATION;
180 int EmulatedCamera2::triggerAction(uint32_t trigger_id,
181 int ext1, int ext2) {
182 return INVALID_OPERATION;
185 /** Custom tag query methods */
187 const char* EmulatedCamera2::getVendorSectionName(uint32_t tag) {
191 const char* EmulatedCamera2::getVendorTagName(uint32_t tag) {
195 int EmulatedCamera2::getVendorTagType(uint32_t tag) {
201 int EmulatedCamera2::dump(int fd) {
202 return INVALID_OPERATION;
205 /****************************************************************************
207 ***************************************************************************/
209 /****************************************************************************
210 * Camera API callbacks as defined by camera2_device_ops structure. See
211 * hardware/libhardware/include/hardware/camera2.h for information on each
212 * of these callbacks. Implemented in this class, these callbacks simply
213 * dispatch the call into an instance of EmulatedCamera2 class defined by the
214 * 'camera_device2' parameter, or set a member value in the same.
215 ***************************************************************************/
217 EmulatedCamera2* getInstance(const camera2_device_t *d) {
218 const EmulatedCamera2* cec = static_cast<const EmulatedCamera2*>(d);
219 return const_cast<EmulatedCamera2*>(cec);
222 int EmulatedCamera2::set_request_queue_src_ops(const camera2_device_t *d,
223 const camera2_request_queue_src_ops *queue_src_ops) {
224 EmulatedCamera2* ec = getInstance(d);
225 ec->mRequestQueueSrc = queue_src_ops;
229 int EmulatedCamera2::notify_request_queue_not_empty(const camera2_device_t *d) {
230 EmulatedCamera2* ec = getInstance(d);
231 return ec->requestQueueNotify();
234 int EmulatedCamera2::set_frame_queue_dst_ops(const camera2_device_t *d,
235 const camera2_frame_queue_dst_ops *queue_dst_ops) {
236 EmulatedCamera2* ec = getInstance(d);
237 ec->mFrameQueueDst = queue_dst_ops;
241 int EmulatedCamera2::get_in_progress_count(const camera2_device_t *d) {
242 EmulatedCamera2* ec = getInstance(d);
243 return ec->getInProgressCount();
246 int EmulatedCamera2::flush_captures_in_progress(const camera2_device_t *d) {
247 EmulatedCamera2* ec = getInstance(d);
248 return ec->flushCapturesInProgress();
251 int EmulatedCamera2::construct_default_request(const camera2_device_t *d,
252 int request_template,
253 camera_metadata_t **request) {
254 EmulatedCamera2* ec = getInstance(d);
255 return ec->constructDefaultRequest(request_template, request);
258 int EmulatedCamera2::allocate_stream(const camera2_device_t *d,
262 const camera2_stream_ops_t *stream_ops,
264 uint32_t *format_actual,
266 uint32_t *max_buffers) {
267 EmulatedCamera2* ec = getInstance(d);
268 return ec->allocateStream(width, height, format, stream_ops,
269 stream_id, format_actual, usage, max_buffers);
272 int EmulatedCamera2::register_stream_buffers(const camera2_device_t *d,
275 buffer_handle_t *buffers) {
276 EmulatedCamera2* ec = getInstance(d);
277 return ec->registerStreamBuffers(stream_id,
281 int EmulatedCamera2::release_stream(const camera2_device_t *d,
282 uint32_t stream_id) {
283 EmulatedCamera2* ec = getInstance(d);
284 return ec->releaseStream(stream_id);
287 int EmulatedCamera2::allocate_reprocess_stream(const camera2_device_t *d,
291 const camera2_stream_in_ops_t *reprocess_stream_ops,
293 uint32_t *consumer_usage,
294 uint32_t *max_buffers) {
295 EmulatedCamera2* ec = getInstance(d);
296 return ec->allocateReprocessStream(width, height, format,
297 reprocess_stream_ops, stream_id, consumer_usage, max_buffers);
300 int EmulatedCamera2::allocate_reprocess_stream_from_stream(
301 const camera2_device_t *d,
302 uint32_t output_stream_id,
303 const camera2_stream_in_ops_t *reprocess_stream_ops,
304 uint32_t *stream_id) {
305 EmulatedCamera2* ec = getInstance(d);
306 return ec->allocateReprocessStreamFromStream(output_stream_id,
307 reprocess_stream_ops, stream_id);
311 int EmulatedCamera2::release_reprocess_stream(const camera2_device_t *d,
312 uint32_t stream_id) {
313 EmulatedCamera2* ec = getInstance(d);
314 return ec->releaseReprocessStream(stream_id);
317 int EmulatedCamera2::trigger_action(const camera2_device_t *d,
321 EmulatedCamera2* ec = getInstance(d);
322 return ec->triggerAction(trigger_id, ext1, ext2);
325 int EmulatedCamera2::set_notify_callback(const camera2_device_t *d,
326 camera2_notify_callback notify_cb, void* user) {
327 EmulatedCamera2* ec = getInstance(d);
328 Mutex::Autolock l(ec->mMutex);
329 ec->mNotifyCb = notify_cb;
330 ec->mNotifyUserPtr = user;
334 int EmulatedCamera2::get_metadata_vendor_tag_ops(const camera2_device_t *d,
335 vendor_tag_query_ops_t **ops) {
336 EmulatedCamera2* ec = getInstance(d);
337 *ops = static_cast<vendor_tag_query_ops_t*>(
342 const char* EmulatedCamera2::get_camera_vendor_section_name(
343 const vendor_tag_query_ops_t *v,
345 EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
346 return ec->getVendorSectionName(tag);
349 const char* EmulatedCamera2::get_camera_vendor_tag_name(
350 const vendor_tag_query_ops_t *v,
352 EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
353 return ec->getVendorTagName(tag);
356 int EmulatedCamera2::get_camera_vendor_tag_type(
357 const vendor_tag_query_ops_t *v,
359 EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
360 return ec->getVendorTagType(tag);
363 int EmulatedCamera2::dump(const camera2_device_t *d, int fd) {
364 EmulatedCamera2* ec = getInstance(d);
368 int EmulatedCamera2::close(struct hw_device_t* device) {
369 EmulatedCamera2* ec =
370 static_cast<EmulatedCamera2*>(
371 reinterpret_cast<camera2_device_t*>(device) );
373 ALOGE("%s: Unexpected NULL camera2 device", __FUNCTION__);
376 return ec->closeCamera();
379 void EmulatedCamera2::sendNotification(int32_t msgType,
380 int32_t ext1, int32_t ext2, int32_t ext3) {
381 camera2_notify_callback notifyCb;
383 Mutex::Autolock l(mMutex);
384 notifyCb = mNotifyCb;
386 if (notifyCb != NULL) {
387 notifyCb(msgType, ext1, ext2, ext3, mNotifyUserPtr);
391 camera2_device_ops_t EmulatedCamera2::sDeviceOps = {
392 EmulatedCamera2::set_request_queue_src_ops,
393 EmulatedCamera2::notify_request_queue_not_empty,
394 EmulatedCamera2::set_frame_queue_dst_ops,
395 EmulatedCamera2::get_in_progress_count,
396 EmulatedCamera2::flush_captures_in_progress,
397 EmulatedCamera2::construct_default_request,
398 EmulatedCamera2::allocate_stream,
399 EmulatedCamera2::register_stream_buffers,
400 EmulatedCamera2::release_stream,
401 EmulatedCamera2::allocate_reprocess_stream,
402 EmulatedCamera2::allocate_reprocess_stream_from_stream,
403 EmulatedCamera2::release_reprocess_stream,
404 EmulatedCamera2::trigger_action,
405 EmulatedCamera2::set_notify_callback,
406 EmulatedCamera2::get_metadata_vendor_tag_ops,
407 EmulatedCamera2::dump
410 }; /* namespace android */