OutputConfiguration
class OutputConfiguration : Parcelable
kotlin.Any | |
↳ | android.hardware.camera2.params.OutputConfiguration |
A class for describing camera output, which contains a Surface
and its specific configuration for creating capture session.
There are several ways to instantiate, modify and use OutputConfigurations. The most common and recommended usage patterns are summarized in the following list:
- Passing a
Surface
to the constructor and using the OutputConfiguration instance as argument toCameraDevice#createCaptureSessionByOutputConfigurations
. This is the most frequent usage and clients should consider it first before other more complicated alternatives. - Passing only a surface source class as an argument to the constructor. This is usually followed by a call to create a capture session (see
CameraDevice#createCaptureSessionByOutputConfigurations
and aSurface
add calladdSurface
with a validSurface
. The sequence completes withCameraCaptureSession#finalizeOutputConfigurations
. This is the deferred usage case which aims to enhance performance by allowing the resource-intensive capture session create call to execute in parallel with anySurface
initialization, such as waiting for aandroid.view.SurfaceView
to be ready as part of the UI initialization. - The third and most complex usage pattern involves surface sharing. Once instantiated an OutputConfiguration can be enabled for surface sharing via
enableSurfaceSharing
. This must be done before creating a new capture session and enables calls toCameraCaptureSession#updateOutputConfiguration
. An OutputConfiguration with enabled surface sharing can be modified viaaddSurface
orremoveSurface
. The updates to this OutputConfiguration will only come into effect afterCameraCaptureSession#updateOutputConfiguration
returns without throwing exceptions. Such updates can be done as long as the session is active. Clients should always consider the additional requirements and limitations placed on the output surfaces (for more details seeenableSurfaceSharing
,addSurface
,removeSurface
,CameraCaptureSession#updateOutputConfiguration
). A trade-off exists between additional complexity and flexibility. If exercised correctly surface sharing can switch between different output surfaces without interrupting any ongoing repeating capture requests. This saves time and can significantly improve the user experience. - Surface sharing can be used in combination with deferred surfaces. The rules from both cases are combined and clients must call
enableSurfaceSharing
before creating a capture session. Attach and/or remove output surfaces viaaddSurface
/removeSurface
and finalize the configuration usingCameraCaptureSession#finalizeOutputConfigurations
.CameraCaptureSession#updateOutputConfiguration
can be called after the configuration finalize method returns without exceptions. - If the camera device supports multi-resolution output streams,
android.hardware.camera2.CameraCharacteristics#SCALER_MULTI_RESOLUTION_STREAM_CONFIGURATION_MAP
will contain the formats and their corresponding stream info. The application can use an OutputConfiguration created with the multi-resolution stream info queried fromandroid.hardware.camera2.params.MultiResolutionStreamConfigurationMap#getOutputInfo
andandroid.hardware.camera2.MultiResolutionImageReader
to capture variable size images.
As of Android P
, all formats except ImageFormat#JPEG
and ImageFormat#RAW_PRIVATE
can be used for sharing, subject to device support. On prior API levels, only ImageFormat#PRIVATE
format may be used.
Summary
Constants | |
---|---|
static Int |
Automatic mirroring based on camera facing |
static Int |
Camera output is mirrored horizontally |
static Int |
No mirror transform is applied |
static Int |
Camera output is mirrored vertically |
static Int |
Invalid surface group ID. |
static Int |
Timestamp is synchronized to choreographer. |
static Int |
Default timestamp base. |
static Int |
Timestamp base roughly the same as |
static Int |
Timestamp base roughly the same as |
static Int |
Timestamp base of |
Inherited constants | |
---|---|
Public constructors | |
---|---|
OutputConfiguration(surface: Surface) Create a new |
|
OutputConfiguration(surfaceGroupId: Int, surface: Surface) Create a new |
|
OutputConfiguration(surfaceSize: Size, klass: Class<T>) Create a new |
|
OutputConfiguration(format: Int, surfaceSize: Size) Create a new |
|
OutputConfiguration(surfaceGroupId: Int, format: Int, surfaceSize: Size) Create a new |
|
OutputConfiguration(format: Int, surfaceSize: Size, usage: Long) Create a new |
|
OutputConfiguration(surfaceGroupId: Int, format: Int, surfaceSize: Size, usage: Long) Create a new |
Public methods | |
---|---|
Unit |
addSensorPixelModeUsed(sensorPixelModeUsed: Int) Add a sensor pixel mode that this OutputConfiguration will be used in. |
Unit |
addSurface(surface: Surface) Add a surface to this OutputConfiguration. |
static MutableCollection<OutputConfiguration!> |
createInstancesForMultiResolutionOutput(multiResolutionImageReader: MultiResolutionImageReader) Create a list of |
static MutableList<OutputConfiguration!> |
createInstancesForMultiResolutionOutput(streams: MutableCollection<MultiResolutionStreamInfo!>, format: Int) Create a list of |
Int | |
Unit |
Enable multiple surfaces sharing the same OutputConfiguration |
Boolean |
Check if this |
Long |
Return current dynamic range profile. |
Int |
Get the maximum supported shared |
Int |
Get the current mirroring mode |
Long |
Get the current stream use case |
Surface? |
Get the |
Int |
Get the surface group ID associated with this |
MutableList<Surface!> |
Get the immutable list of surfaces associated with this |
Int |
Get the current timestamp base |
Int |
hashCode() Returns a hash code value for the object. |
Boolean |
Whether readout timestamp is used for this OutputConfiguration. |
Unit |
removeSensorPixelModeUsed(sensorPixelModeUsed: Int) Remove a sensor pixel mode, previously added through addSensorPixelModeUsed, from this OutputConfiguration. |
Unit |
removeSurface(surface: Surface) Remove a surface from this OutputConfiguration. |
Unit |
setDynamicRangeProfile(profile: Long) Set a specific device supported dynamic range profile. |
Unit |
setMirrorMode(mirrorMode: Int) Set the mirroring mode for this output target |
Unit |
setPhysicalCameraId(physicalCameraId: String?) Set the id of the physical camera for this OutputConfiguration |
Unit |
Use the camera sensor's readout time for the image timestamp. |
Unit |
setStreamUseCase(streamUseCase: Long) Set stream use case for this OutputConfiguration |
static Unit |
setSurfacesForMultiResolutionOutput(outputConfigurations: MutableCollection<OutputConfiguration!>, multiResolutionImageReader: MultiResolutionImageReader) Set the OutputConfiguration surfaces corresponding to the |
Unit |
setTimestampBase(timestampBase: Int) Set timestamp base for this output target |
Unit |
writeToParcel(dest: Parcel, flags: Int) |
Properties | |
---|---|
static Parcelable.Creator<OutputConfiguration!> |
Constants
MIRROR_MODE_AUTO
static val MIRROR_MODE_AUTO: Int
Automatic mirroring based on camera facing
This is the default mirroring mode for the camera device. With this mode, the camera output is mirrored horizontally for front-facing cameras. There is no mirroring for rear-facing and external cameras.
Value: 0
MIRROR_MODE_H
static val MIRROR_MODE_H: Int
Camera output is mirrored horizontally
The camera output is mirrored horizontally, the same behavior as in AUTO mode for front facing camera.
Value: 2
MIRROR_MODE_NONE
static val MIRROR_MODE_NONE: Int
No mirror transform is applied
No mirroring is applied to the camera output regardless of the camera facing.
Value: 1
MIRROR_MODE_V
static val MIRROR_MODE_V: Int
Camera output is mirrored vertically
Value: 3
SURFACE_GROUP_ID_NONE
static val SURFACE_GROUP_ID_NONE: Int
Invalid surface group ID.
An OutputConfiguration
with this value indicates that the included surface doesn't belong to any surface group.
Value: -1
TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED
static val TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED: Int
Timestamp is synchronized to choreographer.
The timestamp of the output images are overridden with choreographer pulses from the display subsystem for smoother display of camera frames. An output target of SurfaceView uses this time base by default. Note that the timestamp override is done for fixed camera frame rate only.
This timestamp base isn't applicable to SurfaceTexture targets. SurfaceTexture's updateTexImage
function always uses the latest image from the camera stream. In the case of a TextureView, the image is displayed right away.
Timestamps with this time base cannot directly match the timestamps in CameraCaptureSession.CaptureCallback#onCaptureStarted
, android.hardware.camera2.CameraCaptureSession.CaptureCallback#onReadoutStarted
, or the sensor timestamps in android.hardware.camera2.CaptureResult
. This timestamp base shouldn't be used if the timestamp needs to be used for audio-video synchronization.
Value: 4
TIMESTAMP_BASE_DEFAULT
static val TIMESTAMP_BASE_DEFAULT: Int
Default timestamp base.
The camera device decides the timestamp based on the properties of the output surface.
TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED
. The timestamp is overridden with choreographer pulses from the display subsystem for smoother display of camera frames when the camera device runs in fixed frame rate. The timestamp is roughly in the same time base as android.os.SystemClock#uptimeMillis
.android.hardware.HardwareBuffer#USAGE_VIDEO_ENCODE
usage flag, the timestamp base is TIMESTAMP_BASE_MONOTONIC
, which is roughly the same time base as android.os.SystemClock#uptimeMillis
.TIMESTAMP_BASE_SENSOR
, the same as what's specified by CameraCharacteristics#SENSOR_INFO_TIMESTAMP_SOURCE
.
- For a SurfaceTexture output surface, the camera system re-spaces the delivery of output frames based on image readout intervals, reducing viewfinder jitter. The timestamps of images remain to be
TIMESTAMP_BASE_SENSOR
.
Note that the reduction of frame jitter for SurfaceView and SurfaceTexture comes with slight increase in photon-to-photon latency, which is the time from when photons hit the scene to when the corresponding pixels show up on the screen. If the photon-to-photon latency is more important than the smoothness of viewfinder, TIMESTAMP_BASE_SENSOR
should be used instead.
Value: 0
TIMESTAMP_BASE_MONOTONIC
static val TIMESTAMP_BASE_MONOTONIC: Int
Timestamp base roughly the same as android.os.SystemClock#uptimeMillis
.
The timestamps of the output images are monotonically increasing, and are roughly in the same time base as android.os.SystemClock#uptimeMillis
. The timestamps with this time base can be directly used for audio-video sync in video recording.
If the camera device's CameraCharacteristics#SENSOR_INFO_TIMESTAMP_SOURCE
is REALTIME, timestamps with this time base cannot directly match the timestamps in CameraCaptureSession.CaptureCallback#onCaptureStarted
, android.hardware.camera2.CameraCaptureSession.CaptureCallback#onReadoutStarted
, or the sensor timestamps in android.hardware.camera2.CaptureResult
.
Value: 2
TIMESTAMP_BASE_REALTIME
static val TIMESTAMP_BASE_REALTIME: Int
Timestamp base roughly the same as android.os.SystemClock#elapsedRealtime
.
The timestamps of the output images are roughly in the same time base as android.os.SystemClock#elapsedRealtime
. The timestamps with this time base cannot be directly used for audio-video sync in video recording.
If the camera device's CameraCharacteristics#SENSOR_INFO_TIMESTAMP_SOURCE
is UNKNOWN, timestamps with this time base cannot directly match the timestamps in CameraCaptureSession.CaptureCallback#onCaptureStarted
, android.hardware.camera2.CameraCaptureSession.CaptureCallback#onReadoutStarted
, or the sensor timestamps in android.hardware.camera2.CaptureResult
.
If using a REALTIME timestamp base on a device that supports only TIMESTAMP_SOURCE_UNKNOWN, the accuracy of timestamps is only what is guaranteed in the documentation for UNKNOWN. In particular, they have no guarantees about being accurate enough to use in fusing image data with the output of inertial sensors, for features such as image stabilization or augmented reality.
Value: 3
TIMESTAMP_BASE_SENSOR
static val TIMESTAMP_BASE_SENSOR: Int
Timestamp base of CameraCharacteristics#SENSOR_INFO_TIMESTAMP_SOURCE
.
The timestamps of the output images are in the time base as specified by android.hardware.camera2.CameraCharacteristics#SENSOR_INFO_TIMESTAMP_SOURCE
. The application can look up the corresponding result metadata by matching the timestamp with a android.hardware.camera2.CameraCaptureSession.CaptureCallback#onCaptureStarted
, or with a android.hardware.camera2.CameraCaptureSession.CaptureCallback#onReadoutStarted
if readout timestamp is used.
Value: 1
Public constructors
OutputConfiguration
OutputConfiguration(surface: Surface)
Create a new OutputConfiguration
instance with a Surface
.
Parameters | |
---|---|
surface |
Surface: A Surface for camera to output to.
This constructor creates a default configuration, with a surface group ID of {@value #SURFACE_GROUP_ID_NONE}. This value cannot benull . |
OutputConfiguration
OutputConfiguration(
surfaceGroupId: Int,
surface: Surface)
Create a new OutputConfiguration
instance with a Surface
, with a surface group ID.
A surface group ID is used to identify which surface group this output surface belongs to. A surface group is a group of output surfaces that are not intended to receive camera output buffer streams simultaneously. The CameraDevice
may be able to share the buffers used by all the surfaces from the same surface group, therefore may reduce the overall memory footprint. The application should only set the same set ID for the streams that are not simultaneously streaming. A negative ID indicates that this surface doesn't belong to any surface group. The default value is {@value #SURFACE_GROUP_ID_NONE}.
For example, a video chat application that has an adaptive output resolution feature would need two (or more) output resolutions, to switch resolutions without any output glitches. However, at any given time, only one output is active to minimize outgoing network bandwidth and encoding overhead. To save memory, the application should set the video outputs to have the same non-negative group ID, so that the camera device can share the same memory region for the alternating outputs.
It is not an error to include output streams with the same group ID in the same capture request, but the resulting memory consumption may be higher than if the two streams were not in the same surface group to begin with, especially if the outputs have substantially different dimensions.
Parameters | |
---|---|
surfaceGroupId |
Int: A group ID for this output, used for sharing memory between multiple outputs. |
surface |
Surface: A Surface for camera to output to. This value cannot be null . |
OutputConfiguration
OutputConfiguration(
surfaceSize: Size,
klass: Class<T>)
Create a new OutputConfiguration
instance, with desired Surface size and Surface source class.
This constructor takes an argument for desired Surface size and the Surface source class without providing the actual output Surface. This is used to setup an output configuration with a deferred Surface. The application can use this output configuration to create a session.
Starting from Android V
, the deferred Surface can be obtained: (1) from android.view.SurfaceView
by calling android.view.SurfaceHolder#getSurface
, (2) from android.graphics.SurfaceTexture
via android.view.Surface#Surface(android.graphics.SurfaceTexture)
, (3) from android.media.MediaRecorder
via android.media.MediaRecorder#getSurface
or android.media.MediaCodec#createPersistentInputSurface
, or (4) from android.media.MediaCodec
via android.media.MediaCodec#createInputSurface
or android.media.MediaCodec#createPersistentInputSurface
.
- Surfaces for
android.view.SurfaceView
andandroid.graphics.SurfaceTexture
can be deferred until after android.hardware.camera2.CameraDevice#createCaptureSession. In that case, the output Surface must be set viaaddSurface
, and the Surface configuration must be finalized viaCameraCaptureSession#finalizeOutputConfigurations
before submitting a request with the Surface target. - For all other target types, the output Surface must be set by
addSurface
, andCameraCaptureSession#finalizeOutputConfigurations
is not needed because the OutputConfiguration used to create the session will contain the actual Surface.
Before Android V
, only and android.graphics.SurfaceTexture
are supported. Both kind of outputs can be deferred until after android.hardware.camera2.CameraDevice#createCaptureSessionByOutputConfigurations
.
An OutputConfiguration object created by this constructor can be used for android.hardware.camera2.CameraDevice.CameraDeviceSetup#isSessionConfigurationSupported
and android.hardware.camera2.CameraDevice.CameraDeviceSetup#getSessionCharacteristics
without having called addSurface
.
Parameters | |
---|---|
surfaceSize |
Size: Size for the deferred surface. This value cannot be null . |
klass |
Class<T>: a non-null Class object reference that indicates the source of this surface. Only SurfaceHolder.class , SurfaceTexture.class , , and MediaCodec.class are supported. Before Android V , only SurfaceHolder.class and are supported. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the Surface source class is not supported, or Surface size is zero. |
OutputConfiguration
OutputConfiguration(
format: Int,
surfaceSize: Size)
Create a new OutputConfiguration
instance for an ImageReader
for a given format and size.
This constructor creates an OutputConfiguration for an ImageReader without providing the actual output Surface. The actual output Surface must be set via addSurface
before creating the capture session.
An OutputConfiguration object created by this constructor can be used for android.hardware.camera2.CameraDevice.CameraDeviceSetup#isSessionConfigurationSupported
and android.hardware.camera2.CameraDevice.CameraDeviceSetup#getSessionCharacteristics
without having called addSurface
.
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the Surface size is null or zero. |
OutputConfiguration
OutputConfiguration(
surfaceGroupId: Int,
format: Int,
surfaceSize: Size)
Create a new OutputConfiguration
instance for an ImageReader
for a given surfaceGroupId, format, and size.
This constructor creates an OutputConfiguration for an ImageReader without providing the actual output Surface. The actual output Surface must be set via addSurface
before creating the capture session.
An OutputConfiguration object created by this constructor can be used for android.hardware.camera2.CameraDevice.CameraDeviceSetup#isSessionConfigurationSupported
and android.hardware.camera2.CameraDevice.CameraDeviceSetup#getSessionCharacteristics
without having called addSurface
.
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the Surface size is null or zero. |
OutputConfiguration
OutputConfiguration(
format: Int,
surfaceSize: Size,
usage: Long)
Create a new OutputConfiguration
instance for an ImageReader
for a given format, size, and usage flags.
This constructor creates an OutputConfiguration for an ImageReader without providing the actual output Surface. The actual output Surface must be set via addSurface
before creating the capture session.
An OutputConfiguration object created by this constructor can be used for android.hardware.camera2.CameraDevice.CameraDeviceSetup#isSessionConfigurationSupported
and android.hardware.camera2.CameraDevice.CameraDeviceSetup#getSessionCharacteristics
without having called addSurface
.
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the Surface size is null or zero. |
OutputConfiguration
OutputConfiguration(
surfaceGroupId: Int,
format: Int,
surfaceSize: Size,
usage: Long)
Create a new OutputConfiguration
instance for an ImageReader
for a given surface group id, format, size, and usage flags.
This constructor creates an OutputConfiguration for an ImageReader without providing the actual output Surface. The actual output Surface must be set via addSurface
before creating the capture session.
An OutputConfiguration object created by this constructor can be used for android.hardware.camera2.CameraDevice.CameraDeviceSetup#isSessionConfigurationSupported
and android.hardware.camera2.CameraDevice.CameraDeviceSetup#getSessionCharacteristics
without having called addSurface
.
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the Surface size is null or zero. |
Public methods
addSensorPixelModeUsed
fun addSensorPixelModeUsed(sensorPixelModeUsed: Int): Unit
Add a sensor pixel mode that this OutputConfiguration will be used in.
In the case that this output stream configuration (format, width, height) is available through android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP
configurations and android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP_MAXIMUM_RESOLUTION
, configurations, the camera sub-system will assume that this OutputConfiguration
will be used only with android.hardware.camera2.CaptureRequest
s which has android.hardware.camera2.CaptureRequest#SENSOR_PIXEL_MODE
set to android.hardware.camera2.CameraMetadata#SENSOR_PIXEL_MODE_DEFAULT
. In such cases, if clients intend to use the OutputConfiguration
(s) in a android.hardware.camera2.CaptureRequest
with other sensor pixel modes, they must specify which android.hardware.camera2.CaptureRequest#SENSOR_PIXEL_MODE
(s) they will use this OutputConfiguration
with, by calling this method. In case this output stream configuration (format, width, height) is only in android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP_MAXIMUM_RESOLUTION
, configurations, this output target must only be used with android.hardware.camera2.CaptureRequest
s which has android.hardware.camera2.CaptureRequest#SENSOR_PIXEL_MODE
set to android.hardware.camera2.CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION
and that is what the camera sub-system will assume. If clients add android.hardware.camera2.CameraMetadata#SENSOR_PIXEL_MODE_DEFAULT
in this case, session configuration will fail, if this OutputConfiguration
is included. In case this output stream configuration (format, width, height) is only in android.hardware.camera2.CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP
, configurations, this output target must only be used with android.hardware.camera2.CaptureRequest
s which has android.hardware.camera2.CaptureRequest#SENSOR_PIXEL_MODE
set to android.hardware.camera2.CameraMetadata#SENSOR_PIXEL_MODE_DEFAULT
and that is what the camera sub-system will assume. If clients add android.hardware.camera2.CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION
in this case, session configuration will fail, if this OutputConfiguration
is included.
Parameters | |
---|---|
sensorPixelModeUsed |
Int: The sensor pixel mode this OutputConfiguration will be used with
Value is android.hardware.camera2.CameraMetadata#SENSOR_PIXEL_MODE_DEFAULT , or android.hardware.camera2.CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION |
addSurface
fun addSurface(surface: Surface): Unit
Add a surface to this OutputConfiguration.
This function can be called before or after android.hardware.camera2.CameraDevice#createCaptureSessionByOutputConfigurations
. If it's called after, the application must finalize the capture session with CameraCaptureSession#finalizeOutputConfigurations
. It is possible to call this method after the output configurations have been finalized only in cases of enabled surface sharing see enableSurfaceSharing
. The modified output configuration must be updated with CameraCaptureSession#updateOutputConfiguration
. If this function is called before session creation, CameraCaptureSession#finalizeOutputConfigurations
doesn't need to be called.
If the OutputConfiguration was constructed by android.hardware.camera2.params.OutputConfiguration#OutputConfiguration(android.util.Size,java.lang.Class)
, the added surface must be obtained:
- from
android.view.SurfaceView
by callingandroid.view.SurfaceHolder#getSurface
- from
android.graphics.SurfaceTexture
by callingandroid.view.Surface#Surface(android.graphics.SurfaceTexture)
- from
android.media.MediaRecorder
by callingandroid.media.MediaRecorder#getSurface
orandroid.media.MediaCodec#createPersistentInputSurface
- from
android.media.MediaCodec
by callingandroid.media.MediaCodec#createInputSurface
orandroid.media.MediaCodec#createPersistentInputSurface()
If the OutputConfiguration was constructed by OutputConfiguration(int,android.util.Size)
or its variants, the added surface must be obtained from android.media.ImageReader
by calling android.media.ImageReader#getSurface
.
If the OutputConfiguration was constructed by other constructors, the added surface must be compatible with the existing surface. See enableSurfaceSharing
for details of compatible surfaces.
If the OutputConfiguration already contains a Surface, enableSurfaceSharing
must be called before calling this function to add a new Surface.
Parameters | |
---|---|
surface |
Surface: The surface to be added. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if the Surface is invalid, the Surface's dataspace/format doesn't match, or adding the Surface would exceed number of shared surfaces supported. |
java.lang.IllegalStateException |
if the Surface was already added to this OutputConfiguration, or if the OutputConfiguration is not shared and it already has a surface associated with it. |
createInstancesForMultiResolutionOutput
static fun createInstancesForMultiResolutionOutput(multiResolutionImageReader: MultiResolutionImageReader): MutableCollection<OutputConfiguration!>
Create a list of OutputConfiguration
instances for the outputs used by a android.hardware.camera2.MultiResolutionImageReader
.
This constructor takes an argument for a android.hardware.camera2.MultiResolutionImageReader
.
Parameters | |
---|---|
multiResolutionImageReader |
MultiResolutionImageReader: The multi-resolution image reader object. This value cannot be null . |
Return | |
---|---|
MutableCollection<OutputConfiguration!> |
This value cannot be null . |
createInstancesForMultiResolutionOutput
static fun createInstancesForMultiResolutionOutput(
streams: MutableCollection<MultiResolutionStreamInfo!>,
format: Int
): MutableList<OutputConfiguration!>
Create a list of OutputConfiguration
instances for a MultiResolutionImageReader
.
This method can be used to create query OutputConfigurations for a MultiResolutionImageReader that can be included in a SessionConfiguration passed into android.hardware.camera2.CameraDevice.CameraDeviceSetup#isSessionConfigurationSupported
before opening and setting up a camera device in full, at which point setSurfacesForMultiResolutionOutput
can be used to link to the actual MultiResolutionImageReader.
This constructor takes same arguments used to create a MultiResolutionImageReader
: a collection of MultiResolutionStreamInfo
objects and the format.
Return | |
---|---|
MutableList<OutputConfiguration!> |
The list of OutputConfiguration objects for a MultiResolutionImageReader. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If the streams is null or doesn't contain at least 2 items, or if format isn't a valid camera format. |
describeContents
fun describeContents(): Int
Return | |
---|---|
Int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR |
enableSurfaceSharing
fun enableSurfaceSharing(): Unit
Enable multiple surfaces sharing the same OutputConfiguration
For advanced use cases, a camera application may require more streams than the combination guaranteed by android.hardware.camera2.CameraDevice#createCaptureSession. In this case, more than one compatible surface can be attached to an OutputConfiguration so that they map to one camera stream, and the outputs share memory buffers when possible. Due to buffer sharing clients should be careful when adding surface outputs that modify their input data. If such case exists, camera clients should have an additional mechanism to synchronize read and write access between individual consumers.
Two surfaces are compatible in the below cases:
CameraDevice#createCaptureSessionByOutputConfigurations
is guaranteed to succeed. CameraDevice#createCaptureSessionByOutputConfigurations
will succeed. Otherwise, it fails with android.hardware.camera2.CameraCaptureSession.StateCallback#onConfigureFailed
.
To enable surface sharing, this function must be called before android.hardware.camera2.CameraDevice#createCaptureSessionByOutputConfigurations
or android.hardware.camera2.CameraDevice#createReprocessableCaptureSessionByConfigurations
. Calling this function after CameraDevice#createCaptureSessionByOutputConfigurations
has no effect.
Up to getMaxSharedSurfaceCount
surfaces can be shared for an OutputConfiguration. The supported surfaces for sharing must be of type SurfaceTexture, SurfaceView, MediaRecorder, MediaCodec, or implementation defined ImageReader.
This function must not be called from OutputConfigurations created by #createInstancesForMultiResolutionOutput.
Exceptions | |
---|---|
java.lang.IllegalStateException |
If this OutputConfiguration is created via #createInstancesForMultiResolutionOutput to back a MultiResolutionImageReader. |
equals
fun equals(other: Any?): Boolean
Check if this OutputConfiguration
is equal to another OutputConfiguration
.
Two output configurations are only equal if and only if the underlying surfaces, surface properties (width, height, format, dataspace) when the output configurations are created, and all other configuration parameters are equal.
Parameters | |
---|---|
obj |
This value may be null . |
Return | |
---|---|
Boolean |
true if the objects were equal, false otherwise |
getDynamicRangeProfile
fun getDynamicRangeProfile(): Long
Return current dynamic range profile.
getMaxSharedSurfaceCount
fun getMaxSharedSurfaceCount(): Int
Get the maximum supported shared Surface
count.
Return | |
---|---|
Int |
the maximum number of surfaces that can be added per each OutputConfiguration. |
See Also
getMirrorMode
fun getMirrorMode(): Int
Get the current mirroring mode
If no setMirrorMode
is called first, this function returns MIRROR_MODE_AUTO
.
getStreamUseCase
fun getStreamUseCase(): Long
Get the current stream use case
If no setStreamUseCase
is called first, this function returns DEFAULT
.
Return | |
---|---|
Long |
the currently set stream use case |
getSurface
fun getSurface(): Surface?
Get the Surface
associated with this OutputConfiguration
. If more than one surface is associated with this OutputConfiguration
, return the first one as specified in the constructor or OutputConfiguration#addSurface
.
Return | |
---|---|
Surface? |
This value may be null . |
getSurfaceGroupId
fun getSurfaceGroupId(): Int
Get the surface group ID associated with this OutputConfiguration
.
Return | |
---|---|
Int |
the surface group ID associated with this OutputConfiguration . The default value is {@value #SURFACE_GROUP_ID_NONE}. |
getSurfaces
fun getSurfaces(): MutableList<Surface!>
Get the immutable list of surfaces associated with this OutputConfiguration
.
Return | |
---|---|
MutableList<Surface!> |
the list of surfaces associated with this OutputConfiguration as specified in the constructor and OutputConfiguration#addSurface . The list should not be modified. This value cannot be null . |
getTimestampBase
fun getTimestampBase(): Int
Get the current timestamp base
If no setTimestampBase
is called first, this function returns TIMESTAMP_BASE_DEFAULT
.
Return | |
---|---|
Int |
The currently set timestamp base Value is android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_DEFAULT , android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_SENSOR , android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_MONOTONIC , android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_REALTIME , android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED , or android.hardware.camera2.params.OutputConfiguration.TIMESTAMP_BASE_READOUT_SENSOR |
hashCode
fun hashCode(): Int
Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap
.
The general contract of hashCode
is:
- Whenever it is invoked on the same object more than once during an execution of a Java application, the
hashCode
method must consistently return the same integer, provided no information used inequals
comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application. - If two objects are equal according to the
equals
method, then calling thehashCode
method on each of the two objects must produce the same integer result. - It is not required that if two objects are unequal according to the
equals
method, then calling thehashCode
method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Return | |
---|---|
Int |
a hash code value for this object. |
isReadoutTimestampEnabled
fun isReadoutTimestampEnabled(): Boolean
Whether readout timestamp is used for this OutputConfiguration.
See Also
removeSensorPixelModeUsed
fun removeSensorPixelModeUsed(sensorPixelModeUsed: Int): Unit
Remove a sensor pixel mode, previously added through addSensorPixelModeUsed, from this OutputConfiguration.
Sensor pixel modes added via calls to addSensorPixelModeUsed
can also be removed from the OutputConfiguration.
Parameters | |
---|---|
sensorPixelModeUsed |
Int: The sensor pixel mode to be removed. Value is android.hardware.camera2.CameraMetadata#SENSOR_PIXEL_MODE_DEFAULT , or android.hardware.camera2.CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If the sensor pixel mode wasn't previously added through addSensorPixelModeUsed . |
removeSurface
fun removeSurface(surface: Surface): Unit
Remove a surface from this OutputConfiguration.
Surfaces added via calls to addSurface
can also be removed from the OutputConfiguration. The only notable exception is the surface associated with the OutputConfiguration (see getSurface
) which was passed as part of the constructor or was added first in the case of OutputConfiguration#OutputConfiguration(Size, Class)
, android.hardware.camera2.params.OutputConfiguration#OutputConfiguration(int,android.util.Size)
, android.hardware.camera2.params.OutputConfiguration#OutputConfiguration(int,android.util.Size,long)
, android.hardware.camera2.params.OutputConfiguration#OutputConfiguration(int,int,android.util.Size)
, android.hardware.camera2.params.OutputConfiguration#OutputConfiguration(int,int,android.util.Size,long)
.
Parameters | |
---|---|
surface |
Surface: The surface to be removed. This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If the surface is associated with this OutputConfiguration (see getSurface ) or the surface didn't get added with addSurface . |
setDynamicRangeProfile
fun setDynamicRangeProfile(profile: Long): Unit
Set a specific device supported dynamic range profile.
Clients can choose from any profile advertised as supported in CameraCharacteristics.REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES queried using DynamicRangeProfiles#getSupportedProfiles()
. If this is not explicitly set, then the default profile will be DynamicRangeProfiles#STANDARD
.
Do note that invalid combinations between the registered output surface pixel format and the configured dynamic range profile will cause capture session initialization failure. Invalid combinations include any 10-bit dynamic range profile advertised in DynamicRangeProfiles#getSupportedProfiles()
combined with an output Surface pixel format different from ImageFormat#PRIVATE
(the default for Surfaces initialized by android.view.SurfaceView
, android.view.TextureView
, android.media.MediaRecorder
, android.media.MediaCodec
etc.) or ImageFormat#YCBCR_P010
.
setMirrorMode
fun setMirrorMode(mirrorMode: Int): Unit
Set the mirroring mode for this output target
If this function is not called, the mirroring mode for this output is MIRROR_MODE_AUTO
, with which the camera API will mirror the output images horizontally for front facing camera.
For efficiency, the mirror effect is applied as a transform flag, so it is only effective in some outputs. It works automatically for SurfaceView and TextureView outputs. For manual use of SurfaceTexture, it is reflected in the value of android.graphics.SurfaceTexture#getTransformMatrix
. For other end points, such as ImageReader, MediaRecorder, or MediaCodec, the mirror mode has no effect. If mirroring is needed for such outputs, the application needs to mirror the image buffers itself before passing them onward.
setPhysicalCameraId
fun setPhysicalCameraId(physicalCameraId: String?): Unit
Set the id of the physical camera for this OutputConfiguration
In the case one logical camera is made up of multiple physical cameras, it could be desirable for the camera application to request streams from individual physical cameras. This call achieves it by mapping the OutputConfiguration to the physical camera id.
The valid physical camera ids can be queried by android.hardware.camera2.CameraCharacteristics#getPhysicalCameraIds
.
Passing in a null physicalCameraId means that the OutputConfiguration is for a logical stream.
This function must be called before android.hardware.camera2.CameraDevice#createCaptureSessionByOutputConfigurations
or android.hardware.camera2.CameraDevice#createReprocessableCaptureSessionByConfigurations
. Calling this function after CameraDevice#createCaptureSessionByOutputConfigurations
or android.hardware.camera2.CameraDevice#createReprocessableCaptureSessionByConfigurations
has no effect.
As of Android 12
, an image buffer from a physical camera stream can be used for reprocessing to logical camera streams and streams from the same physical camera if the camera device supports multi-resolution input and output streams. See CameraCharacteristics#SCALER_MULTI_RESOLUTION_STREAM_CONFIGURATION_MAP
for details. The behaviors of reprocessing from a non-physical camera stream to a physical camera stream, and from a physical camera stream to a physical camera stream of different physical camera, are device-specific and not guaranteed to be supported.
On prior API levels, the surface belonging to a physical camera OutputConfiguration must not be used as input or output of a reprocessing request.
Parameters | |
---|---|
physicalCameraId |
String?: This value may be null . |
setReadoutTimestampEnabled
fun setReadoutTimestampEnabled(on: Boolean): Unit
Use the camera sensor's readout time for the image timestamp.
The start of the camera sensor readout after exposure. For a rolling shutter camera sensor, the timestamp is typically equal to (the start of exposure time) + (exposure time) + (certain fixed offset)
. The fixed offset can vary per session, depending on the underlying sensor configuration. The benefit of using readout time is that when camera runs in a fixed frame rate, the timestamp intervals between frames are constant.
Readout timestamp is supported only if android.hardware.camera2.CameraCharacteristics#SENSOR_READOUT_TIMESTAMP
is CameraMetadata#SENSOR_READOUT_TIMESTAMP_HARDWARE
.
As long as readout timestamp is supported, if the timestamp base is TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED
, or if the timestamp base is DEFAULT for a SurfaceView output, the image timestamps for the output are always readout time regardless of whether this function is called.
Parameters | |
---|---|
on |
Boolean: The output image timestamp is the start of exposure time if false, and the start of readout time if true. |
setStreamUseCase
fun setStreamUseCase(streamUseCase: Long): Unit
Set stream use case for this OutputConfiguration
Stream use case is used to describe the purpose of the stream, whether it's for live preview, still image capture, video recording, or their combinations. This flag is useful for scenarios where the immediate consumer target isn't sufficient to indicate the stream's usage.
The main difference between stream use case and capture intent is that the former enables the camera device to optimize camera hardware and software pipelines based on user scenarios for each stream, whereas the latter is mainly a hint to camera to decide optimal 3A strategy that's applicable to the whole session. The camera device carries out configurations such as selecting tuning parameters, choosing camera sensor mode, and constructing image processing pipeline based on the streams's use cases. Capture intents are then used to fine tune 3A behaviors such as adjusting AE/AF convergence speed, and capture intents may change during the lifetime of a session. For example, for a session with a PREVIEW_VIDEO_STILL use case stream and a STILL_CAPTURE use case stream, the capture intents may be PREVIEW with fast 3A convergence speed and flash metering with automatic control for live preview, STILL_CAPTURE with best 3A parameters for still photo capture, or VIDEO_RECORD with slower 3A convergence speed for better video playback experience.
The supported stream use cases supported by a camera device can be queried by android.hardware.camera2.CameraCharacteristics#SCALER_AVAILABLE_STREAM_USE_CASES
.
The mandatory stream combinations involving stream use cases can be found at android.hardware.camera2.CameraDevice#createCaptureSession, as well as queried via android.hardware.camera2.params.MandatoryStreamCombination
. The application is strongly recommended to select one of the guaranteed stream combinations where all streams' use cases are set to non-DEFAULT values. If the application chooses a stream combination not in the mandatory list, the camera device may ignore some use case flags due to hardware constraints or implementation details.
This function must be called before android.hardware.camera2.CameraDevice#createCaptureSession or android.hardware.camera2.CameraDevice#createCaptureSessionByOutputConfigurations
. Calling this function after android.hardware.camera2.CameraDevice#createCaptureSession or CameraDevice#createCaptureSessionByOutputConfigurations
has no effect to the camera session.
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If the streamUseCase isn't within the range of valid values. |
setSurfacesForMultiResolutionOutput
static fun setSurfacesForMultiResolutionOutput(
outputConfigurations: MutableCollection<OutputConfiguration!>,
multiResolutionImageReader: MultiResolutionImageReader
): Unit
Set the OutputConfiguration surfaces corresponding to the MultiResolutionImageReader
.
This function should be used together with #createInstancesForMultiResolutionOutput. The application calls #createInstancesForMultiResolutionOutput first to create a list of OutputConfiguration objects without the actual MultiResolutionImageReader. Once the MultiResolutionImageReader is created later during full camera setup, the application then calls this function to assign the surfaces to the OutputConfiguration instances.
Parameters | |
---|---|
outputConfigurations |
MutableCollection<OutputConfiguration!>: The OutputConfiguration objects created by #createInstancesForMultiResolutionOutput This value cannot be null . |
multiResolutionImageReader |
MultiResolutionImageReader: The MultiResolutionImageReader object created from the same MultiResolutionStreamInfo parameters as outputConfigurations . This value cannot be null . |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If outputConfigurations or multiResolutionImageReader is null , the outputConfigurations and multiResolutionImageReader sizes don't match, or if the multiResolutionImageReader 's surfaces don't match with the outputConfigurations . |
java.lang.IllegalStateException |
If outputConfigurations already contains valid output surfaces. |
setTimestampBase
fun setTimestampBase(timestampBase: Int): Unit
Set timestamp base for this output target
Timestamp base describes the time domain of images from this camera output and its relationship with android.hardware.camera2.CameraCharacteristics#SENSOR_INFO_TIMESTAMP_SOURCE
.
If this function is not called, the timestamp base for this output is TIMESTAMP_BASE_DEFAULT
, with which the camera device adjusts timestamps based on the output target.
See TIMESTAMP_BASE_DEFAULT
, TIMESTAMP_BASE_SENSOR
, and TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED
for details of each timestamp base.
Parameters | |
---|---|
timestampBase |
Int: The timestamp base to be set. Value is android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_DEFAULT , android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_SENSOR , android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_MONOTONIC , android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_REALTIME , android.hardware.camera2.params.OutputConfiguration#TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED , or android.hardware.camera2.params.OutputConfiguration.TIMESTAMP_BASE_READOUT_SENSOR |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
If the timestamp base isn't within the range of valid values. |
writeToParcel
fun writeToParcel(
dest: Parcel,
flags: Int
): Unit
Parameters | |
---|---|
dest |
Parcel: The Parcel in which the object should be written. This value cannot be null . |
flags |
Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE . Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE , and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |