Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Octo4a 2.1.0 - Camera service refactor #496

Merged
merged 14 commits into from
Jul 14, 2024
Merged

Conversation

feelfreelinux
Copy link
Owner

Includes changes from #489, with some minor fixes. On top of that, support for manually setting the focus length has been implemented.

cobryan05 and others added 11 commits June 8, 2024 16:47
This is a refactor of the CameraService. It fixes many issues and hopefully
adds few.

This should decrease CPU usage and increase reliability.
I'm not convinced if my camera is even autofocusing or
if it's just being shaken around by the printer... but this
is the closest I've been able to get to 'fixed focus'
Clearing the Preview surface provider before unbinding the use case
seems to fix most of the issues.
Setting the state triggers a callback which uses the
cameraControl, so should probably set it first.
I don't know why. New versions of CameraX it does nothing, old
versions of CameraX it closes the image, which is manually done
immediately after the call anyway. But it seems to be stopping
my camera from going into an error state by calling it...
I really hate this thing. It works great on my cheap, but new, BluView4
phone, but I *will* get this stupid thing to work on my Galaxy S5.

The camera on my Galaxy S5 will crash and require a full phone
reboot if an 'enableTorch' call is called while an imageCapture with
flashmode on attempts to take a picture... so now I'm manually turning
on the flash for ImageCapture. This can sometimes mess with image focus
or exposure, as when FlashMode was set on the ImageCapture object the phone
would go through its AutoExposure/AutoFocus routine before snapping a picture.
Turning the flash on for a bit before the capture call seems to help for some
reason but isn't perfect. I don't know why it helps at all because the camera
shouldn't be 'seeing' anything different as long as the flash is on before
the camera, but it seems to help.

I found that when ImageCapture has flash mode on that calling enableTorch
on the CameraControl returned from binding ImageCapture would cause the
ImageCapture to take a snapshot (this is what was crashing my camera:
calling enableTorch(false) would *trigger* ImageCapture to take a picture,
which would try to control the flash and crash). So now when a use case
references the flash it passes along its CameraControl (instead of grabbing
the first non-null CameraControl in the list). With the change to make
ImageCapture use manual flash this shouldn't really have any affect.
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...)
@feelfreelinux feelfreelinux merged commit 3e9716a into master Jul 14, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants