Skip to content

Commit

Permalink
use current (main) thread for device callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
pvasa committed Feb 1, 2022
1 parent bc5a973 commit 76db9f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object Config {

private const val majorVersion = 3
private const val minorVersion = 5
private const val patchVersion = 5
private const val patchVersion = 7
private const val versionClassifier = "alpha"

val versionName: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ internal open class Camera2(
private val preview: PreviewImpl,
private val config: CameraConfiguration,
private val cameraJob: Job,
context: Context
context: Context,
) : CameraInterface {

final override val coroutineContext: CoroutineContext get() = Dispatchers.Default + cameraJob
Expand Down Expand Up @@ -231,15 +231,15 @@ internal open class Camera2(
session: CameraCaptureSession,
request: CaptureRequest,
timestamp: Long,
frameNumber: Long
frameNumber: Long,
) {
launch(Dispatchers.Main) { preview.shutterView.show() }
}

override fun onCaptureCompleted(
session: CameraCaptureSession,
request: CaptureRequest,
result: TotalCaptureResult
result: TotalCaptureResult,
) {
if (!videoManager.isVideoRecording) unlockFocus()
}
Expand Down Expand Up @@ -285,7 +285,7 @@ internal open class Camera2(
*/
private fun android.media.Image.setCropRect(
sensorOutputOrientation: Int,
imageOutputOrientation: Int
imageOutputOrientation: Int,
): Boolean {

val isScreenPortrait: Boolean = screenRotation % 180 == 0
Expand Down Expand Up @@ -502,7 +502,7 @@ internal open class Camera2(
final override var screenRotation: Int = 0

final override val isActive: Boolean
get() = cameraJob.isActive && backgroundHandler.looper.thread.isAlive == true
get() = cameraJob.isActive && backgroundHandler.looper.thread.isAlive

final override val isCameraOpened: Boolean get() = camera != null

Expand Down Expand Up @@ -557,7 +557,7 @@ internal open class Camera2(
override fun onCaptureCompleted(
session: CameraCaptureSession,
request: CaptureRequest,
result: TotalCaptureResult
result: TotalCaptureResult,
) {
val afState: Int? = result.get(CaptureResult.CONTROL_AF_STATE)
val aeState: Int? = result.get(CaptureResult.CONTROL_AE_STATE)
Expand Down Expand Up @@ -850,7 +850,7 @@ internal open class Camera2(
}
collectCameraInfo()
prepareSingleCaptureReader()
cameraManager.openCamera(this.cameraId, cameraDeviceCallback, backgroundHandler)
cameraManager.openCamera(this.cameraId, cameraDeviceCallback, null)
return@runCatching true
}
.getOrElse {
Expand Down Expand Up @@ -1122,7 +1122,9 @@ internal open class Camera2(
return
}

lifecycleRegistry.currentState = Lifecycle.State.STARTED
launch(Dispatchers.Main) {
lifecycleRegistry.currentState = Lifecycle.State.STARTED
}

val surfaces: List<Surface> = runCatching { setupSurfaces(previewRequestBuilder) }
.getOrElse {
Expand All @@ -1140,7 +1142,7 @@ internal open class Camera2(
@Throws(IllegalStateException::class)
private fun setupSurfaces(
captureRequestBuilder: CaptureRequest.Builder,
shouldAddMediaRecorderSurface: Boolean = false
shouldAddMediaRecorderSurface: Boolean = false,
): MutableList<Surface> {

val surfaces: MutableList<Surface> = mutableListOf()
Expand Down

0 comments on commit 76db9f0

Please sign in to comment.