-
Notifications
You must be signed in to change notification settings - Fork 6
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
CameraX update to rc02 (part 1) #638
Draft
mzorz
wants to merge
18
commits into
trunk
Choose a base branch
from
try/camerax-update-1.0.0-rc-02
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…on from CameraX.bindToLifecycle
… to 9:16 and simplify
…ther go when it's resumed
…rm and optimal preview size calcultaed and requested by CameraX on surfaceRequest, rolling back
…ing the custom initializer on Application anymore
…l to avoid android.hardware.camera2.impl.CameraDeviceImpl null reference
You can test the changes on this Pull Request by downloading the APK here. |
This was referenced Feb 22, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR makes all the necessary changes to bring CameraX in the Stories library from alpha-06 to latest release candidate at then moment of this writing, Rc02
In particular, this PR implements the SurfaceProvider interface, and we used PreviewView's source code and MediaPipe's implementation as examples.
Reasons to upgrade
RECORD_AUDIO
permission for API < 23Plan of action
Given we were several versions behind, but found alpha06 quite stable for the use cases we implemented (with some workarounds as well), we made a plan to make the upgrade in steps, to contain changes in a way that makes the refactor easier to understand.
The original plan after analyzing what each version brought in terms of changes was along these lines:
1.0.0-rc-01, 1.0.0-rc-02With several of the releases having some breaking API changes, no doubt the one that demanded more refactoring was
alpha-07
, which coincidentally was the first one to be tackled in the plan. However, after wrangling the needed modifications foralpha-07
, we realized we weren't really that far from moving on with the rest of the versions all the way up torc-02
, so instead of generating unnecessary overhead by writing different stacked PRs for each version we decided to finish writing all the changes in one go, which would also make testing a lot easier. In the end, most of the changes were due to the surface provider pattern introduced in alpha-07 and how to go about it with our own BackgroundSurfaceManager.History
In the Stories library architecture, we have a
BackgroundSurfaceManager
, which is essential to how it all works in Stories. One of the main needs we had when architecting the library was to keep the ability to have one Surface / TextureView and being able to switch between live preview / video recording / video playback easily, in a way that would feel snappy to the user.This optimization (keeping the Surface and being able to serve it different data streams as it was attached to live camera preview or a pre-recorded video player, for instance), is in essence different from the way things were architected in the CameraX library to operate.
CameraX offers a new PreviewView component which encapsulates all of the problems live previewing or image capturing from a camera have, and then also take care of handling the rendering without much hurdle for the developer, at the expense of making it arguably harder to extend. There's a door open though, which is the Surface provider pattern introduced in
alpha-07
, which is the way in which CameraX allows developers to override and come up with their own defined behavior.Citing the documentation here (https://developer.android.com/jetpack/androidx/releases/camera#camera-core-1.0.0-alpha07):
Stories' BackgroundSurfaceManager operates at a horizontal level, while CameraX's PreviewView crosses all layers from the View layer to the hardware layer..
CameraX's PreviewView
The recommended way forward when using the CameraX library is to use PreviewView, but this would pose some bigger refactors on our side, given PreviewView is a vertical block (view, view handler, model, library stack) and it would be difficult to use with our own BackgroundSurfaceManager. Besides that, we would have to implement a SurfaceProvider ourselves and then provide the surface to CameraX library but most of the joy of PreviewView would then be left unused.
We did implement our own surface provider in this PR, but knowing in then long run it would be nice to stick to CameraX's recommended practices PreviewView
PreviewView is tested on Google's test labs (https://medium.com/androiddevelopers/camerax-a-glimpse-into-the-past-present-and-future-19e22d8d2748), which is certainly one of the main goals which gave birth to the the CameraX library effort in the first place. For this reason, we'll look forward into further refactoring BackgroundSurfaceManager to include PreviewView, once the VideoCapture use case is stabilized as well.
Current status
As of now, and as we'll see in subsequent PRs, the VideoCapture (undocumented) use case showed some regressions as per our tests on different handsets, so we're leaving this PR as a draft and documenting our findings so we can resume work on this later on.
To summarize:
Tested front / rear cameras switching use cases from ImageCapture to VideoCapture on then following handsets running Android 8.x / 9 / 10: Pixel 2, Pixel 3, Samsung J2, Samsung A31, Samsung Tab S5e, Xaiomi Redmi Note 5.
Video in front camera on the Samsung J2 & Samsung Tab S5e:
General list in the issue tracker for CameraX:
https://issuetracker.google.com/u/1/issues?q=componentid:618491%20status:open%20video
Note: We also tried adding the use case to the basic CameraX sample app but results showed the same issues on the handsets we used to test.