/*
* Copyright (C) 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @addtogroup Camera
* @{
*/
/**
* @file NdkCameraDevice.h
*/
/*
* This file defines an NDK API.
* Do not remove methods.
* Do not change method signatures.
* Do not change the value of constants.
* Do not change the size of any of the classes defined in here.
* Do not reference types that are not part of the NDK.
* Do not #include files that aren't part of the NDK.
*/
#include The camera device needs to be re-opened to be used again. The Android device may need to be shut down and restarted to restore
* camera function, or there may be a persistent hardware problem.
* An attempt at recovery may be possible by closing the
* CameraDevice and the CameraManager, and trying to acquire all resources
* again from scratch. Any attempt to call API methods on this ACameraDevice will return
* {@link ACAMERA_ERROR_CAMERA_DISCONNECTED}. The disconnection could be due to a
* change in security policy or permissions; the physical disconnection
* of a removable camera device; or the camera being needed for a
* higher-priority camera API client. Application should clean up the camera with {@link ACameraDevice_close} after
* this happens, as it is not recoverable until the camera can be opened
* again. This indicates a failure of the camera device or camera service in some way.
* Any attempt to call API methods on this ACameraDevice in the future will return
* {@link ACAMERA_ERROR_CAMERA_DISCONNECTED}. There may still be capture completion or camera stream callbacks that will be called
* after this error is received. Application should clean up the camera with {@link ACameraDevice_close} after this
* happens. Further attempts at recovery are error-code specific. After this call, all calls to the active ACameraCaptureSession associated to this
* ACameraDevice will return {@link ACAMERA_ERROR_SESSION_CLOSED} except for calls to
* {@link ACameraCaptureSession_close}. This method will stop all repeating captures sent via
* {@link ACameraCaptureSession_setRepeatingRequest} and block until all capture requests sent via
* {@link ACameraCaptureSession_capture} is complete. Once the method returns, the camera device
* will be removed from memory and access to the closed camera device pointer will cause a crash. The settings are chosen to be the best options for this camera device,
* so it is not recommended to reuse the same request for a different camera device. The container is used in {@link ACameraDevice_createCaptureSession} method to create a capture
* session. Use {@link ACaptureSessionOutputContainer_free} to free the container and its memory
* after application no longer needs the ACaptureSessionOutputContainer. The ACaptureSessionOutput is used in {@link ACaptureSessionOutputContainer_add} method to add
* an output {@link ANativeWindow} to ACaptureSessionOutputContainer. Use
* {@link ACaptureSessionOutput_free} to free the object and its memory after application no longer
* needs the {@link ACaptureSessionOutput}. This method has no effect if the ACaptureSessionOutput does not exist in
* ACaptureSessionOutputContainer. If there is a preexisting session, the previous session will be closed
* automatically. However, app still needs to call {@link ACameraCaptureSession_close} on previous
* session. Otherwise the resources held by previous session will NOT be freed. The active capture session determines the set of potential output {@link ANativeWindow}s for
* the camera device for each capture request. A given request may use all
* or only some of the outputs. Once the ACameraCaptureSession is created, requests can be
* submitted with {@link ACameraCaptureSession_capture} or
* {@link ACameraCaptureSession_setRepeatingRequest}. Often the {@link ANativeWindow} used with this method can be obtained from a Surface java object by
* {@link ANativeWindow_fromSurface} NDK method. Surfaces or ANativeWindow suitable for inclusion as a camera
* output can be created for various use cases and targets: The camera device will query each ANativeWindow's size and formats upon this
* call, so they must be set to a valid setting at this time. It can take several hundred milliseconds for the session's configuration to complete,
* since camera hardware may need to be powered on or reconfigured. If a prior ACameraCaptureSession already exists when this method is called, the previous
* session will no longer be able to accept new capture requests and will be closed. Any
* in-progress capture requests made on the prior session will be completed before it's closed.
* To minimize the transition time,
* the ACameraCaptureSession_abortCaptures method can be used to discard the remaining
* requests for the prior capture session before a new one is created. Note that once the new
* session is created, the old one can no longer have its captures aborted. Using larger resolution outputs, or more outputs, can result in slower
* output rate from the device. Configuring a session with an empty list will close the current session, if
* any. This can be used to release the current session's target surfaces for another use. While any of the sizes from {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS} can be used when
* a single output stream is configured, a given camera device may not be able to support all
* combination of sizes, formats, and targets when multiple outputs are configured at once. The
* tables below list the maximum guaranteed resolutions for combinations of streams and targets,
* given the capabilities of the camera device. If an application tries to create a session using a set of targets that exceed the limits
* described in the below tables, one of three possibilities may occur. First, the session may
* be successfully created and work normally. Second, the session may be successfully created,
* but the camera device won't meet the frame rate guarantees as described in
* {@link ACAMERA_SCALER_AVAILABLE_MIN_FRAME_DURATIONS}. Or third, if the output set
* cannot be used at all, session creation will fail entirely, with
* {@link ACAMERA_ERROR_STREAM_CONFIGURE_FAIL} being returned. For the type column `PRIV` refers to output format {@link AIMAGE_FORMAT_PRIVATE},
* `YUV` refers to output format {@link AIMAGE_FORMAT_YUV_420_888},
* `JPEG` refers to output format {@link AIMAGE_FORMAT_JPEG},
* and `RAW` refers to output format {@link AIMAGE_FORMAT_RAW16}
*
*
* For the maximum size column, `PREVIEW` refers to the best size match to the
* device's screen resolution, or to 1080p `(1920x1080)`, whichever is
* smaller. `RECORD` refers to the camera device's maximum supported recording resolution,
* as determined by
* android.media.CamcorderProfiles. And `MAXIMUM` refers to the
* camera device's maximum output resolution for that format or target from
* {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS}. To use these tables, determine the number and the formats/targets of outputs needed, and
* find the row(s) of the table with those targets. The sizes indicate the maximum set of sizes
* that can be used; it is guaranteed that for those targets, the listed sizes and anything
* smaller from the list given by {@link ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS} can be
* successfully used to create a session. For example, if a row indicates that a 8 megapixel
* (MP) YUV_420_888 output can be used together with a 2 MP `PRIV` output, then a session
* can be created with targets `[8 MP YUV, 2 MP PRIV]` or targets `[2 MP YUV, 2 MP PRIV]`;
* but a session with targets `[8 MP YUV, 4 MP PRIV]`, targets `[4 MP YUV, 4 MP PRIV]`,
* or targets `[8 MP PRIV, 2 MP YUV]` would not be guaranteed to work, unless
* some other row of the table lists such a combination. Legacy devices ({@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL}
* `== `{@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY LEGACY}) support at
* least the following stream combinations:
*
*
*
*/
camera_status_t ACameraDevice_close(ACameraDevice* device);
/**
* Return the camera id associated with this camera device.
*
* @param device the camera device to be closed
*
* @return camera ID string. The returned string is managed by framework and should not be
* delete/free by the application. Also the returned string must not be used after the device
* has been closed.
*/
const char* ACameraDevice_getId(const ACameraDevice* device);
typedef enum {
/**
* Create a request suitable for a camera preview window. Specifically, this
* means that high frame rate is given priority over the highest-quality
* post-processing. These requests would normally be used with the
* {@link ACameraCaptureSession_setRepeatingRequest} method.
* This template is guaranteed to be supported on all camera devices.
*
* @see ACameraDevice_createCaptureRequest
*/
TEMPLATE_PREVIEW = 1,
/**
* Create a request suitable for still image capture. Specifically, this
* means prioritizing image quality over frame rate. These requests would
* commonly be used with the {@link ACameraCaptureSession_capture} method.
* This template is guaranteed to be supported on all camera devices.
*
* @see ACameraDevice_createCaptureRequest
*/
TEMPLATE_STILL_CAPTURE = 2,
/**
* Create a request suitable for video recording. Specifically, this means
* that a stable frame rate is used, and post-processing is set for
* recording quality. These requests would commonly be used with the
* {@link ACameraCaptureSession_setRepeatingRequest} method.
* This template is guaranteed to be supported on all camera devices.
*
* @see ACameraDevice_createCaptureRequest
*/
TEMPLATE_RECORD = 3,
/**
* Create a request suitable for still image capture while recording
* video. Specifically, this means maximizing image quality without
* disrupting the ongoing recording. These requests would commonly be used
* with the {@link ACameraCaptureSession_capture} method while a request based on
* {@link TEMPLATE_RECORD} is is in use with {@link ACameraCaptureSession_setRepeatingRequest}.
* This template is guaranteed to be supported on all camera devices.
*
* @see ACameraDevice_createCaptureRequest
*/
TEMPLATE_VIDEO_SNAPSHOT = 4,
/**
* Create a request suitable for zero shutter lag still capture. This means
* means maximizing image quality without compromising preview frame rate.
* AE/AWB/AF should be on auto mode.
*
* @see ACameraDevice_createCaptureRequest
*/
TEMPLATE_ZERO_SHUTTER_LAG = 5,
/**
* A basic template for direct application control of capture
* parameters. All automatic control is disabled (auto-exposure, auto-white
* balance, auto-focus), and post-processing parameters are set to preview
* quality. The manual capture parameters (exposure, sensitivity, and so on)
* are set to reasonable defaults, but should be overriden by the
* application depending on the intended use case.
* This template is guaranteed to be supported on camera devices that support the
* {@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_MANUAL_SENSOR} capability.
*
* @see ACameraDevice_createCaptureRequest
*/
TEMPLATE_MANUAL = 6,
} ACameraDevice_request_template;
/**
* Create a ACaptureRequest for capturing images, initialized with template
* for a target use case.
*
*
*
*
* @see TEMPLATE_PREVIEW
* @see TEMPLATE_RECORD
* @see TEMPLATE_STILL_CAPTURE
* @see TEMPLATE_VIDEO_SNAPSHOT
* @see TEMPLATE_MANUAL
*/
camera_status_t ACameraDevice_createCaptureRequest(
const ACameraDevice* device, ACameraDevice_request_template templateId,
/*out*/ACaptureRequest** request);
typedef struct ACaptureSessionOutputContainer ACaptureSessionOutputContainer;
typedef struct ACaptureSessionOutput ACaptureSessionOutput;
/**
* Create a capture session output container.
*
*
*
*/
camera_status_t ACaptureSessionOutputContainer_create(
/*out*/ACaptureSessionOutputContainer** container);
/**
* Free a capture session output container.
*
* @param container the {@link ACaptureSessionOutputContainer} to be freed.
*
* @see ACaptureSessionOutputContainer_create
*/
void ACaptureSessionOutputContainer_free(ACaptureSessionOutputContainer* container);
/**
* Create a ACaptureSessionOutput object.
*
*
*
*
* @see ACaptureSessionOutputContainer_add
*/
camera_status_t ACaptureSessionOutput_create(
ANativeWindow* anw, /*out*/ACaptureSessionOutput** output);
/**
* Free a ACaptureSessionOutput object.
*
* @param output the {@link ACaptureSessionOutput} to be freed.
*
* @see ACaptureSessionOutput_create
*/
void ACaptureSessionOutput_free(ACaptureSessionOutput* output);
/**
* Add an {@link ACaptureSessionOutput} object to {@link ACaptureSessionOutputContainer}.
*
* @param container the {@link ACaptureSessionOutputContainer} of interest.
* @param output the output {@link ACaptureSessionOutput} to be added to container.
*
* @return
*
*/
camera_status_t ACaptureSessionOutputContainer_add(
ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output);
/**
* Remove an {@link ACaptureSessionOutput} object from {@link ACaptureSessionOutputContainer}.
*
*
*
*/
camera_status_t ACaptureSessionOutputContainer_remove(
ACaptureSessionOutputContainer* container, const ACaptureSessionOutput* output);
/**
* Create a new camera capture session by providing the target output set of {@link ANativeWindow}
* to the camera device.
*
*
*
*
*
*
*
* LEGACY-level guaranteed configurations
* Target 1 Target 2 Target 3 Sample use case(s)
* Type Max size Type Max size Type Max size
* `PRIV` `MAXIMUM` Simple preview, GPU video processing, or no-preview video recording.
* `JPEG` `MAXIMUM` No-viewfinder still image capture.
* `YUV ` `MAXIMUM` In-application video/image processing.
* `PRIV` `PREVIEW` `JPEG` `MAXIMUM` Standard still imaging.
* `YUV ` `PREVIEW` `JPEG` `MAXIMUM` In-app processing plus still capture.
* `PRIV` `PREVIEW` `PRIV` `PREVIEW` Standard recording.
* `PRIV` `PREVIEW` `YUV ` `PREVIEW` Preview plus in-app processing.
* `PRIV` `PREVIEW` `YUV ` `PREVIEW` `JPEG` `MAXIMUM` Still capture plus in-app processing.
*
Limited-level ({@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL} * `== `{@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED LIMITED}) devices * support at least the following stream combinations in addition to those for * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY LEGACY} devices: * *
LIMITED-level additional guaranteed configurations | ||||||
---|---|---|---|---|---|---|
Target 1 | Target 2 | Target 3 | Sample use case(s) | |||
Type | Max size | Type | Max size | Type | Max size | |
`PRIV` | `PREVIEW` | `PRIV` | `RECORD ` | High-resolution video recording with preview. | ||
`PRIV` | `PREVIEW` | `YUV ` | `RECORD ` | High-resolution in-app video processing with preview. | ||
`YUV ` | `PREVIEW` | `YUV ` | `RECORD ` | Two-input in-app video processing. | ||
`PRIV` | `PREVIEW` | `PRIV` | `RECORD ` | `JPEG` | `RECORD ` | High-resolution recording with video snapshot. |
`PRIV` | `PREVIEW` | `YUV ` | `RECORD ` | `JPEG` | `RECORD ` | High-resolution in-app processing with video snapshot. |
`YUV ` | `PREVIEW` | `YUV ` | `PREVIEW` | `JPEG` | `MAXIMUM` | Two-input in-app processing with still capture. |
FULL-level ({@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL} * `== `{@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_FULL FULL}) devices * support at least the following stream combinations in addition to those for * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED LIMITED} devices: * *
FULL-level additional guaranteed configurations | ||||||
---|---|---|---|---|---|---|
Target 1 | Target 2 | Target 3 | Sample use case(s) | |||
Type | Max size | Type | Max size | Type | Max size | |
`PRIV` | `PREVIEW` | `PRIV` | `MAXIMUM` | Maximum-resolution GPU processing with preview. | ||
`PRIV` | `PREVIEW` | `YUV ` | `MAXIMUM` | Maximum-resolution in-app processing with preview. | ||
`YUV ` | `PREVIEW` | `YUV ` | `MAXIMUM` | Maximum-resolution two-input in-app processsing. | ||
`PRIV` | `PREVIEW` | `PRIV` | `PREVIEW` | `JPEG` | `MAXIMUM` | Video recording with maximum-size video snapshot |
`YUV ` | `640x480` | `PRIV` | `PREVIEW` | `YUV ` | `MAXIMUM` | Standard video recording plus maximum-resolution in-app processing. |
`YUV ` | `640x480` | `YUV ` | `PREVIEW` | `YUV ` | `MAXIMUM` | Preview plus two-input maximum-resolution in-app processing. |
RAW-capability ({@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES} includes * {@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_RAW RAW}) devices additionally support * at least the following stream combinations on both * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_FULL FULL} and * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED LIMITED} devices: * *
RAW-capability additional guaranteed configurations | ||||||
---|---|---|---|---|---|---|
Target 1 | Target 2 | Target 3 | Sample use case(s) | |||
Type | Max size | Type | Max size | Type | Max size | |
`RAW ` | `MAXIMUM` | No-preview DNG capture. | ||||
`PRIV` | `PREVIEW` | `RAW ` | `MAXIMUM` | Standard DNG capture. | ||
`YUV ` | `PREVIEW` | `RAW ` | `MAXIMUM` | In-app processing plus DNG capture. | ||
`PRIV` | `PREVIEW` | `PRIV` | `PREVIEW` | `RAW ` | `MAXIMUM` | Video recording with DNG capture. |
`PRIV` | `PREVIEW` | `YUV ` | `PREVIEW` | `RAW ` | `MAXIMUM` | Preview with in-app processing and DNG capture. |
`YUV ` | `PREVIEW` | `YUV ` | `PREVIEW` | `RAW ` | `MAXIMUM` | Two-input in-app processing plus DNG capture. |
`PRIV` | `PREVIEW` | `JPEG` | `MAXIMUM` | `RAW ` | `MAXIMUM` | Still capture with simultaneous JPEG and DNG. |
`YUV ` | `PREVIEW` | `JPEG` | `MAXIMUM` | `RAW ` | `MAXIMUM` | In-app processing with simultaneous JPEG and DNG. |
BURST-capability ({@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES} includes * {@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_BURST_CAPTURE BURST_CAPTURE}) devices * support at least the below stream combinations in addition to those for * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED LIMITED} devices. Note that all * FULL-level devices support the BURST capability, and the below list is a strict subset of the * list for FULL-level devices, so this table is only relevant for LIMITED-level devices that * support the BURST_CAPTURE capability. * *
BURST-capability additional guaranteed configurations | ||||
---|---|---|---|---|
Target 1 | Target 2 | Sample use case(s) | ||
Type | Max size | Type | Max size | |
`PRIV` | `PREVIEW` | `PRIV` | `MAXIMUM` | Maximum-resolution GPU processing with preview. |
`PRIV` | `PREVIEW` | `YUV ` | `MAXIMUM` | Maximum-resolution in-app processing with preview. |
`YUV ` | `PREVIEW` | `YUV ` | `MAXIMUM` | Maximum-resolution two-input in-app processsing. |
LEVEL-3 ({@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL} * `== `{@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_3 LEVEL_3}) * support at least the following stream combinations in addition to the combinations for * {@link ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL_FULL FULL} and for * RAW capability ({@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES} includes * {@link ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_RAW RAW}): * *
LEVEL-3 additional guaranteed configurations | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
Target 1 | Target 2 | Target 3 | Target 4 | Sample use case(s) | ||||||
Type | Max size | Type | Max size | Type | Max size | Type | Max size | |||
`PRIV` | `PREVIEW` | `PRIV` | `640x480` | `YUV` | `MAXIMUM` | `RAW` | `MAXIMUM` | In-app viewfinder analysis with dynamic selection of output format. | ||
`PRIV` | `PREVIEW` | `PRIV` | `640x480` | `JPEG` | `MAXIMUM` | `RAW` | `MAXIMUM` | In-app viewfinder analysis with dynamic selection of output format. |
Since the capabilities of camera devices vary greatly, a given camera device may support * target combinations with sizes outside of these guarantees, but this can only be tested for * by attempting to create a session with such targets.
* * @param device the camera device of interest. * @param outputs the {@link ACaptureSessionOutputContainer} describes all output streams. * @param callbacks the {@link ACameraCaptureSession_stateCallbacks capture session state callbacks}. * @param session the created {@link ACameraCaptureSession} will be filled here if the method call * succeeds. * * @return