Closed janoonaj closed 1 year ago
Same problem here: https://github.com/opentok/opentok-android-sdk-samples/issues/460
I opened a ticket internally with Vonage through my company login.
@janoonaj could you please try with: https://github.com/opentok/opentok-android-sdk-samples/pull/462
@vona-ben @v-kpheng Hello, it is more stable .
For us, in production, your PR is a good enough, but I would like to share with you the crash we are seeing.
There is a race condition. If you take your time it works perfectly. If you make some quick changes it crashes
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.tokbox.sample.basicvideocapturercamera2, PID: 25044
java.lang.IllegalStateException: Session has been closed; further changes are illegal.
at android.hardware.camera2.impl.CameraCaptureSessionImpl.checkNotClosed(CameraCaptureSessionImpl.java:902)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.stopRepeating(CameraCaptureSessionImpl.java:418)
at com.tokbox.sample.basicvideocapturercamera2.MirrorVideoCapturer.stopCapture(MirrorVideoCapturer.java:447)
at com.opentok.android.PublisherKit.d(Unknown Source:4)
at com.opentok.android.PublisherKit.$r8$lambda$6BMkMXi2EstSU_HgeV7ZQb4y6yA(Unknown Source:0)
at com.opentok.android.PublisherKit$$ExternalSyntheticLambda0.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7884)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Disconnected from the target VM, address: 'localhost:54156', transport: 'socket'
Steps to reproduce
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(!OpenTokConfig.isValid()) {
finishWithMessage("Invalid OpenTokConfig. " + OpenTokConfig.getDescription());
return;
}
publisherViewContainer = findViewById(R.id.publisherview);
subscriberViewContainer = findViewById(R.id.subscriberview);
requestPermissions();
Button clickButton = (Button) findViewById(R.id.button);
clickButton.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View v) {
if(publisher.getPublishVideo()) {
publisher.setPublishVideo(false);
} else
publisher.setPublishVideo(true);
}
});
}
Thank you for sharing @janoonaj. I will follow up internally regarding this issue.
@vona-ben, any updates?
Hello I'm not sure if this is similar case or not.
But using previous version of SDK, if client camera and microphone were turned off, we were unpublishing the Publisher
from the session and later we were calling publisher.onStop()
(base on this docs https://api.support.vonage.com/hc/en-us/articles/6646183450396-Camara-Still-in-Use-after-Session-Disconnect-on-Android) to release the camera (and to hide the Android indicator that camera/mic is in use)
But now in the newest version (2.24.2-2.25.2) after releasing the publisher and calling publisher.onStop()
the app is crashing with the log:
java.lang.IllegalStateException: Session has been closed; further changes are illegal.
at android.hardware.camera2.impl.CameraCaptureSessionImpl.checkNotClosed(CameraCaptureSessionImpl.java:902)
at android.hardware.camera2.impl.CameraCaptureSessionImpl.stopRepeating(CameraCaptureSessionImpl.java:418)
at com.opentok.android.Camera2VideoCapturer.stopCapture(Unknown Source:30)
at com.opentok.android.PublisherKit.d(Unknown Source:4)
at com.opentok.android.PublisherKit.$r8$lambda$6BMkMXi2EstSU_HgeV7ZQb4y6yA(Unknown Source:0)
at com.opentok.android.PublisherKit$$ExternalSyntheticLambda20.run(Unknown Source:2)
If i comment out the line about publisher.onStop
there is no crash, and indication disappears after a short while.
Does it mean that onStop
is called automatically in the newer SDK version and we should not call it on our own?
What should we do?
Hello @michal-luszczuk In our case, the problem is that custom publisher "MirrorVideoCapturer" from their example was too old.
We copy-paste and then, adapt them to our requeriments. But it was not updated in this examples.
Can you try to apply the changes or can you try this example project?
More information here https://github.com/opentok/opentok-android-sdk-samples/pull/462
Hi @michal-luszczuk
Sorry for the delay, indeed onStop is called automatically in the newer SDK version and it's not needed anymore to call it.
Hi @janoonaj
Thank you for reporting that issue, I managed to reproduce the issue, and I have opened a ticket internally. in the meantime It would be better to implement a safeguard to avoid switching the video on/off quickly.
FYI, this is being tracked internally via https://jira.vonage.com/browse/VIDCS-1208
@janoonaj our solution for our internal ticket https://jira.vonage.com/browse/VIDCS-1208 was already validated and closed by our QA department.
In a soon to be released v2.26.1 version (between this and the following week), we correctly handle the camera states for all invoked actions.
I will close the ticket. If for some reason you find these changes do not solve your problem, please re-open it.
Describe the bug If you publish video, unpublish video and publish again, the app crashes. It works fine on 2.24.1
To Reproduce
Update examples to 2.25.0
Open example Camera2 basic video capturer
Add a button
Add this code in MainActivity
Press the button two times.
Crash.
FATAL EXCEPTION: main Process: com.tokbox.sample.basicvideocapturercamera2, PID: 5975 com.tokbox.sample.basicvideocapturercamera2.MirrorVideoCapturer$Camera2Exception: Start Capture called before init successfully completed at com.tokbox.sample.basicvideocapturercamera2.MirrorVideoCapturer.startCapture(MirrorVideoCapturer.java:401)
Device (please compete the following information):
Additional context After a publishvideo = false the camera should be released but it is not. It is not completely closed so when the user wants to open it again, the camera is on "CLOSING" state and it crashes.
In previous SDK versions the camera was not released and reopened again, it was stable.