public interface CameraDeviceSetupCompat


Interface for checking if a SessionConfiguration is supported by the device.

This interface is a compatible version of the CameraDevice.CameraDeviceSetup class.

Implementations of this interface must be able to check if a SessionConfiguration is supported. They will check both the output streams and the session parameters, then return whether the combination works for the given camera. For example, a camera device may support HDR and 60FPS frame rate, but not both at the same time.

Summary

Nested types

Result of a isSessionConfigurationSupported query.

Public methods

abstract @NonNull CameraDeviceSetupCompat.SupportQueryResult

Checks if the SessionConfiguration is supported.

abstract @NonNull CameraDeviceSetupCompat.SupportQueryResult

Checks if the set of features in SessionConfigurationLegacy is supported for the given camera.

Public methods

isSessionConfigurationSupported

Added in 1.5.0-beta02
abstract @NonNull CameraDeviceSetupCompat.SupportQueryResult isSessionConfigurationSupported(
    @NonNull SessionConfiguration sessionConfig
)

Checks if the SessionConfiguration is supported.

Note: The Play Services implementation does not support querying android.hardware.camera2.params.OutputConfigurations without an associated surface and will throw an IllegalArgumentException if an OutputConfiguration without an associated surface is passed. A android.view.Surface can be associated with an OutputConfiguration either during construction, or later with addSurface. This is an unfortunate limitation of Android Framework APIs. For queries that are performance sensitive and need to happen before the final surface is ready, it is recommended to create temporary android.hardware.camera2.params.OutputConfiguration with a concrete surface from newInstance that matches the desired final surface instead.

Following are examples of some common final surfaces, and how ImageReader can be used to query them:

  • SurfaceTexture.class:
    ImageReader.newInstance(1920, 1080, PixelFormat.PRIVATE, 1,
                            HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE)
  • MediaRecorder.class/MediaCodec.class:
    ImageReader.newInstance(1920, 1080, ImageFormat.PRIVATE, 1,
                            HardwareBuffer.USAGE_VIDEO_ENCODE)
  • SurfaceView.class:
    ImageReader.newInstance(1920, 1080, ImageFormat.PRIVATE, 1,
                            HardwareBuffer.USAGE_COMPOSER_OVERLAY)
Parameters
@NonNull SessionConfiguration sessionConfig

The SessionConfiguration to check.

Throws
android.hardware.camera2.CameraAccessException

if the camera device is no longer connected or has encountered a fatal error.

java.lang.IllegalArgumentException

if play-services implementation is included and an android.hardware.camera2.params.OutputConfiguration with a deferred Surface is passed.

isSessionConfigurationSupportedLegacy

Added in 1.5.0-beta02
abstract @NonNull CameraDeviceSetupCompat.SupportQueryResult isSessionConfigurationSupportedLegacy(
    @NonNull SessionConfigurationLegacy sessionConfig
)

Checks if the set of features in SessionConfigurationLegacy is supported for the given camera.

This method and the legacy classes are provided to allow querying camera device capabilities without the need to call openCamera. It must only be used for devices that do not support CameraDevice.CameraDeviceSetup and will throw an IllegalStateException when used for a cameraId for which isCameraDeviceSetupSupported returns true.

Even on older devices that do not support android.hardware.camera2.CameraDevice.CameraDeviceSetup, if the CameraDevice object can be obtained using openCamera, then isSessionConfigurationSupported should be used as the android.hardware.camera2.CaptureRequest returned by Camera2 generally has more information pre-filled from the template which may change the result.

Note that this method does not, and can not query camera2's isSessionConfigurationSupported, so the returned getSource will never be SOURCE_ANDROID_FRAMEWORK. Additionally, there is a small possibility that the result of Camera2's isSessionConfigurationSupported contradicts the result of this call. In such cases, a RESULT_UNSUPPORTED result can be considered authoritative, but RESULT_SUPPORTED may or may not be correct and is considered best effort.

WARNING: Use this method is discouraged for most developers. isSessionConfigurationSupported should be used wherever possible. This method should only be used if performance is critical on older devices and you understand and protect against the caveats documented above.

Parameters
@NonNull SessionConfigurationLegacy sessionConfig

The SessionConfigurationLegacy to check.

Throws
java.lang.IllegalStateException

if the camera device supports

java.lang.IllegalArgumentException

if play-services implementation is included and an android.hardware.camera2.params.OutputConfiguration with a deferred Surface is passed. See note in isSessionConfigurationSupported