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.
17 #ifndef HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H
18 #define HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H
21 * Contains declaration of a class EmulatedCamera that encapsulates
22 * functionality common to all version 2.0 emulated camera devices. Instances
23 * of this class (for each emulated camera) are created during the construction
24 * of the EmulatedCameraFactory instance. This class serves as an entry point
25 * for all camera API calls that defined by camera2_device_ops_t API.
28 #include "hardware/camera2.h"
29 #include "system/camera_metadata.h"
30 #include "EmulatedBaseCamera.h"
31 #include <utils/Thread.h>
32 #include <utils/Mutex.h>
36 /* Encapsulates functionality common to all version 2.0 emulated camera devices
38 * Note that EmulatedCameraFactory instantiates object of this class just once,
39 * when EmulatedCameraFactory instance gets constructed. Connection to /
40 * disconnection from the actual camera device is handled by calls to
41 * connectDevice(), and closeCamera() methods of this class that are invoked in
42 * response to hw_module_methods_t::open, and camera_device::close callbacks.
44 class EmulatedCamera2 : public camera2_device, public EmulatedBaseCamera {
46 /* Constructs EmulatedCamera2 instance.
48 * cameraId - Zero based camera identifier, which is an index of the camera
49 * instance in camera factory's array.
50 * module - Emulated camera HAL module descriptor.
52 EmulatedCamera2(int cameraId,
53 struct hw_module_t* module);
55 /* Destructs EmulatedCamera2 instance. */
56 virtual ~EmulatedCamera2();
58 /****************************************************************************
60 ***************************************************************************/
64 /****************************************************************************
66 ***************************************************************************/
69 virtual status_t Initialize();
71 /****************************************************************************
72 * Camera module API and generic hardware device API implementation
73 ***************************************************************************/
76 virtual status_t connectCamera(hw_device_t** device);
78 virtual status_t closeCamera();
80 virtual status_t getCameraInfo(struct camera_info* info) = 0;
82 /****************************************************************************
83 * Camera API implementation.
84 * These methods are called from the camera API callback routines.
85 ***************************************************************************/
88 /** Request input queue notification */
89 virtual int requestQueueNotify();
91 /** Count of requests in flight */
92 virtual int getInProgressCount();
94 /** Cancel all captures in flight */
95 virtual int flushCapturesInProgress();
97 virtual int constructDefaultRequest(
99 camera_metadata_t **request);
101 /** Output stream creation and management */
102 virtual int allocateStream(
106 const camera2_stream_ops_t *stream_ops,
108 uint32_t *format_actual,
110 uint32_t *max_buffers);
112 virtual int registerStreamBuffers(
115 buffer_handle_t *buffers);
117 virtual int releaseStream(uint32_t stream_id);
119 /** Input stream creation and management */
120 virtual int allocateReprocessStream(
124 const camera2_stream_in_ops_t *reprocess_stream_ops,
126 uint32_t *consumer_usage,
127 uint32_t *max_buffers);
129 virtual int allocateReprocessStreamFromStream(
130 uint32_t output_stream_id,
131 const camera2_stream_in_ops_t *reprocess_stream_ops,
132 uint32_t *stream_id);
134 virtual int releaseReprocessStream(uint32_t stream_id);
136 /** 3A action triggering */
137 virtual int triggerAction(uint32_t trigger_id,
138 int32_t ext1, int32_t ext2);
140 /** Custom tag definitions */
141 virtual const char* getVendorSectionName(uint32_t tag);
142 virtual const char* getVendorTagName(uint32_t tag);
143 virtual int getVendorTagType(uint32_t tag);
147 virtual int dump(int fd);
149 /****************************************************************************
150 * Camera API callbacks as defined by camera2_device_ops structure. See
151 * hardware/libhardware/include/hardware/camera2.h for information on each
152 * of these callbacks. Implemented in this class, these callbacks simply
153 * dispatch the call into an instance of EmulatedCamera2 class defined in
154 * the 'camera_device2' parameter.
155 ***************************************************************************/
158 /** Input request queue */
159 static int set_request_queue_src_ops(const camera2_device_t *,
160 const camera2_request_queue_src_ops *queue_src_ops);
161 static int notify_request_queue_not_empty(const camera2_device_t *);
163 /** Output frame queue */
164 static int set_frame_queue_dst_ops(const camera2_device_t *,
165 const camera2_frame_queue_dst_ops *queue_dst_ops);
167 /** In-progress request management */
168 static int get_in_progress_count(const camera2_device_t *);
170 static int flush_captures_in_progress(const camera2_device_t *);
172 /** Request template creation */
173 static int construct_default_request(const camera2_device_t *,
174 int request_template,
175 camera_metadata_t **request);
177 /** Stream management */
178 static int allocate_stream(const camera2_device_t *,
182 const camera2_stream_ops_t *stream_ops,
184 uint32_t *format_actual,
186 uint32_t *max_buffers);
188 static int register_stream_buffers(const camera2_device_t *,
191 buffer_handle_t *buffers);
193 static int release_stream(const camera2_device_t *,
196 static int allocate_reprocess_stream(const camera2_device_t *,
200 const camera2_stream_in_ops_t *reprocess_stream_ops,
202 uint32_t *consumer_usage,
203 uint32_t *max_buffers);
205 static int allocate_reprocess_stream_from_stream(const camera2_device_t *,
206 uint32_t output_stream_id,
207 const camera2_stream_in_ops_t *reprocess_stream_ops,
208 uint32_t *stream_id);
210 static int release_reprocess_stream(const camera2_device_t *,
214 static int trigger_action(const camera2_device_t *,
219 /** Notifications to application */
220 static int set_notify_callback(const camera2_device_t *,
221 camera2_notify_callback notify_cb,
224 /** Vendor metadata registration */
225 static int get_metadata_vendor_tag_ops(const camera2_device_t *,
226 vendor_tag_query_ops_t **ops);
227 // for get_metadata_vendor_tag_ops
228 static const char* get_camera_vendor_section_name(
229 const vendor_tag_query_ops_t *,
231 static const char* get_camera_vendor_tag_name(
232 const vendor_tag_query_ops_t *,
234 static int get_camera_vendor_tag_type(
235 const vendor_tag_query_ops_t *,
238 static int dump(const camera2_device_t *, int fd);
240 /** For hw_device_t ops */
241 static int close(struct hw_device_t* device);
243 /****************************************************************************
244 * Data members shared with implementations
245 ***************************************************************************/
247 /** Mutex for calls through camera2 device interface */
252 const camera2_request_queue_src_ops *mRequestQueueSrc;
253 const camera2_frame_queue_dst_ops *mFrameQueueDst;
255 struct TagOps : public vendor_tag_query_ops {
256 EmulatedCamera2 *parent;
258 TagOps mVendorTagOps;
260 void sendNotification(int32_t msgType,
261 int32_t ext1, int32_t ext2, int32_t ext3);
263 /****************************************************************************
265 ***************************************************************************/
267 static camera2_device_ops_t sDeviceOps;
268 camera2_notify_callback mNotifyCb;
269 void* mNotifyUserPtr;
272 }; /* namespace android */
274 #endif /* HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H */