Hi all!
using version 1.2.2 of CameraX `CAPTURE_MODE_ZERO_SHUTTER_LAG` sometimes fail to work as expected. When it does, this statement is printed in the logcat:
```
(ZslControlImpl) dequeueImageFromBuffer no such element
```
This happens only with this particular camera implementation where I need to set the focus distance of the camera to the device minimum focus distance.
In order to get this value I need to bind my use cases, get the value, then call `bindToLifecycle()` again.
So I have a function in a base class for binding use cases that looks something like this:
```
fun bindUseCasesToLifeCycle(
view: PreviewView,
cameraSelector: CameraSelector,
preview: Preview?,
imageCapture: ImageCapture?,
imageAnalysis: ImageAnalysis?
) {
cameraProvider?.unbindAll()
camera = cameraProvider?.bindToLifecycle(
viewLifecycleOwner,
cameraSelector,
preview,
imageCapture,
imageAnalysis
)
preview?.setSurfaceProvider(view.surfaceProvider)
}
```
then for the implementation where the minimum focus distance is needed I use something like this:
```
override fun bindUseCasesToLifeCycle(
view: PreviewView,
cameraSelector: CameraSelector,
preview: Preview?,
imageCapture: ImageCapture?,
imageAnalysis: ImageAnalysis?
) {
val builder = Preview.Builder()
super.bindUseCasesToLifeCycle(
view,
cameraSelector,
this.preview,
imageCapture,
imageAnalysis
)
camera?.minimumFocusDistance()?.let { minFocus ->
setFocusDistance(builder, minFocus)
}
this.preview = builder.build()
super.bindUseCasesToLifeCycle(
view,
cameraSelector,
this.preview,
imageCapture,
imageAnalysis
)
}
```
`minimumFocusDistance()` is an extension function on `Camera`:
```
fun Camera?.minimumFocusDistance(): Float? {
val characteristics = this?.cameraInfo?.let { info ->
Camera2CameraInfo.extractCameraCharacteristics(info)
}
return characteristics?.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE)
}
```
and `setFocusDistance()` is this:
```
fun setFocusDistance(builder: ExtendableBuilder<*>, distance: Float) {
val extender = Camera2Interop.Extender(builder)
extender.setCaptureRequestOption(
CaptureRequest.CONTROL_AF_MODE,
CameraMetadata.CONTROL_AF_MODE_OFF
)
extender.setCaptureRequestOption(CaptureRequest.LENS_FOCUS_DISTANCE, distance)
}
```
FWIW, in another, simpler implementation, where use cases are only bound once, `CAPTURE_MODE_ZERO_SHUTTER_LAG` works flawlessly.
My questions:
- does the minimum focus distance implementation demoed above look correct?
- if it does, is there anything wrong with my implementation that would cause ZSL to fail?
- if not, any suggestion on debugging this further?
Thanks in advance for the help!