SessionConfig
public class SessionConfig
ExtensionSessionConfig |
A |
HighSpeedVideoSessionConfig |
A |
Represents the configuration for establishing and managing a camera session within CameraX.
When used with camera-lifecycle, this SessionConfig is expected to be used for starting a camera session (e.g. by being bound to the androidx.lifecycle.LifecycleOwner via androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle API which allows the lifecycle events to start and stop the camera session with this given configuration).
It consists of a collection of UseCase, session parameters to be applied on the camera session, and common properties like the field-of-view defined by ViewPort, the CameraEffect, frame rate, required or preferred GroupableFeature groups etc.
Constraints
useCases: This cannot be empty.
-
The value must be one of the supported frame rates queried by
CameraInfo.getSupportedFrameRateRangeswith a specificSessionConfig, or anIllegalArgumentExceptionwill be thrown duringSessionConfigbinding (i.e. when callingandroidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycleorandroidx.camera.lifecycle.LifecycleCameraProvider.bindToLifecycle). -
When this value is set, no individual
UseCasecan have a target frame rate set (e.g., viaPreview.Builder.setTargetFrameRateorVideoCapture.Builder.setTargetFrameRate); doing so will result in anIllegalArgumentException.
requiredFeatureGroup and preferredFeatureGroup:
-
Avoid using non-groupable APIs for any feature that is groupable (see
GroupableFeatureto know which features are groupable). Doing so can lead to conflicting configurations. -
Avoid setting multiple
GroupableFeatures with the sameGroupableFeature.featureTypeas required, as they conflict with each other. If they are set as preferred, only one will be selected according to the feature priorities, which are defined by the ordering in thepreferredFeatureGrouplist.
Not complying with these constraints will lead to an IllegalArgumentException. The following code sample explains this further.
import androidx.camera.core.CameraEffect import androidx.camera.core.DynamicRange import androidx.camera.core.ImageAnalysis import androidx.camera.core.Preview import androidx.camera.core.SessionConfig import androidx.camera.core.featuregroup.GroupableFeature.Companion.FPS_60 import androidx.camera.core.featuregroup.GroupableFeature.Companion.HDR_HLG10 import androidx.camera.core.featuregroup.GroupableFeature.Companion.PREVIEW_STABILIZATION import androidx.camera.video.GroupableFeatures.FHD_RECORDING import androidx.camera.video.GroupableFeatures.UHD_RECORDING import androidx.camera.video.Recorder import androidx.camera.video.VideoCapture // Create a session config where HDR is mandatory while 60 FPS (higher priority) and preview // stabilization are optional SessionConfig( useCases = listOf(Preview.Builder().build()), requiredFeatureGroup = setOf(HDR_HLG10), preferredFeatureGroup = listOf(FPS_60, PREVIEW_STABILIZATION), ) // Creating the following SessionConfig will throw an exception as there are conflicting // information. HDR is mentioned once as required and then again as preferred, it can't be both! SessionConfig( useCases = listOf(Preview.Builder().build()), requiredFeatureGroup = setOf(HDR_HLG10), preferredFeatureGroup = listOf(FPS_60, HDR_HLG10), ) // Creating the following SessionConfig will throw an exception as a groupable feature (HDR) is // configured with non-grouping API while using grouping API as well. HDR is configured to the // with a non-grouping API through the Preview use case, so it can't be grouped together // properly with the other groupable features. Instead, it should be configured like the first // SessionConfig construction in this code snippet. SessionConfig( useCases = listOf(Preview.Builder().apply { setDynamicRange(DynamicRange.HLG_10_BIT) }.build()), preferredFeatureGroup = listOf(FPS_60, PREVIEW_STABILIZATION), ) // Creating the following SessionConfig will throw an exception due to the conflicting // information. The features UHD_RECORDING and FHD_RECORDING share the same type // (FEATURE_TYPE_RECORDING_QUALITY), meaning both can't be simultaneously required. This is // akin to requesting the final video recording size to be both UHD and FHD at the same time. SessionConfig( useCases = listOf(Preview.Builder().build(), VideoCapture.withOutput(Recorder.Builder().build())), requiredFeatureGroup = setOf(HDR_HLG10, UHD_RECORDING, FHD_RECORDING), preferredFeatureGroup = listOf(FPS_60), ) // Creating the following SessionConfig will throw an exception as ImageAnalysis is not yet // supported with groupable features. SessionConfig( useCases = listOf(ImageAnalysis.Builder().build()), requiredFeatureGroup = setOf(HDR_HLG10), preferredFeatureGroup = listOf(FPS_60, HDR_HLG10), ) // Creating the following SessionConfig will throw an exception as CameraEffect is not yet // supported with groupable features. SessionConfig( useCases = listOf(Preview.Builder().build()), requiredFeatureGroup = setOf(HDR_HLG10), preferredFeatureGroup = listOf(FPS_60, HDR_HLG10), effects = effects, )
| Throws | |
|---|---|
IllegalArgumentException |
If the combination of config options are conflicting or unsupported, or if the |
| See also | |
|---|---|
bindToLifecycle |
Summary
Nested types |
|---|
public final class SessionConfig.BuilderBuilder for |
Public constructors |
|---|
SessionConfig(@NonNull UseCase... useCases)Creates the SessionConfig from use cases only. |
SessionConfig(Creates a |
Public methods |
|
|---|---|
final @NonNull List<@NonNull CameraEffect> |
The list of |
final @NonNull Consumer<@NonNull Set<@NonNull GroupableFeature>> |
Gets the feature selection listener set to this session config. |
final @NonNull Executor |
Gets the executor set to this session config for feature selection listener invocation. |
final @NonNull Range<@NonNull Integer> |
The desired frame rate range for the camera session. |
final @NonNull List<@NonNull GroupableFeature> |
A list of preferred |
final @NonNull Set<@NonNull GroupableFeature> |
A set of |
final @NonNull List<@NonNull UseCase> |
The list of |
final ViewPort |
The |
final boolean |
Whether to use auto rotation. |
final void |
setFeatureSelectionListener(Sets a listener to know which features are finally selected when a session config is bound, based on the user-defined priorities/ordering for |
@NonNull String |
toString() |
Public constructors
SessionConfig
public SessionConfig(@NonNull UseCase... useCases)
Creates the SessionConfig from use cases only.
SessionConfig
public SessionConfig(
@NonNull List<@NonNull UseCase> useCases,
ViewPort viewPort,
@NonNull List<@NonNull CameraEffect> effects,
@NonNull Range<@NonNull Integer> frameRateRange,
@NonNull Set<@NonNull GroupableFeature> requiredFeatureGroup,
@NonNull List<@NonNull GroupableFeature> preferredFeatureGroup
)
Creates a SessionConfig from the given parameters.
| Parameters | |
|---|---|
@NonNull List<@NonNull UseCase> useCases |
The list of |
ViewPort viewPort |
The |
@NonNull List<@NonNull CameraEffect> effects |
The list of |
@NonNull Range<@NonNull Integer> frameRateRange |
The desired frame rate range for the camera session. If this value is not set, the default is
|
@NonNull Set<@NonNull GroupableFeature> requiredFeatureGroup |
A set of mandatory |
@NonNull List<@NonNull GroupableFeature> preferredFeatureGroup |
A list of preferred |
| Throws | |
|---|---|
IllegalArgumentException |
If the combination of config options are conflicting or unsupported, or if the |
| See also | |
|---|---|
setAutoRotationEnabled |
Public methods
getEffects
public final @NonNull List<@NonNull CameraEffect> getEffects()
The list of CameraEffect to be applied on the camera session. If not set, the default is no effects.
getFeatureSelectionListener
public final @NonNull Consumer<@NonNull Set<@NonNull GroupableFeature>> getFeatureSelectionListener()
Gets the feature selection listener set to this session config.
| See also | |
|---|---|
setFeatureSelectionListener |
getFeatureSelectionListenerExecutor
public final @NonNull Executor getFeatureSelectionListenerExecutor()
Gets the executor set to this session config for feature selection listener invocation.
| See also | |
|---|---|
setFeatureSelectionListener |
getFrameRateRange
public final @NonNull Range<@NonNull Integer> getFrameRateRange()
The desired frame rate range for the camera session. If this value is not set, the default is FRAME_RATE_RANGE_UNSPECIFIED, which means no specific frame rate. The range defines the acceptable minimum and maximum frame rate for the camera session: - A dynamic range (e.g., [15, 30]) allows the camera to adjust its frame rate within the bounds, benefiting previewing in low light by enabling longer exposures for brighter, less noisy images. - Conversely, a fixed range (e.g., [30, 30]) ensures a stable frame rate crucial for video recording, though it can lead to darker, noisier video in low light due to shorter exposure times.
getPreferredFeatureGroup
public final @NonNull List<@NonNull GroupableFeature> getPreferredFeatureGroup()
A list of preferred GroupableFeature ordered according to priority in descending order, i.e. a feature with a lower index in the list is considered to have a higher priority. If not set, the default is an empty list. See SessionConfig.Builder.setPreferredFeatureGroup for more info.
getRequiredFeatureGroup
public final @NonNull Set<@NonNull GroupableFeature> getRequiredFeatureGroup()
A set of GroupableFeature that are mandatory for the camera session configuration. If not set, the default is an empty set. See SessionConfig.Builder.setRequiredFeatureGroup for more info.
getUseCases
public final @NonNull List<@NonNull UseCase> getUseCases()
The list of UseCase to be attached to the camera and receive camera data.
getViewPort
public final ViewPort getViewPort()
The ViewPort to be applied on the camera session. If not set, the default is no viewport.
isAutoRotationEnabled
public final boolean isAutoRotationEnabled()
Whether to use auto rotation. When enabled, CameraX will monitor the device motion sensor and set the target rotation for ImageCapture, androidx.camera.video.VideoCapture and ImageAnalysis.
setFeatureSelectionListener
public final void setFeatureSelectionListener(
@NonNull Executor executor,
@NonNull Consumer<@NonNull Set<@NonNull GroupableFeature>> listener
)
Sets a listener to know which features are finally selected when a session config is bound, based on the user-defined priorities/ordering for preferredFeatureGroup and device capabilities.
Both the required and the selected preferred features are notified to the listener. The listener is invoked when this session config is bound to camera (e.g. when the androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle API is invoked). It is invoked even when no preferred features are selected, providing either the required features or an empty set (if no feature was set as required).
Alternatively, the CameraInfo.isSessionConfigSupported API can be used to query if a set of features is supported before binding.