The second Android 11 Developer Preview is now available, test it out and share your feedback.

Camera2DeviceSurfaceManager

class Camera2DeviceSurfaceManager : CameraDeviceSurfaceManager
kotlin.Any
   ↳ androidx.camera.camera2.internal.Camera2DeviceSurfaceManager

Camera device manager to provide the guaranteed supported stream capabilities related info for all camera devices

android.hardware.camera2.CameraDevice#createCaptureSession defines the default guaranteed stream combinations for different hardware level devices. It defines what combination of surface configuration type and size pairs can be supported for different hardware level camera devices. This structure is used to store the guaranteed supported stream capabilities related info.

Summary

Public methods

Boolean
checkSupported(@NonNull cameraId: String, @Nullable surfaceConfigList: MutableList<SurfaceConfig!>?)

Check whether the input surface configuration list is under the capability of any combination of this object.

Rational?
getCorrectedAspectRatio(@NonNull cameraId: String, rotation: Int)

Returns the corrected aspect ratio for the camera id or null if no correction is needed.

Size
getMaxOutputSize(@NonNull cameraId: String, imageFormat: Int)

Get max supported output size for specific camera device and image format

Size

Retrieves the preview size, choosing the smaller of the display size and 1080P.

MutableMap<UseCase!, Size!>
getSuggestedResolutions(@NonNull cameraId: String, @Nullable originalUseCases: MutableList<UseCase!>?, @NonNull newUseCases: MutableList<UseCase!>)

Retrieves a map of suggested resolutions for the given list of use cases.

Boolean

Checks whether the use case requires a corrected aspect ratio due to device constraints.

SurfaceConfig?
transformSurfaceConfig(@NonNull cameraId: String, imageFormat: Int, @NonNull size: Size)

Transform to a SurfaceConfig object with cameraId, image format and size info

Public methods

checkSupported

fun checkSupported(
    @NonNull cameraId: String,
    @Nullable surfaceConfigList: MutableList<SurfaceConfig!>?
): Boolean

Check whether the input surface configuration list is under the capability of any combination of this object.

Parameters
cameraId String: the camera id of the camera device to be compared
surfaceConfigList MutableList<SurfaceConfig!>?: the surface configuration list to be compared
Return
Boolean the check result that whether it could be supported
Exceptions
IllegalStateException if not initialized

getCorrectedAspectRatio

@Nullable fun getCorrectedAspectRatio(
    @NonNull cameraId: String,
    rotation: Int
): Rational?

Returns the corrected aspect ratio for the camera id or null if no correction is needed.

Parameters
cameraId String: the camera Id of the device that requires correction
rotation Int: desired rotation of output aspect ratio relative to natural orientation
Return
Rational? the corrected aspect ratio for the use case
Exceptions
IllegalStateException if not initialized
IllegalArgumentException if supported surface information for given camera id can't be found.

getMaxOutputSize

@NonNull fun getMaxOutputSize(
    @NonNull cameraId: String,
    imageFormat: Int
): Size

Get max supported output size for specific camera device and image format

Parameters
cameraId String: the camera Id
imageFormat Int: the image format info
Return
Size the max supported output size for the image format
Exceptions
IllegalStateException if not initialized

getPreviewSize

@NonNull fun getPreviewSize(): Size

Retrieves the preview size, choosing the smaller of the display size and 1080P.

Return
Size preview size from SurfaceSizeDefinition
Exceptions
IllegalStateException if not initialized

getSuggestedResolutions

@NonNull fun getSuggestedResolutions(
    @NonNull cameraId: String,
    @Nullable originalUseCases: MutableList<UseCase!>?,
    @NonNull newUseCases: MutableList<UseCase!>
): MutableMap<UseCase!, Size!>

Retrieves a map of suggested resolutions for the given list of use cases.

Parameters
cameraId String: the camera id of the camera device used by the use cases
originalUseCases MutableList<UseCase!>?: list of use cases with existing surfaces
newUseCases MutableList<UseCase!>: list of new use cases
Return
MutableMap<UseCase!, Size!> map of suggested resolutions for given use cases
Exceptions
IllegalStateException if not initialized

requiresCorrectedAspectRatio

fun requiresCorrectedAspectRatio(@NonNull cameraId: String): Boolean

Checks whether the use case requires a corrected aspect ratio due to device constraints.

Parameters
cameraId String: the camera Id
Return
Boolean the check result that whether aspect ratio need to be corrected
Exceptions
IllegalStateException if not initialized
IllegalArgumentException if supported surface information for given camera id can't be found.

transformSurfaceConfig

@Nullable fun transformSurfaceConfig(
    @NonNull cameraId: String,
    imageFormat: Int,
    @NonNull size: Size
): SurfaceConfig?

Transform to a SurfaceConfig object with cameraId, image format and size info

Parameters
cameraId String: the camera id of the camera device to transform the object
imageFormat Int: the image format info for the surface configuration object
size Size: the size info for the surface configuration object
Return
SurfaceConfig? new SurfaceConfig object
Exceptions
IllegalStateException if not initialized