Fix RuntimeException during call initialization.

This commit is contained in:
Alex Hart
2021-08-10 17:08:55 -03:00
committed by GitHub
parent 3baf10f0e9
commit 824a8ac5f2
14 changed files with 121 additions and 55 deletions

View File

@@ -22,7 +22,7 @@ public class BroadcastVideoSink implements VideoSink {
public static final int DEVICE_ROTATION_IGNORE = -1;
private final EglBase eglBase;
private final EglBaseWrapper eglBase;
private final WeakHashMap<VideoSink, Boolean> sinks;
private final WeakHashMap<Object, Point> requestingSizes;
private boolean dirtySizes;
@@ -32,7 +32,7 @@ public class BroadcastVideoSink implements VideoSink {
private boolean rotateWithDevice;
public BroadcastVideoSink() {
this(null, false, true, 0);
this(new EglBaseWrapper(null), false, true, 0);
}
/**
@@ -41,7 +41,7 @@ public class BroadcastVideoSink implements VideoSink {
* @param rotateWithDevice Rotate video frame to match device orientation
* @param deviceOrientationDegrees Device orientation in degrees
*/
public BroadcastVideoSink(@Nullable EglBase eglBase, boolean forceRotate, boolean rotateWithDevice, int deviceOrientationDegrees) {
public BroadcastVideoSink(@NonNull EglBaseWrapper eglBase, boolean forceRotate, boolean rotateWithDevice, int deviceOrientationDegrees) {
this.eglBase = eglBase;
this.sinks = new WeakHashMap<>();
this.requestingSizes = new WeakHashMap<>();
@@ -52,7 +52,7 @@ public class BroadcastVideoSink implements VideoSink {
this.rotateWithDevice = rotateWithDevice;
}
public @Nullable EglBase getEglBase() {
public @NonNull EglBaseWrapper getLockableEglBase() {
return eglBase;
}

View File

@@ -144,9 +144,9 @@ public class CallParticipantView extends ConstraintLayout {
renderer.setVisibility(hasContentToRender ? View.VISIBLE : View.GONE);
if (participant.isVideoEnabled()) {
if (participant.getVideoSink().getEglBase() != null) {
renderer.init(participant.getVideoSink().getEglBase());
}
participant.getVideoSink().getLockableEglBase().performWithValidEglBase(eglBase -> {
renderer.init(eglBase);
});
renderer.attachBroadcastVideoSink(participant.getVideoSink());
} else {
renderer.attachBroadcastVideoSink(null);

View File

@@ -0,0 +1,70 @@
package org.thoughtcrime.securesms.components.webrtc
import android.opengl.EGL14
import org.signal.core.util.logging.Log
import org.webrtc.EglBase
import org.webrtc.EglBase10
import org.webrtc.EglBase14
import java.util.concurrent.locks.Lock
import java.util.concurrent.locks.ReentrantLock
import java.util.function.Consumer
import javax.microedition.khronos.egl.EGL10
import kotlin.concurrent.withLock
private val TAG = Log.tag(EglBaseWrapper::class.java)
/**
* Wrapper which allows caller to perform synchronized actions on an EglBase object.
*/
class EglBaseWrapper(val eglBase: EglBase?) {
private val lock: Lock = ReentrantLock()
fun require(): EglBase = requireNotNull(eglBase)
@Volatile
private var isReleased: Boolean = false
fun performWithValidEglBase(consumer: Consumer<EglBase>) {
if (isReleased) {
Log.d(TAG, "Tried to use a released EglBase", Exception())
return
}
if (eglBase == null) {
return
}
lock.withLock {
if (isReleased) {
Log.d(TAG, "Tried to use a released EglBase", Exception())
return
}
val hasSharedContext = when (val context: EglBase.Context = eglBase.eglBaseContext) {
is EglBase14.Context -> context.rawContext != EGL14.EGL_NO_CONTEXT
is EglBase10.Context -> context.rawContext != EGL10.EGL_NO_CONTEXT
else -> throw IllegalStateException("Unknown context")
}
if (hasSharedContext) {
consumer.accept(eglBase)
}
}
}
fun releaseEglBase() {
if (isReleased || eglBase == null) {
return
}
lock.withLock {
if (isReleased) {
return
}
isReleased = true
eglBase.release()
}
}
}

View File

@@ -47,7 +47,6 @@ import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.RecipientId;
import org.thoughtcrime.securesms.ringrtc.CameraState;
import org.thoughtcrime.securesms.util.BlurTransformation;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.SetUtil;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.views.Stub;
@@ -377,9 +376,10 @@ public class WebRtcCallView extends ConstraintLayout {
smallLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
largeLocalRender.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
if (localCallParticipant.getVideoSink().getEglBase() != null) {
largeLocalRender.init(localCallParticipant.getVideoSink().getEglBase());
}
localCallParticipant.getVideoSink().getLockableEglBase().performWithValidEglBase(eglBase -> {
largeLocalRender.init(eglBase);
});
videoToggle.setChecked(localCallParticipant.isVideoEnabled(), false);
smallLocalRender.setRenderInPip(true);