Status Update
Comments
th...@gmail.com <th...@gmail.com> #2
Hi Doudera,
Thank you for reporting this issue. It is working as intended. This is because the state of CameraControl follows Camera. Once the Camera is closed, all settings will be restored, just like the settings of the focus area and zoom level. The app can restore the torch state by resetting torch at the time of activity onResume.
ch...@google.com <ch...@google.com>
ch...@google.com <ch...@google.com> #3
thank you for the fast reply. The behaviour is unexpected to me because if you have the same code as before and just add logging like this:
camera = cameraProvider.bindToLifecycle(
this, cameraSelector, preview, imageCapture, imageAnalyzer)
.apply {
Log.d(TAG, "Enabling torch after binding") // <-- called everytime it returns to Activity so next statement should be applied
cameraControl.enableTorch(true)
}
The log is always called even when returning to Activity so I suppose it should be applied. Why it is not applied when it is called?
Unfortunately, I cannot make it work even with your hint. I tried to add camera?.cameraControl?.enableTorch(true) to onResume() but without any effect. Can you please describe more how to reset torch state onResume().
As you said the same happens with setZoomRatio() etc.
Thank you, Martin
th...@gmail.com <th...@gmail.com> #4
Hi Doudera, Thank you for the detail description. It sounds like some problem in the code. I will investigate it more.
ch...@google.com <ch...@google.com> #5
From the log, it shows the camera state
-> open -> enable torch -> close -> open
The torch was gone because it restarted the camera.
It needs to investigate more about why it open/close so frequently.
th...@gmail.com <th...@gmail.com> #6
In CameraXBasic, it looks like the "cameraProvider.unbindAll()" call in CameraFragment.bindCameraUseCases() method will cause the camera close.
Since camera operation is in another thread, a timing causes the enableTorch() failed because the camera is in closed state at that moment.
It can be detected by checking the returned ListenableFuture result from cameraControl.enableTorch()
020-03-29 12:34:56.139 4946-4946/com.android.example.cameraxbasic E/CameraXBasic: enableTorch
2020-03-29 12:34:56.225 4946-5035/com.android.example.cameraxbasic D/Camera: Transitioning camera internal state: OPENED --> CLOSING
2020-03-29 12:34:56.226 4946-4946/com.android.example.cameraxbasic E/CameraXBasic: enableTorch fail by java.util.concurrent.ExecutionException: androidx.camera.core.CameraControl$OperationCanceledException: Camera is not active.
java.util.concurrent.ExecutionException: androidx.camera.core.CameraControl$OperationCanceledException: Camera is not active.
at androidx.concurrent.futures.AbstractResolvableFuture.getDoneValue(AbstractResolvableFuture.java:518)
at androidx.concurrent.futures.AbstractResolvableFuture.get(AbstractResolvableFuture.java:475)
at androidx.concurrent.futures.CallbackToFutureAdapter$SafeFuture.get(CallbackToFutureAdapter.java:199)
at com.android.example.cameraxbasic.fragments.CameraFragment$bindCameraUseCases$1$2$1.run(CameraFragment.kt:310)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7476)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:968)
Caused by: androidx.camera.core.CameraControl$OperationCanceledException: Camera is not active.
at androidx.camera.camera2.internal.TorchControl.setActive(TorchControl.java:112)
at androidx.camera.camera2.internal.Camera2CameraControl.setActive(Camera2CameraControl.java:135)
at androidx.camera.camera2.internal.Camera2CameraImpl.tryRemoveOnlineUseCases(Camera2CameraImpl.java:727)
at androidx.camera.camera2.internal.Camera2CameraImpl.lambda$removeOnlineUseCase$13$Camera2CameraImpl(Camera2CameraImpl.java:699)
at androidx.camera.camera2.internal.-$$Lambda$Camera2CameraImpl$5wc8VkOCNW87m5eLEZfzgWUl-nY.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:216)
at android.os.HandlerThread.run(HandlerThread.java:67)
It is a defect that CameraX should guarantee the order of the camera request.
Another topic is that why camera will be closed when resuming the CameraFragment.
CameraX is lifecycle aware, if UseCases is bound and pause/resume the page, CameraX will restart those UseCases automatically. So actually it doesn't have to unbind and rebind those UseCases. Unbind and rebind UseCases causes it open camera twice and meet this timing issue. In CameraXBasic, it will unbind and rebind UseCases in onViewCreated().
It is easier to be done in an Activity, just put the bindToLifecycle(...) code in the Activity.onCreate(). For Fragment, maybe Fragment.onAttach() is something like Activity.onCreate, but not pretty sure if it is practical. Or alternatively, it has to unbind all use case in a paired callback such like Fragment.onDestroyView() to prevent Camera from being automatically opened when resuming.
ch...@google.com <ch...@google.com> #7
Branch: androidx-master-dev
commit 76ad175d0c681ddc6a1b86ff35b180f97049da0d
Author: leo huang <leohuang@google.com>
Date: Sat Jul 11 11:15:41 2020
Fix CameraControl.enableTorch is not working
The issue is caused by a race condition. Camera2CameraControl#setActive(true) is called on the main thread, but #setActive(false) is called on the camera thread. It will cause the control to be in a wrong state and not work properly.
The solution is to post all operations to camera thread to ensure the API calls are executed in the correct order.
But it must update the "LiveData" in advance on the main thread to maintain an existing behavior, i.e. user can immediately obtain the new LiveData value through continuous API calls on the main thread. However, trying to maintain this behavior will conflict with the above solution. There are 2 issues that need to be corrected to ensure the final LiveData value is correct.
(1) LiveData that was updated earlier on the main thread may reset by "setActive(false)" executed on the camera thread. This issue can be resolved by updating LiveData again in the posted camera operation since the tasks on the camera thread always have correct order.
(2) Before updating LiveData on the main thread, it cannot directly check the "active state" of CameraControl because the "active state" is only correct on the camera thread. The solution is to create a synchronized "use count" that can be queried on all threads. In this way, "use count" represents whether CameraControl accepts new requests, "active state" represents whether the requests are sent to Camera.
"Relnote: Fix the CameraControl unable to work by a race condition"
Bug: 152333890
Bug: 160928870
Bug: 160714166
Test: ./gradlew camera:camera-camera2:connectedAndroidTest; ./gradlew camera:camera-camera2:test
Change-Id: I2279f7bda1a9edf90af0c46b2db749d59821e0cc
M camera/camera-camera2/src/androidTest/java/androidx/camera/camera2/CameraControlDeviceTest.java
M camera/camera-camera2/src/androidTest/java/androidx/camera/camera2/internal/Camera2CameraControlTest.java
M camera/camera-camera2/src/androidTest/java/androidx/camera/camera2/internal/ZoomControlDeviceTest.java
M camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/Camera2CameraControl.java
M camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/Camera2CameraImpl.java
M camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/FocusMeteringControl.java
M camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/TorchControl.java
M camera/camera-camera2/src/main/java/androidx/camera/camera2/internal/ZoomControl.java
M camera/camera-camera2/src/test/java/androidx/camera/camera2/internal/TorchControlTest.java
M camera/camera-camera2/src/test/java/androidx/camera/camera2/internal/ZoomControlTest.java
th...@gmail.com <th...@gmail.com> #8
For Huawei Mate 20 Lite it's HWSNE
. Unfortunately, I'm unable to provide you info for Honor 9X.
ch...@google.com <ch...@google.com> #9
Hi,
We're clarifying this issue with the camera framework team and need your further help to provide some more information. So that we can know all the details and might be able to improve the CTS tests to cover this in the future.
- What is the problematic image size when capturing the image in target aspect ratio 4:3 setting?
- Could you help to provide the JPEG supported sizes list of the Huawei Mate 20 Lite device? I'm not sure whether it is the same as you have been provided in
.b/161156062#comment4 - Could you provide a bugreport that is dumped right after operating to capture the problematic 4:3 image?
Thanks in advance.
th...@gmail.com <th...@gmail.com> #10
Hi,
- I didn't specify target resolution, but I've check with max available resolution (3840x5120) and custom one (1200x1600), both times the issue has occurred.
- Yes, it is the same list I've provided.
- In attachments.
Please let me know when you will have any plans to cover this issue.
ch...@google.com <ch...@google.com> #11
Thanks. This issue will be targeted to be fixed in Dec release.
th...@gmail.com <th...@gmail.com> #12
Thank you. I'm looking forward to it.
ch...@google.com <ch...@google.com> #13
Hi,
Could you help to install and check whether the issue can be resolved by the attached apk?
What I modified:
- Force CameraFragment#aspectRatio() to return AspectRatio.RATIO_4_3.
- Do not use JPEG_ORIENTATION capture request parameter and rotate the output image according the target rotation setting. This is only applied to the Huawei Mate 20 Lite and Honor 9X devices by Build.BRAND and Build.MODEL.
Please take pictures in 0, 90 and 180 and also help to dump and extract logs with tag "b171492111-debug". So that I can analyze whether the solution work as expectation.
Thanks.
wu...@google.com <wu...@google.com> #14
Friendly ping :)
ma...@shelfwise.ai <ma...@shelfwise.ai> #15
Sorry for the delay, I was trying to borrow the Huawei device again. Unfortunately I'm unable to get this device in next few weeks. Does it stop the fix from being added to library?
Best.
ch...@google.com <ch...@google.com> #16
Hi,
It won't stop the fix. The purpose is just to verify my solution can really resolve the problem since I do not have device to verify it. I'll still prepare the fix in the next release.
ap...@google.com <ap...@google.com> #17
Branch: androidx-master-dev
commit 5995a6a42d1bddfa42276d2c7c730605624fa84b
Author: charcoalchen <charcoalchen@google.com>
Date: Thu Oct 29 15:44:03 2020
Fixed orientation issue when capturing 4:3 images on some devices.
1. Add ImageCapture capture option quirk to not use CaptureRequest.JPEG_ORIENTATION on some devices. (On some devices, the orientation value in the embedded exif of the captured images may be 0 but the image buffer data actually is not rotated to upright orientation by HAL.)
2. For those devices, we can't use CaptureRequest.JPEG_ORIENTATION parameter and need to set the orientation value according to the target rotation setting.
Relnote:"Fixed orientation issue when capturing 4:3 images on some devices."
Bug: 171492111
Test: ./gradlew bOS
Change-Id: I0e3fb7705daeb5b8caa98e80215a545f8a3ca484
M camera/camera-core/src/main/java/androidx/camera/core/ImageCapture.java
M camera/camera-core/src/main/java/androidx/camera/core/ImageSaver.java
M camera/camera-core/src/main/java/androidx/camera/core/internal/compat/quirk/DeviceQuirksLoader.java
A camera/camera-core/src/main/java/androidx/camera/core/internal/compat/quirk/ImageCaptureRotationOptionQuirk.java
A camera/camera-core/src/main/java/androidx/camera/core/internal/compat/workaround/ExifRotationAvailability.java
A camera/camera-core/src/main/java/androidx/camera/core/internal/compat/workaround/package-info.java
A camera/camera-core/src/test/java/androidx/camera/core/internal/compat/quirk/ImageCaptureRotationOptionQuirkTest.java
A camera/camera-core/src/test/java/androidx/camera/core/internal/compat/workaround/ExifRotationAvailabilityTest.java
ch...@google.com <ch...@google.com> #18
th...@gmail.com <th...@gmail.com> #19
Hi,
Great news, it works on real users' devices. Thank you for resolving this.
Description
CAMERAX VERSION: 1.0.0-beta10
DEVICE NAME: Huawei Mate 20 Lite
DESCRIPTION:
Originally I've opened issue here .
Some of the users have reported that their photos are cropped and rotated. I've noticed that all of them have the same devices, i.a. Huawei Mate 20 Lite (SNE-LX1), Honor 9X (STK-LX1).
I couldn't reproduce the issue on my devices, that's why the previous issue has been closed, but I have finally managed to borrow Huawei Mate 20 Lite and test it.
The reproduction steps are very easy, just download the official CameraXBasic Sample , force the app to always use AspectRatio.RATIO_4_3 and run on a affected device (or maybe this is not an easy step). The result is that the photos are cropped and rotated (see the attachment).