Status Update
Comments
ho...@google.com <ho...@google.com>
ho...@google.com <ho...@google.com> #2
sc...@google.com <sc...@google.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
da...@gmail.com <da...@gmail.com> #4
ho...@google.com <ho...@google.com> #5
OK, let me close this issue, you are welcome to file new bug in any time. Thanks.
da...@gmail.com <da...@gmail.com> #6
sc...@google.com <sc...@google.com> #7
Yes we will fix it. It is just that we think that workaround fixes your problem so we'd like to close this one and track the issue internally.
but since you are still interested at the update of the fix, I reopen the bug and will keep you posted on this bug.
Scott
wu...@google.com <wu...@google.com>
ap...@google.com <ap...@google.com> #8
Branch: androidx-master-dev
commit f988306fdba1791fc0d7cf8414e71316f1c38b5b
Author: weginlee <weginlee@google.com>
Date: Tue Apr 07 18:29:23 2020
Fix PreviewView black screen on ViewPager2 behavior.
In ViewPager2 usage, there is no update on PreviewView when the user
swipes out the preview fragment and swipes back in. The CL only fixes the
issue on TextureViewImplementation. No solution works out yet for
SurfaceViewImplementation.
Check out the issue detail and solution design: go/camerax-previewview-viewpager2
Relnote: "Fix PreviewView black screen issues when swiped out Preview
fragment and then swiped back in ViewPager2. Also fixed the issue when
removeView(previewview) and then addView(previewView)."
Bug: 149877652, 147354615
Test: Test: ./gradlew bOS &&
./gradlew camera:camera-*:connectedCheck &&
verify the solution on API 23 ~ 30.
Change-Id: Iab5555fa4bbcca4020ba0dc55135c15009d24908
M camera/camera-view/src/androidTest/java/androidx/camera/view/PreviewViewTest.java
M camera/camera-view/src/androidTest/java/androidx/camera/view/TextureViewImplementationTest.java
M camera/camera-view/src/main/java/androidx/camera/view/PreviewView.java
M camera/camera-view/src/main/java/androidx/camera/view/PreviewViewImplementation.java
M camera/camera-view/src/main/java/androidx/camera/view/SurfaceViewImplementation.java
M camera/camera-view/src/main/java/androidx/camera/view/TextureViewImplementation.java
we...@google.com <we...@google.com> #9
The issue is fixed for PreviewView TextureView mode. There is the problem on SurfaceView mode and suggest to use TextureView mode for ViewPager2 (PreviewView default is TextureView mode).
The fix will be included on CameraX May release.
ap...@google.com <ap...@google.com> #10
Branch: androidx-master-dev
commit cd3acc79df278aac68aabac7cb2009f10a955b9f
Author: weginlee <weginlee@google.com>
Date: Wed Apr 08 17:28:43 2020
Add UIWidgetsTestApp to check CameraX functions.
The UIWidgetsTestApp is used to validate CameraX functions in generic UI Widgets behavior.
In the 1st version, it is tested for ViewPager2. There are two fragments in the ViewPager2. One uses
textureview implementation of PreviewView, and another is blank textview.
Bug: 149877652, 147354615
Test: ./gradlew bOS &&
camera:integration-tests:camera-testapp-viewpager2:lintDebug &&
Manual test
Change-Id: I82108866046af14ad9fc7bca77b53686926ff8ff
A camera/integration-tests/uiwidgetstestapp/build.gradle
A camera/integration-tests/uiwidgetstestapp/src/main/AndroidManifest.xml
A camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/CameraFragment.kt
A camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/TextViewFragment.kt
A camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/ViewPager2Activity.kt
A camera/integration-tests/uiwidgetstestapp/src/main/res/layout/activity_viewpager2.xml
A camera/integration-tests/uiwidgetstestapp/src/main/res/layout/fragment_textureview.xml
A camera/integration-tests/uiwidgetstestapp/src/main/res/layout/fragment_textview.xml
A camera/integration-tests/uiwidgetstestapp/src/main/res/values/strings.xml
A camera/integration-tests/uiwidgetstestapp/src/main/res/values/styles.xml
M settings.gradle
ap...@google.com <ap...@google.com> #11
Branch: androidx-master-dev
commit b0057ef570535e6c19a0045897d48b08ebd5e3b6
Author: Wegin Lee <weginlee@google.com>
Date: Thu May 28 12:52:02 2020
Add integration tests for ViewPager2Activity in UIWidgetsTestApp
1. For the activity stop/resume, check PreviewView.StreamSate.Streaming to verify
PreviewView upate
2. Besides, for
to make sure textutre view use the same surface texture when detach windown and
then attach window.
Bug: 149877652, 147354615
Test: Pass ViewPager2ActivityTest on API 23 ~ 29.
./gradlew camera:integration-tests:camera-testapp-uiwidgets:connectedCheck
Change-Id: Ib8e5a4414c90f38a747054aeb34c99c05ba384b7
A camera/integration-tests/uiwidgetstestapp/src/androidTest/java/androidx/camera/integration/uiwidgets/ViewPager2ActivityTest.kt
A camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/BaseActivity.kt
M camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/CameraFragment.kt
M camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/ViewPager2Activity.kt
M camera/integration-tests/uiwidgetstestapp/src/main/res/layout/fragment_textview.xml
ch...@gmail.com <ch...@gmail.com> #12
This issue is still occuring on 1.1.0-rc01
sc...@google.com <sc...@google.com> #13
Hi ,
Do you use PreviewView ? Can you try setting
If issue still happens, it would be helpful go give more information or code snippet showing how you configure CameraX with ViewPager2.
Scott
sc...@google.com <sc...@google.com> #14
The fix was only for TextureView (COMPATIBLE mode).
Reopen it to track the SurfaceView issue.
ch...@gmail.com <ch...@gmail.com> #15
In COMPATIBLE mode when the fragment is off screen the camera is still bound and active and running through the use cases. But when the fragment is back into view it works perfect. I'm not sure if this matters but I'm using ViewPager2 inside a Fragment and not inside an Activity
Below is the camera binding
@SuppressLint("UnsafeOptInUsageError", "RestrictedApi")
private fun startCamera() {
// Create an instance of the ProcessCameraProvider,
// which will be used to bind the use cases to a lifecycle owner.
val cameraProviderFuture = ProcessCameraProvider.getInstance(requireContext())
// Add a listener to the cameraProviderFuture.
// The first argument is a Runnable, which will be where the magic actually happens.
// The second argument (way down below) is an Executor that runs on the main thread.
cameraProviderFuture.addListener({
// Add a ProcessCameraProvider, which binds the lifecycle of your camera to
// the LifecycleOwner within the application's life.
cameraProvider = cameraProviderFuture.get()
// Initialize the Preview object, get a surface provider from your PreviewView,
// and set it on the preview instance.
val preview = Preview.Builder()
.build().also {
it.setSurfaceProvider(
binding.previewView.surfaceProvider
)
}
// Setup the ImageAnalyzer for the ImageAnalysis use case
val builder = ImageAnalysis.Builder()
val ext: Camera2Interop.Extender<*> = Camera2Interop.Extender(builder)
ext.setCaptureRequestOption(
CaptureRequest.CONTROL_AE_MODE,
CaptureRequest.CONTROL_AE_MODE_ON
)
ext.setCaptureRequestOption(
CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO
)
ext.setCaptureRequestOption(
CaptureRequest.CONTROL_AWB_MODE,
CaptureRequest.CONTROL_AWB_MODE_AUTO
)
ext.setCaptureRequestOption(
CaptureRequest.CONTROL_AE_ANTIBANDING_MODE,
CaptureRequest.CONTROL_AE_ANTIBANDING_MODE_AUTO
)
ext.setCaptureRequestOption(
CaptureRequest.COLOR_CORRECTION_MODE,
CaptureRequest.COLOR_CORRECTION_MODE_FAST
)
ext.setCaptureRequestOption(
CaptureRequest.COLOR_CORRECTION_ABERRATION_MODE,
CaptureRequest.COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY
)
ext.setCaptureRequestOption(
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE,
CaptureRequest.CONTROL_VIDEO_STABILIZATION_MODE_ON
)
ext.setCaptureRequestOption(
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE,
CaptureRequest.LENS_OPTICAL_STABILIZATION_MODE_ON
)
ext.setCaptureRequestOption(
CaptureRequest.CONTROL_SCENE_MODE,
CaptureRequest.CONTROL_SCENE_MODE_BARCODE
)
val imageAnalysis = builder
.setTargetResolution(Size(1536, 2048))
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.build()
.also {
it.setAnalyzer(cameraExecutor, AcfLabelAnalyzer { barcodes ->
if (processing.compareAndSet(false, true)) {
handleScan2(barcodes)
}
})
}
// Select back camera
val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
try {
// Unbind any bound use cases before rebinding
cameraProvider?.unbindAll()
// Bind use cases to lifecycleOwner
val useCaseGroup = UseCaseGroup.Builder()
.addUseCase(preview)
.addUseCase(imageAnalysis)
.build()
camera = cameraProvider?.bindToLifecycle(requireParentFragment().viewLifecycleOwner, cameraSelector, useCaseGroup)
val cameraControl = camera?.cameraControl
cameraControl?.setLinearZoom(0.4f)
cameraControl?.enableTorch(true)
} catch (e: Exception) {
Log.e("PreviewUseCase", "Binding failed! :(", e)
}
}, ContextCompat.getMainExecutor(requireContext()))
}
Below is the ViewPager2 setup in the onViewCreated()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding = FragmentCaptureTabsBinding.bind(view)
adapter = ViewPagerAdapter(childFragmentManager, lifecycle)
adapter.addFrag(CaptureFragment(), "Capture")
adapter.addFrag(LostOrUnauthorizedFragment(), "Tab 2")
binding.viewpager.adapter = adapter
if (adapter.itemCount < 2) {
binding.tablayout.visibility = View.GONE
}
TabLayoutMediator(binding.tablayout, binding.viewpager) { tab, position ->
tab.text = adapter.getPageTitle(position)
}.attach()
}
sc...@google.com <sc...@google.com> #16
To clarify, are you saying that the issue is fixed after setting COMPATIBLE mode Or are there still issues?
ch...@gmail.com <ch...@gmail.com> #17
In COMPATIBLE mode and the fragment is off screen, onPause() called I would expect the camera to be paused unbinded.
ch...@gmail.com <ch...@gmail.com> #18
In unconfigured mode same thing happens with camera being paused but when onResume() is called the PreviewView is black.
sc...@google.com <sc...@google.com> #19
OK. So using Compatible mode does fix the black preview issue.
Regarding the behavior that camera is not stopped when onPaused. This is by design. CameraX only closes the camera when onStop happens. This make sense in the scenario of multi-window, For example, if apps is paused due to focus changes to another window, then camera can still be working and showing preview.
For the scenario of viewpager, it has the benefits of showing preview even when swiping the page.
If you really need to control the timing of camera open/close, you can
Scott
mi...@google.com <mi...@google.com>
mi...@google.com <mi...@google.com> #20
Branch: androidx-main
commit 0b72345967d9c59ac22057dbbabd303d7f9dffd4
Author: mingdatsai <mingdatsai@google.com>
Date: Thu Aug 25 18:24:01 2022
Fix SurfaceViewImplementation black screen issue on ViewPager2
* Add invalidate() method to notify the surface requesters that
the previously provided surface is no longer valid.
* Notify Preview to resend SurfaceRequest when SurfaceView in
SurfaceViewImplementation recreates a new surface.
* Add test for newly exposed API on SurfaceRequest.
* Add test for that SurfaceViewImplementation uses with ViewPager2.
For details, please see design doc: go/camerax-surface-view-viewpager2.
Relnote: "Fix PreviewView SurfaceView implementation black screen issue
on ViewPager2. As part of the fix, PreviewView will reuse its
SurfaceView if the requested resolution is not changed."
Bug: 242023282
Test: manual test and ./gradlew camera:camera-view:testDebug
Change-Id: Ib3f27c45c8ad1f9fc837454961a27087fe2f38ff
M camera/camera-core/src/androidTest/java/androidx/camera/core/SurfaceRequestTest.kt
M camera/camera-core/src/androidTest/java/androidx/camera/core/processing/DefaultSurfaceProcessorTest.kt
M camera/camera-core/src/main/java/androidx/camera/core/Preview.java
M camera/camera-core/src/main/java/androidx/camera/core/SurfaceRequest.java
M camera/camera-core/src/main/java/androidx/camera/core/processing/SettableSurface.java
M camera/camera-core/src/main/java/androidx/camera/core/processing/SurfaceProcessorNode.java
M camera/camera-core/src/test/java/androidx/camera/core/processing/SettableSurfaceTest.kt
M camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceProcessorNodeTest.kt
M camera/camera-core/src/test/java/androidx/camera/core/processing/SurfaceProcessorWithExecutorTest.kt
M camera/camera-video/src/main/java/androidx/camera/video/VideoCapture.java
M camera/camera-view/src/androidTest/java/androidx/camera/view/PreviewViewDeviceTest.kt
M camera/camera-view/src/androidTest/java/androidx/camera/view/SurfaceViewImplementationTest.kt
M camera/camera-view/src/androidTest/java/androidx/camera/view/TextureViewImplementationTest.kt
M camera/camera-view/src/main/java/androidx/camera/view/PreviewView.java
M camera/camera-view/src/main/java/androidx/camera/view/SurfaceViewImplementation.java
M camera/camera-view/src/test/java/androidx/camera/view/PreviewViewTest.java
M camera/integration-tests/uiwidgetstestapp/src/androidTest/java/androidx/camera/integration/uiwidgets/viewpager/ViewPager2ActivityTest.kt
M camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/viewpager/BaseActivity.kt
M camera/integration-tests/uiwidgetstestapp/src/main/java/androidx/camera/integration/uiwidgets/viewpager/CameraFragment.kt
Description
def camerax_version = '1.0.0-alpha08'
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha05"
implementation "androidx.camera:camera-lifecycle:1.0.0-alpha02"
ANDROID OS BUILD NUMBER: android 10 QP1A.191005.007.A3
DEVICE NAME: Google Pixel
DESCRIPTION:
Preview disappears after Fragment onPause is called, but when onStop is not called
This is the case when it is in a viewpage2
STEPS TO REPRODUCE:
1. Build and launch app attached
2. Swipe view pager right then left
3. Preview is gone
OBSERVED RESULTS:
No preview after onPause
EXPECTED RESULTS:
Preview should remain
REPRODUCIBILITY: 5 of out 5
CODE FRAGMENTS:
See attachment