twilio / twilio-video-app-android

A collaboration application built with the Twilio Video Android SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help wanted: Can't create camera capturers.

VanKhulup opened this issue · comments

Greetings! I've recently got quite a few crashes from the production version of the app because the app could not create camera capturers. I'm using CameraCapturerCompat class from Twilio Video App to select appropriate CameraCapturer implementation. But it seems like few devices can't start image capturing. The range of affected OS versions is 7.0 - 10, and the affected devices are different.
image
Unfortunately, I don't have access to any of these devices, and my own test devices don't have this issue. I've managed to get this crash reproduced by removing the check for PRIVATE image format within isCameraSupported method within CameraCapturerCompat. So my guess is that few devices that might not support this image format.

So my question is this - what is the reasoning, from SDK's point of view, to have this check?

Hi @VanKhulup! Thank you for reaching out. Is there a stack trace from the devices that reported the crash? Sharing this will help us further troubleshoot this issue. Thanks!

Also, what version of the SDK are you using?

I'm using SDK version 6.0.0. I think the stack trace won't tell much - it's just plain viewModel initialization flow.

 java.lang.IllegalArgumentException: could not create neither Camera2 nor Camera1 capturers
at private.TwilioPublishingViewModel.<init>(TwilioPublishingViewModel.kt:36)
at private.video.core.generic.THViewModelProvider.create(THViewModelProvider.kt:35)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:187)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)

The crash itself is cause when the following method fails to create capturer, and so returns null:

fun newInstance(context: Context): CameraCapturerCompat? {
            return if (Camera2Capturer.isSupported(context)) {
                Camera2Enumerator(context).getFrontAndBackCameraIds(context)?.let { cameraIds ->
                    val cameraCapturer = Camera2Capturer(context, cameraIds.first
                            ?: cameraIds.second ?: "")
                    CameraCapturerCompat(cameraIds.first, cameraIds.second, camera2Capturer = cameraCapturer)
                }
            } else {
                Camera1Enumerator().getFrontAndBackCameraIds(context)?.let { cameraIds ->
                    val cameraCapturer = CameraCapturer(context, cameraIds.first ?: cameraIds.second
                    ?: "")
                    CameraCapturerCompat(cameraIds.first, cameraIds.second, cameraCapturer = cameraCapturer)
                }
            }
        }

This devices on SDK version 5.12.0 was crashing with following stack trace:

java.lang.IllegalStateException: Camera2Capturer is not supported on this device
        at com.twilio.video.Preconditions.checkState(Preconditions.java:447)
        at com.twilio.video.Camera2Capturer.<init>(Camera2Capturer.java:233)
        at com.twilio.video.Camera2Capturer.<init>(Camera2Capturer.java:217)
        at private.session.participant.twilio.TwilioPublishingViewModel.initCameraCapturer(TwilioPublishingViewModel.kt:201)

This issue actually forced me to try and go with CameraCapturerCompat implementation

Thanks for the additional information @VanKhulup. The function could be returning null if the cameras on the device do not meet the conditions defined in the isCameraIdSupported function. Do you have any additional details on which exact devices this crash is occurring on? I can try running instrumentation tests against this class in Firebase Test Lab against an array of devices to see if I can reproduce it in the meantime.

image
image
image

these are top affected devices/manufacturers/OS versions

Thank you for sharing this info @VanKhulup. I'll troubleshoot further with FTL to see if I can reproduce this issue.

Hi @VanKhulup. I encountered the same bug you reported here after testing the CameraCapturerCompat class against some of the same devices you listed above. Take a look at #174 as it resolves this issue. Please let me know if you encounter anymore issues. Thanks!

@Alton09 Thanks! We'll release hotfix ASAP and I'll let you know if this issue will still be present after that. Could you elaborate a bit on how this commit fixes the issue? The affected devices will fall back to legacy CameraCapturer, which would not require ImageFormat.PRIVATE to work? Or this format was not the reason for crashes?

Hi @VanKhulup. So before this pull request, devices that use the legacy CameraCapturer instead of the Camera2Capturer were invoking the getCameraCharacteristics(cameraId) method within isCameraIdSupported which is only supported in the android camera2 api. I added a check that only camera2 compatible devices invoke it. Hope that helps!