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:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user