opentok / opentok-android-sdk-samples

Sample applications illustrating best practices using OpenTok Android SDK.
https://tokbox.com/developer/sdks/android/
MIT License
210 stars 169 forks source link

Black screen, camera not opened and video does not start with Camera2 example #451

Closed janoonaj closed 1 year ago

janoonaj commented 1 year ago

Hello,

in production we have seen that sometimes, when starting a call, the screen is black on the mobile and the publisher does not broadcast.

It happens once in ten or fifteen attempts. Tested and demonstrated with SDK 2.24.2

It is easily reproducible, just launch the camera2 example, connect it to an opentok playground session, and open and close the application ten or twenty times until it happens.

On some attempt the video will be black on the mobile screen, instead of playing the camera video.

The problem is here

https://github.com/opentok/opentok-android-sdk-samples/blob/main/Basic-Video-Capturer-Camera-2-Java/app/src/main/java/com/tokbox/sample/basicvideocapturercamera2/MirrorVideoCapturer.java#L398

the cameraOpen event triggered by Android arrives at the same millisecond that executeAfterCameraOpened is triggered.

When line 395 cameraState is executed, CameraState.SETUP . When line 399 executeAfterCameraOpened is executed it is null.

Possible solution: to change the SDK so that the post event is executed after the camera is open. This way you will not cause race conditions.

IdanBMAquant commented 1 year ago

We also in our company suffer from this bug, We will appreciate if you can fix this as soon as possible, thanks.

janoonaj commented 1 year ago

@v-kpheng Is it fixed in the new Android SDK version?

Thanks a lot

v-kpheng commented 1 year ago

@janoonaj, we added some changes to fix some race conditions in the Camera2 capturer code in Android SDK 2.25.0. Can you please test if the issue can still be reproduced?

janoonaj commented 1 year ago

@v-kpheng Hello. No, it still happens. And, actually, now it is even more unstable. Change the videopublisher to false and then to true will probably crash your app.

jintgeorge commented 1 year ago

@janoonaj Are you still reproducing this issue with Basic-Video-Capturer-Camera-2-Java app?

janoonaj commented 1 year ago

hello @jintgeorge @v-kpheng

It does NOT happen in PR #462 :)

It still happens in main branch, so it will be solved when the pr is passed.

Thanks a lot!!!!!!!!!

vona-ben commented 1 year ago

fixed in PR https://github.com/opentok/opentok-android-sdk-samples/pull/462

janoonaj commented 1 year ago

thanks a lot!