• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H
18 #define HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H
19 
20 /*
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.
26  */
27 
28 #include "hardware/camera2.h"
29 #include "system/camera_metadata.h"
30 #include "EmulatedBaseCamera.h"
31 
32 namespace android {
33 
34 /* Encapsulates functionality common to all version 2.0 emulated camera devices
35  *
36  * Note that EmulatedCameraFactory instantiates object of this class just once,
37  * when EmulatedCameraFactory instance gets constructed. Connection to /
38  * disconnection from the actual camera device is handled by calls to
39  * connectDevice(), and closeCamera() methods of this class that are invoked in
40  * response to hw_module_methods_t::open, and camera_device::close callbacks.
41  */
42 class EmulatedCamera2 : public camera2_device, public EmulatedBaseCamera {
43 public:
44     /* Constructs EmulatedCamera2 instance.
45      * Param:
46      *  cameraId - Zero based camera identifier, which is an index of the camera
47      *      instance in camera factory's array.
48      *  module - Emulated camera HAL module descriptor.
49      */
50     EmulatedCamera2(int cameraId,
51             struct hw_module_t* module);
52 
53     /* Destructs EmulatedCamera2 instance. */
54     virtual ~EmulatedCamera2();
55 
56     /****************************************************************************
57      * Abstract API
58      ***************************************************************************/
59 
60 public:
61 
62     /****************************************************************************
63      * Public API
64      ***************************************************************************/
65 
66 public:
67     virtual status_t Initialize();
68 
69     /****************************************************************************
70      * Camera API implementation
71      ***************************************************************************/
72 
73 public:
74     virtual status_t connectCamera(hw_device_t** device);
75 
76     virtual status_t closeCamera();
77 
78     virtual status_t getCameraInfo(struct camera_info* info);
79 
80     /****************************************************************************
81      * Camera API implementation.
82      * These methods are called from the camera API callback routines.
83      ***************************************************************************/
84 
85 protected:
86     /** Request input queue */
87 
88     int setRequestQueueSrcOps(
89         camera2_metadata_queue_src_ops *request_queue_src_ops);
90 
91     int requestQueueNotifyNotEmpty();
92 
93     /** Reprocessing input queue */
94 
95     int setReprocessQueueSrcOps(
96         camera2_metadata_queue_src_ops *reprocess_queue_src_ops);
97 
98     int reprocessQueueNotifyNotEmpty();
99 
100     /** Frame output queue */
101 
102     int setFrameQueueDstOps(camera2_metadata_queue_dst_ops *frame_queue_dst_ops);
103 
104     int frameQueueBufferCount();
105     int frameQueueDequeue(camera_metadata_t **buffer);
106     int frameQueueFree(camera_metadata_t *old_buffer);
107 
108     /** Notifications to application */
109     int setNotifyCallback(camera2_notify_callback notify_cb);
110 
111     /** Count of requests in flight */
112     int getInProgressCount();
113 
114     /** Cancel all captures in flight */
115     int flushCapturesInProgress();
116 
117     /** Reprocessing input stream management */
118     int reprocessStreamDequeueBuffer(buffer_handle_t** buffer,
119             int *stride);
120 
121     int reprocessStreamEnqueueBuffer(buffer_handle_t* buffer);
122 
123     int reprocessStreamCancelBuffer(buffer_handle_t* buffer);
124 
125     int reprocessStreamSetBufferCount(int count);
126 
127     int reprocessStreamSetCrop(int left, int top, int right, int bottom);
128 
129     int reprocessStreamSetTimestamp(int64_t timestamp);
130 
131     int reprocessStreamSetUsage(int usage);
132 
133     int reprocessStreamSetSwapInterval(int interval);
134 
135     int reprocessStreamGetMinUndequeuedBufferCount(int *count);
136 
137     int reprocessStreamLockBuffer(buffer_handle_t *buffer);
138 
139     /** Output stream creation and management */
140 
141     int getStreamSlotCount();
142 
143     int allocateStream(uint32_t stream_slot,
144             uint32_t width,
145             uint32_t height,
146             int format,
147             camera2_stream_ops_t *stream_ops);
148 
149     int releaseStream(uint32_t stream_slot);
150 
151     /** Custom tag definitions */
152     const char* getVendorSectionName(uint32_t tag);
153     const char* getVendorTagName(uint32_t tag);
154     int         getVendorTagType(uint32_t tag);
155 
156     /** Shutdown and debug methods */
157 
158     int release();
159 
160     int dump(int fd);
161 
162     int close();
163 
164     /****************************************************************************
165      * Camera API callbacks as defined by camera2_device_ops structure.  See
166      * hardware/libhardware/include/hardware/camera2.h for information on each
167      * of these callbacks. Implemented in this class, these callbacks simply
168      * dispatch the call into an instance of EmulatedCamera2 class defined in the
169      * 'camera_device2' parameter.
170      ***************************************************************************/
171 
172 private:
173     /** Input request queue */
174     static int set_request_queue_src_ops(camera2_device_t *,
175             camera2_metadata_queue_src_ops *queue_src_ops);
176     static int get_request_queue_dst_ops(camera2_device_t *,
177             camera2_metadata_queue_dst_ops **queue_dst_ops);
178     // for get_request_queue_dst_ops
179     static int request_queue_notify_queue_not_empty(
180         camera2_metadata_queue_dst_ops *);
181 
182     /** Input reprocess queue */
183     static int set_reprocess_queue_src_ops(camera2_device_t *,
184             camera2_metadata_queue_src_ops *reprocess_queue_src_ops);
185     static int get_reprocess_queue_dst_ops(camera2_device_t *,
186             camera2_metadata_queue_dst_ops **queue_dst_ops);
187     // for reprocess_queue_dst_ops
188     static int reprocess_queue_notify_queue_not_empty(
189             camera2_metadata_queue_dst_ops *);
190 
191     /** Output frame queue */
192     static int set_frame_queue_dst_ops(camera2_device_t *,
193             camera2_metadata_queue_dst_ops *queue_dst_ops);
194     static int get_frame_queue_src_ops(camera2_device_t *,
195             camera2_metadata_queue_src_ops **queue_src_ops);
196     // for get_frame_queue_src_ops
197     static int frame_queue_buffer_count(camera2_metadata_queue_src_ops *);
198     static int frame_queue_dequeue(camera2_metadata_queue_src_ops *,
199             camera_metadata_t **buffer);
200     static int frame_queue_free(camera2_metadata_queue_src_ops *,
201             camera_metadata_t *old_buffer);
202 
203     /** Notifications to application */
204     static int set_notify_callback(camera2_device_t *,
205             camera2_notify_callback notify_cb);
206 
207     /** In-progress request management */
208     static int get_in_progress_count(camera2_device_t *);
209 
210     static int flush_captures_in_progress(camera2_device_t *);
211 
212     /** Input reprocessing stream */
213     static int get_reprocess_stream_ops(camera2_device_t *,
214             camera2_stream_ops_t **stream);
215     // for get_reprocess_stream_ops
216     static int reprocess_stream_dequeue_buffer(camera2_stream_ops *,
217             buffer_handle_t** buffer, int *stride);
218     static int reprocess_stream_enqueue_buffer(camera2_stream_ops *,
219             buffer_handle_t* buffer);
220     static int reprocess_stream_cancel_buffer(camera2_stream_ops *,
221             buffer_handle_t* buffer);
222     static int reprocess_stream_set_buffer_count(camera2_stream_ops *,
223             int count);
224     static int reprocess_stream_set_crop(camera2_stream_ops *,
225             int left, int top, int right, int bottom);
226     static int reprocess_stream_set_timestamp(camera2_stream_ops *,
227             int64_t timestamp);
228     static int reprocess_stream_set_usage(camera2_stream_ops *,
229             int usage);
230     static int reprocess_stream_set_swap_interval(camera2_stream_ops *,
231             int interval);
232     static int reprocess_stream_get_min_undequeued_buffer_count(
233             const camera2_stream_ops *,
234             int *count);
235     static int reprocess_stream_lock_buffer(camera2_stream_ops *,
236             buffer_handle_t* buffer);
237 
238     /** Output stream allocation and management */
239 
240     static int get_stream_slot_count(camera2_device_t *);
241 
242     static int allocate_stream(camera2_device_t *,
243             uint32_t stream_slot,
244             uint32_t width,
245             uint32_t height,
246             uint32_t format,
247             camera2_stream_ops_t *stream_ops);
248 
249     static int release_stream(camera2_device_t *,
250             uint32_t stream_slot);
251 
252     static void release(camera2_device_t *);
253 
254     /** Vendor metadata registration */
255 
256     static int get_metadata_vendor_tag_ops(camera2_device_t *,
257             vendor_tag_query_ops_t **ops);
258     // for get_metadata_vendor_tag_ops
259     static const char* get_camera_vendor_section_name(
260             const vendor_tag_query_ops_t *,
261             uint32_t tag);
262     static const char* get_camera_vendor_tag_name(
263             const vendor_tag_query_ops_t *,
264             uint32_t tag);
265     static int get_camera_vendor_tag_type(
266             const vendor_tag_query_ops_t *,
267             uint32_t tag);
268 
269     static int dump(camera2_device_t *, int fd);
270 
271     static int close(struct hw_device_t* device);
272 
273     /****************************************************************************
274      * Data members
275      ***************************************************************************/
276 
277   private:
278     static camera2_device_ops_t sDeviceOps;
279 
280     struct QueueDstOps : public camera2_metadata_queue_dst_ops {
281         EmulatedCamera2 *parent;
282     };
283 
284     struct QueueSrcOps : public camera2_metadata_queue_src_ops {
285         EmulatedCamera2 *parent;
286     };
287 
288     struct StreamOps : public camera2_stream_ops {
289         EmulatedCamera2 *parent;
290     };
291 
292     struct TagOps : public vendor_tag_query_ops {
293         EmulatedCamera2 *parent;
294     };
295 
296     QueueDstOps mRequestQueueDstOps;
297     QueueDstOps mReprocessQueueDstOps;
298     QueueSrcOps mFrameQueueSrcOps;
299     StreamOps   mReprocessStreamOps;
300     TagOps      mVendorTagOps;
301 };
302 
303 }; /* namespace android */
304 
305 #endif  /* HW_EMULATOR_CAMERA_EMULATED_CAMERA2_H */
306