OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 * SurfaceTextureHelper constructor. The callee is not allowed to make another EGLContext current | 43 * SurfaceTextureHelper constructor. The callee is not allowed to make another EGLContext current |
44 * on the calling thread. | 44 * on the calling thread. |
45 */ | 45 */ |
46 public interface OnTextureFrameAvailableListener { | 46 public interface OnTextureFrameAvailableListener { |
47 abstract void onTextureFrameAvailable( | 47 abstract void onTextureFrameAvailable( |
48 int oesTextureId, float[] transformMatrix, long timestampNs); | 48 int oesTextureId, float[] transformMatrix, long timestampNs); |
49 } | 49 } |
50 | 50 |
51 /** | 51 /** |
52 * Construct a new SurfaceTextureHelper sharing OpenGL resources with |sharedC ontext|. A dedicated | 52 * Construct a new SurfaceTextureHelper sharing OpenGL resources with |sharedC ontext|. A dedicated |
53 * thread and handler is created for handling the SurfaceTexture. | 53 * thread and handler is created for handling the SurfaceTexture. May return n ull if EGL fails to |
54 * initialize a pixel buffer surface and make it current. | |
54 */ | 55 */ |
55 public static SurfaceTextureHelper create( | 56 public static SurfaceTextureHelper create( |
56 final String threadName, final EglBase.Context sharedContext) { | 57 final String threadName, final EglBase.Context sharedContext) { |
57 final HandlerThread thread = new HandlerThread(threadName); | 58 final HandlerThread thread = new HandlerThread(threadName); |
58 thread.start(); | 59 thread.start(); |
59 final Handler handler = new Handler(thread.getLooper()); | 60 final Handler handler = new Handler(thread.getLooper()); |
60 | 61 |
61 // The onFrameAvailable() callback will be executed on the SurfaceTexture ct or thread. See: | 62 // The onFrameAvailable() callback will be executed on the SurfaceTexture ct or thread. See: |
62 // http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.andr oid/android/5.1.1_r1/android/graphics/SurfaceTexture.java#195. | 63 // http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.andr oid/android/5.1.1_r1/android/graphics/SurfaceTexture.java#195. |
63 // Therefore, in order to control the callback thread on API lvl < 21, the S urfaceTextureHelper | 64 // Therefore, in order to control the callback thread on API lvl < 21, the S urfaceTextureHelper |
64 // is constructed on the |handler| thread. | 65 // is constructed on the |handler| thread. |
65 return ThreadUtils.invokeUninterruptibly(handler, new Callable<SurfaceTextur eHelper>() { | 66 return ThreadUtils.invokeUninterruptibly(handler, new Callable<SurfaceTextur eHelper>() { |
66 @Override | 67 @Override |
67 public SurfaceTextureHelper call() { | 68 public SurfaceTextureHelper call() { |
68 return new SurfaceTextureHelper(sharedContext, handler); | 69 try { |
70 return new SurfaceTextureHelper(sharedContext, handler); | |
71 } catch (RuntimeException e) { | |
72 Logging.e(TAG, threadName + " create failure", e); | |
73 return null; | |
74 } | |
69 } | 75 } |
70 }); | 76 }); |
71 } | 77 } |
72 | 78 |
73 // State for YUV conversion, instantiated on demand. | 79 // State for YUV conversion, instantiated on demand. |
74 static private class YuvConverter { | 80 static private class YuvConverter { |
75 private final EglBase eglBase; | 81 private final EglBase eglBase; |
76 private final GlShader shader; | 82 private final GlShader shader; |
77 private boolean released = false; | 83 private boolean released = false; |
78 | 84 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
308 } | 314 } |
309 }; | 315 }; |
310 | 316 |
311 private SurfaceTextureHelper(EglBase.Context sharedContext, Handler handler) { | 317 private SurfaceTextureHelper(EglBase.Context sharedContext, Handler handler) { |
312 if (handler.getLooper().getThread() != Thread.currentThread()) { | 318 if (handler.getLooper().getThread() != Thread.currentThread()) { |
313 throw new IllegalStateException("SurfaceTextureHelper must be created on t he handler thread"); | 319 throw new IllegalStateException("SurfaceTextureHelper must be created on t he handler thread"); |
314 } | 320 } |
315 this.handler = handler; | 321 this.handler = handler; |
316 | 322 |
317 eglBase = EglBase.create(sharedContext, EglBase.CONFIG_PIXEL_BUFFER); | 323 eglBase = EglBase.create(sharedContext, EglBase.CONFIG_PIXEL_BUFFER); |
318 eglBase.createDummyPbufferSurface(); | 324 try { |
319 eglBase.makeCurrent(); | 325 // Both these statements have been observed to fail on rare occasions. |
perkj_webrtc
2016/05/09 13:28:36
Can you file an open source bug with information o
magjed_webrtc
2016/05/09 14:30:21
Done.
| |
326 eglBase.createDummyPbufferSurface(); | |
327 eglBase.makeCurrent(); | |
328 } catch (RuntimeException e) { | |
329 // Clean up before rethrowing the exception. | |
330 eglBase.release(); | |
331 handler.getLooper().quit(); | |
332 throw e; | |
333 } | |
320 | 334 |
321 oesTextureId = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES); | 335 oesTextureId = GlUtil.generateTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES); |
322 surfaceTexture = new SurfaceTexture(oesTextureId); | 336 surfaceTexture = new SurfaceTexture(oesTextureId); |
323 surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailab leListener() { | 337 surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailab leListener() { |
324 @Override | 338 @Override |
325 public void onFrameAvailable(SurfaceTexture surfaceTexture) { | 339 public void onFrameAvailable(SurfaceTexture surfaceTexture) { |
326 hasPendingTexture = true; | 340 hasPendingTexture = true; |
327 tryDeliverTextureFrame(); | 341 tryDeliverTextureFrame(); |
328 } | 342 } |
329 }); | 343 }); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 synchronized (this) { | 490 synchronized (this) { |
477 if (yuvConverter != null) | 491 if (yuvConverter != null) |
478 yuvConverter.release(); | 492 yuvConverter.release(); |
479 } | 493 } |
480 GLES20.glDeleteTextures(1, new int[] {oesTextureId}, 0); | 494 GLES20.glDeleteTextures(1, new int[] {oesTextureId}, 0); |
481 surfaceTexture.release(); | 495 surfaceTexture.release(); |
482 eglBase.release(); | 496 eglBase.release(); |
483 handler.getLooper().quit(); | 497 handler.getLooper().quit(); |
484 } | 498 } |
485 } | 499 } |
OLD | NEW |