Camera2Interop.Extender


@ExperimentalCamera2Interop
public final class Camera2Interop.Extender<T extends Object>


Extends baseBuilder to add Camera2 options.

Use Camera2Interop.forUseCase, Camera2Interop.forImageCapture, or Camera2Interop.forSessionConfig in Java, or the camera2Interop extension function in Kotlin instead (e.g. UseCase.Builder.camera2Interop for physical camera ID or SessionConfig.Builder.camera2Interop for capture request options and callbacks).

Parameters
<T extends Object>

the type being built by the extendable builder.

Summary

Public constructors

<T extends Object> Extender(@NonNull ExtendableBuilder<@NonNull T> baseBuilder)

This method is deprecated. Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Public methods

final @NonNull Camera2Interop.Extender<@NonNull T>
<ValueT extends Object> setCaptureRequestOption(
    @NonNull CaptureRequest.Key<@NonNull ValueT> key,
    @NonNull ValueT value
)

This method is deprecated. Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

final @NonNull Camera2Interop.Extender<@NonNull T>

This method is deprecated. Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

final @NonNull Camera2Interop.Extender<@NonNull T>
@RequiresApi(value = 28)
setPhysicalCameraId(@NonNull String cameraId)

This method is deprecated. Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

final @NonNull Camera2Interop.Extender<@NonNull T>

This method is deprecated. Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

final @NonNull Camera2Interop.Extender<@NonNull T>

This method is deprecated. Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

final @NonNull Camera2Interop.Extender<@NonNull T>
@RequiresApi(value = 33)
setStreamUseCase(long streamUseCase)

This method is deprecated. Use the camera2Interop extension function on UseCase.Builder (e.g., 'builder.camera2Interop { setPhysicalCameraId(physicalCameraId) }') or SessionConfig.Builder for capture request options and callbacks instead.

Public constructors

Extender

public <T extends Object> Extender(@NonNull ExtendableBuilder<@NonNull T> baseBuilder)

Creates an Extender that can be used to add Camera2 options to another Builder.

Parameters
<T extends Object>

the type being built by the extendable builder.

@NonNull ExtendableBuilder<@NonNull T> baseBuilder

The builder being extended.

Public methods

setCaptureRequestOption

Added in 1.0.0
Deprecated in 1.7.0-alpha03
public final @NonNull Camera2Interop.Extender<@NonNull T> <ValueT extends Object> setCaptureRequestOption(
    @NonNull CaptureRequest.Key<@NonNull ValueT> key,
    @NonNull ValueT value
)

Sets a CaptureRequest.Key and Value on the configuration.

The value will override any value set by CameraX internally with the risk of interfering with some CameraX CameraControl APIs as well as 3A behavior. When applied to an androidx.camera.core.ImageCapture.Builder, options set for still capture requests override corresponding keys set in repeating requests.

Parameters
<ValueT extends Object>

The type of the value.

@NonNull CaptureRequest.Key<@NonNull ValueT> key

The CaptureRequest.Key which will be set.

@NonNull ValueT value

The value for the key.

Returns
@NonNull Camera2Interop.Extender<@NonNull T>

The current Extender.

setDeviceStateCallback

Added in 1.0.0
Deprecated in 1.7.0-alpha03
public final @NonNull Camera2Interop.Extender<@NonNull T> setDeviceStateCallback(
    @NonNull CameraDevice.StateCallback stateCallback
)

Sets a CameraDevice.StateCallback.

The caller is expected to use the CameraDevice instance accessed through the callback methods responsibly. Generally safe usages include: (1) querying the device for its id, (2) using the callbacks to determine what state the device is currently in. Generally unsafe usages include: (1) creating a new CameraCaptureSession, (2) creating a new CaptureRequest, (3) closing the device. When the caller uses the device beyond the safe usage limits, the usage may still work in conjunction with CameraX, but any strong guarantees provided by CameraX about the validity of the camera state become void.

