camera3.h
Go to the documentation of this file.
1 /*
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.2 [ CAMERA_DEVICE_API_VERSION_3_2 ]
25  *
26  * This is the current recommended version of the camera device HAL.
27  *
28  * Supports the android.hardware.Camera API, and as of v3.2, the
29  * android.hardware.camera2 API in LIMITED or FULL modes.
30  *
31  * Camera devices that support this version of the HAL must return
32  * CAMERA_DEVICE_API_VERSION_3_2 in camera_device_t.common.version and in
33  * camera_info_t.device_version (from camera_module_t.get_camera_info).
34  *
35  * CAMERA_DEVICE_API_VERSION_3_2:
36  * Camera modules that may contain version 3.2 devices must implement at
37  * least version 2.2 of the camera module interface (as defined by
38  * camera_module_t.common.module_api_version).
39  *
40  * <= CAMERA_DEVICE_API_VERSION_3_1:
41  * Camera modules that may contain version 3.1 (or 3.0) devices must
42  * implement at least version 2.0 of the camera module interface
43  * (as defined by camera_module_t.common.module_api_version).
44  *
45  * See camera_common.h for more versioning details.
46  *
47  * Documentation index:
48  * S1. Version history
49  * S2. Startup and operation sequencing
50  * S3. Operational modes
51  * S4. 3A modes and state machines
52  * S5. Cropping
53  * S6. Error management
54  * S7. Key Performance Indicator (KPI) glossary
55  * S8. Sample Use Cases
56  * S9. Notes on Controls and Metadata
57  */
58 
59 /**
60  * S1. Version history:
61  *
62  * 1.0: Initial Android camera HAL (Android 4.0) [camera.h]:
63  *
64  * - Converted from C++ CameraHardwareInterface abstraction layer.
65  *
66  * - Supports android.hardware.Camera API.
67  *
68  * 2.0: Initial release of expanded-capability HAL (Android 4.2) [camera2.h]:
69  *
70  * - Sufficient for implementing existing android.hardware.Camera API.
71  *
72  * - Allows for ZSL queue in camera service layer
73  *
74  * - Not tested for any new features such manual capture control, Bayer RAW
75  * capture, reprocessing of RAW data.
76  *
77  * 3.0: First revision of expanded-capability HAL:
78  *
79  * - Major version change since the ABI is completely different. No change to
80  * the required hardware capabilities or operational model from 2.0.
81  *
82  * - Reworked input request and stream queue interfaces: Framework calls into
83  * HAL with next request and stream buffers already dequeued. Sync framework
84  * support is included, necessary for efficient implementations.
85  *
86  * - Moved triggers into requests, most notifications into results.
87  *
88  * - Consolidated all callbacks into framework into one structure, and all
89  * setup methods into a single initialize() call.
90  *
91  * - Made stream configuration into a single call to simplify stream
92  * management. Bidirectional streams replace STREAM_FROM_STREAM construct.
93  *
94  * - Limited mode semantics for older/limited hardware devices.
95  *
96  * 3.1: Minor revision of expanded-capability HAL:
97  *
98  * - configure_streams passes consumer usage flags to the HAL.
99  *
100  * - flush call to drop all in-flight requests/buffers as fast as possible.
101  *
102  * 3.2: Minor revision of expanded-capability HAL:
103  *
104  * - Deprecates get_metadata_vendor_tag_ops. Please use get_vendor_tag_ops
105  * in camera_common.h instead.
106  *
107  * - register_stream_buffers deprecated. All gralloc buffers provided
108  * by framework to HAL in process_capture_request may be new at any time.
109  *
110  * - add partial result support. process_capture_result may be called
111  * multiple times with a subset of the available result before the full
112  * result is available.
113  *
114  * - add manual template to camera3_request_template. The applications may
115  * use this template to control the capture settings directly.
116  *
117  * - Rework the bidirectional and input stream specifications.
118  *
119  * - change the input buffer return path. The buffer is returned in
120  * process_capture_result instead of process_capture_request.
121  *
122  */
123 
124 /**
125  * S2. Startup and general expected operation sequence:
126  *
127  * 1. Framework calls camera_module_t->common.open(), which returns a
128  * hardware_device_t structure.
129  *
130  * 2. Framework inspects the hardware_device_t->version field, and instantiates
131  * the appropriate handler for that version of the camera hardware device. In
132  * case the version is CAMERA_DEVICE_API_VERSION_3_0, the device is cast to
133  * a camera3_device_t.
134  *
135  * 3. Framework calls camera3_device_t->ops->initialize() with the framework
136  * callback function pointers. This will only be called this one time after
137  * open(), before any other functions in the ops structure are called.
138  *
139  * 4. The framework calls camera3_device_t->ops->configure_streams() with a list
140  * of input/output streams to the HAL device.
141  *
142  * 5. <= CAMERA_DEVICE_API_VERSION_3_1:
143  *
144  * The framework allocates gralloc buffers and calls
145  * camera3_device_t->ops->register_stream_buffers() for at least one of the
146  * output streams listed in configure_streams. The same stream is registered
147  * only once.
148  *
149  * >= CAMERA_DEVICE_API_VERSION_3_2:
150  *
151  * camera3_device_t->ops->register_stream_buffers() is not called and must
152  * be NULL.
153  *
154  * 6. The framework requests default settings for some number of use cases with
155  * calls to camera3_device_t->ops->construct_default_request_settings(). This
156  * may occur any time after step 3.
157  *
158  * 7. The framework constructs and sends the first capture request to the HAL,
159  * with settings based on one of the sets of default settings, and with at
160  * least one output stream, which has been registered earlier by the
161  * framework. This is sent to the HAL with
162  * camera3_device_t->ops->process_capture_request(). The HAL must block the
163  * return of this call until it is ready for the next request to be sent.
164  *
165  * >= CAMERA_DEVICE_API_VERSION_3_2:
166  *
167  * The buffer_handle_t provided in the camera3_stream_buffer_t array
168  * in the camera3_capture_request_t may be new and never-before-seen
169  * by the HAL on any given new request.
170  *
171  * 8. The framework continues to submit requests, and call
172  * construct_default_request_settings to get default settings buffers for
173  * other use cases.
174  *
175  * <= CAMERA_DEVICE_API_VERSION_3_1:
176  *
177  * The framework may call register_stream_buffers() at this time for
178  * not-yet-registered streams.
179  *
180  * 9. When the capture of a request begins (sensor starts exposing for the
181  * capture), the HAL calls camera3_callback_ops_t->notify() with the SHUTTER
182  * event, including the frame number and the timestamp for start of exposure.
183  *
184  * <= CAMERA_DEVICE_API_VERSION_3_1:
185  *
186  * This notify call must be made before the first call to
187  * process_capture_result() for that frame number.
188  *
189  * >= CAMERA_DEVICE_API_VERSION_3_2:
190  *
191  * The camera3_callback_ops_t->notify() call with the SHUTTER event should
192  * be made as early as possible since the framework will be unable to
193  * deliver gralloc buffers to the application layer (for that frame) until
194  * it has a valid timestamp for the start of exposure.
195  *
196  * Both partial metadata results and the gralloc buffers may be sent to the
197  * framework at any time before or after the SHUTTER event.
198  *
199  * 10. After some pipeline delay, the HAL begins to return completed captures to
200  * the framework with camera3_callback_ops_t->process_capture_result(). These
201  * are returned in the same order as the requests were submitted. Multiple
202  * requests can be in flight at once, depending on the pipeline depth of the
203  * camera HAL device.
204  *
205  * >= CAMERA_DEVICE_API_VERSION_3_2:
206  *
207  * Once a buffer is returned by process_capture_result as part of the
208  * camera3_stream_buffer_t array, and the fence specified by release_fence
209  * has been signaled (this is a no-op for -1 fences), the ownership of that
210  * buffer is considered to be transferred back to the framework. After that,
211  * the HAL must no longer retain that particular buffer, and the
212  * framework may clean up the memory for it immediately.
213  *
214  * process_capture_result may be called multiple times for a single frame,
215  * each time with a new disjoint piece of metadata and/or set of gralloc
216  * buffers. The framework will accumulate these partial metadata results
217  * into one result.
218  *
219  * In particular, it is legal for a process_capture_result to be called
220  * simultaneously for both a frame N and a frame N+1 as long as the
221  * above rule holds for gralloc buffers (both input and output).
222  *
223  * 11. After some time, the framework may stop submitting new requests, wait for
224  * the existing captures to complete (all buffers filled, all results
225  * returned), and then call configure_streams() again. This resets the camera
226  * hardware and pipeline for a new set of input/output streams. Some streams
227  * may be reused from the previous configuration; if these streams' buffers
228  * had already been registered with the HAL, they will not be registered
229  * again. The framework then continues from step 7, if at least one
230  * registered output stream remains (otherwise, step 5 is required first).
231  *
232  * 12. Alternatively, the framework may call camera3_device_t->common->close()
233  * to end the camera session. This may be called at any time when no other
234  * calls from the framework are active, although the call may block until all
235  * in-flight captures have completed (all results returned, all buffers
236  * filled). After the close call returns, no more calls to the
237  * camera3_callback_ops_t functions are allowed from the HAL. Once the
238  * close() call is underway, the framework may not call any other HAL device
239  * functions.
240  *
241  * 13. In case of an error or other asynchronous event, the HAL must call
242  * camera3_callback_ops_t->notify() with the appropriate error/event
243  * message. After returning from a fatal device-wide error notification, the
244  * HAL should act as if close() had been called on it. However, the HAL must
245  * either cancel or complete all outstanding captures before calling
246  * notify(), so that once notify() is called with a fatal error, the
247  * framework will not receive further callbacks from the device. Methods
248  * besides close() should return -ENODEV or NULL after the notify() method
249  * returns from a fatal error message.
250  */
251 
252 /**
253  * S3. Operational modes:
254  *
255  * The camera 3 HAL device can implement one of two possible operational modes;
256  * limited and full. Full support is expected from new higher-end
257  * devices. Limited mode has hardware requirements roughly in line with those
258  * for a camera HAL device v1 implementation, and is expected from older or
259  * inexpensive devices. Full is a strict superset of limited, and they share the
260  * same essential operational flow, as documented above.
261  *
262  * The HAL must indicate its level of support with the
263  * android.info.supportedHardwareLevel static metadata entry, with 0 indicating
264  * limited mode, and 1 indicating full mode support.
265  *
266  * Roughly speaking, limited-mode devices do not allow for application control
267  * of capture settings (3A control only), high-rate capture of high-resolution
268  * images, raw sensor readout, or support for YUV output streams above maximum
269  * recording resolution (JPEG only for large images).
270  *
271  * ** Details of limited mode behavior:
272  *
273  * - Limited-mode devices do not need to implement accurate synchronization
274  * between capture request settings and the actual image data
275  * captured. Instead, changes to settings may take effect some time in the
276  * future, and possibly not for the same output frame for each settings
277  * entry. Rapid changes in settings may result in some settings never being
278  * used for a capture. However, captures that include high-resolution output
279  * buffers ( > 1080p ) have to use the settings as specified (but see below
280  * for processing rate).
281  *
282  * - Limited-mode devices do not need to support most of the
283  * settings/result/static info metadata. Specifically, only the following settings
284  * are expected to be consumed or produced by a limited-mode HAL device:
285  *
286  * android.control.aeAntibandingMode (controls and dynamic)
287  * android.control.aeExposureCompensation (controls and dynamic)
288  * android.control.aeLock (controls and dynamic)
289  * android.control.aeMode (controls and dynamic)
290  * android.control.aeRegions (controls and dynamic)
291  * android.control.aeTargetFpsRange (controls and dynamic)
292  * android.control.aePrecaptureTrigger (controls and dynamic)
293  * android.control.afMode (controls and dynamic)
294  * android.control.afRegions (controls and dynamic)
295  * android.control.awbLock (controls and dynamic)
296  * android.control.awbMode (controls and dynamic)
297  * android.control.awbRegions (controls and dynamic)
298  * android.control.captureIntent (controls and dynamic)
299  * android.control.effectMode (controls and dynamic)
300  * android.control.mode (controls and dynamic)
301  * android.control.sceneMode (controls and dynamic)
302  * android.control.videoStabilizationMode (controls and dynamic)
303  * android.control.aeAvailableAntibandingModes (static)
304  * android.control.aeAvailableModes (static)
305  * android.control.aeAvailableTargetFpsRanges (static)
306  * android.control.aeCompensationRange (static)
307  * android.control.aeCompensationStep (static)
308  * android.control.afAvailableModes (static)
309  * android.control.availableEffects (static)
310  * android.control.availableSceneModes (static)
311  * android.control.availableVideoStabilizationModes (static)
312  * android.control.awbAvailableModes (static)
313  * android.control.maxRegions (static)
314  * android.control.sceneModeOverrides (static)
315  * android.control.aeState (dynamic)
316  * android.control.afState (dynamic)
317  * android.control.awbState (dynamic)
318  *
319  * android.flash.mode (controls and dynamic)
320  * android.flash.info.available (static)
321  *
322  * android.info.supportedHardwareLevel (static)
323  *
324  * android.jpeg.gpsCoordinates (controls and dynamic)
325  * android.jpeg.gpsProcessingMethod (controls and dynamic)
326  * android.jpeg.gpsTimestamp (controls and dynamic)
327  * android.jpeg.orientation (controls and dynamic)
328  * android.jpeg.quality (controls and dynamic)
329  * android.jpeg.thumbnailQuality (controls and dynamic)
330  * android.jpeg.thumbnailSize (controls and dynamic)
331  * android.jpeg.availableThumbnailSizes (static)
332  * android.jpeg.maxSize (static)
333  *
334  * android.lens.info.minimumFocusDistance (static)
335  *
336  * android.request.id (controls and dynamic)
337  *
338  * android.scaler.cropRegion (controls and dynamic)
339  * android.scaler.availableStreamConfigurations (static)
340  * android.scaler.availableMinFrameDurations (static)
341  * android.scaler.availableStallDurations (static)
342  * android.scaler.availableMaxDigitalZoom (static)
343  * android.scaler.maxDigitalZoom (static)
344  * android.scaler.croppingType (static)
345  *
346  * android.sensor.orientation (static)
347  * android.sensor.timestamp (dynamic)
348  *
349  * android.statistics.faceDetectMode (controls and dynamic)
350  * android.statistics.info.availableFaceDetectModes (static)
351  * android.statistics.faceIds (dynamic)
352  * android.statistics.faceLandmarks (dynamic)
353  * android.statistics.faceRectangles (dynamic)
354  * android.statistics.faceScores (dynamic)
355  *
356  * android.sync.frameNumber (dynamic)
357  * android.sync.maxLatency (static)
358  *
359  * - Captures in limited mode that include high-resolution (> 1080p) output
360  * buffers may block in process_capture_request() until all the output buffers
361  * have been filled. A full-mode HAL device must process sequences of
362  * high-resolution requests at the rate indicated in the static metadata for
363  * that pixel format. The HAL must still call process_capture_result() to
364  * provide the output; the framework must simply be prepared for
365  * process_capture_request() to block until after process_capture_result() for
366  * that request completes for high-resolution captures for limited-mode
367  * devices.
368  *
369  * - Full-mode devices must support below additional capabilities:
370  * - 30fps at maximum resolution is preferred, more than 20fps is required.
371  * - Per frame control (android.sync.maxLatency == PER_FRAME_CONTROL).
372  * - Sensor manual control metadata. See MANUAL_SENSOR defined in
373  * android.request.availableCapabilities.
374  * - Post-processing manual control metadata. See MANUAL_POST_PROCESSING defined
375  * in android.request.availableCapabilities.
376  *
377  */
378 
379 /**
380  * S4. 3A modes and state machines:
381  *
382  * While the actual 3A algorithms are up to the HAL implementation, a high-level
383  * state machine description is defined by the HAL interface, to allow the HAL
384  * device and the framework to communicate about the current state of 3A, and to
385  * trigger 3A events.
386  *
387  * When the device is opened, all the individual 3A states must be
388  * STATE_INACTIVE. Stream configuration does not reset 3A. For example, locked
389  * focus must be maintained across the configure() call.
390  *
391  * Triggering a 3A action involves simply setting the relevant trigger entry in
392  * the settings for the next request to indicate start of trigger. For example,
393  * the trigger for starting an autofocus scan is setting the entry
394  * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTROL_AF_TRIGGER_START for one
395  * request, and cancelling an autofocus scan is triggered by setting
396  * ANDROID_CONTROL_AF_TRIGGER to ANDROID_CONTRL_AF_TRIGGER_CANCEL. Otherwise,
397  * the entry will not exist, or be set to ANDROID_CONTROL_AF_TRIGGER_IDLE. Each
398  * request with a trigger entry set to a non-IDLE value will be treated as an
399  * independent triggering event.
400  *
401  * At the top level, 3A is controlled by the ANDROID_CONTROL_MODE setting, which
402  * selects between no 3A (ANDROID_CONTROL_MODE_OFF), normal AUTO mode
403  * (ANDROID_CONTROL_MODE_AUTO), and using the scene mode setting
404  * (ANDROID_CONTROL_USE_SCENE_MODE).
405  *
406  * - In OFF mode, each of the individual AE/AF/AWB modes are effectively OFF,
407  * and none of the capture controls may be overridden by the 3A routines.
408  *
409  * - In AUTO mode, Auto-focus, auto-exposure, and auto-whitebalance all run
410  * their own independent algorithms, and have their own mode, state, and
411  * trigger metadata entries, as listed in the next section.
412  *
413  * - In USE_SCENE_MODE, the value of the ANDROID_CONTROL_SCENE_MODE entry must
414  * be used to determine the behavior of 3A routines. In SCENE_MODEs other than
415  * FACE_PRIORITY, the HAL must override the values of
416  * ANDROId_CONTROL_AE/AWB/AF_MODE to be the mode it prefers for the selected
417  * SCENE_MODE. For example, the HAL may prefer SCENE_MODE_NIGHT to use
418  * CONTINUOUS_FOCUS AF mode. Any user selection of AE/AWB/AF_MODE when scene
419  * must be ignored for these scene modes.
420  *
421  * - For SCENE_MODE_FACE_PRIORITY, the AE/AWB/AF_MODE controls work as in
422  * ANDROID_CONTROL_MODE_AUTO, but the 3A routines must bias toward metering
423  * and focusing on any detected faces in the scene.
424  *
425  * S4.1. Auto-focus settings and result entries:
426  *
427  * Main metadata entries:
428  *
429  * ANDROID_CONTROL_AF_MODE: Control for selecting the current autofocus
430  * mode. Set by the framework in the request settings.
431  *
432  * AF_MODE_OFF: AF is disabled; the framework/app directly controls lens
433  * position.
434  *
435  * AF_MODE_AUTO: Single-sweep autofocus. No lens movement unless AF is
436  * triggered.
437  *
438  * AF_MODE_MACRO: Single-sweep up-close autofocus. No lens movement unless
439  * AF is triggered.
440  *
441  * AF_MODE_CONTINUOUS_VIDEO: Smooth continuous focusing, for recording
442  * video. Triggering immediately locks focus in current
443  * position. Canceling resumes cotinuous focusing.
444  *
445  * AF_MODE_CONTINUOUS_PICTURE: Fast continuous focusing, for
446  * zero-shutter-lag still capture. Triggering locks focus once currently
447  * active sweep concludes. Canceling resumes continuous focusing.
448  *
449  * AF_MODE_EDOF: Advanced extended depth of field focusing. There is no
450  * autofocus scan, so triggering one or canceling one has no effect.
451  * Images are focused automatically by the HAL.
452  *
453  * ANDROID_CONTROL_AF_STATE: Dynamic metadata describing the current AF
454  * algorithm state, reported by the HAL in the result metadata.
455  *
456  * AF_STATE_INACTIVE: No focusing has been done, or algorithm was
457  * reset. Lens is not moving. Always the state for MODE_OFF or MODE_EDOF.
458  * When the device is opened, it must start in this state.
459  *
460  * AF_STATE_PASSIVE_SCAN: A continuous focus algorithm is currently scanning
461  * for good focus. The lens is moving.
462  *
463  * AF_STATE_PASSIVE_FOCUSED: A continuous focus algorithm believes it is
464  * well focused. The lens is not moving. The HAL may spontaneously leave
465  * this state.
466  *
467  * AF_STATE_PASSIVE_UNFOCUSED: A continuous focus algorithm believes it is
468  * not well focused. The lens is not moving. The HAL may spontaneously
469  * leave this state.
470  *
471  * AF_STATE_ACTIVE_SCAN: A scan triggered by the user is underway.
472  *
473  * AF_STATE_FOCUSED_LOCKED: The AF algorithm believes it is focused. The
474  * lens is not moving.
475  *
476  * AF_STATE_NOT_FOCUSED_LOCKED: The AF algorithm has been unable to
477  * focus. The lens is not moving.
478  *
479  * ANDROID_CONTROL_AF_TRIGGER: Control for starting an autofocus scan, the
480  * meaning of which is mode- and state- dependent. Set by the framework in
481  * the request settings.
482  *
483  * AF_TRIGGER_IDLE: No current trigger.
484  *
485  * AF_TRIGGER_START: Trigger start of AF scan. Effect is mode and state
486  * dependent.
487  *
488  * AF_TRIGGER_CANCEL: Cancel current AF scan if any, and reset algorithm to
489  * default.
490  *
491  * Additional metadata entries:
492  *
493  * ANDROID_CONTROL_AF_REGIONS: Control for selecting the regions of the FOV
494  * that should be used to determine good focus. This applies to all AF
495  * modes that scan for focus. Set by the framework in the request
496  * settings.
497  *
498  * S4.2. Auto-exposure settings and result entries:
499  *
500  * Main metadata entries:
501  *
502  * ANDROID_CONTROL_AE_MODE: Control for selecting the current auto-exposure
503  * mode. Set by the framework in the request settings.
504  *
505  * AE_MODE_OFF: Autoexposure is disabled; the user controls exposure, gain,
506  * frame duration, and flash.
507  *
508  * AE_MODE_ON: Standard autoexposure, with flash control disabled. User may
509  * set flash to fire or to torch mode.
510  *
511  * AE_MODE_ON_AUTO_FLASH: Standard autoexposure, with flash on at HAL's
512  * discretion for precapture and still capture. User control of flash
513  * disabled.
514  *
515  * AE_MODE_ON_ALWAYS_FLASH: Standard autoexposure, with flash always fired
516  * for capture, and at HAL's discretion for precapture.. User control of
517  * flash disabled.
518  *
519  * AE_MODE_ON_AUTO_FLASH_REDEYE: Standard autoexposure, with flash on at
520  * HAL's discretion for precapture and still capture. Use a flash burst
521  * at end of precapture sequence to reduce redeye in the final
522  * picture. User control of flash disabled.
523  *
524  * ANDROID_CONTROL_AE_STATE: Dynamic metadata describing the current AE
525  * algorithm state, reported by the HAL in the result metadata.
526  *
527  * AE_STATE_INACTIVE: Initial AE state after mode switch. When the device is
528  * opened, it must start in this state.
529  *
530  * AE_STATE_SEARCHING: AE is not converged to a good value, and is adjusting
531  * exposure parameters.
532  *
533  * AE_STATE_CONVERGED: AE has found good exposure values for the current
534  * scene, and the exposure parameters are not changing. HAL may
535  * spontaneously leave this state to search for better solution.
536  *
537  * AE_STATE_LOCKED: AE has been locked with the AE_LOCK control. Exposure
538  * values are not changing.
539  *
540  * AE_STATE_FLASH_REQUIRED: The HAL has converged exposure, but believes
541  * flash is required for a sufficiently bright picture. Used for
542  * determining if a zero-shutter-lag frame can be used.
543  *
544  * AE_STATE_PRECAPTURE: The HAL is in the middle of a precapture
545  * sequence. Depending on AE mode, this mode may involve firing the
546  * flash for metering, or a burst of flash pulses for redeye reduction.
547  *
548  * ANDROID_CONTROL_AE_PRECAPTURE_TRIGGER: Control for starting a metering
549  * sequence before capturing a high-quality image. Set by the framework in
550  * the request settings.
551  *
552  * PRECAPTURE_TRIGGER_IDLE: No current trigger.
553  *
554  * PRECAPTURE_TRIGGER_START: Start a precapture sequence. The HAL should
555  * use the subsequent requests to measure good exposure/white balance
556  * for an upcoming high-resolution capture.
557  *
558  * Additional metadata entries:
559  *
560  * ANDROID_CONTROL_AE_LOCK: Control for locking AE controls to their current
561  * values
562  *
563  * ANDROID_CONTROL_AE_EXPOSURE_COMPENSATION: Control for adjusting AE
564  * algorithm target brightness point.
565  *
566  * ANDROID_CONTROL_AE_TARGET_FPS_RANGE: Control for selecting the target frame
567  * rate range for the AE algorithm. The AE routine cannot change the frame
568  * rate to be outside these bounds.
569  *
570  * ANDROID_CONTROL_AE_REGIONS: Control for selecting the regions of the FOV
571  * that should be used to determine good exposure levels. This applies to
572  * all AE modes besides OFF.
573  *
574  * S4.3. Auto-whitebalance settings and result entries:
575  *
576  * Main metadata entries:
577  *
578  * ANDROID_CONTROL_AWB_MODE: Control for selecting the current white-balance
579  * mode.
580  *
581  * AWB_MODE_OFF: Auto-whitebalance is disabled. User controls color matrix.
582  *
583  * AWB_MODE_AUTO: Automatic white balance is enabled; 3A controls color
584  * transform, possibly using more complex transforms than a simple
585  * matrix.
586  *
587  * AWB_MODE_INCANDESCENT: Fixed white balance settings good for indoor
588  * incandescent (tungsten) lighting, roughly 2700K.
589  *
590  * AWB_MODE_FLUORESCENT: Fixed white balance settings good for fluorescent
591  * lighting, roughly 5000K.
592  *
593  * AWB_MODE_WARM_FLUORESCENT: Fixed white balance settings good for
594  * fluorescent lighting, roughly 3000K.
595  *
596  * AWB_MODE_DAYLIGHT: Fixed white balance settings good for daylight,
597  * roughly 5500K.
598  *
599  * AWB_MODE_CLOUDY_DAYLIGHT: Fixed white balance settings good for clouded
600  * daylight, roughly 6500K.
601  *
602  * AWB_MODE_TWILIGHT: Fixed white balance settings good for
603  * near-sunset/sunrise, roughly 15000K.
604  *
605  * AWB_MODE_SHADE: Fixed white balance settings good for areas indirectly
606  * lit by the sun, roughly 7500K.
607  *
608  * ANDROID_CONTROL_AWB_STATE: Dynamic metadata describing the current AWB
609  * algorithm state, reported by the HAL in the result metadata.
610  *
611  * AWB_STATE_INACTIVE: Initial AWB state after mode switch. When the device
612  * is opened, it must start in this state.
613  *
614  * AWB_STATE_SEARCHING: AWB is not converged to a good value, and is
615  * changing color adjustment parameters.
616  *
617  * AWB_STATE_CONVERGED: AWB has found good color adjustment values for the
618  * current scene, and the parameters are not changing. HAL may
619  * spontaneously leave this state to search for better solution.
620  *
621  * AWB_STATE_LOCKED: AWB has been locked with the AWB_LOCK control. Color
622  * adjustment values are not changing.
623  *
624  * Additional metadata entries:
625  *
626  * ANDROID_CONTROL_AWB_LOCK: Control for locking AWB color adjustments to
627  * their current values.
628  *
629  * ANDROID_CONTROL_AWB_REGIONS: Control for selecting the regions of the FOV
630  * that should be used to determine good color balance. This applies only
631  * to auto-WB mode.
632  *
633  * S4.4. General state machine transition notes
634  *
635  * Switching between AF, AE, or AWB modes always resets the algorithm's state
636  * to INACTIVE. Similarly, switching between CONTROL_MODE or
637  * CONTROL_SCENE_MODE if CONTROL_MODE == USE_SCENE_MODE resets all the
638  * algorithm states to INACTIVE.
639  *
640  * The tables below are per-mode.
641  *
642  * S4.5. AF state machines
643  *
644  * when enabling AF or changing AF mode
645  *| state | trans. cause | new state | notes |
646  *+--------------------+---------------+--------------------+------------------+
647  *| Any | AF mode change| INACTIVE | |
648  *+--------------------+---------------+--------------------+------------------+
649  *
650  * mode = AF_MODE_OFF or AF_MODE_EDOF
651  *| state | trans. cause | new state | notes |
652  *+--------------------+---------------+--------------------+------------------+
653  *| INACTIVE | | INACTIVE | Never changes |
654  *+--------------------+---------------+--------------------+------------------+
655  *
656  * mode = AF_MODE_AUTO or AF_MODE_MACRO
657  *| state | trans. cause | new state | notes |
658  *+--------------------+---------------+--------------------+------------------+
659  *| INACTIVE | AF_TRIGGER | ACTIVE_SCAN | Start AF sweep |
660  *| | | | Lens now moving |
661  *+--------------------+---------------+--------------------+------------------+
662  *| ACTIVE_SCAN | AF sweep done | FOCUSED_LOCKED | If AF successful |
663  *| | | | Lens now locked |
664  *+--------------------+---------------+--------------------+------------------+
665  *| ACTIVE_SCAN | AF sweep done | NOT_FOCUSED_LOCKED | If AF successful |
666  *| | | | Lens now locked |
667  *+--------------------+---------------+--------------------+------------------+
668  *| ACTIVE_SCAN | AF_CANCEL | INACTIVE | Cancel/reset AF |
669  *| | | | Lens now locked |
670  *+--------------------+---------------+--------------------+------------------+
671  *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
672  *+--------------------+---------------+--------------------+------------------+
673  *| FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
674  *| | | | Lens now moving |
675  *+--------------------+---------------+--------------------+------------------+
676  *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Cancel/reset AF |
677  *+--------------------+---------------+--------------------+------------------+
678  *| NOT_FOCUSED_LOCKED | AF_TRIGGER | ACTIVE_SCAN | Start new sweep |
679  *| | | | Lens now moving |
680  *+--------------------+---------------+--------------------+------------------+
681  *| All states | mode change | INACTIVE | |
682  *+--------------------+---------------+--------------------+------------------+
683  *
684  * mode = AF_MODE_CONTINUOUS_VIDEO
685  *| state | trans. cause | new state | notes |
686  *+--------------------+---------------+--------------------+------------------+
687  *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
688  *| | new scan | | Lens now moving |
689  *+--------------------+---------------+--------------------+------------------+
690  *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
691  *| | | | Lens now locked |
692  *+--------------------+---------------+--------------------+------------------+
693  *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
694  *| | current scan | | Lens now locked |
695  *+--------------------+---------------+--------------------+------------------+
696  *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
697  *| | current scan | | Lens now locked |
698  *+--------------------+---------------+--------------------+------------------+
699  *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
700  *| | | | if focus is good |
701  *| | | | Lens now locked |
702  *+--------------------+---------------+--------------------+------------------+
703  *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
704  *| | | | if focus is bad |
705  *| | | | Lens now locked |
706  *+--------------------+---------------+--------------------+------------------+
707  *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
708  *| | | | position |
709  *| | | | Lens now locked |
710  *+--------------------+---------------+--------------------+------------------+
711  *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
712  *| | new scan | | Lens now moving |
713  *+--------------------+---------------+--------------------+------------------+
714  *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
715  *| | new scan | | Lens now moving |
716  *+--------------------+---------------+--------------------+------------------+
717  *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
718  *| | | | Lens now locked |
719  *+--------------------+---------------+--------------------+------------------+
720  *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
721  *| | | | Lens now locked |
722  *+--------------------+---------------+--------------------+------------------+
723  *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
724  *+--------------------+---------------+--------------------+------------------+
725  *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
726  *+--------------------+---------------+--------------------+------------------+
727  *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
728  *+--------------------+---------------+--------------------+------------------+
729  *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
730  *+--------------------+---------------+--------------------+------------------+
731  *
732  * mode = AF_MODE_CONTINUOUS_PICTURE
733  *| state | trans. cause | new state | notes |
734  *+--------------------+---------------+--------------------+------------------+
735  *| INACTIVE | HAL initiates | PASSIVE_SCAN | Start AF scan |
736  *| | new scan | | Lens now moving |
737  *+--------------------+---------------+--------------------+------------------+
738  *| INACTIVE | AF_TRIGGER | NOT_FOCUSED_LOCKED | AF state query |
739  *| | | | Lens now locked |
740  *+--------------------+---------------+--------------------+------------------+
741  *| PASSIVE_SCAN | HAL completes | PASSIVE_FOCUSED | End AF scan |
742  *| | current scan | | Lens now locked |
743  *+--------------------+---------------+--------------------+------------------+
744  *| PASSIVE_SCAN | HAL fails | PASSIVE_UNFOCUSED | End AF scan |
745  *| | current scan | | Lens now locked |
746  *+--------------------+---------------+--------------------+------------------+
747  *| PASSIVE_SCAN | AF_TRIGGER | FOCUSED_LOCKED | Eventual trans. |
748  *| | | | once focus good |
749  *| | | | Lens now locked |
750  *+--------------------+---------------+--------------------+------------------+
751  *| PASSIVE_SCAN | AF_TRIGGER | NOT_FOCUSED_LOCKED | Eventual trans. |
752  *| | | | if cannot focus |
753  *| | | | Lens now locked |
754  *+--------------------+---------------+--------------------+------------------+
755  *| PASSIVE_SCAN | AF_CANCEL | INACTIVE | Reset lens |
756  *| | | | position |
757  *| | | | Lens now locked |
758  *+--------------------+---------------+--------------------+------------------+
759  *| PASSIVE_FOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
760  *| | new scan | | Lens now moving |
761  *+--------------------+---------------+--------------------+------------------+
762  *| PASSIVE_UNFOCUSED | HAL initiates | PASSIVE_SCAN | Start AF scan |
763  *| | new scan | | Lens now moving |
764  *+--------------------+---------------+--------------------+------------------+
765  *| PASSIVE_FOCUSED | AF_TRIGGER | FOCUSED_LOCKED | Immediate trans. |
766  *| | | | Lens now locked |
767  *+--------------------+---------------+--------------------+------------------+
768  *| PASSIVE_UNFOCUSED | AF_TRIGGER | NOT_FOCUSED_LOCKED | Immediate trans. |
769  *| | | | Lens now locked |
770  *+--------------------+---------------+--------------------+------------------+
771  *| FOCUSED_LOCKED | AF_TRIGGER | FOCUSED_LOCKED | No effect |
772  *+--------------------+---------------+--------------------+------------------+
773  *| FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
774  *+--------------------+---------------+--------------------+------------------+
775  *| NOT_FOCUSED_LOCKED | AF_TRIGGER | NOT_FOCUSED_LOCKED | No effect |
776  *+--------------------+---------------+--------------------+------------------+
777  *| NOT_FOCUSED_LOCKED | AF_CANCEL | INACTIVE | Restart AF scan |
778  *+--------------------+---------------+--------------------+------------------+
779  *
780  * S4.6. AE and AWB state machines
781  *
782  * The AE and AWB state machines are mostly identical. AE has additional
783  * FLASH_REQUIRED and PRECAPTURE states. So rows below that refer to those two
784  * states should be ignored for the AWB state machine.
785  *
786  * when enabling AE/AWB or changing AE/AWB mode
787  *| state | trans. cause | new state | notes |
788  *+--------------------+---------------+--------------------+------------------+
789  *| Any | mode change | INACTIVE | |
790  *+--------------------+---------------+--------------------+------------------+
791  *
792  * mode = AE_MODE_OFF / AWB mode not AUTO
793  *| state | trans. cause | new state | notes |
794  *+--------------------+---------------+--------------------+------------------+
795  *| INACTIVE | | INACTIVE | AE/AWB disabled |
796  *+--------------------+---------------+--------------------+------------------+
797  *
798  * mode = AE_MODE_ON_* / AWB_MODE_AUTO
799  *| state | trans. cause | new state | notes |
800  *+--------------------+---------------+--------------------+------------------+
801  *| INACTIVE | HAL initiates | SEARCHING | |
802  *| | AE/AWB scan | | |
803  *+--------------------+---------------+--------------------+------------------+
804  *| INACTIVE | AE/AWB_LOCK | LOCKED | values locked |
805  *| | on | | |
806  *+--------------------+---------------+--------------------+------------------+
807  *| SEARCHING | HAL finishes | CONVERGED | good values, not |
808  *| | AE/AWB scan | | changing |
809  *+--------------------+---------------+--------------------+------------------+
810  *| SEARCHING | HAL finishes | FLASH_REQUIRED | converged but too|
811  *| | AE scan | | dark w/o flash |
812  *+--------------------+---------------+--------------------+------------------+
813  *| SEARCHING | AE/AWB_LOCK | LOCKED | values locked |
814  *| | on | | |
815  *+--------------------+---------------+--------------------+------------------+
816  *| CONVERGED | HAL initiates | SEARCHING | values locked |
817  *| | AE/AWB scan | | |
818  *+--------------------+---------------+--------------------+------------------+
819  *| CONVERGED | AE/AWB_LOCK | LOCKED | values locked |
820  *| | on | | |
821  *+--------------------+---------------+--------------------+------------------+
822  *| FLASH_REQUIRED | HAL initiates | SEARCHING | values locked |
823  *| | AE/AWB scan | | |
824  *+--------------------+---------------+--------------------+------------------+
825  *| FLASH_REQUIRED | AE/AWB_LOCK | LOCKED | values locked |
826  *| | on | | |
827  *+--------------------+---------------+--------------------+------------------+
828  *| LOCKED | AE/AWB_LOCK | SEARCHING | values not good |
829  *| | off | | after unlock |
830  *+--------------------+---------------+--------------------+------------------+
831  *| LOCKED | AE/AWB_LOCK | CONVERGED | values good |
832  *| | off | | after unlock |
833  *+--------------------+---------------+--------------------+------------------+
834  *| LOCKED | AE_LOCK | FLASH_REQUIRED | exposure good, |
835  *| | off | | but too dark |
836  *+--------------------+---------------+--------------------+------------------+
837  *| All AE states | PRECAPTURE_ | PRECAPTURE | Start precapture |
838  *| | START | | sequence |
839  *+--------------------+---------------+--------------------+------------------+
840  *| PRECAPTURE | Sequence done.| CONVERGED | Ready for high- |
841  *| | AE_LOCK off | | quality capture |
842  *+--------------------+---------------+--------------------+------------------+
843  *| PRECAPTURE | Sequence done.| LOCKED | Ready for high- |
844  *| | AE_LOCK on | | quality capture |
845  *+--------------------+---------------+--------------------+------------------+
846  *
847  */
848 
849 /**
850  * S5. Cropping:
851  *
852  * Cropping of the full pixel array (for digital zoom and other use cases where
853  * a smaller FOV is desirable) is communicated through the
854  * ANDROID_SCALER_CROP_REGION setting. This is a per-request setting, and can
855  * change on a per-request basis, which is critical for implementing smooth
856  * digital zoom.
857  *
858  * The region is defined as a rectangle (x, y, width, height), with (x, y)
859  * describing the top-left corner of the rectangle. The rectangle is defined on
860  * the coordinate system of the sensor active pixel array, with (0,0) being the
861  * top-left pixel of the active pixel array. Therefore, the width and height
862  * cannot be larger than the dimensions reported in the
863  * ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY static info field. The minimum allowed
864  * width and height are reported by the HAL through the
865  * ANDROID_SCALER_MAX_DIGITAL_ZOOM static info field, which describes the
866  * maximum supported zoom factor. Therefore, the minimum crop region width and
867  * height are:
868  *
869  * {width, height} =
870  * { floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[0] /
871  * ANDROID_SCALER_MAX_DIGITAL_ZOOM),
872  * floor(ANDROID_SENSOR_ACTIVE_PIXEL_ARRAY[1] /
873  * ANDROID_SCALER_MAX_DIGITAL_ZOOM) }
874  *
875  * If the crop region needs to fulfill specific requirements (for example, it
876  * needs to start on even coordinates, and its width/height needs to be even),
877  * the HAL must do the necessary rounding and write out the final crop region
878  * used in the output result metadata. Similarly, if the HAL implements video
879  * stabilization, it must adjust the result crop region to describe the region
880  * actually included in the output after video stabilization is applied. In
881  * general, a camera-using application must be able to determine the field of
882  * view it is receiving based on the crop region, the dimensions of the image
883  * sensor, and the lens focal length.
884  *
885  * It is assumed that the cropping is applied after raw to other color space
886  * conversion. Raw streams (RAW16 and RAW_OPAQUE) don't have this conversion stage,
887  * and are not croppable. Therefore, the crop region must be ignored by the HAL
888  * for raw streams.
889  *
890  * Since the crop region applies to all non-raw streams, which may have different aspect
891  * ratios than the crop region, the exact sensor region used for each stream may
892  * be smaller than the crop region. Specifically, each stream should maintain
893  * square pixels and its aspect ratio by minimally further cropping the defined
894  * crop region. If the stream's aspect ratio is wider than the crop region, the
895  * stream should be further cropped vertically, and if the stream's aspect ratio
896  * is narrower than the crop region, the stream should be further cropped
897  * horizontally.
898  *
899  * In all cases, the stream crop must be centered within the full crop region,
900  * and each stream is only either cropped horizontally or vertical relative to
901  * the full crop region, never both.
902  *
903  * For example, if two streams are defined, a 640x480 stream (4:3 aspect), and a
904  * 1280x720 stream (16:9 aspect), below demonstrates the expected output regions
905  * for each stream for a few sample crop regions, on a hypothetical 3 MP (2000 x
906  * 1500 pixel array) sensor.
907  *
908  * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
909  *
910  * 640x480 stream crop: (500, 375, 1000, 750) (equal to crop region)
911  * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
912  *
913  * 0 1000 2000
914  * +---------+---------+---------+----------+
915  * | Active pixel array |
916  * | |
917  * | |
918  * + +-------------------+ + 375
919  * | | | |
920  * | O===================O |
921  * | I 1280x720 stream I |
922  * + I I + 750
923  * | I I |
924  * | O===================O |
925  * | | | |
926  * + +-------------------+ + 1125
927  * | Crop region, 640x480 stream |
928  * | |
929  * | |
930  * +---------+---------+---------+----------+ 1500
931  *
932  * Crop region: (500, 375, 1333, 750) (16:9 aspect ratio)
933  *
934  * 640x480 stream crop: (666, 375, 1000, 750) (marked with =)
935  * 1280x720 stream crop: (500, 375, 1333, 750) (equal to crop region)
936  *
937  * 0 1000 2000
938  * +---------+---------+---------+----------+
939  * | Active pixel array |
940  * | |
941  * | |
942  * + +---O==================O---+ + 375
943  * | | I 640x480 stream I | |
944  * | | I I | |
945  * | | I I | |
946  * + | I I | + 750
947  * | | I I | |
948  * | | I I | |
949  * | | I I | |
950  * + +---O==================O---+ + 1125
951  * | Crop region, 1280x720 stream |
952  * | |
953  * | |
954  * +---------+---------+---------+----------+ 1500
955  *
956  * Crop region: (500, 375, 750, 750) (1:1 aspect ratio)
957  *
958  * 640x480 stream crop: (500, 469, 750, 562) (marked with =)
959  * 1280x720 stream crop: (500, 543, 750, 414) (marged with #)
960  *
961  * 0 1000 2000
962  * +---------+---------+---------+----------+
963  * | Active pixel array |
964  * | |
965  * | |
966  * + +--------------+ + 375
967  * | O==============O |
968  * | ################ |
969  * | # # |
970  * + # # + 750
971  * | # # |
972  * | ################ 1280x720 |
973  * | O==============O 640x480 |
974  * + +--------------+ + 1125
975  * | Crop region |
976  * | |
977  * | |
978  * +---------+---------+---------+----------+ 1500
979  *
980  * And a final example, a 1024x1024 square aspect ratio stream instead of the
981  * 480p stream:
982  *
983  * Crop region: (500, 375, 1000, 750) (4:3 aspect ratio)
984  *
985  * 1024x1024 stream crop: (625, 375, 750, 750) (marked with #)
986  * 1280x720 stream crop: (500, 469, 1000, 562) (marked with =)
987  *
988  * 0 1000 2000
989  * +---------+---------+---------+----------+
990  * | Active pixel array |
991  * | |
992  * | 1024x1024 stream |
993  * + +--###############--+ + 375
994  * | | # # | |
995  * | O===================O |
996  * | I 1280x720 stream I |
997  * + I I + 750
998  * | I I |
999  * | O===================O |
1000  * | | # # | |
1001  * + +--###############--+ + 1125
1002  * | Crop region |
1003  * | |
1004  * | |
1005  * +---------+---------+---------+----------+ 1500
1006  *
1007  */
1008 
1009 /**
1010  * S6. Error management:
1011  *
1012  * Camera HAL device ops functions that have a return value will all return
1013  * -ENODEV / NULL in case of a serious error. This means the device cannot
1014  * continue operation, and must be closed by the framework. Once this error is
1015  * returned by some method, or if notify() is called with ERROR_DEVICE, only
1016  * the close() method can be called successfully. All other methods will return
1017  * -ENODEV / NULL.
1018  *
1019  * If a device op is called in the wrong sequence, for example if the framework
1020  * calls configure_streams() is called before initialize(), the device must
1021  * return -ENOSYS from the call, and do nothing.
1022  *
1023  * Transient errors in image capture must be reported through notify() as follows:
1024  *
1025  * - The failure of an entire capture to occur must be reported by the HAL by
1026  * calling notify() with ERROR_REQUEST. Individual errors for the result
1027  * metadata or the output buffers must not be reported in this case.
1028  *
1029  * - If the metadata for a capture cannot be produced, but some image buffers
1030  * were filled, the HAL must call notify() with ERROR_RESULT.
1031  *
1032  * - If an output image buffer could not be filled, but either the metadata was
1033  * produced or some other buffers were filled, the HAL must call notify() with
1034  * ERROR_BUFFER for each failed buffer.
1035  *
1036  * In each of these transient failure cases, the HAL must still call
1037  * process_capture_result, with valid output and input (if an input buffer was
1038  * submitted) buffer_handle_t. If the result metadata could not be produced, it
1039  * should be NULL. If some buffers could not be filled, they must be returned with
1040  * process_capture_result in the error state, their release fences must be set to
1041  * the acquire fences passed by the framework, or -1 if they have been waited on by
1042  * the HAL already.
1043  *
1044  * Invalid input arguments result in -EINVAL from the appropriate methods. In
1045  * that case, the framework must act as if that call had never been made.
1046  *
1047  */
1048 
1049 /**
1050  * S7. Key Performance Indicator (KPI) glossary:
1051  *
1052  * This includes some critical definitions that are used by KPI metrics.
1053  *
1054  * Pipeline Latency:
1055  * For a given capture request, the duration from the framework calling
1056  * process_capture_request to the HAL sending capture result and all buffers
1057  * back by process_capture_result call. To make the Pipeline Latency measure
1058  * independent of frame rate, it is measured by frame count.
1059  *
1060  * For example, when frame rate is 30 (fps), the frame duration (time interval
1061  * between adjacent frame capture time) is 33 (ms).
1062  * If it takes 5 frames for framework to get the result and buffers back for
1063  * a given request, then the Pipeline Latency is 5 (frames), instead of
1064  * 5 x 33 = 165 (ms).
1065  *
1066  * The Pipeline Latency is determined by android.request.pipelineDepth and
1067  * android.request.pipelineMaxDepth, see their definitions for more details.
1068  *
1069  */
1070 
1071 /**
1072  * S8. Sample Use Cases:
1073  *
1074  * This includes some typical use case examples the camera HAL may support.
1075  *
1076  * S8.1 Zero Shutter Lag (ZSL) with CAMERA3_STREAM_BIDIRECTIONAL stream.
1077  *
1078  * For this use case, the bidirectional stream will be used by the framework as follows:
1079  *
1080  * 1. The framework includes a buffer from this stream as output buffer in a
1081  * request as normal.
1082  *
1083  * 2. Once the HAL device returns a filled output buffer to the framework,
1084  * the framework may do one of two things with the filled buffer:
1085  *
1086  * 2. a. The framework uses the filled data, and returns the now-used buffer
1087  * to the stream queue for reuse. This behavior exactly matches the
1088  * OUTPUT type of stream.
1089  *
1090  * 2. b. The framework wants to reprocess the filled data, and uses the
1091  * buffer as an input buffer for a request. Once the HAL device has
1092  * used the reprocessing buffer, it then returns it to the
1093  * framework. The framework then returns the now-used buffer to the
1094  * stream queue for reuse.
1095  *
1096  * 3. The HAL device will be given the buffer again as an output buffer for
1097  * a request at some future point.
1098  *
1099  * For ZSL use case, the pixel format for bidirectional stream will be
1100  * HAL_PIXEL_FORMAT_RAW_OPAQUE or HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED if it
1101  * is listed in android.scaler.availableInputOutputFormatsMap. When
1102  * HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, the gralloc
1103  * usage flags for the consumer endpoint will be set to GRALLOC_USAGE_HW_CAMERA_ZSL.
1104  * A configuration stream list that has BIDIRECTIONAL stream used as input, will
1105  * usually also have a distinct OUTPUT stream to get the reprocessing data. For example,
1106  * for the ZSL use case, the stream list might be configured with the following:
1107  *
1108  * - A HAL_PIXEL_FORMAT_RAW_OPAQUE bidirectional stream is used
1109  * as input.
1110  * - And a HAL_PIXEL_FORMAT_BLOB (JPEG) output stream.
1111  *
1112  */
1113 
1114 /**
1115  * S9. Notes on Controls and Metadata
1116  *
1117  * This section contains notes about the interpretation and usage of various metadata tags.
1118  *
1119  * S9.1 HIGH_QUALITY and FAST modes.
1120  *
1121  * Many camera post-processing blocks may be listed as having HIGH_QUALITY,
1122  * FAST, and OFF operating modes. These blocks will typically also have an
1123  * 'available modes' tag representing which of these operating modes are
1124  * available on a given device. The general policy regarding implementing
1125  * these modes is as follows:
1126  *
1127  * 1. Operating mode controls of hardware blocks that cannot be disabled
1128  * must not list OFF in their corresponding 'available modes' tags.
1129  *
1130  * 2. OFF will always be included in their corresponding 'available modes'
1131  * tag if it is possible to disable that hardware block.
1132  *
1133  * 3. FAST must always be included in the 'available modes' tags for all
1134  * post-processing blocks supported on the device. If a post-processing
1135  * block also has a slower and higher quality operating mode that does
1136  * not meet the framerate requirements for FAST mode, HIGH_QUALITY should
1137  * be included in the 'available modes' tag to represent this operating
1138  * mode.
1139  */
1140 __BEGIN_DECLS
1141 
1142 struct camera3_device;
1143 
1144 /**********************************************************************
1145  *
1146  * Camera3 stream and stream buffer definitions.
1147  *
1148  * These structs and enums define the handles and contents of the input and
1149  * output streams connecting the HAL to various framework and application buffer
1150  * consumers. Each stream is backed by a gralloc buffer queue.
1151  *
1152  */
1153 
1154 /**
1155  * camera3_stream_type_t:
1156  *
1157  * The type of the camera stream, which defines whether the camera HAL device is
1158  * the producer or the consumer for that stream, and how the buffers of the
1159  * stream relate to the other streams.
1160  */
1161 typedef enum camera3_stream_type {
1162  /**
1163  * This stream is an output stream; the camera HAL device will be
1164  * responsible for filling buffers from this stream with newly captured or
1165  * reprocessed image data.
1166  */
1168 
1169  /**
1170  * This stream is an input stream; the camera HAL device will be responsible
1171  * for reading buffers from this stream and sending them through the camera
1172  * processing pipeline, as if the buffer was a newly captured image from the
1173  * imager.
1174  *
1175  * The pixel format for input stream can be any format reported by
1176  * android.scaler.availableInputOutputFormatsMap. The pixel format of the
1177  * output stream that is used to produce the reprocessing data may be any
1178  * format reported by android.scaler.availableStreamConfigurations. The
1179  * supported input/output stream combinations depends the camera device
1180  * capabilities, see android.scaler.availableInputOutputFormatsMap for
1181  * stream map details.
1182  *
1183  * This kind of stream is generally used to reprocess data into higher
1184  * quality images (that otherwise would cause a frame rate performance
1185  * loss), or to do off-line reprocessing.
1186  *
1187  */
1189 
1190  /**
1191  * This stream can be used for input and output. Typically, the stream is
1192  * used as an output stream, but occasionally one already-filled buffer may
1193  * be sent back to the HAL device for reprocessing.
1194  *
1195  * This kind of stream is meant generally for Zero Shutter Lag (ZSL)
1196  * features, where copying the captured image from the output buffer to the
1197  * reprocessing input buffer would be expensive. See S8.1 for more details.
1198  *
1199  * Note that the HAL will always be reprocessing data it produced.
1200  *
1201  */
1203 
1204  /**
1205  * Total number of framework-defined stream types
1206  */
1208 
1210 
1211 /**
1212  * camera3_stream_t:
1213  *
1214  * A handle to a single camera input or output stream. A stream is defined by
1215  * the framework by its buffer resolution and format, and additionally by the
1216  * HAL with the gralloc usage flags and the maximum in-flight buffer count.
1217  *
1218  * The stream structures are owned by the framework, but pointers to a
1219  * camera3_stream passed into the HAL by configure_streams() are valid until the
1220  * end of the first subsequent configure_streams() call that _does not_ include
1221  * that camera3_stream as an argument, or until the end of the close() call.
1222  *
1223  * All camera3_stream framework-controlled members are immutable once the
1224  * camera3_stream is passed into configure_streams(). The HAL may only change
1225  * the HAL-controlled parameters during a configure_streams() call, except for
1226  * the contents of the private pointer.
1227  *
1228  * If a configure_streams() call returns a non-fatal error, all active streams
1229  * remain valid as if configure_streams() had not been called.
1230  *
1231  * The endpoint of the stream is not visible to the camera HAL device.
1232  * In DEVICE_API_VERSION_3_1, this was changed to share consumer usage flags
1233  * on streams where the camera is a producer (OUTPUT and BIDIRECTIONAL stream
1234  * types) see the usage field below.
1235  */
1236 typedef struct camera3_stream {
1237 
1238  /*****
1239  * Set by framework before configure_streams()
1240  */
1241 
1242  /**
1243  * The type of the stream, one of the camera3_stream_type_t values.
1244  */
1246 
1247  /**
1248  * The width in pixels of the buffers in this stream
1249  */
1250  uint32_t width;
1251 
1252  /**
1253  * The height in pixels of the buffers in this stream
1254  */
1255  uint32_t height;
1256 
1257  /**
1258  * The pixel format for the buffers in this stream. Format is a value from
1259  * the HAL_PIXEL_FORMAT_* list in system/core/include/system/graphics.h, or
1260  * from device-specific headers.
1261  *
1262  * If HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED is used, then the platform
1263  * gralloc module will select a format based on the usage flags provided by
1264  * the camera device and the other endpoint of the stream.
1265  *
1266  * <= CAMERA_DEVICE_API_VERSION_3_1:
1267  *
1268  * The camera HAL device must inspect the buffers handed to it in the
1269  * subsequent register_stream_buffers() call to obtain the
1270  * implementation-specific format details, if necessary.
1271  *
1272  * >= CAMERA_DEVICE_API_VERSION_3_2:
1273  *
1274  * register_stream_buffers() won't be called by the framework, so the HAL
1275  * should configure the ISP and sensor pipeline based purely on the sizes,
1276  * usage flags, and formats for the configured streams.
1277  */
1278  int format;
1279 
1280  /*****
1281  * Set by HAL during configure_streams().
1282  */
1283 
1284  /**
1285  * The gralloc usage flags for this stream, as needed by the HAL. The usage
1286  * flags are defined in gralloc.h (GRALLOC_USAGE_*), or in device-specific
1287  * headers.
1288  *
1289  * For output streams, these are the HAL's producer usage flags. For input
1290  * streams, these are the HAL's consumer usage flags. The usage flags from
1291  * the producer and the consumer will be combined together and then passed
1292  * to the platform gralloc HAL module for allocating the gralloc buffers for
1293  * each stream.
1294  *
1295  * Version information:
1296  *
1297  * == CAMERA_DEVICE_API_VERSION_3_0:
1298  *
1299  * No initial value guaranteed when passed via configure_streams().
1300  * HAL may not use this field as input, and must write over this field
1301  * with its usage flags.
1302  *
1303  * >= CAMERA_DEVICE_API_VERSION_3_1:
1304  *
1305  * For stream_type OUTPUT and BIDIRECTIONAL, when passed via
1306  * configure_streams(), the initial value of this is the consumer's
1307  * usage flags. The HAL may use these consumer flags to decide stream
1308  * configuration.
1309  * For stream_type INPUT, when passed via configure_streams(), the initial
1310  * value of this is 0.
1311  * For all streams passed via configure_streams(), the HAL must write
1312  * over this field with its usage flags.
1313  */
1314  uint32_t usage;
1315 
1316  /**
1317  * The maximum number of buffers the HAL device may need to have dequeued at
1318  * the same time. The HAL device may not have more buffers in-flight from
1319  * this stream than this value.
1320  */
1321  uint32_t max_buffers;
1322 
1323  /**
1324  * A handle to HAL-private information for the stream. Will not be inspected
1325  * by the framework code.
1326  */
1327  void *priv;
1328 
1330 
1331 /**
1332  * camera3_stream_configuration_t:
1333  *
1334  * A structure of stream definitions, used by configure_streams(). This
1335  * structure defines all the output streams and the reprocessing input
1336  * stream for the current camera use case.
1337  */
1339  /**
1340  * The total number of streams requested by the framework. This includes
1341  * both input and output streams. The number of streams will be at least 1,
1342  * and there will be at least one output-capable stream.
1343  */
1344  uint32_t num_streams;
1345 
1346  /**
1347  * An array of camera stream pointers, defining the input/output
1348  * configuration for the camera HAL device.
1349  *
1350  * At most one input-capable stream may be defined (INPUT or BIDIRECTIONAL)
1351  * in a single configuration.
1352  *
1353  * At least one output-capable stream must be defined (OUTPUT or
1354  * BIDIRECTIONAL).
1355  */
1357 
1359 
1360 /**
1361  * camera3_buffer_status_t:
1362  *
1363  * The current status of a single stream buffer.
1364  */
1366  /**
1367  * The buffer is in a normal state, and can be used after waiting on its
1368  * sync fence.
1369  */
1371 
1372  /**
1373  * The buffer does not contain valid data, and the data in it should not be
1374  * used. The sync fence must still be waited on before reusing the buffer.
1375  */
1377 
1379 
1380 /**
1381  * camera3_stream_buffer_t:
1382  *
1383  * A single buffer from a camera3 stream. It includes a handle to its parent
1384  * stream, the handle to the gralloc buffer itself, and sync fences
1385  *
1386  * The buffer does not specify whether it is to be used for input or output;
1387  * that is determined by its parent stream type and how the buffer is passed to
1388  * the HAL device.
1389  */
1390 typedef struct camera3_stream_buffer {
1391  /**
1392  * The handle of the stream this buffer is associated with
1393  */
1395 
1396  /**
1397  * The native handle to the buffer
1398  */
1399  buffer_handle_t *buffer;
1400 
1401  /**
1402  * Current state of the buffer, one of the camera3_buffer_status_t
1403  * values. The framework will not pass buffers to the HAL that are in an
1404  * error state. In case a buffer could not be filled by the HAL, it must
1405  * have its status set to CAMERA3_BUFFER_STATUS_ERROR when returned to the
1406  * framework with process_capture_result().
1407  */
1408  int status;
1409 
1410  /**
1411  * The acquire sync fence for this buffer. The HAL must wait on this fence
1412  * fd before attempting to read from or write to this buffer.
1413  *
1414  * The framework may be set to -1 to indicate that no waiting is necessary
1415  * for this buffer.
1416  *
1417  * When the HAL returns an output buffer to the framework with
1418  * process_capture_result(), the acquire_fence must be set to -1. If the HAL
1419  * never waits on the acquire_fence due to an error in filling a buffer,
1420  * when calling process_capture_result() the HAL must set the release_fence
1421  * of the buffer to be the acquire_fence passed to it by the framework. This
1422  * will allow the framework to wait on the fence before reusing the buffer.
1423  *
1424  * For input buffers, the HAL must not change the acquire_fence field during
1425  * the process_capture_request() call.
1426  *
1427  * >= CAMERA_DEVICE_API_VERSION_3_2:
1428  *
1429  * When the HAL returns an input buffer to the framework with
1430  * process_capture_result(), the acquire_fence must be set to -1. If the HAL
1431  * never waits on input buffer acquire fence due to an error, the sync
1432  * fences should be handled similarly to the way they are handled for output
1433  * buffers.
1434  */
1436 
1437  /**
1438  * The release sync fence for this buffer. The HAL must set this fence when
1439  * returning buffers to the framework, or write -1 to indicate that no
1440  * waiting is required for this buffer.
1441  *
1442  * For the output buffers, the fences must be set in the output_buffers
1443  * array passed to process_capture_result().
1444  *
1445  * <= CAMERA_DEVICE_API_VERSION_3_1:
1446  *
1447  * For the input buffer, the release fence must be set by the
1448  * process_capture_request() call.
1449  *
1450  * >= CAMERA_DEVICE_API_VERSION_3_2:
1451  *
1452  * For the input buffer, the fences must be set in the input_buffer
1453  * passed to process_capture_result().
1454  *
1455  * After signaling the release_fence for this buffer, the HAL
1456  * should not make any further attempts to access this buffer as the
1457  * ownership has been fully transferred back to the framework.
1458  *
1459  * If a fence of -1 was specified then the ownership of this buffer
1460  * is transferred back immediately upon the call of process_capture_result.
1461  */
1463 
1465 
1466 /**
1467  * camera3_stream_buffer_set_t:
1468  *
1469  * The complete set of gralloc buffers for a stream. This structure is given to
1470  * register_stream_buffers() to allow the camera HAL device to register/map/etc
1471  * newly allocated stream buffers.
1472  *
1473  * >= CAMERA_DEVICE_API_VERSION_3_2:
1474  *
1475  * Deprecated (and not used). In particular,
1476  * register_stream_buffers is also deprecated and will never be invoked.
1477  *
1478  */
1480  /**
1481  * The stream handle for the stream these buffers belong to
1482  */
1484 
1485  /**
1486  * The number of buffers in this stream. It is guaranteed to be at least
1487  * stream->max_buffers.
1488  */
1489  uint32_t num_buffers;
1490 
1491  /**
1492  * The array of gralloc buffer handles for this stream. If the stream format
1493  * is set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, the camera HAL device
1494  * should inspect the passed-in buffers to determine any platform-private
1495  * pixel format information.
1496  */
1497  buffer_handle_t **buffers;
1498 
1500 
1501 /**
1502  * camera3_jpeg_blob:
1503  *
1504  * Transport header for compressed JPEG buffers in output streams.
1505  *
1506  * To capture JPEG images, a stream is created using the pixel format
1507  * HAL_PIXEL_FORMAT_BLOB. The buffer size for the stream is calculated by the
1508  * framework, based on the static metadata field android.jpeg.maxSize. Since
1509  * compressed JPEG images are of variable size, the HAL needs to include the
1510  * final size of the compressed image using this structure inside the output
1511  * stream buffer. The JPEG blob ID field must be set to CAMERA3_JPEG_BLOB_ID.
1512  *
1513  * Transport header should be at the end of the JPEG output stream buffer. That
1514  * means the jpeg_blob_id must start at byte[buffer_size -
1515  * sizeof(camera3_jpeg_blob)], where the buffer_size is the size of gralloc buffer.
1516  * Any HAL using this transport header must account for it in android.jpeg.maxSize
1517  * The JPEG data itself starts at the beginning of the buffer and should be
1518  * jpeg_size bytes long.
1519  */
1520 typedef struct camera3_jpeg_blob {
1521  uint16_t jpeg_blob_id;
1522  uint32_t jpeg_size;
1524 
1525 enum {
1527 };
1528 
1529 /**********************************************************************
1530  *
1531  * Message definitions for the HAL notify() callback.
1532  *
1533  * These definitions are used for the HAL notify callback, to signal
1534  * asynchronous events from the HAL device to the Android framework.
1535  *
1536  */
1537 
1538 /**
1539  * camera3_msg_type:
1540  *
1541  * Indicates the type of message sent, which specifies which member of the
1542  * message union is valid.
1543  *
1544  */
1545 typedef enum camera3_msg_type {
1546  /**
1547  * An error has occurred. camera3_notify_msg.message.error contains the
1548  * error information.
1549  */
1551 
1552  /**
1553  * The exposure of a given request has
1554  * begun. camera3_notify_msg.message.shutter contains the information
1555  * the capture.
1556  */
1558 
1559  /**
1560  * Number of framework message types
1561  */
1563 
1565 
1566 /**
1567  * Defined error codes for CAMERA_MSG_ERROR
1568  */
1570  /**
1571  * A serious failure occured. No further frames or buffer streams will
1572  * be produced by the device. Device should be treated as closed. The
1573  * client must reopen the device to use it again. The frame_number field
1574  * is unused.
1575  */
1577 
1578  /**
1579  * An error has occurred in processing a request. No output (metadata or
1580  * buffers) will be produced for this request. The frame_number field
1581  * specifies which request has been dropped. Subsequent requests are
1582  * unaffected, and the device remains operational.
1583  */
1585 
1586  /**
1587  * An error has occurred in producing an output result metadata buffer
1588  * for a request, but output stream buffers for it will still be
1589  * available. Subsequent requests are unaffected, and the device remains
1590  * operational. The frame_number field specifies the request for which
1591  * result metadata won't be available.
1592  */
1594 
1595  /**
1596  * An error has occurred in placing an output buffer into a stream for a
1597  * request. The frame metadata and other buffers may still be
1598  * available. Subsequent requests are unaffected, and the device remains
1599  * operational. The frame_number field specifies the request for which the
1600  * buffer was dropped, and error_stream contains a pointer to the stream
1601  * that dropped the frame.u
1602  */
1604 
1605  /**
1606  * Number of error types
1607  */
1609 
1611 
1612 /**
1613  * camera3_error_msg_t:
1614  *
1615  * Message contents for CAMERA3_MSG_ERROR
1616  */
1617 typedef struct camera3_error_msg {
1618  /**
1619  * Frame number of the request the error applies to. 0 if the frame number
1620  * isn't applicable to the error.
1621  */
1622  uint32_t frame_number;
1623 
1624  /**
1625  * Pointer to the stream that had a failure. NULL if the stream isn't
1626  * applicable to the error.
1627  */
1629 
1630  /**
1631  * The code for this error; one of the CAMERA_MSG_ERROR enum values.
1632  */
1634 
1636 
1637 /**
1638  * camera3_shutter_msg_t:
1639  *
1640  * Message contents for CAMERA3_MSG_SHUTTER
1641  */
1642 typedef struct camera3_shutter_msg {
1643  /**
1644  * Frame number of the request that has begun exposure
1645  */
1646  uint32_t frame_number;
1647 
1648  /**
1649  * Timestamp for the start of capture. This must match the capture result
1650  * metadata's sensor exposure start timestamp.
1651  */
1652  uint64_t timestamp;
1653 
1655 
1656 /**
1657  * camera3_notify_msg_t:
1658  *
1659  * The message structure sent to camera3_callback_ops_t.notify()
1660  */
1661 typedef struct camera3_notify_msg {
1662 
1663  /**
1664  * The message type. One of camera3_notify_msg_type, or a private extension.
1665  */
1666  int type;
1667 
1668  union {
1669  /**
1670  * Error message contents. Valid if type is CAMERA3_MSG_ERROR
1671  */
1673 
1674  /**
1675  * Shutter message contents. Valid if type is CAMERA3_MSG_SHUTTER
1676  */
1678 
1679  /**
1680  * Generic message contents. Used to ensure a minimum size for custom
1681  * message types.
1682  */
1683  uint8_t generic[32];
1684  } message;
1685 
1687 
1688 /**********************************************************************
1689  *
1690  * Capture request/result definitions for the HAL process_capture_request()
1691  * method, and the process_capture_result() callback.
1692  *
1693  */
1694 
1695 /**
1696  * camera3_request_template_t:
1697  *
1698  * Available template types for
1699  * camera3_device_ops.construct_default_request_settings()
1700  */
1702  /**
1703  * Standard camera preview operation with 3A on auto.
1704  */
1706 
1707  /**
1708  * Standard camera high-quality still capture with 3A and flash on auto.
1709  */
1711 
1712  /**
1713  * Standard video recording plus preview with 3A on auto, torch off.
1714  */
1716 
1717  /**
1718  * High-quality still capture while recording video. Application will
1719  * include preview, video record, and full-resolution YUV or JPEG streams in
1720  * request. Must not cause stuttering on video stream. 3A on auto.
1721  */
1723 
1724  /**
1725  * Zero-shutter-lag mode. Application will request preview and
1726  * full-resolution data for each frame, and reprocess it to JPEG when a
1727  * still image is requested by user. Settings should provide highest-quality
1728  * full-resolution images without compromising preview frame rate. 3A on
1729  * auto.
1730  */
1732 
1733  /**
1734  * A basic template for direct application control of capture
1735  * parameters. All automatic control is disabled (auto-exposure, auto-white
1736  * balance, auto-focus), and post-processing parameters are set to preview
1737  * quality. The manual capture parameters (exposure, sensitivity, etc.)
1738  * are set to reasonable defaults, but should be overridden by the
1739  * application depending on the intended use case.
1740  */
1742 
1743  /* Total number of templates */
1745 
1746  /**
1747  * First value for vendor-defined request templates
1748  */
1750 
1752 
1753 /**
1754  * camera3_capture_request_t:
1755  *
1756  * A single request for image capture/buffer reprocessing, sent to the Camera
1757  * HAL device by the framework in process_capture_request().
1758  *
1759  * The request contains the settings to be used for this capture, and the set of
1760  * output buffers to write the resulting image data in. It may optionally
1761  * contain an input buffer, in which case the request is for reprocessing that
1762  * input buffer instead of capturing a new image with the camera sensor. The
1763  * capture is identified by the frame_number.
1764  *
1765  * In response, the camera HAL device must send a camera3_capture_result
1766  * structure asynchronously to the framework, using the process_capture_result()
1767  * callback.
1768  */
1769 typedef struct camera3_capture_request {
1770  /**
1771  * The frame number is an incrementing integer set by the framework to
1772  * uniquely identify this capture. It needs to be returned in the result
1773  * call, and is also used to identify the request in asynchronous
1774  * notifications sent to camera3_callback_ops_t.notify().
1775  */
1776  uint32_t frame_number;
1777 
1778  /**
1779  * The settings buffer contains the capture and processing parameters for
1780  * the request. As a special case, a NULL settings buffer indicates that the
1781  * settings are identical to the most-recently submitted capture request. A
1782  * NULL buffer cannot be used as the first submitted request after a
1783  * configure_streams() call.
1784  */
1786 
1787  /**
1788  * The input stream buffer to use for this request, if any.
1789  *
1790  * If input_buffer is NULL, then the request is for a new capture from the
1791  * imager. If input_buffer is valid, the request is for reprocessing the
1792  * image contained in input_buffer.
1793  *
1794  * In the latter case, the HAL must set the release_fence of the
1795  * input_buffer to a valid sync fence, or to -1 if the HAL does not support
1796  * sync, before process_capture_request() returns.
1797  *
1798  * The HAL is required to wait on the acquire sync fence of the input buffer
1799  * before accessing it.
1800  *
1801  * <= CAMERA_DEVICE_API_VERSION_3_1:
1802  *
1803  * Any input buffer included here will have been registered with the HAL
1804  * through register_stream_buffers() before its inclusion in a request.
1805  *
1806  * >= CAMERA_DEVICE_API_VERSION_3_2:
1807  *
1808  * The buffers will not have been pre-registered with the HAL.
1809  * Subsequent requests may reuse buffers, or provide entirely new buffers.
1810  */
1812 
1813  /**
1814  * The number of output buffers for this capture request. Must be at least
1815  * 1.
1816  */
1818 
1819  /**
1820  * An array of num_output_buffers stream buffers, to be filled with image
1821  * data from this capture/reprocess. The HAL must wait on the acquire fences
1822  * of each stream buffer before writing to them.
1823  *
1824  * The HAL takes ownership of the actual buffer_handle_t entries in
1825  * output_buffers; the framework does not access them until they are
1826  * returned in a camera3_capture_result_t.
1827  *
1828  * <= CAMERA_DEVICE_API_VERSION_3_1:
1829  *
1830  * All the buffers included here will have been registered with the HAL
1831  * through register_stream_buffers() before their inclusion in a request.
1832  *
1833  * >= CAMERA_DEVICE_API_VERSION_3_2:
1834  *
1835  * Any or all of the buffers included here may be brand new in this
1836  * request (having never before seen by the HAL).
1837  */
1839 
1841 
1842 /**
1843  * camera3_capture_result_t:
1844  *
1845  * The result of a single capture/reprocess by the camera HAL device. This is
1846  * sent to the framework asynchronously with process_capture_result(), in
1847  * response to a single capture request sent to the HAL with
1848  * process_capture_request(). Multiple process_capture_result() calls may be
1849  * performed by the HAL for each request.
1850  *
1851  * Each call, all with the same frame
1852  * number, may contain some subset of the output buffers, and/or the result
1853  * metadata. The metadata may only be provided once for a given frame number;
1854  * all other calls must set the result metadata to NULL.
1855  *
1856  * The result structure contains the output metadata from this capture, and the
1857  * set of output buffers that have been/will be filled for this capture. Each
1858  * output buffer may come with a release sync fence that the framework will wait
1859  * on before reading, in case the buffer has not yet been filled by the HAL.
1860  *
1861  * >= CAMERA_DEVICE_API_VERSION_3_2:
1862  *
1863  * The metadata may be provided multiple times for a single frame number. The
1864  * framework will accumulate together the final result set by combining each
1865  * partial result together into the total result set.
1866  *
1867  * If an input buffer is given in a request, the HAL must return it in one of
1868  * the process_capture_result calls, and the call may be to just return the input
1869  * buffer, without metadata and output buffers; the sync fences must be handled
1870  * the same way they are done for output buffers.
1871  *
1872  *
1873  * Performance considerations:
1874  *
1875  * Applications will also receive these partial results immediately, so sending
1876  * partial results is a highly recommended performance optimization to avoid
1877  * the total pipeline latency before sending the results for what is known very
1878  * early on in the pipeline.
1879  *
1880  * A typical use case might be calculating the AF state halfway through the
1881  * pipeline; by sending the state back to the framework immediately, we get a
1882  * 50% performance increase and perceived responsiveness of the auto-focus.
1883  *
1884  */
1885 typedef struct camera3_capture_result {
1886  /**
1887  * The frame number is an incrementing integer set by the framework in the
1888  * submitted request to uniquely identify this capture. It is also used to
1889  * identify the request in asynchronous notifications sent to
1890  * camera3_callback_ops_t.notify().
1891  */
1892  uint32_t frame_number;
1893 
1894  /**
1895  * The result metadata for this capture. This contains information about the
1896  * final capture parameters, the state of the capture and post-processing
1897  * hardware, the state of the 3A algorithms, if enabled, and the output of
1898  * any enabled statistics units.
1899  *
1900  * Only one call to process_capture_result() with a given frame_number may
1901  * include the result metadata. All other calls for the same frame_number
1902  * must set this to NULL.
1903  *
1904  * If there was an error producing the result metadata, result must be an
1905  * empty metadata buffer, and notify() must be called with ERROR_RESULT.
1906  *
1907  * >= CAMERA_DEVICE_API_VERSION_3_2:
1908  *
1909  * Multiple calls to process_capture_result() with a given frame_number
1910  * may include the result metadata.
1911  *
1912  * Partial metadata submitted should not include any metadata key returned
1913  * in a previous partial result for a given frame. Each new partial result
1914  * for that frame must also set a distinct partial_result value.
1915  *
1916  * If notify has been called with ERROR_RESULT, all further partial
1917  * results for that frame are ignored by the framework.
1918  */
1920 
1921  /**
1922  * The number of output buffers returned in this result structure. Must be
1923  * less than or equal to the matching capture request's count. If this is
1924  * less than the buffer count in the capture request, at least one more call
1925  * to process_capture_result with the same frame_number must be made, to
1926  * return the remaining output buffers to the framework. This may only be
1927  * zero if the structure includes valid result metadata or an input buffer
1928  * is returned in this result.
1929  */
1931 
1932  /**
1933  * The handles for the output stream buffers for this capture. They may not
1934  * yet be filled at the time the HAL calls process_capture_result(); the
1935  * framework will wait on the release sync fences provided by the HAL before
1936  * reading the buffers.
1937  *
1938  * The HAL must set the stream buffer's release sync fence to a valid sync
1939  * fd, or to -1 if the buffer has already been filled.
1940  *
1941  * If the HAL encounters an error while processing the buffer, and the
1942  * buffer is not filled, the buffer's status field must be set to
1943  * CAMERA3_BUFFER_STATUS_ERROR. If the HAL did not wait on the acquire fence
1944  * before encountering the error, the acquire fence should be copied into
1945  * the release fence, to allow the framework to wait on the fence before
1946  * reusing the buffer.
1947  *
1948  * The acquire fence must be set to -1 for all output buffers. If
1949  * num_output_buffers is zero, this may be NULL. In that case, at least one
1950  * more process_capture_result call must be made by the HAL to provide the
1951  * output buffers.
1952  *
1953  * When process_capture_result is called with a new buffer for a frame,
1954  * all previous frames' buffers for that corresponding stream must have been
1955  * already delivered (the fences need not have yet been signaled).
1956  *
1957  * >= CAMERA_DEVICE_API_VERSION_3_2:
1958  *
1959  * Gralloc buffers for a frame may be sent to framework before the
1960  * corresponding SHUTTER-notify.
1961  *
1962  * Performance considerations:
1963  *
1964  * Buffers delivered to the framework will not be dispatched to the
1965  * application layer until a start of exposure timestamp has been received
1966  * via a SHUTTER notify() call. It is highly recommended to
1967  * dispatch that call as early as possible.
1968  */
1970 
1971  /**
1972  * >= CAMERA_DEVICE_API_VERSION_3_2:
1973  *
1974  * The handle for the input stream buffer for this capture. It may not
1975  * yet be consumed at the time the HAL calls process_capture_result(); the
1976  * framework will wait on the release sync fences provided by the HAL before
1977  * reusing the buffer.
1978  *
1979  * The HAL should handle the sync fences the same way they are done for
1980  * output_buffers.
1981  *
1982  * Only one input buffer is allowed to be sent per request. Similarly to
1983  * output buffers, the ordering of returned input buffers must be
1984  * maintained by the HAL.
1985  *
1986  * Performance considerations:
1987  *
1988  * The input buffer should be returned as early as possible. If the HAL
1989  * supports sync fences, it can call process_capture_result to hand it back
1990  * with sync fences being set appropriately. If the sync fences are not
1991  * supported, the buffer can only be returned when it is consumed, which
1992  * may take long time; the HAL may choose to copy this input buffer to make
1993  * the buffer return sooner.
1994  */
1996 
1997  /**
1998  * >= CAMERA_DEVICE_API_VERSION_3_2:
1999  *
2000  * In order to take advantage of partial results, the HAL must set the
2001  * static metadata android.request.partialResultCount to the number of
2002  * partial results it will send for each frame.
2003  *
2004  * Each new capture result with a partial result must set
2005  * this field (partial_result) to a distinct inclusive value between
2006  * 1 and android.request.partialResultCount.
2007  *
2008  * HALs not wishing to take advantage of this feature must not
2009  * set an android.request.partialResultCount or partial_result to a value
2010  * other than 1.
2011  *
2012  * This value must be set to 0 when a capture result contains buffers only
2013  * and no metadata.
2014  */
2015  uint32_t partial_result;
2016 
2018 
2019 /**********************************************************************
2020  *
2021  * Callback methods for the HAL to call into the framework.
2022  *
2023  * These methods are used to return metadata and image buffers for a completed
2024  * or failed captures, and to notify the framework of asynchronous events such
2025  * as errors.
2026  *
2027  * The framework will not call back into the HAL from within these callbacks,
2028  * and these calls will not block for extended periods.
2029  *
2030  */
2031 typedef struct camera3_callback_ops {
2032 
2033  /**
2034  * process_capture_result:
2035  *
2036  * Send results from a completed capture to the framework.
2037  * process_capture_result() may be invoked multiple times by the HAL in
2038  * response to a single capture request. This allows, for example, the
2039  * metadata and low-resolution buffers to be returned in one call, and
2040  * post-processed JPEG buffers in a later call, once it is available. Each
2041  * call must include the frame number of the request it is returning
2042  * metadata or buffers for.
2043  *
2044  * A component (buffer or metadata) of the complete result may only be
2045  * included in one process_capture_result call. A buffer for each stream,
2046  * and the result metadata, must be returned by the HAL for each request in
2047  * one of the process_capture_result calls, even in case of errors producing
2048  * some of the output. A call to process_capture_result() with neither
2049  * output buffers or result metadata is not allowed.
2050  *
2051  * The order of returning metadata and buffers for a single result does not
2052  * matter, but buffers for a given stream must be returned in FIFO order. So
2053  * the buffer for request 5 for stream A must always be returned before the
2054  * buffer for request 6 for stream A. This also applies to the result
2055  * metadata; the metadata for request 5 must be returned before the metadata
2056  * for request 6.
2057  *
2058  * However, different streams are independent of each other, so it is
2059  * acceptable and expected that the buffer for request 5 for stream A may be
2060  * returned after the buffer for request 6 for stream B is. And it is
2061  * acceptable that the result metadata for request 6 for stream B is
2062  * returned before the buffer for request 5 for stream A is.
2063  *
2064  * The HAL retains ownership of result structure, which only needs to be
2065  * valid to access during this call. The framework will copy whatever it
2066  * needs before this call returns.
2067  *
2068  * The output buffers do not need to be filled yet; the framework will wait
2069  * on the stream buffer release sync fence before reading the buffer
2070  * data. Therefore, this method should be called by the HAL as soon as
2071  * possible, even if some or all of the output buffers are still in
2072  * being filled. The HAL must include valid release sync fences into each
2073  * output_buffers stream buffer entry, or -1 if that stream buffer is
2074  * already filled.
2075  *
2076  * If the result buffer cannot be constructed for a request, the HAL should
2077  * return an empty metadata buffer, but still provide the output buffers and
2078  * their sync fences. In addition, notify() must be called with an
2079  * ERROR_RESULT message.
2080  *
2081  * If an output buffer cannot be filled, its status field must be set to
2082  * STATUS_ERROR. In addition, notify() must be called with a ERROR_BUFFER
2083  * message.
2084  *
2085  * If the entire capture has failed, then this method still needs to be
2086  * called to return the output buffers to the framework. All the buffer
2087  * statuses should be STATUS_ERROR, and the result metadata should be an
2088  * empty buffer. In addition, notify() must be called with a ERROR_REQUEST
2089  * message. In this case, individual ERROR_RESULT/ERROR_BUFFER messages
2090  * should not be sent.
2091  *
2092  * Performance requirements:
2093  *
2094  * This is a non-blocking call. The framework will return this call in 5ms.
2095  *
2096  * The pipeline latency (see S7 for definition) should be less than or equal to
2097  * 4 frame intervals, and must be less than or equal to 8 frame intervals.
2098  *
2099  */
2100  void (*process_capture_result)(const struct camera3_callback_ops *,
2101  const camera3_capture_result_t *result);
2102 
2103  /**
2104  * notify:
2105  *
2106  * Asynchronous notification callback from the HAL, fired for various
2107  * reasons. Only for information independent of frame capture, or that
2108  * require specific timing. The ownership of the message structure remains
2109  * with the HAL, and the msg only needs to be valid for the duration of this
2110  * call.
2111  *
2112  * Multiple threads may call notify() simultaneously.
2113  *
2114  * <= CAMERA_DEVICE_API_VERSION_3_1:
2115  *
2116  * The notification for the start of exposure for a given request must be
2117  * sent by the HAL before the first call to process_capture_result() for
2118  * that request is made.
2119  *
2120  * >= CAMERA_DEVICE_API_VERSION_3_2:
2121  *
2122  * Buffers delivered to the framework will not be dispatched to the
2123  * application layer until a start of exposure timestamp has been received
2124  * via a SHUTTER notify() call. It is highly recommended to
2125  * dispatch this call as early as possible.
2126  *
2127  * ------------------------------------------------------------------------
2128  * Performance requirements:
2129  *
2130  * This is a non-blocking call. The framework will return this call in 5ms.
2131  */
2132  void (*notify)(const struct camera3_callback_ops *,
2133  const camera3_notify_msg_t *msg);
2134 
2136 
2137 /**********************************************************************
2138  *
2139  * Camera device operations
2140  *
2141  */
2142 typedef struct camera3_device_ops {
2143 
2144  /**
2145  * initialize:
2146  *
2147  * One-time initialization to pass framework callback function pointers to
2148  * the HAL. Will be called once after a successful open() call, before any
2149  * other functions are called on the camera3_device_ops structure.
2150  *
2151  * Performance requirements:
2152  *
2153  * This should be a non-blocking call. The HAL should return from this call
2154  * in 5ms, and must return from this call in 10ms.
2155  *
2156  * Return values:
2157  *
2158  * 0: On successful initialization
2159  *
2160  * -ENODEV: If initialization fails. Only close() can be called successfully
2161  * by the framework after this.
2162  */
2163  int (*initialize)(const struct camera3_device *,
2164  const camera3_callback_ops_t *callback_ops);
2165 
2166  /**********************************************************************
2167  * Stream management
2168  */
2169 
2170  /**
2171  * configure_streams:
2172  *
2173  * CAMERA_DEVICE_API_VERSION_3_0 only:
2174  *
2175  * Reset the HAL camera device processing pipeline and set up new input and
2176  * output streams. This call replaces any existing stream configuration with
2177  * the streams defined in the stream_list. This method will be called at
2178  * least once after initialize() before a request is submitted with
2179  * process_capture_request().
2180  *
2181  * The stream_list must contain at least one output-capable stream, and may
2182  * not contain more than one input-capable stream.
2183  *
2184  * The stream_list may contain streams that are also in the currently-active
2185  * set of streams (from the previous call to configure_stream()). These
2186  * streams will already have valid values for usage, max_buffers, and the
2187  * private pointer.
2188  *
2189  * If such a stream has already had its buffers registered,
2190  * register_stream_buffers() will not be called again for the stream, and
2191  * buffers from the stream can be immediately included in input requests.
2192  *
2193  * If the HAL needs to change the stream configuration for an existing
2194  * stream due to the new configuration, it may rewrite the values of usage
2195  * and/or max_buffers during the configure call.
2196  *
2197  * The framework will detect such a change, and will then reallocate the
2198  * stream buffers, and call register_stream_buffers() again before using
2199  * buffers from that stream in a request.
2200  *
2201  * If a currently-active stream is not included in stream_list, the HAL may
2202  * safely remove any references to that stream. It will not be reused in a
2203  * later configure() call by the framework, and all the gralloc buffers for
2204  * it will be freed after the configure_streams() call returns.
2205  *
2206  * The stream_list structure is owned by the framework, and may not be
2207  * accessed once this call completes. The address of an individual
2208  * camera3_stream_t structure will remain valid for access by the HAL until
2209  * the end of the first configure_stream() call which no longer includes
2210  * that camera3_stream_t in the stream_list argument. The HAL may not change
2211  * values in the stream structure outside of the private pointer, except for
2212  * the usage and max_buffers members during the configure_streams() call
2213  * itself.
2214  *
2215  * If the stream is new, the usage, max_buffer, and private pointer fields
2216  * of the stream structure will all be set to 0. The HAL device must set
2217  * these fields before the configure_streams() call returns. These fields
2218  * are then used by the framework and the platform gralloc module to
2219  * allocate the gralloc buffers for each stream.
2220  *
2221  * Before such a new stream can have its buffers included in a capture
2222  * request, the framework will call register_stream_buffers() with that
2223  * stream. However, the framework is not required to register buffers for
2224  * _all_ streams before submitting a request. This allows for quick startup
2225  * of (for example) a preview stream, with allocation for other streams
2226  * happening later or concurrently.
2227  *
2228  * ------------------------------------------------------------------------
2229  * CAMERA_DEVICE_API_VERSION_3_1 only:
2230  *
2231  * Reset the HAL camera device processing pipeline and set up new input and
2232  * output streams. This call replaces any existing stream configuration with
2233  * the streams defined in the stream_list. This method will be called at
2234  * least once after initialize() before a request is submitted with
2235  * process_capture_request().
2236  *
2237  * The stream_list must contain at least one output-capable stream, and may
2238  * not contain more than one input-capable stream.
2239  *
2240  * The stream_list may contain streams that are also in the currently-active
2241  * set of streams (from the previous call to configure_stream()). These
2242  * streams will already have valid values for usage, max_buffers, and the
2243  * private pointer.
2244  *
2245  * If such a stream has already had its buffers registered,
2246  * register_stream_buffers() will not be called again for the stream, and
2247  * buffers from the stream can be immediately included in input requests.
2248  *
2249  * If the HAL needs to change the stream configuration for an existing
2250  * stream due to the new configuration, it may rewrite the values of usage
2251  * and/or max_buffers during the configure call.
2252  *
2253  * The framework will detect such a change, and will then reallocate the
2254  * stream buffers, and call register_stream_buffers() again before using
2255  * buffers from that stream in a request.
2256  *
2257  * If a currently-active stream is not included in stream_list, the HAL may
2258  * safely remove any references to that stream. It will not be reused in a
2259  * later configure() call by the framework, and all the gralloc buffers for
2260  * it will be freed after the configure_streams() call returns.
2261  *
2262  * The stream_list structure is owned by the framework, and may not be
2263  * accessed once this call completes. The address of an individual
2264  * camera3_stream_t structure will remain valid for access by the HAL until
2265  * the end of the first configure_stream() call which no longer includes
2266  * that camera3_stream_t in the stream_list argument. The HAL may not change
2267  * values in the stream structure outside of the private pointer, except for
2268  * the usage and max_buffers members during the configure_streams() call
2269  * itself.
2270  *
2271  * If the stream is new, max_buffer, and private pointer fields of the
2272  * stream structure will all be set to 0. The usage will be set to the
2273  * consumer usage flags. The HAL device must set these fields before the
2274  * configure_streams() call returns. These fields are then used by the
2275  * framework and the platform gralloc module to allocate the gralloc
2276  * buffers for each stream.
2277  *
2278  * Before such a new stream can have its buffers included in a capture
2279  * request, the framework will call register_stream_buffers() with that
2280  * stream. However, the framework is not required to register buffers for
2281  * _all_ streams before submitting a request. This allows for quick startup
2282  * of (for example) a preview stream, with allocation for other streams
2283  * happening later or concurrently.
2284  *
2285  * ------------------------------------------------------------------------
2286  * >= CAMERA_DEVICE_API_VERSION_3_2:
2287  *
2288  * Reset the HAL camera device processing pipeline and set up new input and
2289  * output streams. This call replaces any existing stream configuration with
2290  * the streams defined in the stream_list. This method will be called at
2291  * least once after initialize() before a request is submitted with
2292  * process_capture_request().
2293  *
2294  * The stream_list must contain at least one output-capable stream, and may
2295  * not contain more than one input-capable stream.
2296  *
2297  * The stream_list may contain streams that are also in the currently-active
2298  * set of streams (from the previous call to configure_stream()). These
2299  * streams will already have valid values for usage, max_buffers, and the
2300  * private pointer.
2301  *
2302  * If the HAL needs to change the stream configuration for an existing
2303  * stream due to the new configuration, it may rewrite the values of usage
2304  * and/or max_buffers during the configure call.
2305  *
2306  * The framework will detect such a change, and may then reallocate the
2307  * stream buffers before using buffers from that stream in a request.
2308  *
2309  * If a currently-active stream is not included in stream_list, the HAL may
2310  * safely remove any references to that stream. It will not be reused in a
2311  * later configure() call by the framework, and all the gralloc buffers for
2312  * it will be freed after the configure_streams() call returns.
2313  *
2314  * The stream_list structure is owned by the framework, and may not be
2315  * accessed once this call completes. The address of an individual
2316  * camera3_stream_t structure will remain valid for access by the HAL until
2317  * the end of the first configure_stream() call which no longer includes
2318  * that camera3_stream_t in the stream_list argument. The HAL may not change
2319  * values in the stream structure outside of the private pointer, except for
2320  * the usage and max_buffers members during the configure_streams() call
2321  * itself.
2322  *
2323  * If the stream is new, max_buffer, and private pointer fields of the
2324  * stream structure will all be set to 0. The usage will be set to the
2325  * consumer usage flags. The HAL device must set these fields before the
2326  * configure_streams() call returns. These fields are then used by the
2327  * framework and the platform gralloc module to allocate the gralloc
2328  * buffers for each stream.
2329  *
2330  * Newly allocated buffers may be included in a capture request at any time
2331  * by the framework. Once a gralloc buffer is returned to the framework
2332  * with process_capture_result (and its respective release_fence has been
2333  * signaled) the framework may free or reuse it at any time.
2334  *
2335  * ------------------------------------------------------------------------
2336  *
2337  * Preconditions:
2338  *
2339  * The framework will only call this method when no captures are being
2340  * processed. That is, all results have been returned to the framework, and
2341  * all in-flight input and output buffers have been returned and their
2342  * release sync fences have been signaled by the HAL. The framework will not
2343  * submit new requests for capture while the configure_streams() call is
2344  * underway.
2345  *
2346  * Postconditions:
2347  *
2348  * The HAL device must configure itself to provide maximum possible output
2349  * frame rate given the sizes and formats of the output streams, as
2350  * documented in the camera device's static metadata.
2351  *
2352  * Performance requirements:
2353  *
2354  * This call is expected to be heavyweight and possibly take several hundred
2355  * milliseconds to complete, since it may require resetting and
2356  * reconfiguring the image sensor and the camera processing pipeline.
2357  * Nevertheless, the HAL device should attempt to minimize the
2358  * reconfiguration delay to minimize the user-visible pauses during
2359  * application operational mode changes (such as switching from still
2360  * capture to video recording).
2361  *
2362  * The HAL should return from this call in 500ms, and must return from this
2363  * call in 1000ms.
2364  *
2365  * Return values:
2366  *
2367  * 0: On successful stream configuration
2368  *
2369  * -EINVAL: If the requested stream configuration is invalid. Some examples
2370  * of invalid stream configurations include:
2371  *
2372  * - Including more than 1 input-capable stream (INPUT or
2373  * BIDIRECTIONAL)
2374  *
2375  * - Not including any output-capable streams (OUTPUT or
2376  * BIDIRECTIONAL)
2377  *
2378  * - Including streams with unsupported formats, or an unsupported
2379  * size for that format.
2380  *
2381  * - Including too many output streams of a certain format.
2382  *
2383  * Note that the framework submitting an invalid stream
2384  * configuration is not normal operation, since stream
2385  * configurations are checked before configure. An invalid
2386  * configuration means that a bug exists in the framework code, or
2387  * there is a mismatch between the HAL's static metadata and the
2388  * requirements on streams.
2389  *
2390  * -ENODEV: If there has been a fatal error and the device is no longer
2391  * operational. Only close() can be called successfully by the
2392  * framework after this error is returned.
2393  */
2394  int (*configure_streams)(const struct camera3_device *,
2395  camera3_stream_configuration_t *stream_list);
2396 
2397  /**
2398  * register_stream_buffers:
2399  *
2400  * >= CAMERA_DEVICE_API_VERSION_3_2:
2401  *
2402  * DEPRECATED. This will not be called and must be set to NULL.
2403  *
2404  * <= CAMERA_DEVICE_API_VERSION_3_1:
2405  *
2406  * Register buffers for a given stream with the HAL device. This method is
2407  * called by the framework after a new stream is defined by
2408  * configure_streams, and before buffers from that stream are included in a
2409  * capture request. If the same stream is listed in a subsequent
2410  * configure_streams() call, register_stream_buffers will _not_ be called
2411  * again for that stream.
2412  *
2413  * The framework does not need to register buffers for all configured
2414  * streams before it submits the first capture request. This allows quick
2415  * startup for preview (or similar use cases) while other streams are still
2416  * being allocated.
2417  *
2418  * This method is intended to allow the HAL device to map or otherwise
2419  * prepare the buffers for later use. The buffers passed in will already be
2420  * locked for use. At the end of the call, all the buffers must be ready to
2421  * be returned to the stream. The buffer_set argument is only valid for the
2422  * duration of this call.
2423  *
2424  * If the stream format was set to HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,
2425  * the camera HAL should inspect the passed-in buffers here to determine any
2426  * platform-private pixel format information.
2427  *
2428  * Performance requirements:
2429  *
2430  * This should be a non-blocking call. The HAL should return from this call
2431  * in 1ms, and must return from this call in 5ms.
2432  *
2433  * Return values:
2434  *
2435  * 0: On successful registration of the new stream buffers
2436  *
2437  * -EINVAL: If the stream_buffer_set does not refer to a valid active
2438  * stream, or if the buffers array is invalid.
2439  *
2440  * -ENOMEM: If there was a failure in registering the buffers. The framework
2441  * must consider all the stream buffers to be unregistered, and can
2442  * try to register again later.
2443  *
2444  * -ENODEV: If there is a fatal error, and the device is no longer
2445  * operational. Only close() can be called successfully by the
2446  * framework after this error is returned.
2447  */
2448  int (*register_stream_buffers)(const struct camera3_device *,
2449  const camera3_stream_buffer_set_t *buffer_set);
2450 
2451  /**********************************************************************
2452  * Request creation and submission
2453  */
2454 
2455  /**
2456  * construct_default_request_settings:
2457  *
2458  * Create capture settings for standard camera use cases.
2459  *
2460  * The device must return a settings buffer that is configured to meet the
2461  * requested use case, which must be one of the CAMERA3_TEMPLATE_*
2462  * enums. All request control fields must be included.
2463  *
2464  * The HAL retains ownership of this structure, but the pointer to the
2465  * structure must be valid until the device is closed. The framework and the
2466  * HAL may not modify the buffer once it is returned by this call. The same
2467  * buffer may be returned for subsequent calls for the same template, or for
2468  * other templates.
2469  *
2470  * Performance requirements:
2471  *
2472  * This should be a non-blocking call. The HAL should return from this call
2473  * in 1ms, and must return from this call in 5ms.
2474  *
2475  * Return values:
2476  *
2477  * Valid metadata: On successful creation of a default settings
2478  * buffer.
2479  *
2480  * NULL: In case of a fatal error. After this is returned, only
2481  * the close() method can be called successfully by the
2482  * framework.
2483  */
2484  const camera_metadata_t* (*construct_default_request_settings)(
2485  const struct camera3_device *,
2486  int type);
2487 
2488  /**
2489  * process_capture_request:
2490  *
2491  * Send a new capture request to the HAL. The HAL should not return from
2492  * this call until it is ready to accept the next request to process. Only
2493  * one call to process_capture_request() will be made at a time by the
2494  * framework, and the calls will all be from the same thread. The next call
2495  * to process_capture_request() will be made as soon as a new request and
2496  * its associated buffers are available. In a normal preview scenario, this
2497  * means the function will be called again by the framework almost
2498  * instantly.
2499  *
2500  * The actual request processing is asynchronous, with the results of
2501  * capture being returned by the HAL through the process_capture_result()
2502  * call. This call requires the result metadata to be available, but output
2503  * buffers may simply provide sync fences to wait on. Multiple requests are
2504  * expected to be in flight at once, to maintain full output frame rate.
2505  *
2506  * The framework retains ownership of the request structure. It is only
2507  * guaranteed to be valid during this call. The HAL device must make copies
2508  * of the information it needs to retain for the capture processing. The HAL
2509  * is responsible for waiting on and closing the buffers' fences and
2510  * returning the buffer handles to the framework.
2511  *
2512  * The HAL must write the file descriptor for the input buffer's release
2513  * sync fence into input_buffer->release_fence, if input_buffer is not
2514  * NULL. If the HAL returns -1 for the input buffer release sync fence, the
2515  * framework is free to immediately reuse the input buffer. Otherwise, the
2516  * framework will wait on the sync fence before refilling and reusing the
2517  * input buffer.
2518  *
2519  * >= CAMERA_DEVICE_API_VERSION_3_2:
2520  *
2521  * The input/output buffers provided by the framework in each request
2522  * may be brand new (having never before seen by the HAL).
2523  *
2524  * ------------------------------------------------------------------------
2525  * Performance considerations:
2526  *
2527  * Handling a new buffer should be extremely lightweight and there should be
2528  * no frame rate degradation or frame jitter introduced.
2529  *
2530  * This call must return fast enough to ensure that the requested frame
2531  * rate can be sustained, especially for streaming cases (post-processing
2532  * quality settings set to FAST). The HAL should return this call in 1
2533  * frame interval, and must return from this call in 4 frame intervals.
2534  *
2535  * Return values:
2536  *
2537  * 0: On a successful start to processing the capture request
2538  *
2539  * -EINVAL: If the input is malformed (the settings are NULL when not
2540  * allowed, there are 0 output buffers, etc) and capture processing
2541  * cannot start. Failures during request processing should be
2542  * handled by calling camera3_callback_ops_t.notify(). In case of
2543  * this error, the framework will retain responsibility for the
2544  * stream buffers' fences and the buffer handles; the HAL should
2545  * not close the fences or return these buffers with
2546  * process_capture_result.
2547  *
2548  * -ENODEV: If the camera device has encountered a serious error. After this
2549  * error is returned, only the close() method can be successfully
2550  * called by the framework.
2551  *
2552  */
2553  int (*process_capture_request)(const struct camera3_device *,
2554  camera3_capture_request_t *request);
2555 
2556  /**********************************************************************
2557  * Miscellaneous methods
2558  */
2559 
2560  /**
2561  * get_metadata_vendor_tag_ops:
2562  *
2563  * Get methods to query for vendor extension metadata tag information. The
2564  * HAL should fill in all the vendor tag operation methods, or leave ops
2565  * unchanged if no vendor tags are defined.
2566  *
2567  * The definition of vendor_tag_query_ops_t can be found in
2568  * system/media/camera/include/system/camera_metadata.h.
2569  *
2570  * >= CAMERA_DEVICE_API_VERSION_3_2:
2571  * DEPRECATED. This function has been deprecated and should be set to
2572  * NULL by the HAL. Please implement get_vendor_tag_ops in camera_common.h
2573  * instead.
2574  */
2575  void (*get_metadata_vendor_tag_ops)(const struct camera3_device*,
2576  vendor_tag_query_ops_t* ops);
2577 
2578  /**
2579  * dump:
2580  *
2581  * Print out debugging state for the camera device. This will be called by
2582  * the framework when the camera service is asked for a debug dump, which
2583  * happens when using the dumpsys tool, or when capturing a bugreport.
2584  *
2585  * The passed-in file descriptor can be used to write debugging text using
2586  * dprintf() or write(). The text should be in ASCII encoding only.
2587  *
2588  * Performance requirements:
2589  *
2590  * This must be a non-blocking call. The HAL should return from this call
2591  * in 1ms, must return from this call in 10ms. This call must avoid
2592  * deadlocks, as it may be called at any point during camera operation.
2593  * Any synchronization primitives used (such as mutex locks or semaphores)
2594  * should be acquired with a timeout.
2595  */
2596  void (*dump)(const struct camera3_device *, int fd);
2597 
2598  /**
2599  * flush:
2600  *
2601  * Flush all currently in-process captures and all buffers in the pipeline
2602  * on the given device. The framework will use this to dump all state as
2603  * quickly as possible in order to prepare for a configure_streams() call.
2604  *
2605  * No buffers are required to be successfully returned, so every buffer
2606  * held at the time of flush() (whether successfully filled or not) may be
2607  * returned with CAMERA3_BUFFER_STATUS_ERROR. Note the HAL is still allowed
2608  * to return valid (CAMERA3_BUFFER_STATUS_OK) buffers during this call,
2609  * provided they are successfully filled.
2610  *
2611  * All requests currently in the HAL are expected to be returned as soon as
2612  * possible. Not-in-process requests should return errors immediately. Any
2613  * interruptible hardware blocks should be stopped, and any uninterruptible
2614  * blocks should be waited on.
2615  *
2616  * More specifically, the HAL must follow below requirements for various cases:
2617  *
2618  * 1. For captures that are too late for the HAL to cancel/stop, and will be
2619  * completed normally by the HAL; i.e. the HAL can send shutter/notify and
2620  * process_capture_result and buffers as normal.
2621  *
2622  * 2. For pending requests that have not done any processing, the HAL must call notify
2623  * CAMERA3_MSG_ERROR_REQUEST, and return all the output buffers with
2624  * process_capture_result in the error state (CAMERA3_BUFFER_STATUS_ERROR).
2625  * The HAL must not place the release fence into an error state, instead,
2626  * the release fences must be set to the acquire fences passed by the framework,
2627  * or -1 if they have been waited on by the HAL already. This is also the path
2628  * to follow for any captures for which the HAL already called notify() with
2629  * CAMERA3_MSG_SHUTTER but won't be producing any metadata/valid buffers for.
2630  * After CAMERA3_MSG_ERROR_REQUEST, for a given frame, only process_capture_results with
2631  * buffers in CAMERA3_BUFFER_STATUS_ERROR are allowed. No further notifys or
2632  * process_capture_result with non-null metadata is allowed.
2633  *
2634  * 3. For partially completed pending requests that will not have all the output
2635  * buffers or perhaps missing metadata, the HAL should follow below:
2636  *
2637  * 3.1. Call notify with CAMERA3_MSG_ERROR_RESULT if some of the expected result
2638  * metadata (i.e. one or more partial metadata) won't be available for the capture.
2639  *
2640  * 3.2. Call notify with CAMERA3_MSG_ERROR_BUFFER for every buffer that won't
2641  * be produced for the capture.
2642  *
2643  * 3.3 Call notify with CAMERA3_MSG_SHUTTER with the capture timestamp before
2644  * any buffers/metadata are returned with process_capture_result.
2645  *
2646  * 3.4 For captures that will produce some results, the HAL must not call
2647  * CAMERA3_MSG_ERROR_REQUEST, since that indicates complete failure.
2648  *
2649  * 3.5. Valid buffers/metadata should be passed to the framework as normal.
2650  *
2651  * 3.6. Failed buffers should be returned to the framework as described for case 2.
2652  * But failed buffers do not have to follow the strict ordering valid buffers do,
2653  * and may be out-of-order with respect to valid buffers. For example, if buffers
2654  * A, B, C, D, E are sent, D and E are failed, then A, E, B, D, C is an acceptable
2655  * return order.
2656  *
2657  * 3.7. For fully-missing metadata, calling CAMERA3_MSG_ERROR_RESULT is sufficient, no
2658  * need to call process_capture_result with NULL metadata or equivalent.
2659  *
2660  * flush() should only return when there are no more outstanding buffers or
2661  * requests left in the HAL. The framework may call configure_streams (as
2662  * the HAL state is now quiesced) or may issue new requests.
2663  *
2664  * Note that it's sufficient to only support fully-succeeded and fully-failed result cases.
2665  * However, it is highly desirable to support the partial failure cases as well, as it
2666  * could help improve the flush call overall performance.
2667  *
2668  * Performance requirements:
2669  *
2670  * The HAL should return from this call in 100ms, and must return from this
2671  * call in 1000ms. And this call must not be blocked longer than pipeline
2672  * latency (see S7 for definition).
2673  *
2674  * Version information:
2675  *
2676  * only available if device version >= CAMERA_DEVICE_API_VERSION_3_1.
2677  *
2678  * Return values:
2679  *
2680  * 0: On a successful flush of the camera HAL.
2681  *
2682  * -EINVAL: If the input is malformed (the device is not valid).
2683  *
2684  * -ENODEV: If the camera device has encountered a serious error. After this
2685  * error is returned, only the close() method can be successfully
2686  * called by the framework.
2687  */
2688  int (*flush)(const struct camera3_device *);
2689 
2690  /* reserved for future use */
2691  void *reserved[8];
2693 
2694 /**********************************************************************
2695  *
2696  * Camera device definition
2697  *
2698  */
2699 typedef struct camera3_device {
2700  /**
2701  * common.version must equal CAMERA_DEVICE_API_VERSION_3_0 to identify this
2702  * device as implementing version 3.0 of the camera device HAL.
2703  *
2704  * Performance requirements:
2705  *
2706  * Camera open (common.module->common.methods->open) should return in 200ms, and must return
2707  * in 500ms.
2708  * Camera close (common.close) should return in 200ms, and must return in 500ms.
2709  *
2710  */
2713  void *priv;
2715 
2716 __END_DECLS
2717 
2718 #endif /* #ifdef ANDROID_INCLUDE_CAMERA3_H */
enum camera3_msg_type camera3_msg_type_t
buffer_handle_t ** buffers
Definition: camera3.h:1497
struct camera3_stream_buffer camera3_stream_buffer_t
uint64_t timestamp
Definition: camera3.h:1652
struct camera_metadata camera_metadata_t
camera3_stream_t * error_stream
Definition: camera3.h:1628
enum camera3_request_template camera3_request_template_t
struct camera3_device_ops camera3_device_ops_t
const camera3_stream_buffer_t * output_buffers
Definition: camera3.h:1969
uint32_t width
Definition: camera3.h:1250
struct camera3_jpeg_blob camera3_jpeg_blob_t
camera3_stream_t ** streams
Definition: camera3.h:1356
struct camera3_stream_configuration camera3_stream_configuration_t
camera3_buffer_status
Definition: camera3.h:1365
uint32_t frame_number
Definition: camera3.h:1646
struct camera3_stream_buffer_set camera3_stream_buffer_set_t
camera3_stream_type
Definition: camera3.h:1161
uint32_t num_output_buffers
Definition: camera3.h:1930
struct camera3_capture_request camera3_capture_request_t
const camera3_stream_buffer_t * output_buffers
Definition: camera3.h:1838
camera3_stream_t * stream
Definition: camera3.h:1394
struct camera3_callback_ops camera3_callback_ops_t
camera3_stream_t * stream
Definition: camera3.h:1483
hw_device_t common
Definition: camera3.h:2711
camera3_error_msg_code
Definition: camera3.h:1569
camera3_device_ops_t * ops
Definition: camera3.h:2712
enum camera3_buffer_status camera3_buffer_status_t
uint32_t frame_number
Definition: camera3.h:1622
struct camera3_notify_msg camera3_notify_msg_t
camera3_request_template
Definition: camera3.h:1701
camera3_error_msg_t error
Definition: camera3.h:1672
struct camera3_device camera3_device_t
uint32_t num_output_buffers
Definition: camera3.h:1817
const camera_metadata_t * result
Definition: camera3.h:1919
uint32_t max_buffers
Definition: camera3.h:1321
buffer_handle_t * buffer
Definition: camera3.h:1399
uint32_t partial_result
Definition: camera3.h:2015
struct camera3_capture_result camera3_capture_result_t
uint32_t jpeg_size
Definition: camera3.h:1522
struct camera3_shutter_msg camera3_shutter_msg_t
struct camera3_stream camera3_stream_t
camera3_shutter_msg_t shutter
Definition: camera3.h:1677
uint16_t jpeg_blob_id
Definition: camera3.h:1521
union camera3_notify_msg::@11 message
uint32_t height
Definition: camera3.h:1255
camera3_stream_buffer_t * input_buffer
Definition: camera3.h:1811
struct camera3_error_msg camera3_error_msg_t
camera3_msg_type
Definition: camera3.h:1545
void * priv
Definition: camera3.h:2713
uint32_t usage
Definition: camera3.h:1314
void * priv
Definition: camera3.h:1327
const camera_metadata_t * settings
Definition: camera3.h:1785
const camera3_stream_buffer_t * input_buffer
Definition: camera3.h:1995
enum camera3_stream_type camera3_stream_type_t
enum camera3_error_msg_code camera3_error_msg_code_t