fix: Avoid "CameraNotReady" errors when updating props in background (#2382)
This commit is contained in:
parent
9ecc09cfe4
commit
a4686022e2
@ -163,23 +163,38 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
|
|||||||
Log.i(TAG, "configure { ... }: Updating CameraSession Configuration... $diff")
|
Log.i(TAG, "configure { ... }: Updating CameraSession Configuration... $diff")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val needsRebuild = config.isActive && (cameraDevice == null || captureSession == null)
|
val needsRebuild = cameraDevice == null || captureSession == null
|
||||||
if (needsRebuild) {
|
if (needsRebuild) {
|
||||||
Log.i(TAG, "Need to rebuild CameraDevice and CameraCaptureSession...")
|
Log.i(TAG, "Need to rebuild CameraDevice and CameraCaptureSession...")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build up session or update any props
|
// Since cameraDevice and captureSession are OS resources, we have three possible paths here:
|
||||||
if (diff.deviceChanged || needsRebuild) {
|
if (needsRebuild) {
|
||||||
// 1. cameraId changed, open device
|
if (config.isActive) {
|
||||||
configureCameraDevice(config)
|
// A: The Camera has been torn down by the OS and we want it to be active - rebuild everything
|
||||||
}
|
Log.i(TAG, "Need to rebuild CameraDevice and CameraCaptureSession...")
|
||||||
if (diff.outputsChanged || needsRebuild) {
|
configureCameraDevice(config)
|
||||||
// 2. outputs changed, build new session
|
configureOutputs(config)
|
||||||
configureOutputs(config)
|
configureCaptureRequest(config)
|
||||||
}
|
} else {
|
||||||
if (diff.sidePropsChanged || needsRebuild) {
|
// B: The Camera has been torn down by the OS but it's currently in the background - ignore this
|
||||||
// 3. zoom etc changed, update repeating request
|
Log.i(TAG, "CameraDevice and CameraCaptureSession is torn down but Camera is not active, skipping update...")
|
||||||
configureCaptureRequest(config)
|
}
|
||||||
|
} else {
|
||||||
|
// C: The Camera has not been torn down and we just want to update some props - update incrementally
|
||||||
|
// Build up session or update any props
|
||||||
|
if (diff.deviceChanged) {
|
||||||
|
// 1. cameraId changed, open device
|
||||||
|
configureCameraDevice(config)
|
||||||
|
}
|
||||||
|
if (diff.outputsChanged) {
|
||||||
|
// 2. outputs changed, build new session
|
||||||
|
configureOutputs(config)
|
||||||
|
}
|
||||||
|
if (diff.sidePropsChanged) {
|
||||||
|
// 3. zoom etc changed, update repeating request
|
||||||
|
configureCaptureRequest(config)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i(TAG, "Successfully updated CameraSession Configuration! isActive: ${config.isActive}")
|
Log.i(TAG, "Successfully updated CameraSession Configuration! isActive: ${config.isActive}")
|
||||||
|
Loading…
Reference in New Issue
Block a user