perf: Use existing cameraQueue instead of yet another Thread (#2459)

* perf: Use existing `cameraQueue` instead of yet another Thread

* fix: Use `coroutineScope` to avoid wrong use of isActive

* fix: Do the same for `CameraSession`

* Lint
This commit is contained in:
Marc Rousavy
2024-01-30 14:26:55 +01:00
committed by GitHub
parent af14f912fb
commit 8c5b60355f
3 changed files with 8 additions and 12 deletions

View File

@@ -23,7 +23,6 @@ import com.mrousavy.camera.types.PixelFormat
import com.mrousavy.camera.types.ResizeMode
import com.mrousavy.camera.types.Torch
import com.mrousavy.camera.types.VideoStabilizationMode
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
@@ -39,7 +38,6 @@ import kotlinx.coroutines.launch
@SuppressLint("ClickableViewAccessibility", "ViewConstructor", "MissingPermission")
class CameraView(context: Context) :
FrameLayout(context),
CoroutineScope,
CameraSession.Callback {
companion object {
const val TAG = "CameraView"
@@ -98,7 +96,7 @@ class CameraView(context: Context) :
internal var frameProcessor: FrameProcessor? = null
override val coroutineContext: CoroutineContext = CameraQueues.cameraQueue.coroutineDispatcher
private val coroutineScope = CoroutineScope(CameraQueues.cameraQueue.coroutineDispatcher)
init {
this.installHierarchyFitter()
@@ -131,7 +129,7 @@ class CameraView(context: Context) :
val now = System.currentTimeMillis()
currentConfigureCall = now
launch {
coroutineScope.launch {
cameraSession.configure { config ->
if (currentConfigureCall != now) {
// configure waits for a lock, and if a new call to update() happens in the meantime we can drop this one.