ExtensionsManager

public final class ExtensionsManager
extends Object

java.lang.Object
   ↳ androidx.camera.extensions.ExtensionsManager


Provides interfaces for third party app developers to get capabilities info of extension functions.

Only a single ExtensionsManager instance can exist within a process, and it can be retrieved with getInstance(Context). After retrieving the ExtensionsManager instance, the availability of a specific extension mode can be checked by isExtensionAvailable(CameraProvider, CameraSelector, int). For an available extension mode, an extension enabled CameraSelector can be obtained by calling getExtensionEnabledCameraSelector(CameraProvider, CameraSelector, int). After binding use cases by the extension enabled CameraSelector, the extension mode will be applied to the bound Preview and ImageCapture. The following sample code describes how to enable an extension mode for use cases.

 void onCreate() {
     // Create a camera provider
     ProcessCameraProvider cameraProvider = ... // Get the provider instance
     // Create an extensions manager
     ExtensionsManager extensionsManager = ... // Get the extensions manager instance

     // Query if extension is available.
     if (mExtensionsManager.isExtensionAvailable(cameraProvider, DEFAULT_BACK_CAMERA,
                ExtensionMode.BOKEH)) {
         // Needs to unbind all use cases before enabling different extension mode.
         cameraProvider.unbindAll();

         // Retrieve extension enabled camera selector
         CameraSelector extensionCameraSelector;
         extensionCameraSelector = extensionsManager.getExtensionEnabledCameraSelector(
                 cameraProvider, DEFAULT_BACK_CAMERA, ExtensionMode.BOKEH);

         // Bind image capture and preview use cases with the extension enabled camera selector.
         ImageCapture imageCapture = new ImageCapture.Builder().build();
         Preview preview = new Preview.Builder().build();
         cameraProvider.bindToLifecycle(this, extensionCameraSelector, imageCapture, preview);
     }
 }
 

Summary

Public methods

Range<Long> getEstimatedCaptureLatencyRange(CameraProvider cameraProvider, CameraSelector cameraSelector, int mode, Size surfaceResolution)

Returns the estimated capture latency range in milliseconds for the target capture resolution.

CameraSelector getExtensionEnabledCameraSelector(CameraProvider cameraProvider, CameraSelector baseCameraSelector, int mode)

Returns a modified CameraSelector that will enable the specified extension mode.

static ListenableFuture<ExtensionsManager> getInstance(Context context)

Retrieves the ExtensionsManager associated with the current process.

boolean isExtensionAvailable(CameraProvider cameraProvider, CameraSelector baseCameraSelector, int mode)

Returns true if the particular extension mode is available for the specified CameraSelector.

Inherited methods

Public methods

getEstimatedCaptureLatencyRange

public Range<Long> getEstimatedCaptureLatencyRange (CameraProvider cameraProvider, 
                CameraSelector cameraSelector, 
                int mode, 
                Size surfaceResolution)

Returns the estimated capture latency range in milliseconds for the target capture resolution.

This includes the time spent processing the multi-frame capture request along with any additional time for encoding of the processed buffer in the framework if necessary.

Parameters
cameraProvider CameraProvider: A CameraProvider will be used to query the information of cameras on the device. The CameraProvider can be the ProcessCameraProvider which is obtained by ProcessCameraProvider.getInstance(Context).

cameraSelector CameraSelector: The CameraSelector to find a camera which supports the specified extension mode.

mode int: The extension mode to check.

surfaceResolution Size: the surface resolution of the ImageCapture which will be used to take a picture. If the input value of this parameter is null or it is not included in the supported output sizes, the maximum capture output size is used to get the estimated range information.

Returns
Range<Long> the range of estimated minimal and maximal capture latency in milliseconds. Returns null if no capture latency info can be provided.

Throws
IllegalArgumentException If this device doesn't support extensions function, or no camera can be found to support the specified extension mode.

getExtensionEnabledCameraSelector

public CameraSelector getExtensionEnabledCameraSelector (CameraProvider cameraProvider, 
                CameraSelector baseCameraSelector, 
                int mode)

Returns a modified CameraSelector that will enable the specified extension mode.

The returned extension CameraSelector can be used to bind use cases to a desired LifecycleOwner and then the specified extension mode will be enabled on the camera.

Parameters
cameraProvider CameraProvider: A CameraProvider will be used to query the information of cameras on the device. The CameraProvider can be the ProcessCameraProvider which is obtained by ProcessCameraProvider.getInstance(Context).

baseCameraSelector CameraSelector: The base CameraSelector on top of which the extension config is applied. isExtensionAvailable(CameraProvider, CameraSelector, int) can be used to check whether any camera can support the specified extension mode for the base camera selector.

mode int: The target extension mode.

Returns
CameraSelector a