Make releaseEglSurface in EglRenderer asynchronous.

BUG=webrtc:6470

Review-Url: https://codereview.webrtc.org/2483143002
Cr-Commit-Position: refs/heads/master@{#14993}
This commit is contained in:
sakal
2016-11-09 01:47:12 -08:00
committed by Commit bot
parent cbe7435288
commit 28ec6bdce8
2 changed files with 13 additions and 7 deletions

View File

@ -435,8 +435,7 @@ public class EglRenderer implements VideoRenderer.Callbacks {
/**
* 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 @@ public class EglRenderer implements VideoRenderer.Callbacks {
eglBase.detachCurrent();
eglBase.releaseSurface();
}
completionLatch.countDown();
completionCallback.run();
}
});
} else {
completionLatch.countDown();
return;
}
}
ThreadUtils.awaitUninterruptibly(completionLatch);
completionCallback.run();
}
/**

View File

@ -16,6 +16,7 @@ import android.graphics.Point;
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 @@ public class SurfaceViewRenderer
@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