feat: Concurrent/Cancellable configure (#2282)

* feat: Cancellable `configure`

* Android

* Update Podfile.lock

* Configure outside of lock

* Update lockfiles

* Use `bundle` for CI

* Update script

* Update Podfile.lock

* fix: Set config at end

* Lint
This commit is contained in:
Marc Rousavy
2023-12-13 16:38:02 +01:00
committed by GitHub
parent 5a81fabedd
commit 977bf56c6d
9 changed files with 4362 additions and 5059 deletions

View File

@@ -65,6 +65,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
// Camera Configuration
private var configuration: CameraConfiguration? = null
private var currentConfigureCall: Long = System.currentTimeMillis()
// Camera State
private var captureSession: CameraCaptureSession? = null
@@ -112,15 +113,26 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
}
suspend fun configure(lambda: (configuration: CameraConfiguration) -> Unit) {
// This is the latest call to configure()
val now = System.currentTimeMillis()
currentConfigureCall = now
Log.i(TAG, "Updating CameraSession Configuration...")
// Let caller configure a new configuration for the Camera.
val config = CameraConfiguration.copyOf(this.configuration)
lambda(config)
val diff = CameraConfiguration.difference(this.configuration, config)
if (!diff.hasAnyDifference) {
Log.w(TAG, "Called configure(...) but nothing changed...")
return
}
mutex.withLock {
Log.i(TAG, "Updating CameraSession Configuration...")
val config = CameraConfiguration.copyOf(this.configuration)
lambda(config)
val diff = CameraConfiguration.difference(this.configuration, config)
if (!diff.hasAnyDifference) {
Log.w(TAG, "Called configure(...) but nothing changed...")
// Cancel configuration if there has already been a new config
if (currentConfigureCall != now) {
// configure() has been called again just now, skip this one so the new call takes over.
return
}