davidliu

Potential fix for camera1 crash when getting dimensions after capture has started

... ... @@ -209,6 +209,8 @@ constructor(
position = enumerator.getCameraPosition(targetDeviceName!!)
)
if (targetVideoCapturer is Camera1Capturer) {
// Cache supported capture formats ahead of time to avoid future camera locks.
Camera1Helper.getSupportedFormats(Camera1Helper.getCameraId(newOptions.deviceId))
return Pair(
Camera1CapturerWithSize(targetVideoCapturer, targetDeviceName),
newOptions
... ...
... ... @@ -10,13 +10,16 @@ internal class Camera1Helper {
companion object {
fun getCameraId(deviceName: String?) = Camera1Enumerator.getCameraIndex(deviceName)
fun getSupportedFormats(cameraId: Int): List<CameraEnumerationAndroid.CaptureFormat> =
Camera1Enumerator.getSupportedFormats(cameraId)
fun findClosestCaptureFormat(
cameraId: Int,
width: Int,
height: Int
): Size {
return CameraEnumerationAndroid.getClosestSupportedSize(
Camera1Enumerator.getSupportedFormats(cameraId)
getSupportedFormats(cameraId)
.map { Size(it.width, it.height) },
width,
height
... ...
... ... @@ -11,13 +11,20 @@ import android.hardware.camera2.CameraManager
*/
internal class Camera2Helper {
companion object {
fun getSupportedFormats(
cameraManager: CameraManager,
cameraId: String?,
): List<CameraEnumerationAndroid.CaptureFormat>? =
Camera2Enumerator.getSupportedFormats(cameraManager, cameraId)
fun findClosestCaptureFormat(
cameraManager: CameraManager,
cameraId: String?,
width: Int,
height: Int
): Size {
val sizes = Camera2Enumerator.getSupportedFormats(cameraManager, cameraId)
val sizes = getSupportedFormats(cameraManager, cameraId)
?.map { Size(it.width, it.height) }
?: emptyList()
return CameraEnumerationAndroid.getClosestSupportedSize(sizes, width, height)
... ...