blob: 5cfdbffead76658dc074f9cadc931e9ac9246f82 [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 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080028 * Supports the android.hardware.Camera APIs.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080029 *
30 * Camera devices that support this version of the HAL must return
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -070031 * CAMERA_DEVICE_API_VERSION_2_0 in camera_device_t.common.version and in
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080032 * camera_info_t.device_version (from camera_module_t.get_camera_info).
33 *
34 * Camera modules that may contain version 2.0 devices must implement at least
35 * version 2.0 of the camera module interface (as defined by
36 * camera_module_t.common.module_api_version).
37 *
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070038 * See camera_common.h for more versioning details.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080039 *
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -080040 * Version history:
41 *
42 * 2.0: Initial release (Android 4.2):
43 * - Sufficient for implementing existing android.hardware.Camera API.
44 * - Allows for ZSL queue in camera service layer
45 * - Not tested for any new features such manual capture control,
46 * Bayer RAW capture, reprocessing of RAW data.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080047 */
48
49__BEGIN_DECLS
50
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -070051struct camera2_device;
52
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070053/**********************************************************************
54 *
55 * Input/output stream buffer queue interface definitions
56 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080057 */
58
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070059/**
60 * Output image stream queue interface. A set of these methods is provided to
61 * the HAL device in allocate_stream(), and are used to interact with the
62 * gralloc buffer queue for that stream. They may not be called until after
63 * allocate_stream returns.
64 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -080065typedef struct camera2_stream_ops {
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070066 /**
67 * Get a buffer to fill from the queue. The size and format of the buffer
68 * are fixed for a given stream (defined in allocate_stream), and the stride
69 * should be queried from the platform gralloc module. The gralloc buffer
70 * will have been allocated based on the usage flags provided by
71 * allocate_stream, and will be locked for use.
72 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -070073 int (*dequeue_buffer)(const struct camera2_stream_ops* w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070074 buffer_handle_t** buffer);
75
76 /**
77 * Push a filled buffer to the stream to be used by the consumer.
78 *
79 * The timestamp represents the time at start of exposure of the first row
80 * of the image; it must be from a monotonic clock, and is measured in
81 * nanoseconds. The timestamps do not need to be comparable between
82 * different cameras, or consecutive instances of the same camera. However,
83 * they must be comparable between streams from the same camera. If one
84 * capture produces buffers for multiple streams, each stream must have the
85 * same timestamp for that buffer, and that timestamp must match the
86 * timestamp in the output frame metadata.
87 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -070088 int (*enqueue_buffer)(const struct camera2_stream_ops* w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070089 int64_t timestamp,
90 buffer_handle_t* buffer);
91 /**
92 * Return a buffer to the queue without marking it as filled.
93 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -070094 int (*cancel_buffer)(const struct camera2_stream_ops* w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070095 buffer_handle_t* buffer);
96 /**
97 * Set the crop window for subsequently enqueued buffers. The parameters are
98 * measured in pixels relative to the buffer width and height.
99 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700100 int (*set_crop)(const struct camera2_stream_ops *w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700101 int left, int top, int right, int bottom);
102
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800103} camera2_stream_ops_t;
104
Eino-Ville Talvala2388a2d2012-08-28 14:01:26 -0700105/**
Eino-Ville Talvala9633d502012-09-13 16:32:14 -0700106 * Temporary definition during transition.
107 *
108 * These formats will be removed and replaced with
109 * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED. To maximize forward compatibility,
110 * HAL implementations are strongly recommended to treat FORMAT_OPAQUE and
111 * FORMAT_ZSL as equivalent to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, and
112 * return HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED in the format_actual output
113 * parameter of allocate_stream, allowing the gralloc module to select the
114 * specific format based on the usage flags from the camera and the stream
115 * consumer.
116 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700117enum {
Eino-Ville Talvala9633d502012-09-13 16:32:14 -0700118 CAMERA2_HAL_PIXEL_FORMAT_OPAQUE = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
119 CAMERA2_HAL_PIXEL_FORMAT_ZSL = -1
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700120};
121
122/**
Eino-Ville Talvalaada3a972012-09-19 11:42:40 -0700123 * Transport header for compressed JPEG buffers in output streams.
124 *
125 * To capture JPEG images, a stream is created using the pixel format
126 * HAL_PIXEL_FORMAT_BLOB, and the static metadata field android.jpeg.maxSize is
127 * used as the buffer size. Since compressed JPEG images are of variable size,
128 * the HAL needs to include the final size of the compressed image using this
129 * structure inside the output stream buffer. The JPEG blob ID field must be set
130 * to CAMERA2_JPEG_BLOB_ID.
Alex Raycecacd42012-09-27 15:48:23 -0700131 *
132 * Transport header should be at the end of the JPEG output stream buffer. That
133 * means the jpeg_blob_id must start at byte[android.jpeg.maxSize -
134 * sizeof(camera2_jpeg_blob)]. Any HAL using this transport header must
135 * account for it in android.jpeg.maxSize. The JPEG data itself starts at
136 * byte[0] and should be jpeg_size bytes long.
Eino-Ville Talvalaada3a972012-09-19 11:42:40 -0700137 */
138typedef struct camera2_jpeg_blob {
139 uint16_t jpeg_blob_id;
140 uint32_t jpeg_size;
Eino-Ville Talvalaada3a972012-09-19 11:42:40 -0700141};
142
143enum {
144 CAMERA2_JPEG_BLOB_ID = 0x00FF
145};
146
147/**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700148 * Input reprocess stream queue management. A set of these methods is provided
Eino-Ville Talvalafa7a91d2012-05-22 10:41:20 -0700149 * to the HAL device in allocate_reprocess_stream(); they are used to interact
150 * with the reprocess stream's input gralloc buffer queue.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700151 */
152typedef struct camera2_stream_in_ops {
153 /**
154 * Get the next buffer of image data to reprocess. The width, height, and
155 * format of the buffer is fixed in allocate_reprocess_stream(), and the
156 * stride and other details should be queried from the platform gralloc
157 * module as needed. The buffer will already be locked for use.
158 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700159 int (*acquire_buffer)(const struct camera2_stream_in_ops *w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700160 buffer_handle_t** buffer);
161 /**
162 * Return a used buffer to the buffer queue for reuse.
163 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700164 int (*release_buffer)(const struct camera2_stream_in_ops *w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700165 buffer_handle_t* buffer);
166
167} camera2_stream_in_ops_t;
168
169/**********************************************************************
170 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800171 * Metadata queue management, used for requests sent to HAL module, and for
172 * frames produced by the HAL.
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700173 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800174 */
175
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700176enum {
177 CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS = -1
178};
179
180/**
181 * Request input queue protocol:
182 *
183 * The framework holds the queue and its contents. At start, the queue is empty.
184 *
185 * 1. When the first metadata buffer is placed into the queue, the framework
186 * signals the device by calling notify_request_queue_not_empty().
187 *
188 * 2. After receiving notify_request_queue_not_empty, the device must call
189 * dequeue() once it's ready to handle the next buffer.
190 *
191 * 3. Once the device has processed a buffer, and is ready for the next buffer,
192 * it must call dequeue() again instead of waiting for a notification. If
193 * there are no more buffers available, dequeue() will return NULL. After
194 * this point, when a buffer becomes available, the framework must call
195 * notify_request_queue_not_empty() again. If the device receives a NULL
196 * return from dequeue, it does not need to query the queue again until a
197 * notify_request_queue_not_empty() call is received from the source.
198 *
199 * 4. If the device calls buffer_count() and receives 0, this does not mean that
200 * the framework will provide a notify_request_queue_not_empty() call. The
201 * framework will only provide such a notification after the device has
202 * received a NULL from dequeue, or on initial startup.
203 *
204 * 5. The dequeue() call in response to notify_request_queue_not_empty() may be
205 * on the same thread as the notify_request_queue_not_empty() call, and may
206 * be performed from within the notify call.
207 *
208 * 6. All dequeued request buffers must be returned to the framework by calling
209 * free_request, including when errors occur, a device flush is requested, or
210 * when the device is shutting down.
211 */
212typedef struct camera2_request_queue_src_ops {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800213 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700214 * Get the count of request buffers pending in the queue. May return
215 * CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS if a repeating request (stream
216 * request) is currently configured. Calling this method has no effect on
217 * whether the notify_request_queue_not_empty() method will be called by the
218 * framework.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800219 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700220 int (*request_count)(const struct camera2_request_queue_src_ops *q);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800221
222 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700223 * Get a metadata buffer from the framework. Returns OK if there is no
224 * error. If the queue is empty, returns NULL in buffer. In that case, the
225 * device must wait for a notify_request_queue_not_empty() message before
226 * attempting to dequeue again. Buffers obtained in this way must be
227 * returned to the framework with free_request().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800228 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700229 int (*dequeue_request)(const struct camera2_request_queue_src_ops *q,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800230 camera_metadata_t **buffer);
231 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700232 * Return a metadata buffer to the framework once it has been used, or if
233 * an error or shutdown occurs.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800234 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700235 int (*free_request)(const struct camera2_request_queue_src_ops *q,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800236 camera_metadata_t *old_buffer);
237
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700238} camera2_request_queue_src_ops_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800239
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700240/**
241 * Frame output queue protocol:
242 *
243 * The framework holds the queue and its contents. At start, the queue is empty.
244 *
245 * 1. When the device is ready to fill an output metadata frame, it must dequeue
246 * a metadata buffer of the required size.
247 *
248 * 2. It should then fill the metadata buffer, and place it on the frame queue
249 * using enqueue_frame. The framework takes ownership of the frame.
250 *
251 * 3. In case of an error, a request to flush the pipeline, or shutdown, the
252 * device must return any affected dequeued frames to the framework by
253 * calling cancel_frame.
254 */
255typedef struct camera2_frame_queue_dst_ops {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800256 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700257 * Get an empty metadata buffer to fill from the framework. The new metadata
258 * buffer will have room for entries number of metadata entries, plus
259 * data_bytes worth of extra storage. Frames dequeued here must be returned
260 * to the framework with either cancel_frame or enqueue_frame.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800261 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700262 int (*dequeue_frame)(const struct camera2_frame_queue_dst_ops *q,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700263 size_t entries, size_t data_bytes,
264 camera_metadata_t **buffer);
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700265
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700266 /**
267 * Return a dequeued metadata buffer to the framework for reuse; do not mark it as
268 * filled. Use when encountering errors, or flushing the internal request queue.
269 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700270 int (*cancel_frame)(const struct camera2_frame_queue_dst_ops *q,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700271 camera_metadata_t *buffer);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800272
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700273 /**
274 * Place a completed metadata frame on the frame output queue.
275 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700276 int (*enqueue_frame)(const struct camera2_frame_queue_dst_ops *q,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700277 camera_metadata_t *buffer);
278
279} camera2_frame_queue_dst_ops_t;
280
281/**********************************************************************
282 *
283 * Notification callback and message definition, and trigger definitions
284 *
285 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800286
287/**
288 * Asynchronous notification callback from the HAL, fired for various
289 * reasons. Only for information independent of frame capture, or that require
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700290 * specific timing. The user pointer must be the same one that was passed to the
291 * device in set_notify_callback().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800292 */
293typedef void (*camera2_notify_callback)(int32_t msg_type,
294 int32_t ext1,
295 int32_t ext2,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700296 int32_t ext3,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800297 void *user);
298
299/**
300 * Possible message types for camera2_notify_callback
301 */
302enum {
303 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700304 * An error has occurred. Argument ext1 contains the error code, and
305 * ext2 and ext3 contain any error-specific information.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800306 */
Eino-Ville Talvaladaacbf42012-03-22 13:09:56 -0700307 CAMERA2_MSG_ERROR = 0x0001,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800308 /**
309 * The exposure of a given request has begun. Argument ext1 contains the
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700310 * frame number, and ext2 and ext3 contain the low-order and high-order
311 * bytes of the timestamp for when exposure began.
312 * (timestamp = (ext3 << 32 | ext2))
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800313 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700314 CAMERA2_MSG_SHUTTER = 0x0010,
315 /**
316 * The autofocus routine has changed state. Argument ext1 contains the new
317 * state; the values are the same as those for the metadata field
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700318 * android.control.afState. Ext2 contains the latest trigger ID passed to
319 * trigger_action(CAMERA2_TRIGGER_AUTOFOCUS) or
320 * trigger_action(CAMERA2_TRIGGER_CANCEL_AUTOFOCUS), or 0 if trigger has not
321 * been called with either of those actions.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700322 */
323 CAMERA2_MSG_AUTOFOCUS = 0x0020,
324 /**
325 * The autoexposure routine has changed state. Argument ext1 contains the
326 * new state; the values are the same as those for the metadata field
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700327 * android.control.aeState. Ext2 contains the latest trigger ID value passed to
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700328 * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
329 * has not been called.
330 */
331 CAMERA2_MSG_AUTOEXPOSURE = 0x0021,
332 /**
333 * The auto-whitebalance routine has changed state. Argument ext1 contains
334 * the new state; the values are the same as those for the metadata field
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700335 * android.control.awbState. Ext2 contains the latest trigger ID passed to
336 * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
337 * has not been called.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700338 */
339 CAMERA2_MSG_AUTOWB = 0x0022
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800340};
341
342/**
343 * Error codes for CAMERA_MSG_ERROR
344 */
345enum {
346 /**
347 * A serious failure occured. Camera device may not work without reboot, and
348 * no further frames or buffer streams will be produced by the
349 * device. Device should be treated as closed.
350 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700351 CAMERA2_MSG_ERROR_HARDWARE = 0x0001,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800352 /**
353 * A serious failure occured. No further frames or buffer streams will be
354 * produced by the device. Device should be treated as closed. The client
355 * must reopen the device to use it again.
356 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700357 CAMERA2_MSG_ERROR_DEVICE,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800358 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700359 * An error has occurred in processing a request. No output (metadata or
360 * buffers) will be produced for this request. ext2 contains the frame
361 * number of the request. Subsequent requests are unaffected, and the device
362 * remains operational.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800363 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700364 CAMERA2_MSG_ERROR_REQUEST,
365 /**
366 * An error has occurred in producing an output frame metadata buffer for a
367 * request, but image buffers for it will still be available. Subsequent
368 * requests are unaffected, and the device remains operational. ext2
369 * contains the frame number of the request.
370 */
371 CAMERA2_MSG_ERROR_FRAME,
372 /**
373 * An error has occurred in placing an output buffer into a stream for a
374 * request. The frame metadata and other buffers may still be
375 * available. Subsequent requests are unaffected, and the device remains
376 * operational. ext2 contains the frame number of the request, and ext3
377 * contains the stream id.
378 */
379 CAMERA2_MSG_ERROR_STREAM,
380 /**
381 * Number of error types
382 */
383 CAMERA2_MSG_NUM_ERRORS
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800384};
385
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700386/**
387 * Possible trigger ids for trigger_action()
388 */
389enum {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800390 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700391 * Trigger an autofocus cycle. The effect of the trigger depends on the
392 * autofocus mode in effect when the trigger is received, which is the mode
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700393 * listed in the latest capture request to be dequeued by the HAL. If the
394 * mode is OFF, EDOF, or FIXED, the trigger has no effect. In AUTO, MACRO,
395 * or CONTINUOUS_* modes, see below for the expected behavior. The state of
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700396 * the autofocus cycle can be tracked in android.control.afMode and the
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700397 * corresponding notifications.
398 *
399 **
400 * In AUTO or MACRO mode, the AF state transitions (and notifications)
401 * when calling with trigger ID = N with the previous ID being K are:
402 *
403 * Initial state Transitions
404 * INACTIVE (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
405 * AF_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
406 * AF_NOT_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
407 * ACTIVE_SCAN (K) -> AF_FOCUSED(N) or AF_NOT_FOCUSED(N)
408 * PASSIVE_SCAN (K) Not used in AUTO/MACRO mode
409 * PASSIVE_FOCUSED (K) Not used in AUTO/MACRO mode
410 *
411 **
412 * In CONTINUOUS_PICTURE mode, triggering AF must lock the AF to the current
413 * lens position and transition the AF state to either AF_FOCUSED or
414 * NOT_FOCUSED. If a passive scan is underway, that scan must complete and
415 * then lock the lens position and change AF state. TRIGGER_CANCEL_AUTOFOCUS
416 * will allow the AF to restart its operation.
417 *
418 * Initial state Transitions
419 * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
420 * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
421 * PASSIVE_SCAN (K) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
422 * AF_FOCUSED (K) no effect except to change next notification ID to N
423 * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
424 *
425 **
426 * In CONTINUOUS_VIDEO mode, triggering AF must lock the AF to the current
427 * lens position and transition the AF state to either AF_FOCUSED or
428 * NOT_FOCUSED. If a passive scan is underway, it must immediately halt, in
429 * contrast with CONTINUOUS_PICTURE mode. TRIGGER_CANCEL_AUTOFOCUS will
430 * allow the AF to restart its operation.
431 *
432 * Initial state Transitions
433 * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
434 * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
435 * PASSIVE_SCAN (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
436 * AF_FOCUSED (K) no effect except to change next notification ID to N
437 * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
438 *
439 * Ext1 is an ID that must be returned in subsequent auto-focus state change
440 * notifications through camera2_notify_callback() and stored in
441 * android.control.afTriggerId.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700442 */
443 CAMERA2_TRIGGER_AUTOFOCUS = 0x0001,
444 /**
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700445 * Send a cancel message to the autofocus algorithm. The effect of the
446 * cancellation depends on the autofocus mode in effect when the trigger is
447 * received, which is the mode listed in the latest capture request to be
448 * dequeued by the HAL. If the AF mode is OFF or EDOF, the cancel has no
449 * effect. For other modes, the lens should return to its default position,
450 * any current autofocus scan must be canceled, and the AF state should be
451 * set to INACTIVE.
452 *
453 * The state of the autofocus cycle can be tracked in android.control.afMode
454 * and the corresponding notification. Continuous autofocus modes may resume
455 * focusing operations thereafter exactly as if the camera had just been set
456 * to a continuous AF mode.
457 *
458 * Ext1 is an ID that must be returned in subsequent auto-focus state change
459 * notifications through camera2_notify_callback() and stored in
460 * android.control.afTriggerId.
461 */
462 CAMERA2_TRIGGER_CANCEL_AUTOFOCUS,
463 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700464 * Trigger a pre-capture metering cycle, which may include firing the flash
465 * to determine proper capture parameters. Typically, this trigger would be
466 * fired for a half-depress of a camera shutter key, or before a snapshot
467 * capture in general. The state of the metering cycle can be tracked in
468 * android.control.aeMode and the corresponding notification. If the
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700469 * auto-exposure mode is OFF, the trigger does nothing.
470 *
471 * Ext1 is an ID that must be returned in subsequent
472 * auto-exposure/auto-white balance state change notifications through
473 * camera2_notify_callback() and stored in android.control.aePrecaptureId.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700474 */
475 CAMERA2_TRIGGER_PRECAPTURE_METERING
476};
477
478/**
479 * Possible template types for construct_default_request()
480 */
481enum {
482 /**
483 * Standard camera preview operation with 3A on auto.
484 */
485 CAMERA2_TEMPLATE_PREVIEW = 1,
486 /**
487 * Standard camera high-quality still capture with 3A and flash on auto.
488 */
489 CAMERA2_TEMPLATE_STILL_CAPTURE,
490 /**
491 * Standard video recording plus preview with 3A on auto, torch off.
492 */
493 CAMERA2_TEMPLATE_VIDEO_RECORD,
494 /**
495 * High-quality still capture while recording video. Application will
496 * include preview, video record, and full-resolution YUV or JPEG streams in
497 * request. Must not cause stuttering on video stream. 3A on auto.
498 */
499 CAMERA2_TEMPLATE_VIDEO_SNAPSHOT,
500 /**
501 * Zero-shutter-lag mode. Application will request preview and
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700502 * full-resolution data for each frame, and reprocess it to JPEG when a
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700503 * still image is requested by user. Settings should provide highest-quality
504 * full-resolution images without compromising preview frame rate. 3A on
505 * auto.
506 */
Eino-Ville Talvala6adfd6b2012-05-14 15:25:27 -0700507 CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG,
508
509 /* Total number of templates */
510 CAMERA2_TEMPLATE_COUNT
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700511};
512
513
514/**********************************************************************
515 *
516 * Camera device operations
517 *
518 */
519typedef struct camera2_device_ops {
520
521 /**********************************************************************
522 * Request and frame queue setup and management methods
523 */
524
525 /**
526 * Pass in input request queue interface methods.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800527 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700528 int (*set_request_queue_src_ops)(const struct camera2_device *,
529 const camera2_request_queue_src_ops_t *request_src_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800530
531 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700532 * Notify device that the request queue is no longer empty. Must only be
533 * called when the first buffer is added a new queue, or after the source
534 * has returned NULL in response to a dequeue call.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800535 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700536 int (*notify_request_queue_not_empty)(const struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800537
538 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700539 * Pass in output frame queue interface methods
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800540 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700541 int (*set_frame_queue_dst_ops)(const struct camera2_device *,
542 const camera2_frame_queue_dst_ops_t *frame_dst_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800543
544 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700545 * Number of camera requests being processed by the device at the moment
546 * (captures/reprocesses that have had their request dequeued, but have not
547 * yet been enqueued onto output pipeline(s) ). No streams may be released
548 * by the framework until the in-progress count is 0.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800549 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700550 int (*get_in_progress_count)(const struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800551
552 /**
553 * Flush all in-progress captures. This includes all dequeued requests
554 * (regular or reprocessing) that have not yet placed any outputs into a
555 * stream or the frame queue. Partially completed captures must be completed
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700556 * normally. No new requests may be dequeued from the request queue until
557 * the flush completes.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800558 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700559 int (*flush_captures_in_progress)(const struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800560
561 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700562 * Create a filled-in default request for standard camera use cases.
563 *
564 * The device must return a complete request that is configured to meet the
565 * requested use case, which must be one of the CAMERA2_TEMPLATE_*
566 * enums. All request control fields must be included, except for
Eino-Ville Talvalafa7a91d2012-05-22 10:41:20 -0700567 * android.request.outputStreams.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700568 *
569 * The metadata buffer returned must be allocated with
570 * allocate_camera_metadata. The framework takes ownership of the buffer.
571 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700572 int (*construct_default_request)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700573 int request_template,
574 camera_metadata_t **request);
575
576 /**********************************************************************
577 * Stream management
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800578 */
579
580 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700581 * allocate_stream:
582 *
583 * Allocate a new output stream for use, defined by the output buffer width,
584 * height, target, and possibly the pixel format. Returns the new stream's
585 * ID, gralloc usage flags, minimum queue buffer count, and possibly the
586 * pixel format, on success. Error conditions:
587 *
588 * - Requesting a width/height/format combination not listed as
589 * supported by the sensor's static characteristics
590 *
591 * - Asking for too many streams of a given format type (2 bayer raw
592 * streams, for example).
593 *
594 * Input parameters:
595 *
596 * - width, height, format: Specification for the buffers to be sent through
Eino-Ville Talvala2388a2d2012-08-28 14:01:26 -0700597 * this stream. Format is a value from the HAL_PIXEL_FORMAT_* list. If
598 * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
599 * gralloc module will select a format based on the usage flags provided
600 * by the camera HAL and the consumer of the stream. The camera HAL should
601 * inspect the buffers handed to it in the register_stream_buffers call to
602 * obtain the implementation-specific format if necessary.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700603 *
604 * - stream_ops: A structure of function pointers for obtaining and queuing
605 * up buffers for this stream. The underlying stream will be configured
606 * based on the usage and max_buffers outputs. The methods in this
607 * structure may not be called until after allocate_stream returns.
608 *
609 * Output parameters:
610 *
611 * - stream_id: An unsigned integer identifying this stream. This value is
612 * used in incoming requests to identify the stream, and in releasing the
613 * stream.
614 *
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700615 * - usage: The gralloc usage mask needed by the HAL device for producing
616 * the requested type of data. This is used in allocating new gralloc
617 * buffers for the stream buffer queue.
618 *
619 * - max_buffers: The maximum number of buffers the HAL device may need to
620 * have dequeued at the same time. The device may not dequeue more buffers
621 * than this value at the same time.
622 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800623 */
624 int (*allocate_stream)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700625 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700626 // inputs
627 uint32_t width,
628 uint32_t height,
629 int format,
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700630 const camera2_stream_ops_t *stream_ops,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700631 // outputs
632 uint32_t *stream_id,
Eino-Ville Talvala2388a2d2012-08-28 14:01:26 -0700633 uint32_t *format_actual, // IGNORED, will be removed
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700634 uint32_t *usage,
635 uint32_t *max_buffers);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800636
637 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700638 * Register buffers for a given stream. This is called after a successful
639 * allocate_stream call, and before the first request referencing the stream
640 * is enqueued. This method is intended to allow the HAL device to map or
641 * otherwise prepare the buffers for later use. num_buffers is guaranteed to
642 * be at least max_buffers (from allocate_stream), but may be larger. The
643 * buffers will already be locked for use. At the end of the call, all the
Eino-Ville Talvala2388a2d2012-08-28 14:01:26 -0700644 * buffers must be ready to be returned to the queue. If the stream format
645 * was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL should
646 * inspect the passed-in buffers here to determine any platform-private
647 * pixel format information.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700648 */
649 int (*register_stream_buffers)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700650 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700651 uint32_t stream_id,
652 int num_buffers,
653 buffer_handle_t *buffers);
654
655 /**
656 * Release a stream. Returns an error if called when get_in_progress_count
657 * is non-zero, or if the stream id is invalid.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800658 */
659 int (*release_stream)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700660 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700661 uint32_t stream_id);
662
663 /**
664 * allocate_reprocess_stream:
665 *
666 * Allocate a new input stream for use, defined by the output buffer width,
667 * height, and the pixel format. Returns the new stream's ID, gralloc usage
668 * flags, and required simultaneously acquirable buffer count, on
669 * success. Error conditions:
670 *
671 * - Requesting a width/height/format combination not listed as
672 * supported by the sensor's static characteristics
673 *
674 * - Asking for too many reprocessing streams to be configured at once.
675 *
676 * Input parameters:
677 *
678 * - width, height, format: Specification for the buffers to be sent through
679 * this stream. Format must be a value from the HAL_PIXEL_FORMAT_* list.
680 *
681 * - reprocess_stream_ops: A structure of function pointers for acquiring
682 * and releasing buffers for this stream. The underlying stream will be
683 * configured based on the usage and max_buffers outputs.
684 *
685 * Output parameters:
686 *
687 * - stream_id: An unsigned integer identifying this stream. This value is
688 * used in incoming requests to identify the stream, and in releasing the
689 * stream. These ids are numbered separately from the input stream ids.
690 *
691 * - consumer_usage: The gralloc usage mask needed by the HAL device for
692 * consuming the requested type of data. This is used in allocating new
693 * gralloc buffers for the stream buffer queue.
694 *
695 * - max_buffers: The maximum number of buffers the HAL device may need to
696 * have acquired at the same time. The device may not have more buffers
697 * acquired at the same time than this value.
698 *
699 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700700 int (*allocate_reprocess_stream)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700701 uint32_t width,
702 uint32_t height,
703 uint32_t format,
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700704 const camera2_stream_in_ops_t *reprocess_stream_ops,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700705 // outputs
706 uint32_t *stream_id,
707 uint32_t *consumer_usage,
708 uint32_t *max_buffers);
709
710 /**
Eino-Ville Talvala7f8dd0a2012-09-04 14:21:07 -0700711 * allocate_reprocess_stream_from_stream:
712 *
713 * Allocate a new input stream for use, which will use the buffers allocated
714 * for an existing output stream. That is, after the HAL enqueues a buffer
715 * onto the output stream, it may see that same buffer handed to it from
716 * this input reprocessing stream. After the HAL releases the buffer back to
717 * the reprocessing stream, it will be returned to the output queue for
718 * reuse.
719 *
720 * Error conditions:
721 *
722 * - Using an output stream of unsuitable size/format for the basis of the
723 * reprocessing stream.
724 *
725 * - Attempting to allocatee too many reprocessing streams at once.
726 *
727 * Input parameters:
728 *
729 * - output_stream_id: The ID of an existing output stream which has
730 * a size and format suitable for reprocessing.
731 *
732 * - reprocess_stream_ops: A structure of function pointers for acquiring
733 * and releasing buffers for this stream. The underlying stream will use
734 * the same graphics buffer handles as the output stream uses.
735 *
736 * Output parameters:
737 *
738 * - stream_id: An unsigned integer identifying this stream. This value is
739 * used in incoming requests to identify the stream, and in releasing the
740 * stream. These ids are numbered separately from the input stream ids.
741 *
742 * The HAL client must always release the reprocessing stream before it
743 * releases the output stream it is based on.
744 *
745 */
746 int (*allocate_reprocess_stream_from_stream)(const struct camera2_device *,
747 uint32_t output_stream_id,
748 const camera2_stream_in_ops_t *reprocess_stream_ops,
749 // outputs
750 uint32_t *stream_id);
751
752 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700753 * Release a reprocessing stream. Returns an error if called when
754 * get_in_progress_count is non-zero, or if the stream id is not
755 * valid.
756 */
757 int (*release_reprocess_stream)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700758 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700759 uint32_t stream_id);
760
761 /**********************************************************************
762 * Miscellaneous methods
763 */
764
765 /**
766 * Trigger asynchronous activity. This is used for triggering special
767 * behaviors of the camera 3A routines when they are in use. See the
768 * documentation for CAMERA2_TRIGGER_* above for details of the trigger ids
769 * and their arguments.
770 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700771 int (*trigger_action)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700772 uint32_t trigger_id,
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700773 int32_t ext1,
774 int32_t ext2);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700775
776 /**
777 * Notification callback setup
778 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700779 int (*set_notify_callback)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700780 camera2_notify_callback notify_cb,
781 void *user);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800782
783 /**
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700784 * Get methods to query for vendor extension metadata tag infomation. May
785 * set ops to NULL if no vendor extension tags are defined.
786 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700787 int (*get_metadata_vendor_tag_ops)(const struct camera2_device*,
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700788 vendor_tag_query_ops_t **ops);
789
790 /**
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800791 * Dump state of the camera hardware
792 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700793 int (*dump)(const struct camera2_device *, int fd);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800794
795} camera2_device_ops_t;
796
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700797/**********************************************************************
798 *
799 * Camera device definition
800 *
801 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800802typedef struct camera2_device {
803 /**
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700804 * common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800805 * this device as implementing version 2.0 of the camera device HAL.
806 */
807 hw_device_t common;
808 camera2_device_ops_t *ops;
809 void *priv;
810} camera2_device_t;
811
812__END_DECLS
813
814#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */