blob: 8b789ec497d60626be7844246956a2fe457ddc75 [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 Talvala2388a2d2012-08-28 14:01:26 -070099/**
100 * Temporary definition during transition. TODO: Remove once HALs no longer
101 * reference this */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700102enum {
Eino-Ville Talvala2388a2d2012-08-28 14:01:26 -0700103 CAMERA2_HAL_PIXEL_FORMAT_OPAQUE = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700104};
105
106/**
107 * Input reprocess stream queue management. A set of these methods is provided
Eino-Ville Talvalafa7a91d2012-05-22 10:41:20 -0700108 * to the HAL device in allocate_reprocess_stream(); they are used to interact
109 * with the reprocess stream's input gralloc buffer queue.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700110 */
111typedef struct camera2_stream_in_ops {
112 /**
113 * Get the next buffer of image data to reprocess. The width, height, and
114 * format of the buffer is fixed in allocate_reprocess_stream(), and the
115 * stride and other details should be queried from the platform gralloc
116 * module as needed. The buffer will already be locked for use.
117 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700118 int (*acquire_buffer)(const struct camera2_stream_in_ops *w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700119 buffer_handle_t** buffer);
120 /**
121 * Return a used buffer to the buffer queue for reuse.
122 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700123 int (*release_buffer)(const struct camera2_stream_in_ops *w,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700124 buffer_handle_t* buffer);
125
126} camera2_stream_in_ops_t;
127
128/**********************************************************************
129 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800130 * Metadata queue management, used for requests sent to HAL module, and for
131 * frames produced by the HAL.
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700132 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800133 */
134
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700135enum {
136 CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS = -1
137};
138
139/**
140 * Request input queue protocol:
141 *
142 * The framework holds the queue and its contents. At start, the queue is empty.
143 *
144 * 1. When the first metadata buffer is placed into the queue, the framework
145 * signals the device by calling notify_request_queue_not_empty().
146 *
147 * 2. After receiving notify_request_queue_not_empty, the device must call
148 * dequeue() once it's ready to handle the next buffer.
149 *
150 * 3. Once the device has processed a buffer, and is ready for the next buffer,
151 * it must call dequeue() again instead of waiting for a notification. If
152 * there are no more buffers available, dequeue() will return NULL. After
153 * this point, when a buffer becomes available, the framework must call
154 * notify_request_queue_not_empty() again. If the device receives a NULL
155 * return from dequeue, it does not need to query the queue again until a
156 * notify_request_queue_not_empty() call is received from the source.
157 *
158 * 4. If the device calls buffer_count() and receives 0, this does not mean that
159 * the framework will provide a notify_request_queue_not_empty() call. The
160 * framework will only provide such a notification after the device has
161 * received a NULL from dequeue, or on initial startup.
162 *
163 * 5. The dequeue() call in response to notify_request_queue_not_empty() may be
164 * on the same thread as the notify_request_queue_not_empty() call, and may
165 * be performed from within the notify call.
166 *
167 * 6. All dequeued request buffers must be returned to the framework by calling
168 * free_request, including when errors occur, a device flush is requested, or
169 * when the device is shutting down.
170 */
171typedef struct camera2_request_queue_src_ops {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800172 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700173 * Get the count of request buffers pending in the queue. May return
174 * CAMERA2_REQUEST_QUEUE_IS_BOTTOMLESS if a repeating request (stream
175 * request) is currently configured. Calling this method has no effect on
176 * whether the notify_request_queue_not_empty() method will be called by the
177 * framework.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800178 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700179 int (*request_count)(const struct camera2_request_queue_src_ops *q);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800180
181 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700182 * Get a metadata buffer from the framework. Returns OK if there is no
183 * error. If the queue is empty, returns NULL in buffer. In that case, the
184 * device must wait for a notify_request_queue_not_empty() message before
185 * attempting to dequeue again. Buffers obtained in this way must be
186 * returned to the framework with free_request().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800187 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700188 int (*dequeue_request)(const struct camera2_request_queue_src_ops *q,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800189 camera_metadata_t **buffer);
190 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700191 * Return a metadata buffer to the framework once it has been used, or if
192 * an error or shutdown occurs.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800193 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700194 int (*free_request)(const struct camera2_request_queue_src_ops *q,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800195 camera_metadata_t *old_buffer);
196
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700197} camera2_request_queue_src_ops_t;
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800198
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700199/**
200 * Frame output queue protocol:
201 *
202 * The framework holds the queue and its contents. At start, the queue is empty.
203 *
204 * 1. When the device is ready to fill an output metadata frame, it must dequeue
205 * a metadata buffer of the required size.
206 *
207 * 2. It should then fill the metadata buffer, and place it on the frame queue
208 * using enqueue_frame. The framework takes ownership of the frame.
209 *
210 * 3. In case of an error, a request to flush the pipeline, or shutdown, the
211 * device must return any affected dequeued frames to the framework by
212 * calling cancel_frame.
213 */
214typedef struct camera2_frame_queue_dst_ops {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800215 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700216 * Get an empty metadata buffer to fill from the framework. The new metadata
217 * buffer will have room for entries number of metadata entries, plus
218 * data_bytes worth of extra storage. Frames dequeued here must be returned
219 * to the framework with either cancel_frame or enqueue_frame.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800220 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700221 int (*dequeue_frame)(const struct camera2_frame_queue_dst_ops *q,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700222 size_t entries, size_t data_bytes,
223 camera_metadata_t **buffer);
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700224
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700225 /**
226 * Return a dequeued metadata buffer to the framework for reuse; do not mark it as
227 * filled. Use when encountering errors, or flushing the internal request queue.
228 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700229 int (*cancel_frame)(const struct camera2_frame_queue_dst_ops *q,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700230 camera_metadata_t *buffer);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800231
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700232 /**
233 * Place a completed metadata frame on the frame output queue.
234 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700235 int (*enqueue_frame)(const struct camera2_frame_queue_dst_ops *q,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700236 camera_metadata_t *buffer);
237
238} camera2_frame_queue_dst_ops_t;
239
240/**********************************************************************
241 *
242 * Notification callback and message definition, and trigger definitions
243 *
244 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800245
246/**
247 * Asynchronous notification callback from the HAL, fired for various
248 * reasons. Only for information independent of frame capture, or that require
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700249 * specific timing. The user pointer must be the same one that was passed to the
250 * device in set_notify_callback().
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800251 */
252typedef void (*camera2_notify_callback)(int32_t msg_type,
253 int32_t ext1,
254 int32_t ext2,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700255 int32_t ext3,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800256 void *user);
257
258/**
259 * Possible message types for camera2_notify_callback
260 */
261enum {
262 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700263 * An error has occurred. Argument ext1 contains the error code, and
264 * ext2 and ext3 contain any error-specific information.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800265 */
Eino-Ville Talvaladaacbf42012-03-22 13:09:56 -0700266 CAMERA2_MSG_ERROR = 0x0001,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800267 /**
268 * The exposure of a given request has begun. Argument ext1 contains the
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700269 * frame number, and ext2 and ext3 contain the low-order and high-order
270 * bytes of the timestamp for when exposure began.
271 * (timestamp = (ext3 << 32 | ext2))
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800272 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700273 CAMERA2_MSG_SHUTTER = 0x0010,
274 /**
275 * The autofocus routine has changed state. Argument ext1 contains the new
276 * state; the values are the same as those for the metadata field
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700277 * android.control.afState. Ext2 contains the latest trigger ID passed to
278 * trigger_action(CAMERA2_TRIGGER_AUTOFOCUS) or
279 * trigger_action(CAMERA2_TRIGGER_CANCEL_AUTOFOCUS), or 0 if trigger has not
280 * been called with either of those actions.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700281 */
282 CAMERA2_MSG_AUTOFOCUS = 0x0020,
283 /**
284 * The autoexposure routine has changed state. Argument ext1 contains the
285 * new state; the values are the same as those for the metadata field
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700286 * android.control.aeState. Ext2 contains the latest trigger ID value passed to
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700287 * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
288 * has not been called.
289 */
290 CAMERA2_MSG_AUTOEXPOSURE = 0x0021,
291 /**
292 * The auto-whitebalance routine has changed state. Argument ext1 contains
293 * the new state; the values are the same as those for the metadata field
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700294 * android.control.awbState. Ext2 contains the latest trigger ID passed to
295 * trigger_action(CAMERA2_TRIGGER_PRECAPTURE_METERING), or 0 if that method
296 * has not been called.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700297 */
298 CAMERA2_MSG_AUTOWB = 0x0022
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800299};
300
301/**
302 * Error codes for CAMERA_MSG_ERROR
303 */
304enum {
305 /**
306 * A serious failure occured. Camera device may not work without reboot, and
307 * no further frames or buffer streams will be produced by the
308 * device. Device should be treated as closed.
309 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700310 CAMERA2_MSG_ERROR_HARDWARE = 0x0001,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800311 /**
312 * A serious failure occured. No further frames or buffer streams will be
313 * produced by the device. Device should be treated as closed. The client
314 * must reopen the device to use it again.
315 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700316 CAMERA2_MSG_ERROR_DEVICE,
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800317 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700318 * An error has occurred in processing a request. No output (metadata or
319 * buffers) will be produced for this request. ext2 contains the frame
320 * number of the request. Subsequent requests are unaffected, and the device
321 * remains operational.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800322 */
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700323 CAMERA2_MSG_ERROR_REQUEST,
324 /**
325 * An error has occurred in producing an output frame metadata buffer for a
326 * request, but image buffers for it will still be available. Subsequent
327 * requests are unaffected, and the device remains operational. ext2
328 * contains the frame number of the request.
329 */
330 CAMERA2_MSG_ERROR_FRAME,
331 /**
332 * An error has occurred in placing an output buffer into a stream for a
333 * request. The frame metadata and other buffers may still be
334 * available. Subsequent requests are unaffected, and the device remains
335 * operational. ext2 contains the frame number of the request, and ext3
336 * contains the stream id.
337 */
338 CAMERA2_MSG_ERROR_STREAM,
339 /**
340 * Number of error types
341 */
342 CAMERA2_MSG_NUM_ERRORS
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800343};
344
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700345/**
346 * Possible trigger ids for trigger_action()
347 */
348enum {
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800349 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700350 * Trigger an autofocus cycle. The effect of the trigger depends on the
351 * autofocus mode in effect when the trigger is received, which is the mode
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700352 * listed in the latest capture request to be dequeued by the HAL. If the
353 * mode is OFF, EDOF, or FIXED, the trigger has no effect. In AUTO, MACRO,
354 * or CONTINUOUS_* modes, see below for the expected behavior. The state of
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700355 * the autofocus cycle can be tracked in android.control.afMode and the
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700356 * corresponding notifications.
357 *
358 **
359 * In AUTO or MACRO mode, the AF state transitions (and notifications)
360 * when calling with trigger ID = N with the previous ID being K are:
361 *
362 * Initial state Transitions
363 * INACTIVE (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
364 * AF_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
365 * AF_NOT_FOCUSED (K) -> ACTIVE_SCAN (N) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
366 * ACTIVE_SCAN (K) -> AF_FOCUSED(N) or AF_NOT_FOCUSED(N)
367 * PASSIVE_SCAN (K) Not used in AUTO/MACRO mode
368 * PASSIVE_FOCUSED (K) Not used in AUTO/MACRO mode
369 *
370 **
371 * In CONTINUOUS_PICTURE mode, triggering AF must lock the AF to the current
372 * lens position and transition the AF state to either AF_FOCUSED or
373 * NOT_FOCUSED. If a passive scan is underway, that scan must complete and
374 * then lock the lens position and change AF state. TRIGGER_CANCEL_AUTOFOCUS
375 * will allow the AF to restart its operation.
376 *
377 * Initial state Transitions
378 * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
379 * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
380 * PASSIVE_SCAN (K) -> AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
381 * AF_FOCUSED (K) no effect except to change next notification ID to N
382 * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
383 *
384 **
385 * In CONTINUOUS_VIDEO mode, triggering AF must lock the AF to the current
386 * lens position and transition the AF state to either AF_FOCUSED or
387 * NOT_FOCUSED. If a passive scan is underway, it must immediately halt, in
388 * contrast with CONTINUOUS_PICTURE mode. TRIGGER_CANCEL_AUTOFOCUS will
389 * allow the AF to restart its operation.
390 *
391 * Initial state Transitions
392 * INACTIVE (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
393 * PASSIVE_FOCUSED (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
394 * PASSIVE_SCAN (K) -> immediate AF_FOCUSED (N) or AF_NOT_FOCUSED (N)
395 * AF_FOCUSED (K) no effect except to change next notification ID to N
396 * AF_NOT_FOCUSED (K) no effect except to change next notification ID to N
397 *
398 * Ext1 is an ID that must be returned in subsequent auto-focus state change
399 * notifications through camera2_notify_callback() and stored in
400 * android.control.afTriggerId.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700401 */
402 CAMERA2_TRIGGER_AUTOFOCUS = 0x0001,
403 /**
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700404 * Send a cancel message to the autofocus algorithm. The effect of the
405 * cancellation depends on the autofocus mode in effect when the trigger is
406 * received, which is the mode listed in the latest capture request to be
407 * dequeued by the HAL. If the AF mode is OFF or EDOF, the cancel has no
408 * effect. For other modes, the lens should return to its default position,
409 * any current autofocus scan must be canceled, and the AF state should be
410 * set to INACTIVE.
411 *
412 * The state of the autofocus cycle can be tracked in android.control.afMode
413 * and the corresponding notification. Continuous autofocus modes may resume
414 * focusing operations thereafter exactly as if the camera had just been set
415 * to a continuous AF mode.
416 *
417 * Ext1 is an ID that must be returned in subsequent auto-focus state change
418 * notifications through camera2_notify_callback() and stored in
419 * android.control.afTriggerId.
420 */
421 CAMERA2_TRIGGER_CANCEL_AUTOFOCUS,
422 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700423 * Trigger a pre-capture metering cycle, which may include firing the flash
424 * to determine proper capture parameters. Typically, this trigger would be
425 * fired for a half-depress of a camera shutter key, or before a snapshot
426 * capture in general. The state of the metering cycle can be tracked in
427 * android.control.aeMode and the corresponding notification. If the
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700428 * auto-exposure mode is OFF, the trigger does nothing.
429 *
430 * Ext1 is an ID that must be returned in subsequent
431 * auto-exposure/auto-white balance state change notifications through
432 * camera2_notify_callback() and stored in android.control.aePrecaptureId.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700433 */
434 CAMERA2_TRIGGER_PRECAPTURE_METERING
435};
436
437/**
438 * Possible template types for construct_default_request()
439 */
440enum {
441 /**
442 * Standard camera preview operation with 3A on auto.
443 */
444 CAMERA2_TEMPLATE_PREVIEW = 1,
445 /**
446 * Standard camera high-quality still capture with 3A and flash on auto.
447 */
448 CAMERA2_TEMPLATE_STILL_CAPTURE,
449 /**
450 * Standard video recording plus preview with 3A on auto, torch off.
451 */
452 CAMERA2_TEMPLATE_VIDEO_RECORD,
453 /**
454 * High-quality still capture while recording video. Application will
455 * include preview, video record, and full-resolution YUV or JPEG streams in
456 * request. Must not cause stuttering on video stream. 3A on auto.
457 */
458 CAMERA2_TEMPLATE_VIDEO_SNAPSHOT,
459 /**
460 * Zero-shutter-lag mode. Application will request preview and
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700461 * full-resolution data for each frame, and reprocess it to JPEG when a
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700462 * still image is requested by user. Settings should provide highest-quality
463 * full-resolution images without compromising preview frame rate. 3A on
464 * auto.
465 */
Eino-Ville Talvala6adfd6b2012-05-14 15:25:27 -0700466 CAMERA2_TEMPLATE_ZERO_SHUTTER_LAG,
467
468 /* Total number of templates */
469 CAMERA2_TEMPLATE_COUNT
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700470};
471
472
473/**********************************************************************
474 *
475 * Camera device operations
476 *
477 */
478typedef struct camera2_device_ops {
479
480 /**********************************************************************
481 * Request and frame queue setup and management methods
482 */
483
484 /**
485 * Pass in input request queue interface methods.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800486 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700487 int (*set_request_queue_src_ops)(const struct camera2_device *,
488 const camera2_request_queue_src_ops_t *request_src_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800489
490 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700491 * Notify device that the request queue is no longer empty. Must only be
492 * called when the first buffer is added a new queue, or after the source
493 * has returned NULL in response to a dequeue call.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800494 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700495 int (*notify_request_queue_not_empty)(const struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800496
497 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700498 * Pass in output frame queue interface methods
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800499 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700500 int (*set_frame_queue_dst_ops)(const struct camera2_device *,
501 const camera2_frame_queue_dst_ops_t *frame_dst_ops);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800502
503 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700504 * Number of camera requests being processed by the device at the moment
505 * (captures/reprocesses that have had their request dequeued, but have not
506 * yet been enqueued onto output pipeline(s) ). No streams may be released
507 * by the framework until the in-progress count is 0.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800508 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700509 int (*get_in_progress_count)(const struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800510
511 /**
512 * Flush all in-progress captures. This includes all dequeued requests
513 * (regular or reprocessing) that have not yet placed any outputs into a
514 * stream or the frame queue. Partially completed captures must be completed
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700515 * normally. No new requests may be dequeued from the request queue until
516 * the flush completes.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800517 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700518 int (*flush_captures_in_progress)(const struct camera2_device *);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800519
520 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700521 * Create a filled-in default request for standard camera use cases.
522 *
523 * The device must return a complete request that is configured to meet the
524 * requested use case, which must be one of the CAMERA2_TEMPLATE_*
525 * enums. All request control fields must be included, except for
Eino-Ville Talvalafa7a91d2012-05-22 10:41:20 -0700526 * android.request.outputStreams.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700527 *
528 * The metadata buffer returned must be allocated with
529 * allocate_camera_metadata. The framework takes ownership of the buffer.
530 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700531 int (*construct_default_request)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700532 int request_template,
533 camera_metadata_t **request);
534
535 /**********************************************************************
536 * Stream management
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800537 */
538
539 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700540 * allocate_stream:
541 *
542 * Allocate a new output stream for use, defined by the output buffer width,
543 * height, target, and possibly the pixel format. Returns the new stream's
544 * ID, gralloc usage flags, minimum queue buffer count, and possibly the
545 * pixel format, on success. Error conditions:
546 *
547 * - Requesting a width/height/format combination not listed as
548 * supported by the sensor's static characteristics
549 *
550 * - Asking for too many streams of a given format type (2 bayer raw
551 * streams, for example).
552 *
553 * Input parameters:
554 *
555 * - width, height, format: Specification for the buffers to be sent through
Eino-Ville Talvala2388a2d2012-08-28 14:01:26 -0700556 * this stream. Format is a value from the HAL_PIXEL_FORMAT_* list. If
557 * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
558 * gralloc module will select a format based on the usage flags provided
559 * by the camera HAL and the consumer of the stream. The camera HAL should
560 * inspect the buffers handed to it in the register_stream_buffers call to
561 * obtain the implementation-specific format if necessary.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700562 *
563 * - stream_ops: A structure of function pointers for obtaining and queuing
564 * up buffers for this stream. The underlying stream will be configured
565 * based on the usage and max_buffers outputs. The methods in this
566 * structure may not be called until after allocate_stream returns.
567 *
568 * Output parameters:
569 *
570 * - stream_id: An unsigned integer identifying this stream. This value is
571 * used in incoming requests to identify the stream, and in releasing the
572 * stream.
573 *
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700574 * - usage: The gralloc usage mask needed by the HAL device for producing
575 * the requested type of data. This is used in allocating new gralloc
576 * buffers for the stream buffer queue.
577 *
578 * - max_buffers: The maximum number of buffers the HAL device may need to
579 * have dequeued at the same time. The device may not dequeue more buffers
580 * than this value at the same time.
581 *
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800582 */
583 int (*allocate_stream)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700584 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700585 // inputs
586 uint32_t width,
587 uint32_t height,
588 int format,
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700589 const camera2_stream_ops_t *stream_ops,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700590 // outputs
591 uint32_t *stream_id,
Eino-Ville Talvala2388a2d2012-08-28 14:01:26 -0700592 uint32_t *format_actual, // IGNORED, will be removed
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700593 uint32_t *usage,
594 uint32_t *max_buffers);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800595
596 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700597 * Register buffers for a given stream. This is called after a successful
598 * allocate_stream call, and before the first request referencing the stream
599 * is enqueued. This method is intended to allow the HAL device to map or
600 * otherwise prepare the buffers for later use. num_buffers is guaranteed to
601 * be at least max_buffers (from allocate_stream), but may be larger. The
602 * buffers will already be locked for use. At the end of the call, all the
Eino-Ville Talvala2388a2d2012-08-28 14:01:26 -0700603 * buffers must be ready to be returned to the queue. If the stream format
604 * was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL should
605 * inspect the passed-in buffers here to determine any platform-private
606 * pixel format information.
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700607 */
608 int (*register_stream_buffers)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700609 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700610 uint32_t stream_id,
611 int num_buffers,
612 buffer_handle_t *buffers);
613
614 /**
615 * Release a stream. Returns an error if called when get_in_progress_count
616 * is non-zero, or if the stream id is invalid.
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800617 */
618 int (*release_stream)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700619 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700620 uint32_t stream_id);
621
622 /**
623 * allocate_reprocess_stream:
624 *
625 * Allocate a new input stream for use, defined by the output buffer width,
626 * height, and the pixel format. Returns the new stream's ID, gralloc usage
627 * flags, and required simultaneously acquirable buffer count, on
628 * success. Error conditions:
629 *
630 * - Requesting a width/height/format combination not listed as
631 * supported by the sensor's static characteristics
632 *
633 * - Asking for too many reprocessing streams to be configured at once.
634 *
635 * Input parameters:
636 *
637 * - width, height, format: Specification for the buffers to be sent through
638 * this stream. Format must be a value from the HAL_PIXEL_FORMAT_* list.
639 *
640 * - reprocess_stream_ops: A structure of function pointers for acquiring
641 * and releasing buffers for this stream. The underlying stream will be
642 * configured based on the usage and max_buffers outputs.
643 *
644 * Output parameters:
645 *
646 * - stream_id: An unsigned integer identifying this stream. This value is
647 * used in incoming requests to identify the stream, and in releasing the
648 * stream. These ids are numbered separately from the input stream ids.
649 *
650 * - consumer_usage: The gralloc usage mask needed by the HAL device for
651 * consuming the requested type of data. This is used in allocating new
652 * gralloc buffers for the stream buffer queue.
653 *
654 * - max_buffers: The maximum number of buffers the HAL device may need to
655 * have acquired at the same time. The device may not have more buffers
656 * acquired at the same time than this value.
657 *
658 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700659 int (*allocate_reprocess_stream)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700660 uint32_t width,
661 uint32_t height,
662 uint32_t format,
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700663 const camera2_stream_in_ops_t *reprocess_stream_ops,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700664 // outputs
665 uint32_t *stream_id,
666 uint32_t *consumer_usage,
667 uint32_t *max_buffers);
668
669 /**
Eino-Ville Talvala7f8dd0a2012-09-04 14:21:07 -0700670 * allocate_reprocess_stream_from_stream:
671 *
672 * Allocate a new input stream for use, which will use the buffers allocated
673 * for an existing output stream. That is, after the HAL enqueues a buffer
674 * onto the output stream, it may see that same buffer handed to it from
675 * this input reprocessing stream. After the HAL releases the buffer back to
676 * the reprocessing stream, it will be returned to the output queue for
677 * reuse.
678 *
679 * Error conditions:
680 *
681 * - Using an output stream of unsuitable size/format for the basis of the
682 * reprocessing stream.
683 *
684 * - Attempting to allocatee too many reprocessing streams at once.
685 *
686 * Input parameters:
687 *
688 * - output_stream_id: The ID of an existing output stream which has
689 * a size and format suitable for reprocessing.
690 *
691 * - reprocess_stream_ops: A structure of function pointers for acquiring
692 * and releasing buffers for this stream. The underlying stream will use
693 * the same graphics buffer handles as the output stream uses.
694 *
695 * Output parameters:
696 *
697 * - stream_id: An unsigned integer identifying this stream. This value is
698 * used in incoming requests to identify the stream, and in releasing the
699 * stream. These ids are numbered separately from the input stream ids.
700 *
701 * The HAL client must always release the reprocessing stream before it
702 * releases the output stream it is based on.
703 *
704 */
705 int (*allocate_reprocess_stream_from_stream)(const struct camera2_device *,
706 uint32_t output_stream_id,
707 const camera2_stream_in_ops_t *reprocess_stream_ops,
708 // outputs
709 uint32_t *stream_id);
710
711 /**
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700712 * Release a reprocessing stream. Returns an error if called when
713 * get_in_progress_count is non-zero, or if the stream id is not
714 * valid.
715 */
716 int (*release_reprocess_stream)(
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700717 const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700718 uint32_t stream_id);
719
720 /**********************************************************************
721 * Miscellaneous methods
722 */
723
724 /**
725 * Trigger asynchronous activity. This is used for triggering special
726 * behaviors of the camera 3A routines when they are in use. See the
727 * documentation for CAMERA2_TRIGGER_* above for details of the trigger ids
728 * and their arguments.
729 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700730 int (*trigger_action)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700731 uint32_t trigger_id,
Eino-Ville Talvalaf7a60c42012-08-03 10:56:57 -0700732 int32_t ext1,
733 int32_t ext2);
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700734
735 /**
736 * Notification callback setup
737 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700738 int (*set_notify_callback)(const struct camera2_device *,
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700739 camera2_notify_callback notify_cb,
740 void *user);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800741
742 /**
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700743 * Get methods to query for vendor extension metadata tag infomation. May
744 * set ops to NULL if no vendor extension tags are defined.
745 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700746 int (*get_metadata_vendor_tag_ops)(const struct camera2_device*,
Eino-Ville Talvalafed0c022012-03-22 13:11:05 -0700747 vendor_tag_query_ops_t **ops);
748
749 /**
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800750 * Dump state of the camera hardware
751 */
Eino-Ville Talvala08a6e5e2012-05-17 17:54:56 -0700752 int (*dump)(const struct camera2_device *, int fd);
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800753
754} camera2_device_ops_t;
755
Eino-Ville Talvala567b4a22012-04-23 09:29:38 -0700756/**********************************************************************
757 *
758 * Camera device definition
759 *
760 */
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800761typedef struct camera2_device {
762 /**
Eino-Ville Talvaladdc026e2012-03-27 16:15:25 -0700763 * common.version must equal CAMERA_DEVICE_API_VERSION_2_0 to identify
Eino-Ville Talvala8bf364e2011-12-22 13:50:37 -0800764 * this device as implementing version 2.0 of the camera device HAL.
765 */
766 hw_device_t common;
767 camera2_device_ops_t *ops;
768 void *priv;
769} camera2_device_t;
770
771__END_DECLS
772
773#endif /* #ifdef ANDROID_INCLUDE_CAMERA2_H */