blob: 7f06c52779091113d39d5c779672d91f5b4dbc96 [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 */
403 CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG
404};
405
406
407/**********************************************************************
408 *
409 * Camera device operations
410 *
411 */
412typedef struct camera2_device_ops {
413
414 /**********************************************************************
415 * Request and frame queue setup and management methods
416 */
417
418 /**
419 * Pass in input request queue interface methods.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800420 */
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700421 int (*set_request_queue_src_ops)(struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700422 camera2_request_queue_src_ops_t *request_src_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800423
424 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700425 * Notify device that the request queue is no longer empty. Must only be
426 * called when the first buffer is added a new queue, or after the source
427 * has returned NULL in response to a dequeue call.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800428 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700429 int (*notify_request_queue_not_empty)(struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800430
431 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700432 * Pass in output frame queue interface methods
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800433 */
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700434 int (*set_frame_queue_dst_ops)(struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700435 camera2_frame_queue_dst_ops_t *frame_dst_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800436
437 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700438 * Number of camera requests being processed by the device at the moment
439 * (captures/reprocesses that have had their request dequeued, but have not
440 * yet been enqueued onto output pipeline(s) ). No streams may be released
441 * by the framework until the in-progress count is 0.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800442 */
443 int (*get_in_progress_count)(struct camera2_device *);
444
445 /**
446 * Flush all in-progress captures. This includes all dequeued requests
447 * (regular or reprocessing) that have not yet placed any outputs into a
448 * stream or the frame queue. Partially completed captures must be completed
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700449 * normally. No new requests may be dequeued from the request queue until
450 * the flush completes.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800451 */
452 int (*flush_captures_in_progress)(struct camera2_device *);
453
454 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700455 * Create a filled-in default request for standard camera use cases.
456 *
457 * The device must return a complete request that is configured to meet the
458 * requested use case, which must be one of the CAMERA2_TEMPLATE_*
459 * enums. All request control fields must be included, except for
460 * android.request.outputStreams and android.request.frameNumber.
461 *
462 * The metadata buffer returned must be allocated with
463 * allocate_camera_metadata. The framework takes ownership of the buffer.
464 */
465 int (*construct_default_request)(struct camera2_device *,
466 int request_template,
467 camera_metadata_t **request);
468
469 /**********************************************************************
470 * Stream management
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800471 */
472
473 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700474 * allocate_stream:
475 *
476 * Allocate a new output stream for use, defined by the output buffer width,
477 * height, target, and possibly the pixel format. Returns the new stream's
478 * ID, gralloc usage flags, minimum queue buffer count, and possibly the
479 * pixel format, on success. Error conditions:
480 *
481 * - Requesting a width/height/format combination not listed as
482 * supported by the sensor's static characteristics
483 *
484 * - Asking for too many streams of a given format type (2 bayer raw
485 * streams, for example).
486 *
487 * Input parameters:
488 *
489 * - width, height, format: Specification for the buffers to be sent through
490 * this stream. Format is a value from the HAL_PIXEL_FORMAT_* list, or
491 * CAMERA2_HAL_PIXEL_FORMAT_OPAQUE. In the latter case, the camera device
492 * must select an appropriate (possible platform-specific) HAL pixel
493 * format to return in format_actual. In the former case, format_actual
494 * must be set to match format.
495 *
496 * - stream_ops: A structure of function pointers for obtaining and queuing
497 * up buffers for this stream. The underlying stream will be configured
498 * based on the usage and max_buffers outputs. The methods in this
499 * structure may not be called until after allocate_stream returns.
500 *
501 * Output parameters:
502 *
503 * - stream_id: An unsigned integer identifying this stream. This value is
504 * used in incoming requests to identify the stream, and in releasing the
505 * stream.
506 *
507 * - format_actual: If the input format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE,
508 * then device must select the appropriate (possible platform-specific)
509 * pixel format and return it in *format_actual. It will be treated as an
510 * opaque value by the framework, and simply passed to the gralloc module
511 * when new buffers need to be allocated. If the input format is one of
512 * the values from HAL_PIXEL_FORMAT_* list, then *format_actual must be
513 * set equal to format. In the latter case, format_actual may also be
514 * NULL, in which case it can be ignored as an output.
515 *
516 * - usage: The gralloc usage mask needed by the HAL device for producing
517 * the requested type of data. This is used in allocating new gralloc
518 * buffers for the stream buffer queue.
519 *
520 * - max_buffers: The maximum number of buffers the HAL device may need to
521 * have dequeued at the same time. The device may not dequeue more buffers
522 * than this value at the same time.
523 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800524 */
525 int (*allocate_stream)(
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700526 struct camera2_device *,
527 // inputs
528 uint32_t width,
529 uint32_t height,
530 int format,
531 camera2_stream_ops_t *stream_ops,
532 // outputs
533 uint32_t *stream_id,
534 uint32_t *format_actual,
535 uint32_t *usage,
536 uint32_t *max_buffers);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800537
538 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700539 * Register buffers for a given stream. This is called after a successful
540 * allocate_stream call, and before the first request referencing the stream
541 * is enqueued. This method is intended to allow the HAL device to map or
542 * otherwise prepare the buffers for later use. num_buffers is guaranteed to
543 * be at least max_buffers (from allocate_stream), but may be larger. The
544 * buffers will already be locked for use. At the end of the call, all the
545 * buffers must be ready to be returned to the queue.
546 */
547 int (*register_stream_buffers)(
548 struct camera2_device *,
549 uint32_t stream_id,
550 int num_buffers,
551 buffer_handle_t *buffers);
552
553 /**
554 * Release a stream. Returns an error if called when get_in_progress_count
555 * is non-zero, or if the stream id is invalid.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800556 */
557 int (*release_stream)(
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700558 struct camera2_device *,
559 uint32_t stream_id);
560
561 /**
562 * allocate_reprocess_stream:
563 *
564 * Allocate a new input stream for use, defined by the output buffer width,
565 * height, and the pixel format. Returns the new stream's ID, gralloc usage
566 * flags, and required simultaneously acquirable buffer count, on
567 * success. Error conditions:
568 *
569 * - Requesting a width/height/format combination not listed as
570 * supported by the sensor's static characteristics
571 *
572 * - Asking for too many reprocessing streams to be configured at once.
573 *
574 * Input parameters:
575 *
576 * - width, height, format: Specification for the buffers to be sent through
577 * this stream. Format must be a value from the HAL_PIXEL_FORMAT_* list.
578 *
579 * - reprocess_stream_ops: A structure of function pointers for acquiring
580 * and releasing buffers for this stream. The underlying stream will be
581 * configured based on the usage and max_buffers outputs.
582 *
583 * Output parameters:
584 *
585 * - stream_id: An unsigned integer identifying this stream. This value is
586 * used in incoming requests to identify the stream, and in releasing the
587 * stream. These ids are numbered separately from the input stream ids.
588 *
589 * - consumer_usage: The gralloc usage mask needed by the HAL device for
590 * consuming the requested type of data. This is used in allocating new
591 * gralloc buffers for the stream buffer queue.
592 *
593 * - max_buffers: The maximum number of buffers the HAL device may need to
594 * have acquired at the same time. The device may not have more buffers
595 * acquired at the same time than this value.
596 *
597 */
598 int (*allocate_reprocess_stream)(struct camera2_device *,
599 uint32_t width,
600 uint32_t height,
601 uint32_t format,
602 camera2_stream_in_ops_t *reprocess_stream_ops,
603 // outputs
604 uint32_t *stream_id,
605 uint32_t *consumer_usage,
606 uint32_t *max_buffers);
607
608 /**
609 * Release a reprocessing stream. Returns an error if called when
610 * get_in_progress_count is non-zero, or if the stream id is not
611 * valid.
612 */
613 int (*release_reprocess_stream)(
614 struct camera2_device *,
615 uint32_t stream_id);
616
617 /**********************************************************************
618 * Miscellaneous methods
619 */
620
621 /**
622 * Trigger asynchronous activity. This is used for triggering special
623 * behaviors of the camera 3A routines when they are in use. See the
624 * documentation for CAMERA2_TRIGGER_* above for details of the trigger ids
625 * and their arguments.
626 */
627 int (*trigger_action)(struct camera2_device *,
628 uint32_t trigger_id,
629 int ext1,
630 int ext2);
631
632 /**
633 * Notification callback setup
634 */
635 int (*set_notify_callback)(struct camera2_device *,
636 camera2_notify_callback notify_cb,
637 void *user);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800638
639 /**
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700640 * Get methods to query for vendor extension metadata tag infomation. May
641 * set ops to NULL if no vendor extension tags are defined.
642 */
643 int (*get_metadata_vendor_tag_ops)(struct camera2_device*,
644 vendor_tag_query_ops_t **ops);
645
646 /**
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800647 * Dump state of the camera hardware
648 */
649 int (*dump)(struct camera2_device *, int fd);
650
651} camera2_device_ops_t;
652
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700653/**********************************************************************
654 *
655 * Camera device definition
656 *
657 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800658typedef struct camera2_device {
659 /**
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700660 * common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800661 * this device as implementing version 2.0 of the camera device HAL.
662 */
663 hw_device_t common;
664 camera2_device_ops_t *ops;
665 void *priv;
666} camera2_device_t;
667
668__END_DECLS
669
670#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */