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