-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[camera] Return all possible cameras on Android #6091
[camera] Return all possible cameras on Android #6091
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). 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. |
Hi everyone, I intentionally did not add any tests for now, because I want to make sure, that this PR has any chances of merging. The way I solved the issue is that the In the Android docs, there is information that non-removable cameras ids are integers from 0 (https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraIdList()). With this fact in mind, I've created this PR, which finally returns all possible cameras on my test device "Alcatel 1s", which was the hardest nut to crack out of all my Android test phones. I'm fully aware that this is not an ideal solution, but with the current state of Camera2 Android API, AFAIK there is sadly no better solution. We were using this change in production for some time now and sometimes there is camera id to which |
Also, I made gradle version changes to the Android example to be able to build it with no strange problems (which I hope is not an issue in any way). |
Can you elaborate on "miserably fails"? What does it do?
Based on the explanation in https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#getPhysicalCameraIds() it sounds like that's expected behavior, and that what you're doing here is explicitly bypassing code that's meant to prevent that situation. It's not clear to me why returning cameras that won't work is a desirable change. |
Hi @stuartmorgan, I meant that the The problem is, that at least from what I've read and tried there is no official way to get these two additional indexes. So the final solution for me was to do a simple loop which tries to find all of them. (and the mechanism to check whether there is a camera for such index, was using the |
But you also said that on other devices these extra camera indexes fail when used. Given the docs I linked to, it sounds like what you are doing here is exposing cameras that are not actually supported for individual use, and if/when they do work it's basically an accident. Am I misunderstanding? |
@stuartmorgan @martingeorgiu https://tech.gc.com/every-camera-every-angle-on-android/ this article may be a great help explaining what is going on here. It seems that Flutter camera for now supports some physical camera setups properly, but it gets lost when using logical camera setups and some of the weirder physical camera setups. For instance the pixel 6 has 2 physical back cameras and 1 logical back camera. The camera returned by the camera flutter plugin is logical, but the zoom instances are set incorrectly on it. The phone supports .7 to 7 zoom levels on its logical camera, but the camera plugin lists 1 as the minimum which stops the android API from swapping between the physical cameras built into the 1 logical camera returned. Looking more into what a good solution for this would look like now without trying to open the physical cameras directly. |
@martingeorgiu let me know if this allows you to get around your issue using the multiple physical cameras combined into a single logical camera. #6150 |
@lucasoskorep Sadly that did not help. The issues with devices where this plugin is not returning all cameras are afaik caused by an intentional restriction of the manufacturer (probably to promote their main camera app) and the cases, where this PR would help, are probably as @stuartmorgan said basically by accident. |
@martingeorgiu oh yeah I see that now - seems my issue is for a different bug. Thanks for clarifying :) |
This PR is Android equivalent to #5636 which I did recently for iOS.
flutter/flutter#91247
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.