Returns
@NonNull Camera2Interop.Extender<@NonNull T>

The current Extender.

setPhysicalCameraId

Added in 1.1.0
Deprecated in 1.7.0-alpha03
@RequiresApi(value = 28)
public final @NonNull Camera2Interop.Extender<@NonNull T> setPhysicalCameraId(@NonNull String cameraId)

Set the ID of the physical camera to get output from.

In the case one logical camera is made up of multiple physical cameras, this call forces the physical camera with the specified camera ID to produce image.

The valid physical camera IDs can be queried by CameraCharacteristics .getPhysicalCameraIds on API >= 28. Passing in an invalid physical camera ID will be ignored.

On API <= 27, the physical camera ID will be ignored since logical camera is not supported on these API levels.

Currently it doesn't support binding use cases with different physical camera IDs. If use cases with different physical camera IDs are bound at the same time, an IllegalArgumentException will be thrown.

Parameters
@NonNull String cameraId

The desired camera ID.

Returns
@NonNull Camera2Interop.Extender<@NonNull T>

The current Extender.

setSessionCaptureCallback

Added in 1.0.0
Deprecated in 1.7.0-alpha03
public final @NonNull Camera2Interop.Extender<@NonNull T> setSessionCaptureCallback(
    @NonNull CameraCaptureSession.CaptureCallback captureCallback
)

Sets a CameraCaptureSession.CaptureCallback.

The caller is expected to use the CameraCaptureSession instance accessed through the callback methods responsibly. Generally safe usages include: (1) querying the session for its properties. Generally unsafe usages include: (1) submitting a new CaptureRequest, (2) stopping an existing CaptureRequest, (3) closing the session, (4) attaching a new android.view.Surface to the session. When the caller uses the session beyond the safe usage limits, the usage may still work in conjunction with CameraX, but any strong guarantees provided by CameraX about the validity of the camera state become void.

The caller is generally free to use the CaptureRequest and CaptureRequest instances accessed through the callback methods.

Returns
@NonNull Camera2Interop.Extender<@NonNull T>

The current Extender.

setSessionStateCallback

Added in 1.0.0
Deprecated in 1.7.0-alpha03
public final @NonNull Camera2Interop.Extender<@NonNull T> setSessionStateCallback(
    @NonNull CameraCaptureSession.StateCallback stateCallback
)

Sets a CameraCaptureSession.StateCallback.

The caller is expected to use the CameraCaptureSession instance accessed through the callback methods responsibly. Generally safe usages include: (1) querying the session for its properties, (2) using the callbacks to determine what state the session is currently in. Generally unsafe usages include: (1) submitting a new CameraCaptureSession, (2) stopping an existing CaptureRequest, (3) closing the session, (4) attaching a new android.view.Surface to the session. When the caller uses the session beyond the safe usage limits, the usage may still work in conjunction with CameraX, but any strong guarantees provided by CameraX about the validity of the camera state become void.

Returns
@NonNull Camera2Interop.Extender<@NonNull T>

The current Extender.

setStreamUseCase

Added in 1.2.0
Deprecated in 1.7.0-alpha03
@RequiresApi(value = 33)
public final @NonNull Camera2Interop.Extender<@NonNull T> setStreamUseCase(long streamUseCase)

Sets a stream use case flag on the given extendable builder.

Requires API 33 or above.

Calling this method will set the stream useCase for the stream associated with the surface whose container class is the UseCase. Valid use cases available on devices can be found in android.hardware.camera2.CameraCharacteristics.SCALER_AVAILABLE_STREAM_USE_CASES The app should make sure the input argument is in the list of supported use cases first.

If a unsupported value is provided, IllegalArgumentException will be thrown.

Parameters
long streamUseCase

The stream use case to set.

Returns
@NonNull Camera2Interop.Extender<@NonNull T>

The current Extender.

See also
setStreamUseCase

to see how Camera2 framework uses this.