blob: 518130bcec1fb8a41b6793de285ac154db7be50d [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 Talvala08a6e5e2012-05-17 17:54:56 -070067 int (*dequeue_buffer)(const 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 Talvala08a6e5e2012-05-17 17:54:56 -070082 int (*enqueue_buffer)(const 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 Talvala08a6e5e2012-05-17 17:54:56 -070088 int (*cancel_buffer)(const 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 Talvala08a6e5e2012-05-17 17:54:56 -070094 int (*set_crop)(const 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
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -070099enum {
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700100 /**
101 * Special pixel format value used to indicate that the framework does not care
102 * what exact pixel format is to be used for an output stream. The device HAL is
103 * free to select any pixel format, platform-specific and otherwise, and this
104 * opaque value will be passed on to the platform gralloc module when buffers
105 * need to be allocated for the stream.
106 */
107 CAMERA2_HAL_PIXEL_FORMAT_OPAQUE = -1,
108 /**
109 * Special pixel format value used to indicate that the framework will use
110 * the output buffers for zero-shutter-lag mode; these buffers should be
111 * efficient to produce at full sensor resolution, and efficient to send
112 * into a reprocess stream for final output processing.
113 */
114 CAMERA2_HAL_PIXEL_FORMAT_ZSL = -2
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700115};
116
117/**
118 * Input reprocess stream queue management. A set of these methods is provided
Eino-Ville Talvalafa7a91d2012-05-22 10:41:20 -0700119 * to the HAL device in allocate_reprocess_stream(); they are used to interact
120 * with the reprocess stream's input gralloc buffer queue.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700121 */
122typedef struct camera2_stream_in_ops {
123 /**
124 * Get the next buffer of image data to reprocess. The width, height, and
125 * format of the buffer is fixed in allocate_reprocess_stream(), and the
126 * stride and other details should be queried from the platform gralloc
127 * module as needed. The buffer will already be locked for use.
128 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700129 int (*acquire_buffer)(const struct camera2_stream_in_ops *w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700130 buffer_handle_t** buffer);
131 /**
132 * Return a used buffer to the buffer queue for reuse.
133 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700134 int (*release_buffer)(const struct camera2_stream_in_ops *w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700135 buffer_handle_t* buffer);
136
137} camera2_stream_in_ops_t;
138
139/**********************************************************************
140 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800141 * Metadata queue management, used for requests sent to HAL module, and for
142 * frames produced by the HAL.
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700143 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800144 */
145
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700146enum {
147 CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS = -1
148};
149
150/**
151 * Request input queue protocol:
152 *
153 * The framework holds the queue and its contents. At start, the queue is empty.
154 *
155 * 1. When the first metadata buffer is placed into the queue, the framework
156 * signals the device by calling notify_request_queue_not_empty().
157 *
158 * 2. After receiving notify_request_queue_not_empty, the device must call
159 * dequeue() once it's ready to handle the next buffer.
160 *
161 * 3. Once the device has processed a buffer, and is ready for the next buffer,
162 * it must call dequeue() again instead of waiting for a notification. If
163 * there are no more buffers available, dequeue() will return NULL. After
164 * this point, when a buffer becomes available, the framework must call
165 * notify_request_queue_not_empty() again. If the device receives a NULL
166 * return from dequeue, it does not need to query the queue again until a
167 * notify_request_queue_not_empty() call is received from the source.
168 *
169 * 4. If the device calls buffer_count() and receives 0, this does not mean that
170 * the framework will provide a notify_request_queue_not_empty() call. The
171 * framework will only provide such a notification after the device has
172 * received a NULL from dequeue, or on initial startup.
173 *
174 * 5. The dequeue() call in response to notify_request_queue_not_empty() may be
175 * on the same thread as the notify_request_queue_not_empty() call, and may
176 * be performed from within the notify call.
177 *
178 * 6. All dequeued request buffers must be returned to the framework by calling
179 * free_request, including when errors occur, a device flush is requested, or
180 * when the device is shutting down.
181 */
182typedef struct camera2_request_queue_src_ops {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800183 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700184 * Get the count of request buffers pending in the queue. May return
185 * CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS if a repeating request (stream
186 * request) is currently configured. Calling this method has no effect on
187 * whether the notify_request_queue_not_empty() method will be called by the
188 * framework.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800189 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700190 int (*request_count)(const struct camera2_request_queue_src_ops *q);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800191
192 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700193 * Get a metadata buffer from the framework. Returns OK if there is no
194 * error. If the queue is empty, returns NULL in buffer. In that case, the
195 * device must wait for a notify_request_queue_not_empty() message before
196 * attempting to dequeue again. Buffers obtained in this way must be
197 * returned to the framework with free_request().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800198 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700199 int (*dequeue_request)(const struct camera2_request_queue_src_ops *q,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800200 camera_metadata_t **buffer);
201 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700202 * Return a metadata buffer to the framework once it has been used, or if
203 * an error or shutdown occurs.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800204 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700205 int (*free_request)(const struct camera2_request_queue_src_ops *q,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800206 camera_metadata_t *old_buffer);
207
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700208} camera2_request_queue_src_ops_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800209
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700210/**
211 * Frame output queue protocol:
212 *
213 * The framework holds the queue and its contents. At start, the queue is empty.
214 *
215 * 1. When the device is ready to fill an output metadata frame, it must dequeue
216 * a metadata buffer of the required size.
217 *
218 * 2. It should then fill the metadata buffer, and place it on the frame queue
219 * using enqueue_frame. The framework takes ownership of the frame.
220 *
221 * 3. In case of an error, a request to flush the pipeline, or shutdown, the
222 * device must return any affected dequeued frames to the framework by
223 * calling cancel_frame.
224 */
225typedef struct camera2_frame_queue_dst_ops {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800226 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700227 * Get an empty metadata buffer to fill from the framework. The new metadata
228 * buffer will have room for entries number of metadata entries, plus
229 * data_bytes worth of extra storage. Frames dequeued here must be returned
230 * to the framework with either cancel_frame or enqueue_frame.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800231 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700232 int (*dequeue_frame)(const struct camera2_frame_queue_dst_ops *q,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700233 size_t entries, size_t data_bytes,
234 camera_metadata_t **buffer);
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700235
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700236 /**
237 * Return a dequeued metadata buffer to the framework for reuse; do not mark it as
238 * filled. Use when encountering errors, or flushing the internal request queue.
239 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700240 int (*cancel_frame)(const struct camera2_frame_queue_dst_ops *q,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700241 camera_metadata_t *buffer);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800242
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700243 /**
244 * Place a completed metadata frame on the frame output queue.
245 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700246 int (*enqueue_frame)(const struct camera2_frame_queue_dst_ops *q,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700247 camera_metadata_t *buffer);
248
249} camera2_frame_queue_dst_ops_t;
250
251/**********************************************************************
252 *
253 * Notification callback and message definition, and trigger definitions
254 *
255 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800256
257/**
258 * Asynchronous notification callback from the HAL, fired for various
259 * reasons. Only for information independent of frame capture, or that require
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700260 * specific timing. The user pointer must be the same one that was passed to the
261 * device in set_notify_callback().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800262 */
263typedef void (*camera2_notify_callback)(int32_t msg_type,
264 int32_t ext1,
265 int32_t ext2,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700266 int32_t ext3,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800267 void *user);
268
269/**
270 * Possible message types for camera2_notify_callback
271 */
272enum {
273 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700274 * An error has occurred. Argument ext1 contains the error code, and
275 * ext2 and ext3 contain any error-specific information.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800276 */
Eino-Ville Talvaladaacbf42012-03-22 13:09:56 -0700277 CAMERA2_MSG_ERROR = 0x0001,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800278 /**
279 * The exposure of a given request has begun. Argument ext1 contains the
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700280 * frame number, and ext2 and ext3 contain the low-order and high-order
281 * bytes of the timestamp for when exposure began.
282 * (timestamp = (ext3 << 32 | ext2))
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800283 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700284 CAMERA2_MSG_SHUTTER = 0x0010,
285 /**
286 * The autofocus routine has changed state. Argument ext1 contains the new
287 * state; the values are the same as those for the metadata field
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700288 * android.control.afState. Ext2 contains the latest trigger ID passed to
289 * trigger_action(CAMERA2_TRIGGER_AUTOFOCUS) or
290 * trigger_action(CAMERA2_TRIGGER_CANCEL_AUTOFOCUS), or 0 if trigger has not
291 * been called with either of those actions.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700292 */
293 CAMERA2_MSG_AUTOFOCUS = 0x0020,
294 /**
295 * The autoexposure routine has changed state. Argument ext1 contains the
296 * new state; the values are the same as those for the metadata field
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700297 * android.control.aeState. Ext2 contains the latest trigger ID value passed to
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700298 * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
299 * has not been called.
300 */
301 CAMERA2_MSG_AUTOEXPOSURE = 0x0021,
302 /**
303 * The auto-whitebalance routine has changed state. Argument ext1 contains
304 * the new state; the values are the same as those for the metadata field
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700305 * android.control.awbState. Ext2 contains the latest trigger ID passed to
306 * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
307 * has not been called.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700308 */
309 CAMERA2_MSG_AUTOWB = 0x0022
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800310};
311
312/**
313 * Error codes for CAMERA_MSG_ERROR
314 */
315enum {
316 /**
317 * A serious failure occured. Camera device may not work without reboot, and
318 * no further frames or buffer streams will be produced by the
319 * device. Device should be treated as closed.
320 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700321 CAMERA2_MSG_ERROR_HARDWARE = 0x0001,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800322 /**
323 * A serious failure occured. No further frames or buffer streams will be
324 * produced by the device. Device should be treated as closed. The client
325 * must reopen the device to use it again.
326 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700327 CAMERA2_MSG_ERROR_DEVICE,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800328 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700329 * An error has occurred in processing a request. No output (metadata or
330 * buffers) will be produced for this request. ext2 contains the frame
331 * number of the request. Subsequent requests are unaffected, and the device
332 * remains operational.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800333 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700334 CAMERA2_MSG_ERROR_REQUEST,
335 /**
336 * An error has occurred in producing an output frame metadata buffer for a
337 * request, but image buffers for it will still be available. Subsequent
338 * requests are unaffected, and the device remains operational. ext2
339 * contains the frame number of the request.
340 */
341 CAMERA2_MSG_ERROR_FRAME,
342 /**
343 * An error has occurred in placing an output buffer into a stream for a
344 * request. The frame metadata and other buffers may still be
345 * available. Subsequent requests are unaffected, and the device remains
346 * operational. ext2 contains the frame number of the request, and ext3
347 * contains the stream id.
348 */
349 CAMERA2_MSG_ERROR_STREAM,
350 /**
351 * Number of error types
352 */
353 CAMERA2_MSG_NUM_ERRORS
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800354};
355
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700356/**
357 * Possible trigger ids for trigger_action()
358 */
359enum {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800360 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700361 * Trigger an autofocus cycle. The effect of the trigger depends on the
362 * autofocus mode in effect when the trigger is received, which is the mode
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700363 * listed in the latest capture request to be dequeued by the HAL. If the
364 * mode is OFF, EDOF, or FIXED, the trigger has no effect. In AUTO, MACRO,
365 * or CONTINUOUS_* modes, see below for the expected behavior. The state of
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700366 * the autofocus cycle can be tracked in android.control.afMode and the
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700367 * corresponding notifications.
368 *
369 **
370 * In AUTO or MACRO mode, the AF state transitions (and notifications)
371 * when calling with trigger ID = N with the previous ID being K are:
372 *
373 * Initial state Transitions
374 * INACTIVE (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
375 * AF_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
376 * AF_NOT_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
377 * ACTIVE_SCAN (K) -> AF_FOCUSED(N) or AF_NOT_FOCUSED(N)
378 * PASSIVE_SCAN (K) Not used in AUTO/MACRO mode
379 * PASSIVE_FOCUSED (K) Not used in AUTO/MACRO mode
380 *
381 **
382 * In CONTINUOUS_PICTURE mode, triggering AF must lock the AF to the current
383 * lens position and transition the AF state to either AF_FOCUSED or
384 * NOT_FOCUSED. If a passive scan is underway, that scan must complete and
385 * then lock the lens position and change AF state. TRIGGER_CANCEL_AUTOFOCUS
386 * will allow the AF to restart its operation.
387 *
388 * Initial state Transitions
389 * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
390 * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
391 * PASSIVE_SCAN (K) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
392 * AF_FOCUSED (K) no effect except to change next notification ID to N
393 * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
394 *
395 **
396 * In CONTINUOUS_VIDEO mode, triggering AF must lock the AF to the current
397 * lens position and transition the AF state to either AF_FOCUSED or
398 * NOT_FOCUSED. If a passive scan is underway, it must immediately halt, in
399 * contrast with CONTINUOUS_PICTURE mode. TRIGGER_CANCEL_AUTOFOCUS will
400 * allow the AF to restart its operation.
401 *
402 * Initial state Transitions
403 * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
404 * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
405 * PASSIVE_SCAN (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
406 * AF_FOCUSED (K) no effect except to change next notification ID to N
407 * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
408 *
409 * Ext1 is an ID that must be returned in subsequent auto-focus state change
410 * notifications through camera2_notify_callback() and stored in
411 * android.control.afTriggerId.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700412 */
413 CAMERA2_TRIGGER_AUTOFOCUS = 0x0001,
414 /**
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700415 * Send a cancel message to the autofocus algorithm. The effect of the
416 * cancellation depends on the autofocus mode in effect when the trigger is
417 * received, which is the mode listed in the latest capture request to be
418 * dequeued by the HAL. If the AF mode is OFF or EDOF, the cancel has no
419 * effect. For other modes, the lens should return to its default position,
420 * any current autofocus scan must be canceled, and the AF state should be
421 * set to INACTIVE.
422 *
423 * The state of the autofocus cycle can be tracked in android.control.afMode
424 * and the corresponding notification. Continuous autofocus modes may resume
425 * focusing operations thereafter exactly as if the camera had just been set
426 * to a continuous AF mode.
427 *
428 * Ext1 is an ID that must be returned in subsequent auto-focus state change
429 * notifications through camera2_notify_callback() and stored in
430 * android.control.afTriggerId.
431 */
432 CAMERA2_TRIGGER_CANCEL_AUTOFOCUS,
433 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700434 * Trigger a pre-capture metering cycle, which may include firing the flash
435 * to determine proper capture parameters. Typically, this trigger would be
436 * fired for a half-depress of a camera shutter key, or before a snapshot
437 * capture in general. The state of the metering cycle can be tracked in
438 * android.control.aeMode and the corresponding notification. If the
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700439 * auto-exposure mode is OFF, the trigger does nothing.
440 *
441 * Ext1 is an ID that must be returned in subsequent
442 * auto-exposure/auto-white balance state change notifications through
443 * camera2_notify_callback() and stored in android.control.aePrecaptureId.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700444 */
445 CAMERA2_TRIGGER_PRECAPTURE_METERING
446};
447
448/**
449 * Possible template types for construct_default_request()
450 */
451enum {
452 /**
453 * Standard camera preview operation with 3A on auto.
454 */
455 CAMERA2_TEMPLATE_PREVIEW = 1,
456 /**
457 * Standard camera high-quality still capture with 3A and flash on auto.
458 */
459 CAMERA2_TEMPLATE_STILL_CAPTURE,
460 /**
461 * Standard video recording plus preview with 3A on auto, torch off.
462 */
463 CAMERA2_TEMPLATE_VIDEO_RECORD,
464 /**
465 * High-quality still capture while recording video. Application will
466 * include preview, video record, and full-resolution YUV or JPEG streams in
467 * request. Must not cause stuttering on video stream. 3A on auto.
468 */
469 CAMERA2_TEMPLATE_VIDEO_SNAPSHOT,
470 /**
471 * Zero-shutter-lag mode. Application will request preview and
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700472 * full-resolution data for each frame, and reprocess it to JPEG when a
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700473 * still image is requested by user. Settings should provide highest-quality
474 * full-resolution images without compromising preview frame rate. 3A on
475 * auto.
476 */
Eino-Ville Talvala6adfd6b2012-05-14 15:25:27 -0700477 CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG,
478
479 /* Total number of templates */
480 CAMERA2_TEMPLATE_COUNT
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700481};
482
483
484/**********************************************************************
485 *
486 * Camera device operations
487 *
488 */
489typedef struct camera2_device_ops {
490
491 /**********************************************************************
492 * Request and frame queue setup and management methods
493 */
494
495 /**
496 * Pass in input request queue interface methods.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800497 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700498 int (*set_request_queue_src_ops)(const struct camera2_device *,
499 const camera2_request_queue_src_ops_t *request_src_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800500
501 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700502 * Notify device that the request queue is no longer empty. Must only be
503 * called when the first buffer is added a new queue, or after the source
504 * has returned NULL in response to a dequeue call.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800505 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700506 int (*notify_request_queue_not_empty)(const struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800507
508 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700509 * Pass in output frame queue interface methods
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800510 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700511 int (*set_frame_queue_dst_ops)(const struct camera2_device *,
512 const camera2_frame_queue_dst_ops_t *frame_dst_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800513
514 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700515 * Number of camera requests being processed by the device at the moment
516 * (captures/reprocesses that have had their request dequeued, but have not
517 * yet been enqueued onto output pipeline(s) ). No streams may be released
518 * by the framework until the in-progress count is 0.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800519 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700520 int (*get_in_progress_count)(const struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800521
522 /**
523 * Flush all in-progress captures. This includes all dequeued requests
524 * (regular or reprocessing) that have not yet placed any outputs into a
525 * stream or the frame queue. Partially completed captures must be completed
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700526 * normally. No new requests may be dequeued from the request queue until
527 * the flush completes.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800528 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700529 int (*flush_captures_in_progress)(const struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800530
531 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700532 * Create a filled-in default request for standard camera use cases.
533 *
534 * The device must return a complete request that is configured to meet the
535 * requested use case, which must be one of the CAMERA2_TEMPLATE_*
536 * enums. All request control fields must be included, except for
Eino-Ville Talvalafa7a91d2012-05-22 10:41:20 -0700537 * android.request.outputStreams.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700538 *
539 * The metadata buffer returned must be allocated with
540 * allocate_camera_metadata. The framework takes ownership of the buffer.
541 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700542 int (*construct_default_request)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700543 int request_template,
544 camera_metadata_t **request);
545
546 /**********************************************************************
547 * Stream management
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800548 */
549
550 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700551 * allocate_stream:
552 *
553 * Allocate a new output stream for use, defined by the output buffer width,
554 * height, target, and possibly the pixel format. Returns the new stream's
555 * ID, gralloc usage flags, minimum queue buffer count, and possibly the
556 * pixel format, on success. Error conditions:
557 *
558 * - Requesting a width/height/format combination not listed as
559 * supported by the sensor's static characteristics
560 *
561 * - Asking for too many streams of a given format type (2 bayer raw
562 * streams, for example).
563 *
564 * Input parameters:
565 *
566 * - width, height, format: Specification for the buffers to be sent through
567 * this stream. Format is a value from the HAL_PIXEL_FORMAT_* list, or
568 * CAMERA2_HAL_PIXEL_FORMAT_OPAQUE. In the latter case, the camera device
569 * must select an appropriate (possible platform-specific) HAL pixel
570 * format to return in format_actual. In the former case, format_actual
571 * must be set to match format.
572 *
573 * - stream_ops: A structure of function pointers for obtaining and queuing
574 * up buffers for this stream. The underlying stream will be configured
575 * based on the usage and max_buffers outputs. The methods in this
576 * structure may not be called until after allocate_stream returns.
577 *
578 * Output parameters:
579 *
580 * - stream_id: An unsigned integer identifying this stream. This value is
581 * used in incoming requests to identify the stream, and in releasing the
582 * stream.
583 *
584 * - format_actual: If the input format is CAMERA2_HAL_PIXEL_FORMAT_OPAQUE,
585 * then device must select the appropriate (possible platform-specific)
586 * pixel format and return it in *format_actual. It will be treated as an
587 * opaque value by the framework, and simply passed to the gralloc module
588 * when new buffers need to be allocated. If the input format is one of
589 * the values from HAL_PIXEL_FORMAT_* list, then *format_actual must be
590 * set equal to format. In the latter case, format_actual may also be
591 * NULL, in which case it can be ignored as an output.
592 *
593 * - usage: The gralloc usage mask needed by the HAL device for producing
594 * the requested type of data. This is used in allocating new gralloc
595 * buffers for the stream buffer queue.
596 *
597 * - max_buffers: The maximum number of buffers the HAL device may need to
598 * have dequeued at the same time. The device may not dequeue more buffers
599 * than this value at the same time.
600 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800601 */
602 int (*allocate_stream)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700603 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700604 // inputs
605 uint32_t width,
606 uint32_t height,
607 int format,
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700608 const camera2_stream_ops_t *stream_ops,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700609 // outputs
610 uint32_t *stream_id,
611 uint32_t *format_actual,
612 uint32_t *usage,
613 uint32_t *max_buffers);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800614
615 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700616 * Register buffers for a given stream. This is called after a successful
617 * allocate_stream call, and before the first request referencing the stream
618 * is enqueued. This method is intended to allow the HAL device to map or
619 * otherwise prepare the buffers for later use. num_buffers is guaranteed to
620 * be at least max_buffers (from allocate_stream), but may be larger. The
621 * buffers will already be locked for use. At the end of the call, all the
622 * buffers must be ready to be returned to the queue.
623 */
624 int (*register_stream_buffers)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700625 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700626 uint32_t stream_id,
627 int num_buffers,
628 buffer_handle_t *buffers);
629
630 /**
631 * Release a stream. Returns an error if called when get_in_progress_count
632 * is non-zero, or if the stream id is invalid.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800633 */
634 int (*release_stream)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700635 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700636 uint32_t stream_id);
637
638 /**
639 * allocate_reprocess_stream:
640 *
641 * Allocate a new input stream for use, defined by the output buffer width,
642 * height, and the pixel format. Returns the new stream's ID, gralloc usage
643 * flags, and required simultaneously acquirable buffer count, on
644 * success. Error conditions:
645 *
646 * - Requesting a width/height/format combination not listed as
647 * supported by the sensor's static characteristics
648 *
649 * - Asking for too many reprocessing streams to be configured at once.
650 *
651 * Input parameters:
652 *
653 * - width, height, format: Specification for the buffers to be sent through
654 * this stream. Format must be a value from the HAL_PIXEL_FORMAT_* list.
655 *
656 * - reprocess_stream_ops: A structure of function pointers for acquiring
657 * and releasing buffers for this stream. The underlying stream will be
658 * configured based on the usage and max_buffers outputs.
659 *
660 * Output parameters:
661 *
662 * - stream_id: An unsigned integer identifying this stream. This value is
663 * used in incoming requests to identify the stream, and in releasing the
664 * stream. These ids are numbered separately from the input stream ids.
665 *
666 * - consumer_usage: The gralloc usage mask needed by the HAL device for
667 * consuming the requested type of data. This is used in allocating new
668 * gralloc buffers for the stream buffer queue.
669 *
670 * - max_buffers: The maximum number of buffers the HAL device may need to
671 * have acquired at the same time. The device may not have more buffers
672 * acquired at the same time than this value.
673 *
674 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700675 int (*allocate_reprocess_stream)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700676 uint32_t width,
677 uint32_t height,
678 uint32_t format,
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700679 const camera2_stream_in_ops_t *reprocess_stream_ops,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700680 // outputs
681 uint32_t *stream_id,
682 uint32_t *consumer_usage,
683 uint32_t *max_buffers);
684
685 /**
686 * Release a reprocessing stream. Returns an error if called when
687 * get_in_progress_count is non-zero, or if the stream id is not
688 * valid.
689 */
690 int (*release_reprocess_stream)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700691 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700692 uint32_t stream_id);
693
694 /**********************************************************************
695 * Miscellaneous methods
696 */
697
698 /**
699 * Trigger asynchronous activity. This is used for triggering special
700 * behaviors of the camera 3A routines when they are in use. See the
701 * documentation for CAMERA2_TRIGGER_* above for details of the trigger ids
702 * and their arguments.
703 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700704 int (*trigger_action)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700705 uint32_t trigger_id,
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700706 int32_t ext1,
707 int32_t ext2);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700708
709 /**
710 * Notification callback setup
711 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700712 int (*set_notify_callback)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700713 camera2_notify_callback notify_cb,
714 void *user);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800715
716 /**
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700717 * Get methods to query for vendor extension metadata tag infomation. May
718 * set ops to NULL if no vendor extension tags are defined.
719 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700720 int (*get_metadata_vendor_tag_ops)(const struct camera2_device*,
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700721 vendor_tag_query_ops_t **ops);
722
723 /**
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800724 * Dump state of the camera hardware
725 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700726 int (*dump)(const struct camera2_device *, int fd);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800727
728} camera2_device_ops_t;
729
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700730/**********************************************************************
731 *
732 * Camera device definition
733 *
734 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800735typedef struct camera2_device {
736 /**
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700737 * common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800738 * this device as implementing version 2.0 of the camera device HAL.
739 */
740 hw_device_t common;
741 camera2_device_ops_t *ops;
742 void *priv;
743} camera2_device_t;
744
745__END_DECLS
746
747#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */