Skip to content

Commit

Permalink
Always call enableTorch() when refcnt+
Browse files Browse the repository at this point in the history
Previously enableTorch(true) would only be called on the first refcnt.
However, sometimes ImageCapture will decide to turn off the flash, which
would require all streams to close to get refcnt down to 0 so that it
could go back up to 1 again to turn back on. By always calling enableTorch,
even when it should already be on, it will allow a new use case to turn
the torch back on (although it must be a new use case, eg a snapshot. Just
opening up new streams without closing existing streams will just share the
same use case and the flash will still be off...)
  • Loading branch information
cobryan05 committed Jun 14, 2024
1 parent 2b1f8a5 commit c06ec6b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/app/src/main/java/com/octo4a/camera/CameraService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ class CameraService : LifecycleService(), MJpegFrameProvider {
synchronized(_torchRefCnt) {
_torchRefCnt += 1
if (_torchRefCnt == 1) {
_logger.log(this) { "Torch now has users" }
}
if (_torchRefCnt > 0 ) {
if (_cameraSettings.flashWhenObserved) {
(cameraControl ?: getCameraControl())?.enableTorch(true)
}
_logger.log(this) { "Torch now has users" }
}
}
}
Expand Down

0 comments on commit c06ec6b

Please sign in to comment.