Status Update
Comments
wu...@google.com <wu...@google.com> #2
Hi, thank for the feedback. We will take a look and update to you soon.
ka...@google.com <ka...@google.com> #3
Thanks for your feedback.
It will be helpful for us to improve our documentation/samples/APIs.
We added the code snippet in javadoc for getAvailableConcurrentCameraInfos() (I will link it to bindToLifecycle() as well):
This is the sample app to show a front + back camera previews in Picture-in-Picutre layout or Side-by-Side layout:
To answer your questions:
- Linking a SingleCameraConfig to an UseCaseGroup seems weird to me since some of these use cases are not related to this camera (in my case I have one Preview for the back camera and one for the front one)
The concurrent camera API is to support front + back camera operating at the same time. The design philosophy is for each camera in concurrent mode, it could bind its own UseCases (e.g. Preview or Preview + ImageCapture, etc,.). That's why in each ConcurrentCamera.SingleCameraConfig, we allow to set UseCaseGroup.
- From my understanding, ProcessCameraProvider.bindToLifecycle makes a combination of all the camera selectors for one UseCaseGroup. However, if it does it in my case, it combines the filters for both front and back camera (line 568) so it can't find a camera that does both at the same time, which seems logical. Is it not possible to have 2 use cases for cameras facing opposites directions?
bindToLifecycle is to bind a list of UseCases to a lifecycle-aware Camera, each Camera is represented by a CameraSelector (e.g. LENS_FACING_FRONT or LENS_FACING_BACK). In dual concurrent camera case, we will have two Cameras (refer to
Whether this device is supporting Concurrent Camera, please check
s....@apparence.io <s....@apparence.io> #4
Your examples helped me, thanks you!
My main issue was that I used the same UseCaseGroup
for all cameras instead of one per camera.
An other problem I had was that I though my Android emulator to be able to use this API (although it seems to work when using Camera2 directly).
When I ran my corrected code on that emulator, I only got black screens and no errors (I tried a sample pure Android project and it did the same).
After struggling for a while, I found out that cameraProvider.availableConcurrentCameraInfos
returns a list of only one camera (instead of a pair of cameras). The PackageManager#FEATURE_CAMERA_CONCURRENT
returned true but that was not enough to know if the device can really use multiple cameras.
My current method to detect if a device supports the concurrent camera feature is the following:
fun isMultiCamSupported(): Boolean {
val concurrentInfos = cameraProvider.availableConcurrentCameraInfos
var hasOnePair = false
for (cameraInfos in concurrentInfos) {
if (cameraInfos.size > 1) {
hasOnePair = true
}
}
return hasOnePair
}
Do you see any problem that may arise with this approach?
When running on a physical device on the Firebase Test Lab, I saw that it works there now.
Also, if you know any emulator able to use the ConcurrentCamera API, it would be much easier for my tests 🙏
ka...@google.com <ka...@google.com> #5
Thanks for your feedback!
-
Do you want to bind two Preview UseCases to one camera? Could you elaborate more on your scenario? In my sample, concurrent camera consists of two cameras, each camera has one UseCaseGroup which could have 1-2 UseCase (e.g. Preview + ImageCapture).
-
I think your approach to detect is correct. All the concurrent camera pairs returned from
cameraProvider.availableConcurrentCameraInfos
should be the source of truth.
Could you provide more information for the emulator you are using? e.g. API version
I'll check if any emulator is guaranteed to work and keep you updated.
wu...@google.com <wu...@google.com>
s....@apparence.io <s....@apparence.io> #6
- Do you want to bind two Preview UseCases to one camera? Could you elaborate more on your scenario? In my sample, concurrent camera consists of two cameras, each camera has one UseCaseGroup which could have 1-2 UseCase (e.g. Preview + ImageCapture).
I originally didn't understand that we could have several UseCaseGroup
(one per camera), but now that I understood, I have one UseCaseGroup
per camera and it works (Example: camera 1: Preview
, camera 2: Preview
).
I don't have a scenario where I want two Preview
for the same camera.
- I think your approach to detect is correct. All the concurrent camera pairs returned from cameraProvider.availableConcurrentCameraInfos should be the source of truth.
Perfect! If this is correct, CameraX might benefit to having it directly inside the API instead of each dev figuring it out.
I am using a Pixel 6 emulator running Android API 33 with Google Apis. Back camera is virtualscene while front camera is emulated.
Other question
When I'll bind several use cases to each camera at once, e.g.:
- camera1: Preview + ImageCapture + ImageAnalysis
- camera2: Preview + ImageCapture + ImageAnalysis
I suspect there will be a problem since it might be too resource intensive (maybe not? I could not try yet).
Is there a way to detect that it won't work? Or are we supposed to try to bindToLifecycle
, catch exceptions and try again with less use cases if it does not work?
When using a single camera for instance, I check wether the device is LEVEL_3 or not before trying to bind Preview + VideoCapture + ImageAnalysis (since it won't work if deviceLevel < LEVEL_3).
ap...@google.com <ap...@google.com> #7
Branch: androidx-main
commit 4f4604d42be6c47e606677100f181c73dd8f456d
Author: Kailiang Chen <kailianc@google.com>
Date: Thu Apr 06 16:34:27 2023
[Concurrent Camera] Improve the javadoc
Bug:
Test: Run on real devices
Change-Id: Ieff3754b24549de62902f6a1cd47b0278f03fcd0
M camera/camera-lifecycle/src/main/java/androidx/camera/lifecycle/ProcessCameraProvider.java
wu...@google.com <wu...@google.com>
ka...@google.com <ka...@google.com> #8
Other question When I'll bind several use cases to each camera at once, e.g.:
- camera1: Preview + ImageCapture + ImageAnalysis
- camera2: Preview + ImageCapture + ImageAnalysis
I suspect there will be a problem since it might be too resource intensive (maybe not? I could not try yet). Is there a way to detect that it won't work? Or are we supposed to try to
bindToLifecycle
, catch >exceptions and try again with less use cases if it does not work?
Sorry for the late reply.
According to the "Concurrent stream guaranteed configurations" table[1], each camera can only bind two UseCases at most (normally Preview + ImageCapture/VideoCapture). If you bind more UseCases than the capability of the device, bindToLifecycle
will throw IllegalArgumentException.
Let me know if you have any other questions.
[1]
ka...@google.com <ka...@google.com> #9
ka...@google.com <ka...@google.com>
wu...@google.com <wu...@google.com> #10
Hey there, just checking in – did you have a chance to try out the method Kailiang suggested? Did it help resolve the issue?
Description
I am working on the CamerAwesome plugin for Flutter and I'm trying to integrate the ConcurrentCamera API but I'm not sure of what we can or cannot achieve with it.
I am using camerax 1.3.0-alpha05.
The basic usage we had in mind was to provide the ability to show the preview of both front and back cameras.
We have a branch updateLifecycle .
feature/multi-cam
on which we are working. The most important part is probably the methodI've commented a few things to try to make a simple use case:
Preview
use case for first the back camera (usingCameraSelector.DEFAULT_BACK_CAMERA
) then the front one (CameraSelector.DEFAULT_FRONT_CAMERA
)UseCaseGroup.Builder
build()
theUseCaseGroup.Builder
ConcurrentCameraConfig
based on these selectors and thisUseCaseGroup
, and bind it:When I try to run that code, I get the following error:
I don't understand a few things:
SingleCameraConfig
to anUseCaseGroup
seems weird to me since some of these use cases are not related to this camera (in my case I have onePreview
for the back camera and one for the front one)ProcessCameraProvider.bindToLifecycle
makes a combination of all the camera selectors for oneUseCaseGroup
. However, if it does it in my case, it combines the filters for both front and back camera (line 568) so it can't find a camera that does both at the same time, which seems logical. Is it not possible to have 2 use cases for cameras facing opposites directions?When I set a generic camera selector (
CameraSelector.Builder().build()
) for both use cases, it does not throw exceptions but previews are black. There may be an issue somewhere else in the code but not sure where.If there's an example on how to implement ConcurrentCamera, I'd be happy to take a look at it 🙏
My test device is a Pixel 6 emulator running Android 13. It seems to be able to show both front and back camera at the same time on the app Dual Camera which probably uses Camera2 directly.