Make releaseEglSurface in EglRenderer asynchronous.
BUG=webrtc:6470
Review-Url: https://codereview.webrtc.org/2483143002
Cr-Commit-Position: refs/heads/master@{#14993}
diff --git a/webrtc/api/android/java/src/org/webrtc/EglRenderer.java b/webrtc/api/android/java/src/org/webrtc/EglRenderer.java
index 9fb035b..65961bb 100644
--- a/webrtc/api/android/java/src/org/webrtc/EglRenderer.java
+++ b/webrtc/api/android/java/src/org/webrtc/EglRenderer.java
@@ -435,8 +435,7 @@
/**
* Release EGL surface. This function will block until the EGL surface is released.
*/
- public void releaseEglSurface() {
- final CountDownLatch completionLatch = new CountDownLatch(1);
+ public void releaseEglSurface(final Runnable completionCallback) {
// Ensure that the render thread is no longer touching the Surface before returning from this
// function.
eglSurfaceCreationRunnable.setSurface(null /* surface */);
@@ -450,14 +449,13 @@
eglBase.detachCurrent();
eglBase.releaseSurface();
}
- completionLatch.countDown();
+ completionCallback.run();
}
});
- } else {
- completionLatch.countDown();
+ return;
}
}
- ThreadUtils.awaitUninterruptibly(completionLatch);
+ completionCallback.run();
}
/**
diff --git a/webrtc/api/android/java/src/org/webrtc/SurfaceViewRenderer.java b/webrtc/api/android/java/src/org/webrtc/SurfaceViewRenderer.java
index 428198d..9fee0d0 100644
--- a/webrtc/api/android/java/src/org/webrtc/SurfaceViewRenderer.java
+++ b/webrtc/api/android/java/src/org/webrtc/SurfaceViewRenderer.java
@@ -16,6 +16,7 @@
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
+import java.util.concurrent.CountDownLatch;
/**
* Implements org.webrtc.VideoRenderer.Callbacks by displaying the video stream on a SurfaceView.
@@ -159,7 +160,14 @@
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
ThreadUtils.checkIsOnMainThread();
- eglRenderer.releaseEglSurface();
+ final CountDownLatch completionLatch = new CountDownLatch(1);
+ eglRenderer.releaseEglSurface(new Runnable() {
+ @Override
+ public void run() {
+ completionLatch.countDown();
+ }
+ });
+ ThreadUtils.awaitUninterruptibly(completionLatch);
}
@Override