blob: bc0ef415f6c47577717fea7a94fd0969752b89e6 [file] [log] [blame]
Eino-Ville Talvalad2a87752012-11-27 18:06:06 -08001/*
2 * Copyright (C) 2013 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_CAMERA3_H
18#define ANDROID_INCLUDE_CAMERA3_H
19
20#include "system/camera_metadata.h"
21#include "camera_common.h"
22
23/**
24 * Camera device HAL 3.0 [ CAMERA_DEVICE_API_VERSION_3_0 ]
25 *
26 * EXPERIMENTAL.
27 *
28 * Supports the android.hardware.Camera API.
29 *
30 * Camera devices that support this version of the HAL must return
31 * CAMERA_DEVICE_API_VERSION_3_0 in camera_device_t.common.version and in
32 * camera_info_t.device_version (from camera_module_t.get_camera_info).
33 *
34 * Camera modules that may contain version 3.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 *
38 * See camera_common.h for more versioning details.
39 *
40 * Version history:
41 *
42 * 1.0: Initial Android camera HAL (Android 4.0) [camera.h]:
43 *
44 * - Converted from C++ CameraHardwareInterface abstraction layer.
45 *
46 * - Supports android.hardware.Camera API.
47 *
48 * 2.0: Initial release of expanded-capability HAL (Android 4.2) [camera2.h]:
49 *
50 * - Sufficient for implementing existing android.hardware.Camera API.
51 *
52 * - Allows for ZSL queue in camera service layer
53 *
54 * - Not tested for any new features such manual capture control, Bayer RAW
55 * capture, reprocessing of RAW data.
56 *
57 * 3.0: First revision of expanded-capability HAL:
58 *
59 * - Major version change since the ABI is completely different. No change to
60 * the required hardware capabilities or operational model from 2.0.
61 *
62 * - Reworked input request and stream queue interfaces: Framework calls into
63 * HAL with next request and stream buffers already dequeued. Sync framework
64 * support is included, necessary for efficient implementations.
65 *
66 * - Moved triggers into requests, most notifications into results.
67 *
68 * - Consolidated all callbacks into framework into one structure, and all
69 * setup methods into a single initialize() call.
70 *
71 * - Made stream configuration into a single call to simplify stream
72 * management. Bidirectional streams replace STREAM_FROM_STREAM construct.
73 *
74 * - Limited mode semantics for older/limited hardware devices.
75 */
76
77/**
78 * Startup and general expected operation sequence:
79 *
80 * 1. Framework calls camera_module_t->common.open(), which returns a
81 * hardware_device_t structure.
82 *
83 * 2. Framework inspects the hardware_device_t->version field, and instantiates
84 * the appropriate handler for that version of the camera hardware device. In
85 * case the version is CAMERA_DEVICE_API_VERSION_3_0, the device is cast to
86 * a camera3_device_t.
87 *
88 * 3. Framework calls camera3_device_t->ops->initialize() with the framework
89 * callback function pointers. This will only be called this one time after
90 * open(), before any other functions in the ops structure are called.
91 *
92 * 4. The framework calls camera3_device_t->ops->configure_streams() with a list
93 * of input/output streams to the HAL device.
94 *
95 * 5. The framework allocates gralloc buffers and calls
96 * camera3_device_t->ops->register_stream_buffers() for at least one of the
97 * output streams listed in configure_streams. The same stream is registered
98 * only once.
99 *
100 * 5. The framework requests default settings for some number of use cases with
101 * calls to camera3_device_t->ops->construct_default_request_settings(). This
102 * may occur any time after step 3.
103 *
104 * 7. The framework constructs and sends the first capture request to the HAL,
105 * with settings based on one of the sets of default settings, and with at
106 * least one output stream, which has been registered earlier by the
107 * framework. This is sent to the HAL with
108 * camera3_device_t->ops->process_capture_request(). The HAL must block the
109 * return of this call until it is ready for the next request to be sent.
110 *
111 * 8. The framework continues to submit requests, and possibly call
112 * register_stream_buffers() for not-yet-registered streams, and call
113 * construct_default_request_settings to get default settings buffers for
114 * other use cases.
115 *
116 * 9. When the capture of a request begins (sensor starts exposing for the
117 * capture), the HAL calls camera3_callback_ops_t->notify() with the SHUTTER
118 * event, including the frame number and the timestamp for start of exposure.
119 *
120 * 10. After some pipeline delay, the HAL begins to return completed captures to
121 * the framework with camera3_callback_ops_t->process_capture_result(). These
122 * are returned in the same order as the requests were submitted. Multiple
123 * requests can be in flight at once, depending on the pipeline depth of the
124 * camera HAL device.
125 *
126 * 11. After some time, the framework may stop submitting new requests, wait for
127 * the existing captures to complete (all buffers filled, all results
128 * returned), and then call configure_streams() again. This resets the camera
129 * hardware and pipeline for a new set of input/output streams. Some streams
130 * may be reused from the previous configuration; if these streams' buffers
131 * had already been registered with the HAL, they will not be registered
132 * again. The framework then continues from step 7, if at least one
133 * registered output stream remains (otherwise, step 5 is required first).
134 *
135 * 12. Alternatively, the framework may call camera3_device_t->common->close()
136 * to end the camera session. This may be called at any time, although the
137 * call may block until all in-flight captures have completed (all results
138 * returned, all buffers filled). After the close call returns, no more calls
139 * to the camera3_callback_ops_t functions are allowed from the HAL. The
140 * framework may not call any methods on the HAL device interface again after
141 * close() returns.
142 *
143 * 13. In case of an error or other asynchronous event, the HAL must call
144 * camera3_callback_ops_t->notify() with the appropriate error/event
145 * message. After returning from a fatal device-wide error notification, the
146 * HAL should act as if close() had been called on it. However, the HAL must
147 * either cancel or complete all outstanding captures before calling
148 * notify(), so that once notify() is called with a fatal error, the
149 * framework will not receive further callbacks from the device. Methods
150 * besides close() should return -ENODEV or NULL after the notify() method
151 * returns from a fatal error message.
152 */
153
154/**
155 * Operational modes:
156 *
157 * The camera 3 HAL device can implement one of two possible operational modes;
158 * limited and full. Full support is expected from new higher-end
159 * devices. Limited mode has hardware requirements roughly in line with those
160 * for a camera HAL device v1 implementation, and is expected from older or
161 * inexpensive devices. Full is a strict superset of limited, and they share the
162 * same essential operational flow, as documented above.
163 *
164 * The HAL must indicate its level of support with the
165 * android.info.supportedHardwareLevel static metadata entry, with 0 indicating
166 * limited mode, and 1 indicating full mode support.
167 *
168 * Roughly speaking, limited-mode devices do not allow for application control
169 * of capture settings (3A control only), high-rate capture of high-resolution
170 * images, raw sensor readout, and support for YUV output streams maximum
171 * recording resolution (JPEG only for large images).
172 *
173 * ** Details of limited mode behavior:
174 *
175 * - Limited-mode devices do not need to implement accurate synchronization
176 * between capture request settings and the actual image data
177 * captured. Instead, changes to settings may take effect some time in the
178 * future, and possibly not for the same output frame for each settings
179 * entry. Rapid changes in settings may result in some settings never being
180 * used for a capture. However, captures that include high-resolution output
181 * buffers ( > 1080p ) have to use the settings as specified (but see below
182 * for processing rate).
183 *
184 * - Limited-mode devices do not need to support most of the
185 * settings/result/static info metadata. Full-mode devices must support all
186 * metadata fields listed in TODO. Specifically, only the following settings
187 * are expected to be consumed or produced by a limited-mode HAL device:
188 *
189 * android.control.aeAntibandingMode (controls)
190 * android.control.aeExposureCompensation (controls)
191 * android.control.aeLock (controls)
192 * android.control.aeMode (controls)
193 * [OFF means ON_FLASH_TORCH - TODO]
194 * android.control.aeRegions (controls)
195 * android.control.aeTargetFpsRange (controls)
196 * android.control.afMode (controls)
197 * [OFF means infinity focus]
198 * android.control.afRegions (controls)
199 * android.control.awbLock (controls)
200 * android.control.awbMode (controls)
201 * [OFF not supported]
202 * android.control.awbRegions (controls)
203 * android.control.captureIntent (controls)
204 * android.control.effectMode (controls)
205 * android.control.mode (controls)
206 * [OFF not supported]
207 * android.control.sceneMode (controls)
208 * android.control.videoStabilizationMode (controls)
209 * android.control.aeAvailableAntibandingModes (static)
210 * android.control.aeAvailableModes (static)
211 * android.control.aeAvailableTargetFpsRanges (static)
212 * android.control.aeCompensationRange (static)
213 * android.control.aeCompensationStep (static)
214 * android.control.afAvailableModes (static)
215 * android.control.availableEffects (static)
216 * android.control.availableSceneModes (static)
217 * android.control.availableVideoStabilizationModes (static)
218 * android.control.awbAvailableModes (static)
219 * android.control.maxRegions (static)
220 * android.control.sceneModeOverrides (static)
221 * android.control.aeRegions (dynamic)
222 * android.control.aeState (dynamic)
223 * android.control.afMode (dynamic)
224 * android.control.afRegions (dynamic)
225 * android.control.afState (dynamic)
226 * android.control.awbMode (dynamic)
227 * android.control.awbRegions (dynamic)
228 * android.control.awbState (dynamic)
229 * android.control.mode (dynamic)
230 *
231 * android.flash.info.available (static)
232 *
233 * android.info.supportedHardwareLevel (static)
234 *
235 * android.jpeg.gpsCoordinates (controls)
236 * android.jpeg.gpsProcessingMethod (controls)
237 * android.jpeg.gpsTimestamp (controls)
238 * android.jpeg.orientation (controls)
239 * android.jpeg.quality (controls)
240 * android.jpeg.thumbnailQuality (controls)
241 * android.jpeg.thumbnailSize (controls)
242 * android.jpeg.availableThumbnailSizes (static)
243 * android.jpeg.maxSize (static)
244 * android.jpeg.gpsCoordinates (dynamic)
245 * android.jpeg.gpsProcessingMethod (dynamic)
246 * android.jpeg.gpsTimestamp (dynamic)
247 * android.jpeg.orientation (dynamic)
248 * android.jpeg.quality (dynamic)
249 * android.jpeg.size (dynamic)
250 * android.jpeg.thumbnailQuality (dynamic)
251 * android.jpeg.thumbnailSize (dynamic)
252 *
253 * android.lens.info.minimumFocusDistance (static)
254 *
255 * android.request.id (controls)
256 * android.request.id (dynamic)
257 *
258 * android.scaler.cropRegion (controls)
259 * [ignores (x,y), assumes center-zoom]
260 * android.scaler.availableFormats (static)
261 * [RAW not supported]
262 * android.scaler.availableJpegMinDurations (static)
263 * android.scaler.availableJpegSizes (static)
264 * android.scaler.availableMaxDigitalZoom (static)
265 * android.scaler.availableProcessedMinDurations (static)
266 * android.scaler.availableProcessedSizes (static)
267 * [full resolution not supported]
268 * android.scaler.maxDigitalZoom (static)
269 * android.scaler.cropRegion (dynamic)
270 *
271 * android.sensor.orientation (static)
272 * android.sensor.timestamp (dynamic)
273 *
274 * android.statistics.faceDetectMode (controls)
275 * android.statistics.info.availableFaceDetectModes (static)
276 * android.statistics.faceDetectMode (dynamic)
277 * android.statistics.faceIds (dynamic)
278 * android.statistics.faceLandmarks (dynamic)
279 * android.statistics.faceRectangles (dynamic)
280 * android.statistics.faceScores (dynamic)
281 *
282 * - Captures in limited mode that include high-resolution (> 1080p) output
283 * buffers may block in process_capture_request() until all the output buffers
284 * have been filled. A full-mode HAL device must process sequences of
285 * high-resolution requests at the rate indicated in the static metadata for
286 * that pixel format. The HAL must still call process_capture_result() to
287 * provide the output; the framework must simply be prepared for
288 * process_capture_request() to block until after process_capture_result() for
289 * that request completes for high-resolution captures for limited-mode
290 * devices.
291 *
292 */
293
294/**
295 * Error management:
296 *
297 * Camera HAL device ops functions that have a return value will all return
298 * -ENODEV / NULL in case of a serious error. This means the device cannot
299 * continue operation, and must be closed by the framework. Once this error is
300 * returned by some method, or if notify() is called with ERROR_DEVICE or
301 * ERROR_HARDWARE, only the close() method can be called successfully. All other
302 * methods will return -ENODEV / NULL.
303 *
304 * Transient errors in image capture must be reported through notify() as follows:
305 *
306 * - The failure of an entire capture to occur must be reported by the HAL by
307 * calling notify() with ERROR_REQUEST. Individual errors for the result
308 * metadata or the output buffers must not be reported in this case.
309 *
310 * - If the metadata for a capture cannot be produced, but some image buffers
311 * were filled, the HAL must call notify() with ERROR_RESULT.
312 *
313 * - If an output image buffer could not be filled, but either the metadata was
314 * produced or some other buffers were filled, the HAL must call notify() with
315 * ERROR_BUFFER for each failed buffer.
316 *
317 * In each of these transient failure cases, the HAL must still call
318 * process_capture_result, with valid output buffer_handle_t. If the result
319 * metadata could not be produced, it should be NULL. If some buffers could not
320 * be filled, their sync fences must be set to the error state.
321 *
322 * Invalid input aguments result in -EINVAL from the appropriate methods. In
323 * that case, the framework should act as if that call had never been made.
324 *
325 */
326
327__BEGIN_DECLS
328
329struct camera3_device;
330
331/**********************************************************************
332 *
333 * Camera3 stream and stream buffer definitions.
334 *
335 * These structs and enums define the handles and contents of the input and
336 * output streams connecting the HAL to various framework and application buffer
337 * consumers. Each stream is backed by a gralloc buffer queue.
338 *
339 */
340
341/**
342 * camera3_stream_type_t:
343 *
344 * The type of the camera stream, which defines whether the camera HAL device is
345 * the producer or the consumer for that stream, and how the buffers of the
346 * stream relate to the other streams.
347 */
348typedef enum camera3_stream_type {
349 /**
350 * This stream is an output stream; the camera HAL device will be
351 * responsible for filling buffers from this stream with newly captured or
352 * reprocessed image data.
353 */
354 CAMERA3_STREAM_OUTPUT = 0,
355
356 /**
357 * This stream is an input stream; the camera HAL device will be responsible
358 * for reading buffers from this stream and sending them through the camera
359 * processing pipeline, as if the buffer was a newly captured image from the
360 * imager.
361 */
362 CAMERA3_STREAM_INPUT = 1,
363
364 /**
365 * This stream can be used for input and output. Typically, the stream is
366 * used as an output stream, but occasionally one already-filled buffer may
367 * be sent back to the HAL device for reprocessing.
368 *
369 * This kind of stream is meant generally for zero-shutter-lag features,
370 * where copying the captured image from the output buffer to the
371 * reprocessing input buffer would be expensive. The stream will be used by
372 * the framework as follows:
373 *
374 * 1. The framework includes a buffer from this stream as output buffer in a
375 * request as normal.
376 *
377 * 2. Once the HAL device returns a filled output buffer to the framework,
378 * the framework may do one of two things with the filled buffer:
379 *
380 * 2. a. The framework uses the filled data, and returns the now-used buffer
381 * to the stream queue for reuse. This behavior exactly matches the
382 * OUTPUT type of stream.
383 *
384 * 2. b. The framework wants to reprocess the filled data, and uses the
385 * buffer as an input buffer for a request. Once the HAL device has
386 * used the reprocessing buffer, it then returns it to the
387 * framework. The framework then returns the now-used buffer to the
388 * stream queue for reuse.
389 *
390 * 3. The HAL device will be given the buffer again as an output buffer for
391 * a request at some future point.
392 *
393 * Note that the HAL will always be reprocessing data it produced.
394 *
395 */
396 CAMERA3_STREAM_BIDIRECTIONAL = 2,
397
398 /**
399 * Total number of framework-defined stream types
400 */
401 CAMERA3_NUM_STREAM_TYPES
402
403} camera3_stream_type_t;
404
405/**
406 * camera3_stream_t:
407 *
408 * A handle to a single camera input or output stream. A stream is defined by
409 * the framework by its buffer resolution and format, and additionally by the
410 * HAL with the gralloc usage flags and the maximum in-flight buffer count.
411 *
412 * The stream structures are owned by the framework, but pointers to a
413 * camera3_stream passed into the HAL by configure_streams() are valid until the
414 * end of the first subsequent configure_streams() call that _does not_ include
415 * that camera3_stream as an argument, or until the end of the close() call.
416 *
417 * All camera3_stream framework-controlled members are immutable once the
418 * camera3_stream is passed into configure_streams(). The HAL may only change
419 * the HAL-controlled parameters during a configure_streams() call, except for
420 * the contents of the private pointer.
421 *
422 * If a configure_streams() call returns a non-fatal error, all active streams
423 * remain valid as if configure_streams() had not been called.
424 *
425 * The endpoint of the stream is not visible to the camera HAL device.
426 */
427typedef struct camera3_stream {
428
429 /*****
430 * Set by framework before configure_streams()
431 */
432
433 /**
434 * The type of the stream, one of the camera3_stream_type_t values.
435 */
436 int stream_type;
437
438 /**
439 * The width in pixels of the buffers in this stream
440 */
441 uint32_t width;
442
443 /**
444 * The height in pixels of the buffers in this stream
445 */
446 uint32_t height;
447
448 /**
449 * The pixel format for the buffers in this stream. Format is a value from
450 * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
451 * from device-specific headers.
452 *
453 * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
454 * gralloc module will select a format based on the usage flags provided by
455 * the camera device and the other endpoint of the stream.
456 *
457 * The camera HAL device must inspect the buffers handed to it in the
458 * subsequent register_stream_buffers() call to obtain the
459 * implementation-specific format details, if necessary.
460 */
461 int format;
462
463 /*****
464 * Set by HAL during configure_streams().
465 */
466
467 /**
468 * The gralloc usage flags for this stream, as needed by the HAL. The usage
469 * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
470 * headers.
471 *
472 * For output streams, these are the HAL's producer usage flags. For input
473 * streams, these are the HAL's consumer usage flags. The usage flags from
474 * the producer and the consumer will be combined together and then passed
475 * to the platform gralloc HAL module for allocating the gralloc buffers for
476 * each stream.
477 */
478 uint32_t usage;
479
480 /**
481 * The maximum number of buffers the HAL device may need to have dequeued at
482 * the same time. The HAL device may not have more buffers in-flight from
483 * this stream than this value.
484 */
485 uint32_t max_buffers;
486
487 /**
488 * A handle to HAL-private information for the stream. Will not be inspected
489 * by the framework code.
490 */
491 void *priv;
492
493} camera3_stream_t;
494
495/**
496 * camera3_stream_configuration_t:
497 *
498 * A structure of stream definitions, used by configure_streams(). This
499 * structure defines all the output streams and the reprocessing input
500 * stream for the current camera use case.
501 */
502typedef struct camera3_stream_configuration {
503 /**
504 * The total number of streams requested by the framework. This includes
505 * both input and output streams. The number of streams will be at least 1,
506 * and there will be at least one output-capable stream.
507 */
508 uint32_t num_streams;
509
510 /**
511 * An array of camera streams, defining the input/output configuration for
512 * the camera HAL device.
513 *
514 * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
515 * in a single configuration.
516 *
517 * At least one output-capable stream must be defined (OUTPUT or
518 * BIDIRECTIONAL).
519 */
520 camera3_stream_t *streams;
521
522} camera3_stream_configuration_t;
523
524/**
525 * camera3_stream_buffer_t:
526 *
527 * A single buffer from a camera3 stream. It includes a handle to its parent
528 * stream, the handle to the gralloc buffer itself, and sync fences
529 *
530 * The buffer does not specify whether it is to be used for input or output;
531 * that is determined by its parent stream type and how the buffer is passed to
532 * the HAL device.
533 */
534typedef struct camera3_stream_buffer {
535 /**
536 * The handle of the stream this buffer is associated with
537 */
538 camera3_stream_t *stream;
539
540 /**
541 * The native handle to the buffer
542 */
543 buffer_handle_t *buffer;
544
545 /**
546 * The acquire sync fence for this buffer. The HAL must wait on this fence
547 * fd before attempting to read from or write to this buffer.
548 *
549 * The framework may be set to -1 to indicate that no waiting is necessary
550 * for this buffer. This field should not be changed by the HAL.
551 */
552 int acquire_fence;
553
554 /**
555 * The release sync fence for this buffer. The HAL must set this fence when
556 * returning buffers to the framework, or write -1 to indicate that no
557 * waiting is required for this buffer.
558 *
559 * For the input buffer, the release fence must be set by the
560 * process_capture_request() call. For the output buffers, the fences must
561 * be set in the output_buffers array passed to process_capture_result().
562 */
563 int release_fence;
564
565} camera3_stream_buffer_t;
566
567/**
568 * camera3_stream_buffer_set_t:
569 *
570 * The complete set of gralloc buffers for a stream. This structure is given to
571 * register_stream_buffers() to allow the camera HAL device to register/map/etc
572 * newly allocated stream buffers.
573 */
574typedef struct camera3_stream_buffer_set {
575 /**
576 * The stream handle for the stream these buffers belong to
577 */
578 camera3_stream_t *stream;
579
580 /**
581 * The number of buffers in this stream. It is guaranteed to be at least
582 * stream->max_buffers.
583 */
584 uint32_t num_buffers;
585
586 /**
587 * The array of gralloc buffer handles for this stream. If the stream format
588 * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
589 * should inspect the passed-in buffers to determine any platform-private
590 * pixel format information.
591 */
592 buffer_handle_t *buffers;
593
594} camera3_stream_buffer_set_t;
595
596/**
597 * camera3_jpeg_blob:
598 *
599 * Transport header for compressed JPEG buffers in output streams.
600 *
601 * To capture JPEG images, a stream is created using the pixel format
602 * HAL_PIXEL_FORMAT_BLOB, and the static metadata field android.jpeg.maxSize is
603 * used as the buffer size. Since compressed JPEG images are of variable size,
604 * the HAL needs to include the final size of the compressed image using this
605 * structure inside the output stream buffer. The JPEG blob ID field must be set
606 * to CAMERA3_JPEG_BLOB_ID.
607 *
608 * Transport header should be at the end of the JPEG output stream buffer. That
609 * means the jpeg_blob_id must start at byte[android.jpeg.maxSize -
610 * sizeof(camera3_jpeg_blob)]. Any HAL using this transport header must
611 * account for it in android.jpeg.maxSize. The JPEG data itself starts at
612 * the beginning of the buffer and should be jpeg_size bytes long.
613 */
614typedef struct camera3_jpeg_blob {
615 uint16_t jpeg_blob_id;
616 uint32_t jpeg_size;
617} camera3_jpeg_blob_t;
618
619enum {
620 CAMERA3_JPEG_BLOB_ID = 0x00FF
621};
622
623/**********************************************************************
624 *
625 * Message definitions for the HAL notify() callback.
626 *
627 * These definitions are used for the HAL notify callback, to signal
628 * asynchronous events from the HAL device to the Android framework.
629 *
630 */
631
632/**
633 * camera3_msg_type:
634 *
635 * Indicates the type of message sent, which specifies which member of the
636 * message union is valid.
637 *
638 */
639typedef enum camera3_msg_type {
640 /**
641 * An error has occurred. camera3_notify_msg.message.error contains the
642 * error information.
643 */
644 CAMERA3_MSG_ERROR = 1,
645
646 /**
647 * The exposure of a given request has
648 * begun. camera3_notify_msg.message.shutter contains the information
649 * the capture.
650 */
651 CAMERA3_MSG_SHUTTER = 2,
652
653 /**
654 * Number of framework message types
655 */
656 CAMERA3_NUM_MESSAGES
657
658} camera3_msg_type_t;
659
660/**
661 * Defined error codes for CAMERA_MSG_ERROR
662 */
663typedef enum camera3_error_msg_code {
664 /**
665 * A serious failure occured. The camera device may not work again
666 * without reboot, and no further frames or buffer streams will be
667 * produced by the device. Device should be treated as closed. The
668 * frame_number field is unused.
669 */
670 CAMERA3_MSG_ERROR_HARDWARE = 1,
671
672 /**
673 * A serious failure occured. No further frames or buffer streams will
674 * be produced by the device. Device should be treated as closed. The
675 * client must reopen the device to use it again. The frame_number field
676 * is unused.
677 */
678 CAMERA3_MSG_ERROR_DEVICE = 2,
679
680 /**
681 * An error has occurred in processing a request. No output (metadata or
682 * buffers) will be produced for this request. The frame_number field
683 * specifies which request has been dropped. Subsequent requests are
684 * unaffected, and the device remains operational.
685 */
686 CAMERA3_MSG_ERROR_REQUEST = 3,
687
688 /**
689 * An error has occurred in producing an output result metadata buffer
690 * for a request, but output stream buffers for it will still be
691 * available. Subsequent requests are unaffected, and the device remains
692 * operational. The frame_number field specifies the request for which
693 * result metadata won't be available.
694 */
695 CAMERA3_MSG_ERROR_RESULT = 4,
696
697 /**
698 * An error has occurred in placing an output buffer into a stream for a
699 * request. The frame metadata and other buffers may still be
700 * available. Subsequent requests are unaffected, and the device remains
701 * operational. The frame_number field specifies the request for which the
702 * buffer was dropped, and error_stream contains a pointer to the stream
703 * that dropped the frame.u
704 */
705 CAMERA3_MSG_ERROR_BUFFER = 5,
706
707 /**
708 * Number of error types
709 */
710 CAMERA3_MSG_NUM_ERRORS
711
712} camera3_error_msg_code_t;
713
714/**
715 * camera3_error_msg_t:
716 *
717 * Message contents for CAMERA3_MSG_ERROR
718 */
719typedef struct camera3_error_msg {
720 /**
721 * Frame number of the request the error applies to. 0 if the frame number
722 * isn't applicable to the error.
723 */
724 uint32_t frame_number;
725
726 /**
727 * Pointer to the stream that had a failure. NULL if the stream isn't
728 * applicable to the error.
729 */
730 camera3_stream_t *error_stream;
731
732 /**
733 * The code for this error; one of the CAMERA_MSG_ERROR enum values.
734 */
735 int error_code;
736
737} camera3_error_msg_t;
738
739/**
740 * camera3_shutter_msg_t:
741 *
742 * Message contents for CAMERA3_MSG_SHUTTER
743 */
744typedef struct camera3_shutter_msg {
745 /**
746 * Frame number of the request that has begun exposure
747 */
748 uint32_t frame_number;
749
750 /**
751 * Timestamp for the start of capture. This must match the capture result
752 * metadata's sensor exposure start timestamp.
753 */
754 uint64_t timestamp;
755
756} camera3_shutter_msg_t;
757
758/**
759 * camera3_notify_msg_t:
760 *
761 * The message structure sent to camera3_callback_ops_t.notify()
762 */
763typedef struct camera3_notify_msg {
764
765 /**
766 * The message type. One of camera3_notify_msg_type, or a private extension.
767 */
768 int type;
769
770 union {
771 /**
772 * Error message contents. Valid if type is CAMERA3_MSG_ERROR
773 */
774 camera3_error_msg_t error;
775
776 /**
777 * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
778 */
779 camera3_shutter_msg_t shutter;
780
781 /**
782 * Generic message contents. Used to ensure a minimum size for custom
783 * message types.
784 */
785 uint8_t generic[32];
786 } message;
787
788} camera3_notify_msg_t;
789
790/**********************************************************************
791 *
792 * Capture request/result definitions for the HAL process_capture_request()
793 * method, and the process_capture_result() callback.
794 *
795 */
796
797/**
798 * camera3_request_template_t:
799 *
800 * Available template types for
801 * camera3_device_ops.construct_default_request_settings()
802 */
803typedef enum camera3_request_template {
804 /**
805 * Standard camera preview operation with 3A on auto.
806 */
807 CAMERA3_TEMPLATE_PREVIEW = 1,
808
809 /**
810 * Standard camera high-quality still capture with 3A and flash on auto.
811 */
812 CAMERA3_TEMPLATE_STILL_CAPTURE = 2,
813
814 /**
815 * Standard video recording plus preview with 3A on auto, torch off.
816 */
817 CAMERA3_TEMPLATE_VIDEO_RECORD = 3,
818
819 /**
820 * High-quality still capture while recording video. Application will
821 * include preview, video record, and full-resolution YUV or JPEG streams in
822 * request. Must not cause stuttering on video stream. 3A on auto.
823 */
824 CAMERA3_TEMPLATE_VIDEO_SNAPSHOT = 4,
825
826 /**
827 * Zero-shutter-lag mode. Application will request preview and
828 * full-resolution data for each frame, and reprocess it to JPEG when a
829 * still image is requested by user. Settings should provide highest-quality
830 * full-resolution images without compromising preview frame rate. 3A on
831 * auto.
832 */
833 CAMERA3_TEMPLATE_ZERO_SHUTTER_LAG = 5,
834
835 /* Total number of templates */
836 CAMERA3_TEMPLATE_COUNT,
837
838 /**
839 * First value for vendor-defined request templates
840 */
841 CAMERA3_VENDOR_TEMPLATE_START = 0x40000000
842
843} camera3_request_template_t;
844
845/**
846 * camera3_capture_request_t:
847 *
848 * A single request for image capture/buffer reprocessing, sent to the Camera
849 * HAL device by the framework in process_capture_request().
850 *
851 * The request contains the settings to be used for this capture, and the set of
852 * output buffers to write the resulting image data in. It may optionally
853 * contain an input buffer, in which case the request is for reprocessing that
854 * input buffer instead of capturing a new image with the camera sensor. The
855 * capture is identified by the frame_number.
856 *
857 * In response, the camera HAL device must send a camera3_capture_result
858 * structure asynchronously to the framework, using the process_capture_result()
859 * callback.
860 */
861typedef struct camera3_capture_request {
862 /**
863 * The frame number is an incrementing integer set by the framework to
864 * uniquely identify this capture. It needs to be returned in the result
865 * call, and is also used to identify the request in asynchronous
866 * notifications sent to camera3_callback_ops_t.notify().
867 */
868 uint32_t frame_number;
869
870 /**
871 * The settings buffer contains the capture and processing parameters for
872 * the request. As a special case, a NULL settings buffer indicates that the
873 * settings are identical to the most-recently submitted capture request. A
874 * NULL buffer cannot be used as the first submitted request after a
875 * configure_streams() call.
876 */
877 const camera_metadata_t *settings;
878
879 /**
880 * The input stream buffer to use for this request, if any.
881 *
882 * If input_buffer is NULL, then the request is for a new capture from the
883 * imager. If input_buffer is valid, the request is for reprocessing the
884 * image contained in input_buffer.
885 *
886 * In the latter case, the HAL must set the release_fence of the
887 * input_buffer to a valid sync fence, or to -1 if the HAL does not support
888 * sync, before process_capture_request() returns.
889 *
890 * The HAL is required to wait on the acquire sync fence of the input buffer
891 * before accessing it.
892 *
893 * Any input buffer included here will have been registered with the HAL
894 * through register_stream_buffers() before its inclusion in a request.
895 */
896 camera3_stream_buffer_t *input_buffer;
897
898 /**
899 * The number of output buffers for this capture request. Must be at least
900 * 1.
901 */
902 uint32_t num_output_buffers;
903
904 /**
905 * An array of num_output_buffers stream buffers, to be filled with image
906 * data from this capture/reprocess. The HAL must wait on the acquire fences
907 * of each stream buffer before writing to them. All the buffers included
908 * here will have been registered with the HAL through
909 * register_stream_buffers() before their inclusion in a request.
910 *
911 * The HAL takes ownership of the actual buffer_handle_t entries in
912 * output_buffers; the framework does not access them until they are
913 * returned in a camera3_capture_result_t.
914 */
915 const camera3_stream_buffer_t *output_buffers;
916
917} camera3_capture_request_t;
918
919/**
920 * camera3_capture_result_t:
921 *
922 * The result of a single capture/reprocess by the camera HAL device. This is
923 * sent to the framework asynchronously with process_capture_result(), in
924 * response to a single capture request sent to the HAL with
925 * process_capture_request().
926 *
927 * The result structure contains the output metadata from this capture, and the
928 * set of output buffers that have been/will be filled for this capture. Each
929 * output buffer may come with a release sync fence that the framework will wait
930 * on before reading, in case the buffer has not yet been filled by the HAL.
931 *
932 */
933typedef struct camera3_capture_result {
934 /**
935 * The frame number is an incrementing integer set by the framework in the
936 * submitted request to uniquely identify this capture. It is also used to
937 * identify the request in asynchronous notifications sent to
938 * camera3_callback_ops_t.notify().
939 */
940 uint32_t frame_number;
941
942 /**
943 * The result metadata for this capture. This contains information about the
944 * final capture parameters, the state of the capture and post-processing
945 * hardware, the state of the 3A algorithms, if enabled, and the output of
946 * any enabled statistics units.
947 */
948 const camera_metadata_t *result;
949
950 /**
951 * The number of output buffers used for this capture. Must equal the
952 * matching capture request's count.
953 */
954 uint32_t num_output_buffers;
955
956 /**
957 * The handles for the output stream buffers for this capture. They may not
958 * yet be filled at the time the HAL calls process_capture_result(); the
959 * framework will wait on the release sync fences provided by the HAL before
960 * reading the buffers.
961 *
962 * The HAL must set the stream buffer's release sync fence to a valid sync
963 * fd, or to -1 if the buffer has already been filled.
964 */
965 const camera3_stream_buffer_t *output_buffers;
966
967} camera3_capture_result_t;
968
969/**********************************************************************
970 *
971 * Callback methods for the HAL to call into the framework.
972 *
973 * These methods are used to return metadata and image buffers for a completed
974 * or failed captures, and to notify the framework of asynchronous events such
975 * as errors.
976 *
977 * The framework will not call back into the HAL from within these callbacks,
978 * and these calls will not block for extended periods.
979 *
980 */
981typedef struct camera3_callback_ops {
982
983 /**
984 * process_capture_result:
985 *
986 * Send a completed capture result metadata buffer to the framework, along
987 * with the possibly completed output stream buffers.
988 *
989 * Captures must be processed in-order, so that the Nth request submitted
990 * will match with the Nth result returned. Only one call to
991 * process_capture_request() should be made at a time to ensure correct
992 * ordering.
993 *
994 * The HAL retains ownership of result structure, which only needs to be
995 * valid to access during this call. The framework will copy whatever it
996 * needs before this call returns.
997 *
998 * The output buffers do not need to be filled yet; the framework will wait
999 * on the stream buffer release sync fence before reading the buffer
1000 * data. Therefore, this method must be called by the HAL as soon as the
1001 * result metadata is available, even if some or all of the output buffers
1002 * are still in processing. The HAL must include valid release sync fences
1003 * into each output_buffers stream buffer entry, or -1 if it does not
1004 * support streams or if that stream buffer is already filled.
1005 *
1006 * If the result buffer cannot be constructed for a request, the HAL should
1007 * return a NULL buffer here, but still provide the output buffers and their
1008 * sync fences. In addition, notify() must be called with an ERROR_RESULT
1009 * message.
1010 *
1011 * If an output buffer cannot be filled, a sync error should be produced by
1012 * the HAL for that buffer; this method should still be called with a valid
1013 * (possibly in an error state) sync fence, if the HAL is using them. In
1014 * addition, notify() must be called with a ERROR_BUFFER message.
1015 *
1016 * If the entire capture has failed, then this method still needs to be
1017 * called to return the output buffers to the framework. All the sync
1018 * fences, if used, should be in the error state, and the result metadata
1019 * should be NULL. In addition, notify() must be called with a ERROR_REQUEST
1020 * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
1021 * should not be sent.
1022 *
1023 */
1024 void (*process_capture_result)(const struct camera3_callback_ops *,
1025 const camera3_capture_result_t *result);
1026
1027 /**
1028 * notify:
1029 *
1030 * Asynchronous notification callback from the HAL, fired for various
1031 * reasons. Only for information independent of frame capture, or that
1032 * require specific timing. The ownership of the message structure remains
1033 * with the HAL, and the msg only needs to be valid for the duration of this
1034 * call.
1035 *
1036 * Multiple threads may call notify() simultaneously.
1037 */
1038 void (*notify)(const struct camera3_callback_ops *,
1039 const camera3_notify_msg_t *msg);
1040
1041} camera3_callback_ops_t;
1042
1043/**********************************************************************
1044 *
1045 * Camera device operations
1046 *
1047 */
1048typedef struct camera3_device_ops {
1049
1050 /**
1051 * initialize:
1052 *
1053 * One-time initialization to pass framework callback function pointers to
1054 * the HAL. Will be called once after a successful open() call, before any
1055 * other functions are called on the camera3_device_ops structure.
1056 *
1057 * Return values:
1058 *
1059 * 0: On successful initialization
1060 *
1061 * -ENODEV: If initialization fails. Only close() can be called successfully
1062 * by the framework after this.
1063 */
1064 int (*initialize)(const struct camera3_device *,
1065 const camera3_callback_ops_t *callback_ops);
1066
1067 /**********************************************************************
1068 * Stream management
1069 */
1070
1071 /**
1072 * configure_streams:
1073 *
1074 * Reset the HAL camera device processing pipeline and set up new input and
1075 * output streams. This call replaces any existing stream configuration with
1076 * the streams defined in the stream_list. This method will be called at
1077 * least once after initialize() before a request is submitted with
1078 * process_capture_request().
1079 *
1080 * The stream_list must contain at least one output-capable stream, and may
1081 * not contain more than one input-capable stream.
1082 *
1083 * The stream_list may contain streams that are also in the currently-active
1084 * set of streams (from the previous call to configure_stream()). These
1085 * streams will already have valid values for usage, max_buffers, and the
1086 * private pointer. If such a stream has already had its buffers registered,
1087 * register_stream_buffers() will not be called again for the stream, and
1088 * buffers from the stream can be immediately included in input requests.
1089 *
1090 * If the HAL needs to change the stream configuration for an existing
1091 * stream due to the new configuration, it may rewrite the values of usage
1092 * and/or max_buffers during the configure call. The framework will detect
1093 * such a change, and will then reallocate the stream buffers, and call
1094 * register_stream_buffers() again before using buffers from that stream in
1095 * a request.
1096 *
1097 * If a currently-active stream is not included in stream_list, the HAL may
1098 * safely remove any references to that stream. It will not be reused in a
1099 * later configure() call by the framework, and all the gralloc buffers for
1100 * it will be freed after the configure_streams() call returns.
1101 *
1102 * The stream_list structure is owned by the framework, and may not be
1103 * accessed once this call completes. The address of an individual
1104 * camera3_stream_t structure will remain valid for access by the HAL until
1105 * the end of the first configure_stream() call which no longer includes
1106 * that camera3_stream_t in the stream_list argument. The HAL may not change
1107 * values in the stream structure outside of the private pointer, except for
1108 * the usage and max_buffers members during the configure_streams() call
1109 * itself.
1110 *
1111 * If the stream is new, the usage, max_buffer, and private pointer fields
1112 * of the stream structure will all be set to 0. The HAL device must set
1113 * these fields before the configure_streams() call returns. These fields
1114 * are then used by the framework and the platform gralloc module to
1115 * allocate the gralloc buffers for each stream.
1116 *
1117 * Before such a new stream can have its buffers included in a capture
1118 * request, the framework will call register_stream_buffers() with that
1119 * stream. However, the framework is not required to register buffers for
1120 * _all_ streams before submitting a request. This allows for quick startup
1121 * of (for example) a preview stream, with allocation for other streams
1122 * happening later or concurrently.
1123 *
1124 * Preconditions:
1125 *
1126 * The framework will only call this method when no captures are being
1127 * processed. That is, all results have been returned to the framework, and
1128 * all in-flight input and output buffers have been returned and their
1129 * release sync fences have been signaled by the HAL. The framework will not
1130 * submit new requests for capture while the configure_streams() call is
1131 * underway.
1132 *
1133 * Postconditions:
1134 *
1135 * The HAL device must configure itself to provide maximum possible output
1136 * frame rate given the sizes and formats of the output streams, as
1137 * documented in the camera device's static metadata.
1138 *
1139 * Performance expectations:
1140 *
1141 * This call is expected to be heavyweight and possibly take several hundred
1142 * milliseconds to complete, since it may require resetting and
1143 * reconfiguring the image sensor and the camera processing pipeline.
1144 * Nevertheless, the HAL device should attempt to minimize the
1145 * reconfiguration delay to minimize the user-visible pauses during
1146 * application operational mode changes (such as switching from still
1147 * capture to video recording).
1148 *
1149 * Return values:
1150 *
1151 * 0: On successful stream configuration
1152 *
1153 * -EINVAL: If the requested stream configuration is invalid. Some examples
1154 * of invalid stream configurations include:
1155 *
1156 * - Including more than 1 input-capable stream (INPUT or
1157 * BIDIRECTIONAL)
1158 *
1159 * - Not including any output-capable streams (OUTPUT or
1160 * BIDIRECTIONAL)
1161 *
1162 * - Including streams with unsupported formats, or an unsupported
1163 * size for that format.
1164 *
1165 * - Including too many output streams of a certain format.
1166 *
1167 * -ENODEV: If there has been a fatal error and the device is no longer
1168 * operational. Only close() can be called successfully by the
1169 * framework after this error is returned.
1170 */
1171 int (*configure_streams)(const struct camera3_device *,
1172 camera3_stream_configuration_t *stream_list);
1173
1174 /**
1175 * register_stream_buffers:
1176 *
1177 * Register buffers for a given stream with the HAL device. This method is
1178 * called by the framework after a new stream is defined by
1179 * configure_streams, and before buffers from that stream are included in a
1180 * capture request. If the same stream is listed in a subsequent
1181 * configure_streams() call, register_stream_buffers will _not_ be called
1182 * again for that stream.
1183 *
1184 * The framework does not need to register buffers for all configured
1185 * streams before it submits the first capture request. This allows quick
1186 * startup for preview (or similar use cases) while other streams are still
1187 * being allocated.
1188 *
1189 * This method is intended to allow the HAL device to map or otherwise
1190 * prepare the buffers for later use. The buffers passed in will already be
1191 * locked for use. At the end of the call, all the buffers must be ready to
1192 * be returned to the stream. The buffer_set argument is only valid for the
1193 * duration of this call.
1194 *
1195 * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
1196 * the camera HAL should inspect the passed-in buffers here to determine any
1197 * platform-private pixel format information.
1198 *
1199 * Return values:
1200 *
1201 * 0: On successful registration of the new stream buffers
1202 *
1203 * -EINVAL: If the stream_buffer_set does not refer to a valid active
1204 * stream, or if the buffers array is invalid.
1205 *
1206 * -ENOMEM: If there was a failure in registering the buffers. The framework
1207 * must consider all the stream buffers to be unregistered, and can
1208 * try to register again later.
1209 *
1210 * -ENODEV: If there is a fatal error, and the device is no longer
1211 * operational. Only close() can be called successfully by the
1212 * framework after this error is returned.
1213 */
1214 int (*register_stream_buffers)(const struct camera3_device *,
1215 const camera3_stream_buffer_set_t *buffer_set);
1216
1217 /**********************************************************************
1218 * Request creation and submission
1219 */
1220
1221 /**
1222 * construct_default_request_settings:
1223 *
1224 * Create capture settings for standard camera use cases.
1225 *
1226 * The device must return a settings buffer that is configured to meet the
1227 * requested use case, which must be one of the CAMERA3_TEMPLATE_*
1228 * enums. All request control fields must be included.
1229 *
1230 * The HAL retains ownership of this structure, but the pointer to the
1231 * structure must be valid until the device is closed. The framework and the
1232 * HAL may not modify the buffer once it is returned by this call. The same
1233 * buffer may be returned for subsequent calls for the same template, or for
1234 * other templates.
1235 *
1236 * Return values:
1237 *
1238 * Valid metadata: On successful creation of a default settings
1239 * buffer.
1240 *
1241 * NULL: In case of a fatal error. After this is returned, only
1242 * the close() method can be called succesfully by the
1243 * framework.
1244 */
1245 const camera_metadata_t* (*construct_default_request_settings)(
1246 const struct camera3_device *,
1247 int type);
1248
1249 /**
1250 * process_capture_request:
1251 *
1252 * Send a new capture request to the HAL. The HAL should not return from
1253 * this call until it is ready to accept the next request to process. Only
1254 * one call to process_capture_request() will be made at a time by the
1255 * framework, and the calls will all be from the same thread. The next call
1256 * to process_capture_request() will be made as soon as a new request and
1257 * its associated buffers are available. In a normal preview scenario, this
1258 * means the function will be called again by the framework almost
1259 * instantly.
1260 *
1261 * The actual request processing is asynchronous, with the results of
1262 * capture being returned by the HAL through the process_capture_result()
1263 * call. This call requires the result metadata to be available, but output
1264 * buffers may simply provide sync fences to wait on. Multiple requests are
1265 * expected to be in flight at once, to maintain full output frame rate.
1266 *
1267 * The framework retains ownership of the request structure. It is only
1268 * guaranteed to be valid during this call. The HAL device must make copies
1269 * of the information it needs to retain for the capture processing.
1270 *
1271 * The HAL must write the file descriptor for the input buffer's release
1272 * sync fence into input_buffer->release_fence, if input_buffer is not
1273 * NULL. If the HAL returns -1 for the input buffer release sync fence, the
1274 * framework is free to immediately reuse the input buffer. Otherwise, the
1275 * framework will wait on the sync fence before refilling and reusing the
1276 * input buffer.
1277 *
1278 * Return values:
1279 *
1280 * 0: On a successful start to processing the capture request
1281 *
1282 * -EINVAL: If the input is malformed (the settings are NULL when not
1283 * allowed, there are 0 output buffers, etc) and capture processing
1284 * cannot start. Failures during request processing should be
1285 * handled by calling camera3_callback_ops_t.notify().
1286 *
1287 * -ENODEV: If the camera device has encountered a serious error. After this
1288 * error is returned, only the close() method can be successfully
1289 * called by the framework.
1290 *
1291 */
1292 int (*process_capture_request)(const struct camera3_device *,
1293 camera3_capture_request_t *request);
1294
1295 /**********************************************************************
1296 * Miscellaneous methods
1297 */
1298
1299 /**
1300 * get_metadata_vendor_tag_ops:
1301 *
1302 * Get methods to query for vendor extension metadata tag infomation. The
1303 * HAL should fill in all the vendor tag operation methods, or leave ops
1304 * unchanged if no vendor tags are defined.
1305 *
1306 * The definition of vendor_tag_query_ops_t can be found in
1307 * system/media/camera/include/system/camera_metadata.h.
1308 *
1309 */
1310 void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
1311 vendor_tag_query_ops_t* ops);
1312
1313 /**
1314 * dump:
1315 *
1316 * Print out debugging state for the camera device. This will be called by
1317 * the framework when the camera service is asked for a debug dump, which
1318 * happens when using the dumpsys tool, or when capturing a bugreport.
1319 *
1320 * The passed-in file descriptor can be used to write debugging text using
1321 * dprintf() or write(). The text should be in ASCII encoding only.
1322 */
1323 void (*dump)(const struct camera3_device *, int fd);
1324
1325} camera3_device_ops_t;
1326
1327/**********************************************************************
1328 *
1329 * Camera device definition
1330 *
1331 */
1332typedef struct camera3_device {
1333 /**
1334 * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
1335 * device as implementing version 3.0 of the camera device HAL.
1336 */
1337 hw_device_t common;
1338 camera3_device_ops_t *ops;
1339 void *priv;
1340} camera3_device_t;
1341
1342__END_DECLS
1343
1344#endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */