SurfaceViewRenderer: Remove use of quitSafely() because it's API lvl 18

I replaced quitSafely() with a CountDownLatch. The reason for not using ThreadUtils.invokeUninterruptibly() is that I want to stop accepting frames asap, and invokeUninterruptibly() would still accept frames during the waiting time.

BUG=webrtc:4742

Review URL: https://codereview.webrtc.org/1418223002

Cr-Commit-Position: refs/heads/master@{#10393}
This commit is contained in:
magjed
2015-10-23 18:14:25 -07:00
committed by Commit bot
parent c3402fc3ef
commit 238b15d543

View File

@ -40,6 +40,8 @@ import android.view.SurfaceView;
import org.webrtc.Logging; import org.webrtc.Logging;
import java.util.concurrent.CountDownLatch;
import javax.microedition.khronos.egl.EGLContext; import javax.microedition.khronos.egl.EGLContext;
/** /**
@ -190,6 +192,7 @@ public class SurfaceViewRenderer extends SurfaceView
* don't call this function, the GL resources might leak. * don't call this function, the GL resources might leak.
*/ */
public void release() { public void release() {
final CountDownLatch eglCleanupBarrier = new CountDownLatch(1);
synchronized (handlerLock) { synchronized (handlerLock) {
if (renderThreadHandler == null) { if (renderThreadHandler == null) {
Logging.d(TAG, "Already released"); Logging.d(TAG, "Already released");
@ -214,13 +217,15 @@ public class SurfaceViewRenderer extends SurfaceView
} }
eglBase.release(); eglBase.release();
eglBase = null; eglBase = null;
eglCleanupBarrier.countDown();
} }
}); });
// Don't accept any more frames or messages to the render thread. // Don't accept any more frames or messages to the render thread.
renderThreadHandler = null; renderThreadHandler = null;
} }
// Quit safely to make sure the EGL/GL cleanup posted above is executed. // Make sure the EGL/GL cleanup posted above is executed.
renderThread.quitSafely(); ThreadUtils.awaitUninterruptibly(eglCleanupBarrier);
renderThread.quit();
synchronized (frameLock) { synchronized (frameLock) {
if (pendingFrame != null) { if (pendingFrame != null) {
VideoRenderer.renderFrameDone(pendingFrame); VideoRenderer.renderFrameDone(pendingFrame);