[camera_android] Reset AE and AF triggers to idle after capture#11330
[camera_android] Reset AE and AF triggers to idle after capture#11330q2a3z wants to merge 1 commit intoflutter:mainfrom
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
There was a problem hiding this comment.
Code Review
The pull request modifies the Camera.java file to explicitly reset camera capture triggers to an idle state. Specifically, it adds code to reset CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER to IDLE after runPrecaptureSequence and CaptureRequest.CONTROL_AF_TRIGGER to IDLE after lockAutoFocus, ensuring proper state management for auto-exposure and auto-focus operations.
camsim99
left a comment
There was a problem hiding this comment.
Thanks for working on this fix! At a high level, this makes sense to me, but there's two things I want to address:
1: The main concern that I have is that CameraCaptureSession.capture is an asynchronous call, so I worry we may be resetting the AE and AF triggers back to idle too soon potentially. Can you clarify if this is true? If so, a solution may be to provide a callback to set the triggers to idle.
2: In order to land this, we will need tests for this change. A good place to add them would be in CameraTest.java.
|
Thank you for the quick reply and the suggestions. Yap, I also thought it might be an async function. It seems like the flash turns off just a split second before the photo is captured. I'll try your suggestion and let you know as soon as I have any updates. Once I've finished checking step 1, I’ll add some tests to CameraTest.java. |
Issue
App freezes during focus/flash sequence in low light.
On high-end camera devices, focusing takes longer in dark environments. Repeatedly requesting focus while using the flash can cause the CaptureRequest to hang.
This log has been captured on my Xperia device.
Root Cause
Camera2 trigger controls are driven by one-shot states (START), but they are not always reset to IDLE once the sequence is complete. On certain devices (like the Xperia 1), this failure to reset can block subsequent capture requests.
Fix
runPrecaptureSequence():Send an AE trigger START, then immediately follow with IDLE in the same execution path.
lockAutoFocus():Send an AF trigger START, then reset to IDLE after the preview request is captured.
Results
AE/AF triggers are now consistently returned to the IDLE state.
The freeze during capture after using the flash on Xperia 1 has been resolved.
Camera trigger sequences are now stable across various device models.
By the way,
I believe CameraX is the way to go for Android camera development. It's been the default since version 0.11.0.
Pre-Review Checklist
[shared_preferences]///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2