in amazon-chime-sdk/src/main/java/com/amazonaws/services/chime/sdk/meetings/audiovideo/video/capture/DefaultCameraCaptureSource.kt [185:233]
override fun start() {
if (ActivityCompat.checkSelfPermission(
context,
Manifest.permission.CAMERA
) != PackageManager.PERMISSION_GRANTED
) {
handleCameraCaptureFail(CaptureSourceError.PermissionError)
throw SecurityException("Missing necessary camera permissions")
}
stop()
logger.info(TAG, "Camera capture start requested with device: $device")
val device = device ?: run {
logger.info(TAG, "Cannot start camera capture with null device")
return
}
val id = device.id ?: run {
logger.info(TAG, "Cannot start camera capture with null device id")
return
}
cameraCharacteristics = cameraManager.getCameraCharacteristics(id).also {
// Store these immediately for convenience
sensorOrientation = it.get(CameraCharacteristics.SENSOR_ORIENTATION) ?: 0
isCameraFrontFacing =
it.get(CameraCharacteristics.LENS_FACING) == CameraMetadata.LENS_FACING_FRONT
}
val maxWidth: Int = this.maxResolution.width
val maxHeight: Int = this.maxResolution.height
val maxFps: Int = 30
val chosenCaptureFormat: VideoCaptureFormat? =
MediaDevice.listSupportedVideoCaptureFormats(cameraManager, device, maxFps, maxWidth, maxHeight).minByOrNull { format ->
abs(format.width - this.format.width) + abs(format.height - this.format.height)
}
val surfaceTextureFormat: VideoCaptureFormat = chosenCaptureFormat ?: run {
handleCameraCaptureFail(CaptureSourceError.ConfigurationFailure)
return
}
surfaceTextureSource =
surfaceTextureCaptureSourceFactory.createSurfaceTextureCaptureSource(
surfaceTextureFormat.width,
surfaceTextureFormat.height,
contentHint
)
surfaceTextureSource?.addVideoSink(this)
surfaceTextureSource?.start()
cameraManager.openCamera(id, cameraDeviceStateCallback, handler)
}