Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Unified Diff: talk/app/webrtc/java/android/org/webrtc/SurfaceTextureHelper.java

Issue 1384923002: SurfaceTextureHelper fixes (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased and removed unused import Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « talk/app/webrtc/androidtests/src/org/webrtc/SurfaceTextureHelperTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: talk/app/webrtc/java/android/org/webrtc/SurfaceTextureHelper.java
diff --git a/talk/app/webrtc/java/android/org/webrtc/SurfaceTextureHelper.java b/talk/app/webrtc/java/android/org/webrtc/SurfaceTextureHelper.java
index a20a7391c2df36a9acb5e3cffbfb6b1f7fe2df3b..4d5a2e62f12346bd2f340e3855aa705887ebc54f 100644
--- a/talk/app/webrtc/java/android/org/webrtc/SurfaceTextureHelper.java
+++ b/talk/app/webrtc/java/android/org/webrtc/SurfaceTextureHelper.java
@@ -65,6 +65,7 @@ final class SurfaceTextureHelper {
private final HandlerThread thread;
private final Handler handler;
+ private final boolean isOwningThread;
private final EglBase eglBase;
private final SurfaceTexture surfaceTexture;
private final int oesTextureId;
@@ -78,9 +79,19 @@ final class SurfaceTextureHelper {
* Construct a new SurfaceTextureHelper sharing OpenGL resources with |sharedContext|.
*/
public SurfaceTextureHelper(EGLContext sharedContext) {
- thread = new HandlerThread(TAG);
- thread.start();
- handler = new Handler(thread.getLooper());
+ this(sharedContext, null);
+ }
+
+ public SurfaceTextureHelper(EGLContext sharedContext, HandlerThread thread) {
+ if (thread == null) {
+ this.thread = new HandlerThread(TAG);
+ this.thread.start();
+ this.isOwningThread = true;
+ } else {
+ this.thread = thread;
+ this.isOwningThread = false;
+ }
+ this.handler = new Handler(this.thread.getLooper());
eglBase = new EglBase(sharedContext, EglBase.ConfigType.PIXEL_BUFFER);
eglBase.createDummyPbufferSurface();
@@ -89,13 +100,8 @@ final class SurfaceTextureHelper {
oesTextureId = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES);
surfaceTexture = new SurfaceTexture(oesTextureId);
- // Reattach EGL context to private thread.
+ // The EGL context will be re-attached to the private thread.
eglBase.detachCurrent();
- handler.post(new Runnable() {
- @Override public void run() {
- eglBase.makeCurrent();
- }
- });
}
/**
@@ -148,6 +154,13 @@ final class SurfaceTextureHelper {
* onTextureFrameAvailable() after this function returns.
*/
public void disconnect() {
+ if (Thread.currentThread() == thread) {
+ isQuitting = true;
+ if (!isTextureInUse) {
+ release();
+ }
+ return;
+ }
final CountDownLatch barrier = new CountDownLatch(1);
handler.postAtFrontOfQueue(new Runnable() {
@Override public void run() {
@@ -171,7 +184,9 @@ final class SurfaceTextureHelper {
isTextureInUse = true;
hasPendingTexture = false;
+ eglBase.makeCurrent();
surfaceTexture.updateTexImage();
+
final float[] transformMatrix = new float[16];
surfaceTexture.getTransformMatrix(transformMatrix);
final long timestampNs = (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@@ -187,9 +202,12 @@ final class SurfaceTextureHelper {
if (isTextureInUse || !isQuitting) {
throw new IllegalStateException("Unexpected release.");
}
+ eglBase.makeCurrent();
GLES20.glDeleteTextures(1, new int[] {oesTextureId}, 0);
surfaceTexture.release();
eglBase.release();
- thread.quitSafely();
+ if (isOwningThread) {
+ thread.quitSafely();
+ }
}
}
« no previous file with comments | « talk/app/webrtc/androidtests/src/org/webrtc/SurfaceTextureHelperTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698