ExtensionSessionConfig


public final class ExtensionSessionConfig extends SessionConfig


A SessionConfig for extension sessions.

This class encapsulates the necessary configurations for a extension session. Once configured, this config can be bound to a camera and lifecycle using androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle or androidx.camera.lifecycle.LifecycleCameraProvider.bindToLifecycle.

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. Note that ImageAnalysis is not supported in extension sessions.

Constraints:

  • When used for binding to a camera via androidx.camera.lifecycle.ProcessCameraProvider.bindToLifecycle or androidx.camera.lifecycle.LifecycleCameraProvider.bindToLifecycle, the list of UseCase provided to the constructor or added via Builder.addUseCase cannot be empty.

Apps can use CameraProvider.getCameraInfo with an ExtensionSessionConfig to obtain the CameraInfo of the camera which can support the given ExtensionSessionConfig.

Usage Example:

// In a coroutine scope
try {
val extensionsManager = ExtensionsManager.getInstanceAsync(context, cameraProvider).await()

val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
if (extensionsManager.isExtensionAvailable(cameraSelector, ExtensionMode.NIGHT)) {
// This is the correct time to create an ExtensionSessionConfig
val imageCapture = ImageCapture.Builder().build()
val preview = Preview.Builder().build()

val config = ExtensionSessionConfig.Builder(
ExtensionMode.NIGHT,
extensionsManager
)
.addUseCase(preview)
.addUseCase(imageCapture)
.build()

// Now it's safe to bind the configuration
cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, config)
} else {
// Handle the case where the extension is not available.
}
} catch (e: Exception) {
// Handle failure
}
Throws
kotlin.IllegalArgumentException

if the given mode is not a valid extension mode.

Summary

Nested types

Builder for ExtensionSessionConfig.

Public constructors

ExtensionSessionConfig(
    int mode,
    @NonNull ExtensionsManager extensionsManager,
    @NonNull UseCase... useCases
)

Creates an ExtensionSessionConfig with a variable number of UseCase instances.

ExtensionSessionConfig(
    int mode,
    @NonNull ExtensionsManager extensionsManager,
    @NonNull List<@NonNull UseCase> useCases,
    ViewPort viewPort,
    @NonNull List<@NonNull CameraEffect> effects
)

Public methods

final @NonNull ExtensionsManager

The ExtensionsManager instance.

final int

The extension mode.

Inherited methods

From androidx.camera.core.SessionConfig
final @NonNull List<@NonNull CameraEffect>

The list of CameraEffect to be applied on the camera session.

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 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.

final @NonNull Set<@NonNull GroupableFeature>

A set of GroupableFeature that are mandatory for the camera session configuration.

final @NonNull List<@NonNull UseCase>

The list of UseCase to be attached to the camera and receive camera data.

final ViewPort

The ViewPort to be applied on the camera session.

final void

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.

@NonNull String

Public constructors

ExtensionSessionConfig

Added in 1.6.0-alpha02
public ExtensionSessionConfig(
    int mode,
    @NonNull ExtensionsManager extensionsManager,
    @NonNull UseCase... useCases
)

Creates an ExtensionSessionConfig with a variable number of UseCase instances.

Parameters
int mode

The extension mode. See ExtensionMode for the list of available modes.

@NonNull ExtensionsManager extensionsManager

The ExtensionsManager instance.

@NonNull UseCase... useCases

The UseCase instances to be attached to the camera and receive camera data.

Throws
kotlin.IllegalArgumentException

if the given mode is not a valid extension mode.

ExtensionSessionConfig

public ExtensionSessionConfig(
    int mode,
    @NonNull ExtensionsManager extensionsManager,
    @NonNull List<@NonNull UseCase> useCases,
    ViewPort viewPort,
    @NonNull List<@NonNull CameraEffect> effects
)
Parameters
int mode

The extension mode. See ExtensionMode for the list of available modes.

@NonNull ExtensionsManager extensionsManager

The ExtensionsManager instance.

@NonNull List<@NonNull UseCase> useCases

The list of UseCase to be attached to the camera and receive camera data.

ViewPort viewPort

The ViewPort to be applied on the camera session. If not set, the default is no viewport.

@NonNull List<@NonNull CameraEffect> effects

The list of CameraEffect to be applied on the camera session. If not set, the default is no effects.

Public methods

getExtensionsManager

Added in 1.6.0-alpha02
public final @NonNull ExtensionsManager getExtensionsManager()

The ExtensionsManager instance.

getMode

Added in 1.6.0-alpha02
public final int getMode()

The extension mode. See ExtensionMode for the list of available modes.