blob: 0764cb176023522ef0abf0f00d9ddbbb911f7930 [file] [log] [blame]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -08001/*
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 ANDROID_INCLUDE_CAMERA2_H
18#define ANDROID_INCLUDE_CAMERA2_H
19
20#include "camera_common.h"
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070021#include "system/camera_metadata.h"
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080022
23/**
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070024 * Camera device HAL 2.0 [ CAMERA_DEVICE_API_VERSION_2_0 ]
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080025 *
26 * EXPERIMENTAL.
27 *
28 * Supports both the android.hardware.ProCamera and
29 * android.hardware.Camera APIs.
30 *
31 * Camera devices that support this version of the HAL must return
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070032 * CAMERA_DEVICE_API_VERSION_2_0 in camera_device_t.common.version and in
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080033 * camera_info_t.device_version (from camera_module_t.get_camera_info).
34 *
35 * Camera modules that may contain version 2.0 devices must implement at least
36 * version 2.0 of the camera module interface (as defined by
37 * camera_module_t.common.module_api_version).
38 *
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070039 * See camera_common.h for more versioning details.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080040 *
41 */
42
43__BEGIN_DECLS
44
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -070045struct camera2_device;
46
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070047/**********************************************************************
48 *
49 * Input/output stream buffer queue interface definitions
50 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080051 */
52
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070053/**
54 * Output image stream queue interface. A set of these methods is provided to
55 * the HAL device in allocate_stream(), and are used to interact with the
56 * gralloc buffer queue for that stream. They may not be called until after
57 * allocate_stream returns.
58 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080059typedef struct camera2_stream_ops {
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070060 /**
61 * Get a buffer to fill from the queue. The size and format of the buffer
62 * are fixed for a given stream (defined in allocate_stream), and the stride
63 * should be queried from the platform gralloc module. The gralloc buffer
64 * will have been allocated based on the usage flags provided by
65 * allocate_stream, and will be locked for use.
66 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080067 int (*dequeue_buffer)(struct camera2_stream_ops* w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070068 buffer_handle_t** buffer);
69
70 /**
71 * Push a filled buffer to the stream to be used by the consumer.
72 *
73 * The timestamp represents the time at start of exposure of the first row
74 * of the image; it must be from a monotonic clock, and is measured in
75 * nanoseconds. The timestamps do not need to be comparable between
76 * different cameras, or consecutive instances of the same camera. However,
77 * they must be comparable between streams from the same camera. If one
78 * capture produces buffers for multiple streams, each stream must have the
79 * same timestamp for that buffer, and that timestamp must match the
80 * timestamp in the output frame metadata.
81 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080082 int (*enqueue_buffer)(struct camera2_stream_ops* w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070083 int64_t timestamp,
84 buffer_handle_t* buffer);
85 /**
86 * Return a buffer to the queue without marking it as filled.
87 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080088 int (*cancel_buffer)(struct camera2_stream_ops* w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070089 buffer_handle_t* buffer);
90 /**
91 * Set the crop window for subsequently enqueued buffers. The parameters are
92 * measured in pixels relative to the buffer width and height.
93 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080094 int (*set_crop)(struct camera2_stream_ops *w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070095 int left, int top, int right, int bottom);
96
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080097} camera2_stream_ops_t;
98
99/**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700100 * Special pixel format value used to indicate that the framework does not care
101 * what exact pixel format is to be used for an output stream. The device HAL is
102 * free to select any pixel format, platform-specific and otherwise, and this
103 * opaque value will be passed on to the platform gralloc module when buffers
104 * need to be allocated for the stream.
105 */
106enum {
107 CAMERA2_HAL_PIXEL_FORMAT_OPAQUE = -1
108};
109
110/**
111 * Input reprocess stream queue management. A set of these methods is provided
112 * to the HAL device in allocate_reprocess_stream(); they are used to interact with the
113 * reprocess stream's input gralloc buffer queue.
114 */
115typedef struct camera2_stream_in_ops {
116 /**
117 * Get the next buffer of image data to reprocess. The width, height, and
118 * format of the buffer is fixed in allocate_reprocess_stream(), and the
119 * stride and other details should be queried from the platform gralloc
120 * module as needed. The buffer will already be locked for use.
121 */
122 int (*acquire_buffer)(struct camera2_stream_in_ops *w,
123 buffer_handle_t** buffer);
124 /**
125 * Return a used buffer to the buffer queue for reuse.
126 */
127 int (*release_buffer)(struct camera2_stream_in_ops *w,
128 buffer_handle_t* buffer);
129
130} camera2_stream_in_ops_t;
131
132/**********************************************************************
133 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800134 * Metadata queue management, used for requests sent to HAL module, and for
135 * frames produced by the HAL.
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700136 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800137 */
138
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700139enum {
140 CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS = -1
141};
142
143/**
144 * Request input queue protocol:
145 *
146 * The framework holds the queue and its contents. At start, the queue is empty.
147 *
148 * 1. When the first metadata buffer is placed into the queue, the framework
149 * signals the device by calling notify_request_queue_not_empty().
150 *
151 * 2. After receiving notify_request_queue_not_empty, the device must call
152 * dequeue() once it's ready to handle the next buffer.
153 *
154 * 3. Once the device has processed a buffer, and is ready for the next buffer,
155 * it must call dequeue() again instead of waiting for a notification. If
156 * there are no more buffers available, dequeue() will return NULL. After
157 * this point, when a buffer becomes available, the framework must call
158 * notify_request_queue_not_empty() again. If the device receives a NULL
159 * return from dequeue, it does not need to query the queue again until a
160 * notify_request_queue_not_empty() call is received from the source.
161 *
162 * 4. If the device calls buffer_count() and receives 0, this does not mean that
163 * the framework will provide a notify_request_queue_not_empty() call. The
164 * framework will only provide such a notification after the device has
165 * received a NULL from dequeue, or on initial startup.
166 *
167 * 5. The dequeue() call in response to notify_request_queue_not_empty() may be
168 * on the same thread as the notify_request_queue_not_empty() call, and may
169 * be performed from within the notify call.
170 *
171 * 6. All dequeued request buffers must be returned to the framework by calling
172 * free_request, including when errors occur, a device flush is requested, or
173 * when the device is shutting down.
174 */
175typedef struct camera2_request_queue_src_ops {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800176 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700177 * Get the count of request buffers pending in the queue. May return
178 * CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS if a repeating request (stream
179 * request) is currently configured. Calling this method has no effect on
180 * whether the notify_request_queue_not_empty() method will be called by the
181 * framework.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800182 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700183 int (*request_count)(struct camera2_request_queue_src_ops *q);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800184
185 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700186 * Get a metadata buffer from the framework. Returns OK if there is no
187 * error. If the queue is empty, returns NULL in buffer. In that case, the
188 * device must wait for a notify_request_queue_not_empty() message before
189 * attempting to dequeue again. Buffers obtained in this way must be
190 * returned to the framework with free_request().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800191 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700192 int (*dequeue_request)(struct camera2_request_queue_src_ops *q,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800193 camera_metadata_t **buffer);
194 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700195 * Return a metadata buffer to the framework once it has been used, or if
196 * an error or shutdown occurs.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800197 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700198 int (*free_request)(struct camera2_request_queue_src_ops *q,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800199 camera_metadata_t *old_buffer);
200
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700201} camera2_request_queue_src_ops_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800202
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700203/**
204 * Frame output queue protocol:
205 *
206 * The framework holds the queue and its contents. At start, the queue is empty.
207 *
208 * 1. When the device is ready to fill an output metadata frame, it must dequeue
209 * a metadata buffer of the required size.
210 *
211 * 2. It should then fill the metadata buffer, and place it on the frame queue
212 * using enqueue_frame. The framework takes ownership of the frame.
213 *
214 * 3. In case of an error, a request to flush the pipeline, or shutdown, the
215 * device must return any affected dequeued frames to the framework by
216 * calling cancel_frame.
217 */
218typedef struct camera2_frame_queue_dst_ops {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800219 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700220 * Get an empty metadata buffer to fill from the framework. The new metadata
221 * buffer will have room for entries number of metadata entries, plus
222 * data_bytes worth of extra storage. Frames dequeued here must be returned
223 * to the framework with either cancel_frame or enqueue_frame.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800224 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700225 int (*dequeue_frame)(struct camera2_frame_queue_dst_ops *q,
226 size_t entries, size_t data_bytes,
227 camera_metadata_t **buffer);
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700228
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700229 /**
230 * Return a dequeued metadata buffer to the framework for reuse; do not mark it as
231 * filled. Use when encountering errors, or flushing the internal request queue.
232 */
233 int (*cancel_frame)(struct camera2_frame_queue_dst_ops *q,
234 camera_metadata_t *buffer);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800235
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700236 /**
237 * Place a completed metadata frame on the frame output queue.
238 */
239 int (*enqueue_frame)(struct camera2_frame_queue_dst_ops *q,
240 camera_metadata_t *buffer);
241
242} camera2_frame_queue_dst_ops_t;
243
244/**********************************************************************
245 *
246 * Notification callback and message definition, and trigger definitions
247 *
248 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800249
250/**
251 * Asynchronous notification callback from the HAL, fired for various
252 * reasons. Only for information independent of frame capture, or that require
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700253 * specific timing. The user pointer must be the same one that was passed to the
254 * device in set_notify_callback().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800255 */
256typedef void (*camera2_notify_callback)(int32_t msg_type,
257 int32_t ext1,
258 int32_t ext2,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700259 int32_t ext3,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800260 void *user);
261
262/**
263 * Possible message types for camera2_notify_callback
264 */
265enum {
266 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700267 * An error has occurred. Argument ext1 contains the error code, and
268 * ext2 and ext3 contain any error-specific information.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800269 */
Eino-Ville Talvaladaacbf42012-03-22 13:09:56 -0700270 CAMERA2_MSG_ERROR = 0x0001,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800271 /**
272 * The exposure of a given request has begun. Argument ext1 contains the
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700273 * frame number, and ext2 and ext3 contain the low-order and high-order
274 * bytes of the timestamp for when exposure began.
275 * (timestamp = (ext3 << 32 | ext2))
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800276 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700277 CAMERA2_MSG_SHUTTER = 0x0010,
278 /**
279 * The autofocus routine has changed state. Argument ext1 contains the new
280 * state; the values are the same as those for the metadata field
281 * android.control.afState. Ext2 contains the latest value passed to
282 * trigger_action(CAMERA2_TRIGGER_AUTOFOCUS), or 0 if that method has not
283 * been called.
284 */
285 CAMERA2_MSG_AUTOFOCUS = 0x0020,
286 /**
287 * The autoexposure routine has changed state. Argument ext1 contains the
288 * new state; the values are the same as those for the metadata field
289 * android.control.aeState. Ext2 containst the latest value passed to
290 * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
291 * has not been called.
292 */
293 CAMERA2_MSG_AUTOEXPOSURE = 0x0021,
294 /**
295 * The auto-whitebalance routine has changed state. Argument ext1 contains
296 * the new state; the values are the same as those for the metadata field
297 * android.control.awbState.
298 */
299 CAMERA2_MSG_AUTOWB = 0x0022
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800300};
301
302/**
303 * Error codes for CAMERA_MSG_ERROR
304 */
305enum {
306 /**
307 * A serious failure occured. Camera device may not work without reboot, and
308 * no further frames or buffer streams will be produced by the
309 * device. Device should be treated as closed.
310 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700311 CAMERA2_MSG_ERROR_HARDWARE = 0x0001,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800312 /**
313 * A serious failure occured. No further frames or buffer streams will be
314 * produced by the device. Device should be treated as closed. The client
315 * must reopen the device to use it again.
316 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700317 CAMERA2_MSG_ERROR_DEVICE,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800318 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700319 * An error has occurred in processing a request. No output (metadata or
320 * buffers) will be produced for this request. ext2 contains the frame
321 * number of the request. Subsequent requests are unaffected, and the device
322 * remains operational.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800323 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700324 CAMERA2_MSG_ERROR_REQUEST,
325 /**
326 * An error has occurred in producing an output frame metadata buffer for a
327 * request, but image buffers for it will still be available. Subsequent
328 * requests are unaffected, and the device remains operational. ext2
329 * contains the frame number of the request.
330 */
331 CAMERA2_MSG_ERROR_FRAME,
332 /**
333 * An error has occurred in placing an output buffer into a stream for a
334 * request. The frame metadata and other buffers may still be
335 * available. Subsequent requests are unaffected, and the device remains
336 * operational. ext2 contains the frame number of the request, and ext3
337 * contains the stream id.
338 */
339 CAMERA2_MSG_ERROR_STREAM,
340 /**
341 * Number of error types
342 */
343 CAMERA2_MSG_NUM_ERRORS
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800344};
345
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700346/**
347 * Possible trigger ids for trigger_action()
348 */
349enum {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800350 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700351 * Trigger an autofocus cycle. The effect of the trigger depends on the
352 * autofocus mode in effect when the trigger is received, which is the mode
353 * listed in the latest capture request to be dequeued. If the mode is off,
354 * the trigger has no effect. If autofocus is already scanning, the trigger
355 * has no effect. In AUTO, MACRO, or CONTINUOUS_* modes, the trigger
356 * otherwise begins an appropriate scan of the scene for focus. The state of
357 * the autofocus cycle can be tracked in android.control.afMode and the
358 * corresponding notification. Ext1 is an id that must be returned in
359 * subsequent auto-focus state change notifications.
360 */
361 CAMERA2_TRIGGER_AUTOFOCUS = 0x0001,
362 /**
363 * Trigger a pre-capture metering cycle, which may include firing the flash
364 * to determine proper capture parameters. Typically, this trigger would be
365 * fired for a half-depress of a camera shutter key, or before a snapshot
366 * capture in general. The state of the metering cycle can be tracked in
367 * android.control.aeMode and the corresponding notification. If the
368 * auto-exposure mode is OFF, the trigger does nothing. Ext1 is an id that
369 * must be returned in subsequent auto-exposure state change notifications.
370 */
371 CAMERA2_TRIGGER_PRECAPTURE_METERING
372};
373
374/**
375 * Possible template types for construct_default_request()
376 */
377enum {
378 /**
379 * Standard camera preview operation with 3A on auto.
380 */
381 CAMERA2_TEMPLATE_PREVIEW = 1,
382 /**
383 * Standard camera high-quality still capture with 3A and flash on auto.
384 */
385 CAMERA2_TEMPLATE_STILL_CAPTURE,
386 /**
387 * Standard video recording plus preview with 3A on auto, torch off.
388 */
389 CAMERA2_TEMPLATE_VIDEO_RECORD,
390 /**
391 * High-quality still capture while recording video. Application will
392 * include preview, video record, and full-resolution YUV or JPEG streams in
393 * request. Must not cause stuttering on video stream. 3A on auto.
394 */
395 CAMERA2_TEMPLATE_VIDEO_SNAPSHOT,
396 /**
397 * Zero-shutter-lag mode. Application will request preview and
398 * full-resolution YUV data for each frame, and reprocess it to JPEG when a
399 * still image is requested by user. Settings should provide highest-quality
400 * full-resolution images without compromising preview frame rate. 3A on
401 * auto.
402 */
Eino-Ville Talvala6adfd6b2012-05-14 15:25:27 -0700403 CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG,
404
405 /* Total number of templates */
406 CAMERA2_TEMPLATE_COUNT
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700407};
408
409
410/**********************************************************************
411 *
412 * Camera device operations
413 *
414 */
415typedef struct camera2_device_ops {
416
417 /**********************************************************************
418 * Request and frame queue setup and management methods
419 */
420
421 /**
422 * Pass in input request queue interface methods.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800423 */
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700424 int (*set_request_queue_src_ops)(struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700425 camera2_request_queue_src_ops_t *request_src_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800426
427 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700428 * Notify device that the request queue is no longer empty. Must only be
429 * called when the first buffer is added a new queue, or after the source
430 * has returned NULL in response to a dequeue call.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800431 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700432 int (*notify_request_queue_not_empty)(struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800433
434 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700435 * Pass in output frame queue interface methods
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800436 */
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700437 int (*set_frame_queue_dst_ops)(struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700438 camera2_frame_queue_dst_ops_t *frame_dst_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800439
440 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700441 * Number of camera requests being processed by the device at the moment
442 * (captures/reprocesses that have had their request dequeued, but have not
443 * yet been enqueued onto output pipeline(s) ). No streams may be released
444 * by the framework until the in-progress count is 0.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800445 */
446 int (*get_in_progress_count)(struct camera2_device *);
447
448 /**
449 * Flush all in-progress captures. This includes all dequeued requests
450 * (regular or reprocessing) that have not yet placed any outputs into a
451 * stream or the frame queue. Partially completed captures must be completed
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700452 * normally. No new requests may be dequeued from the request queue until
453 * the flush completes.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800454 */
455 int (*flush_captures_in_progress)(struct camera2_device *);
456
457 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700458 * Create a filled-in default request for standard camera use cases.
459 *
460 * The device must return a complete request that is configured to meet the
461 * requested use case, which must be one of the CAMERA2_TEMPLATE_*
462 * enums. All request control fields must be included, except for
463 * android.request.outputStreams and android.request.frameNumber.
464 *
465 * The metadata buffer returned must be allocated with
466 * allocate_camera_metadata. The framework takes ownership of the buffer.
467 */
468 int (*construct_default_request)(struct camera2_device *,
469 int request_template,
470 camera_metadata_t **request);
471
472 /**********************************************************************
473 * Stream management
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800474 */
475
476 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700477 * allocate_stream:
478 *
479 * Allocate a new output stream for use, defined by the output buffer width,
480 * height, target, and possibly the pixel format. Returns the new stream's
481 * ID, gralloc usage flags, minimum queue buffer count, and possibly the
482 * pixel format, on success. Error conditions:
483 *
484 * - Requesting a width/height/format combination not listed as
485 * supported by the sensor's static characteristics
486 *
487 * - Asking for too many streams of a given format type (2 bayer raw
488 * streams, for example).
489 *
490 * Input parameters:
491 *
492 * - width, height, format: Specification for the buffers to be sent through
493 * this stream. Format is a value from the HAL_PIXEL_FORMAT_* list, or
494 * CAMERA2_HAL_PIXEL_FORMAT_OPAQUE. In the latter case, the camera device
495 * must select an appropriate (possible platform-specific) HAL pixel
496 * format to return in format_actual. In the former case, format_actual
497 * must be set to match format.
498 *
499 * - stream_ops: A structure of function pointers for obtaining and queuing
500 * up buffers for this stream. The underlying stream will be configured
501 * based on the usage and max_buffers outputs. The methods in this
502 * structure may not be called until after allocate_stream returns.
503 *
504 * Output parameters:
505 *
506 * - stream_id: An unsigned integer identifying this stream. This value is
507 * used in incoming requests to identify the stream, and in releasing the
508 * stream.
509 *
510 * - format_actual: If the input format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE,
511 * then device must select the appropriate (possible platform-specific)
512 * pixel format and return it in *format_actual. It will be treated as an
513 * opaque value by the framework, and simply passed to the gralloc module
514 * when new buffers need to be allocated. If the input format is one of
515 * the values from HAL_PIXEL_FORMAT_* list, then *format_actual must be
516 * set equal to format. In the latter case, format_actual may also be
517 * NULL, in which case it can be ignored as an output.
518 *
519 * - usage: The gralloc usage mask needed by the HAL device for producing
520 * the requested type of data. This is used in allocating new gralloc
521 * buffers for the stream buffer queue.
522 *
523 * - max_buffers: The maximum number of buffers the HAL device may need to
524 * have dequeued at the same time. The device may not dequeue more buffers
525 * than this value at the same time.
526 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800527 */
528 int (*allocate_stream)(
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700529 struct camera2_device *,
530 // inputs
531 uint32_t width,
532 uint32_t height,
533 int format,
534 camera2_stream_ops_t *stream_ops,
535 // outputs
536 uint32_t *stream_id,
537 uint32_t *format_actual,
538 uint32_t *usage,
539 uint32_t *max_buffers);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800540
541 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700542 * Register buffers for a given stream. This is called after a successful
543 * allocate_stream call, and before the first request referencing the stream
544 * is enqueued. This method is intended to allow the HAL device to map or
545 * otherwise prepare the buffers for later use. num_buffers is guaranteed to
546 * be at least max_buffers (from allocate_stream), but may be larger. The
547 * buffers will already be locked for use. At the end of the call, all the
548 * buffers must be ready to be returned to the queue.
549 */
550 int (*register_stream_buffers)(
551 struct camera2_device *,
552 uint32_t stream_id,
553 int num_buffers,
554 buffer_handle_t *buffers);
555
556 /**
557 * Release a stream. Returns an error if called when get_in_progress_count
558 * is non-zero, or if the stream id is invalid.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800559 */
560 int (*release_stream)(
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700561 struct camera2_device *,
562 uint32_t stream_id);
563
564 /**
565 * allocate_reprocess_stream:
566 *
567 * Allocate a new input stream for use, defined by the output buffer width,
568 * height, and the pixel format. Returns the new stream's ID, gralloc usage
569 * flags, and required simultaneously acquirable buffer count, on
570 * success. Error conditions:
571 *
572 * - Requesting a width/height/format combination not listed as
573 * supported by the sensor's static characteristics
574 *
575 * - Asking for too many reprocessing streams to be configured at once.
576 *
577 * Input parameters:
578 *
579 * - width, height, format: Specification for the buffers to be sent through
580 * this stream. Format must be a value from the HAL_PIXEL_FORMAT_* list.
581 *
582 * - reprocess_stream_ops: A structure of function pointers for acquiring
583 * and releasing buffers for this stream. The underlying stream will be
584 * configured based on the usage and max_buffers outputs.
585 *
586 * Output parameters:
587 *
588 * - stream_id: An unsigned integer identifying this stream. This value is
589 * used in incoming requests to identify the stream, and in releasing the
590 * stream. These ids are numbered separately from the input stream ids.
591 *
592 * - consumer_usage: The gralloc usage mask needed by the HAL device for
593 * consuming the requested type of data. This is used in allocating new
594 * gralloc buffers for the stream buffer queue.
595 *
596 * - max_buffers: The maximum number of buffers the HAL device may need to
597 * have acquired at the same time. The device may not have more buffers
598 * acquired at the same time than this value.
599 *
600 */
601 int (*allocate_reprocess_stream)(struct camera2_device *,
602 uint32_t width,
603 uint32_t height,
604 uint32_t format,
605 camera2_stream_in_ops_t *reprocess_stream_ops,
606 // outputs
607 uint32_t *stream_id,
608 uint32_t *consumer_usage,
609 uint32_t *max_buffers);
610
611 /**
612 * Release a reprocessing stream. Returns an error if called when
613 * get_in_progress_count is non-zero, or if the stream id is not
614 * valid.
615 */
616 int (*release_reprocess_stream)(
617 struct camera2_device *,
618 uint32_t stream_id);
619
620 /**********************************************************************
621 * Miscellaneous methods
622 */
623
624 /**
625 * Trigger asynchronous activity. This is used for triggering special
626 * behaviors of the camera 3A routines when they are in use. See the
627 * documentation for CAMERA2_TRIGGER_* above for details of the trigger ids
628 * and their arguments.
629 */
630 int (*trigger_action)(struct camera2_device *,
631 uint32_t trigger_id,
632 int ext1,
633 int ext2);
634
635 /**
636 * Notification callback setup
637 */
638 int (*set_notify_callback)(struct camera2_device *,
639 camera2_notify_callback notify_cb,
640 void *user);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800641
642 /**
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700643 * Get methods to query for vendor extension metadata tag infomation. May
644 * set ops to NULL if no vendor extension tags are defined.
645 */
646 int (*get_metadata_vendor_tag_ops)(struct camera2_device*,
647 vendor_tag_query_ops_t **ops);
648
649 /**
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800650 * Dump state of the camera hardware
651 */
652 int (*dump)(struct camera2_device *, int fd);
653
654} camera2_device_ops_t;
655
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700656/**********************************************************************
657 *
658 * Camera device definition
659 *
660 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800661typedef struct camera2_device {
662 /**
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700663 * common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800664 * this device as implementing version 2.0 of the camera device HAL.
665 */
666 hw_device_t common;
667 camera2_device_ops_t *ops;
668 void *priv;
669} camera2_device_t;
670
671__END_DECLS
672
673#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */