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

Side by Side Diff: webrtc/api/android/java/src/org/webrtc/SurfaceTextureHelper.java

Issue 2436653003: Android YuvConverter: Use OpenGL Framebuffer instead of EGL pixel buffer (Closed)
Patch Set: Rebase against VideoFileRenderer Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/api/android/java/src/org/webrtc/VideoFileRenderer.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 surfaceTexture = new SurfaceTexture(oesTextureId); 127 surfaceTexture = new SurfaceTexture(oesTextureId);
128 surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailab leListener() { 128 surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailab leListener() {
129 @Override 129 @Override
130 public void onFrameAvailable(SurfaceTexture surfaceTexture) { 130 public void onFrameAvailable(SurfaceTexture surfaceTexture) {
131 hasPendingTexture = true; 131 hasPendingTexture = true;
132 tryDeliverTextureFrame(); 132 tryDeliverTextureFrame();
133 } 133 }
134 }); 134 });
135 } 135 }
136 136
137 private YuvConverter getYuvConverter() {
138 // yuvConverter is assigned once
139 if (yuvConverter != null)
140 return yuvConverter;
141
142 synchronized (this) {
143 if (yuvConverter == null)
144 yuvConverter = new YuvConverter(eglBase.getEglBaseContext());
145 return yuvConverter;
146 }
147 }
148
149 /** 137 /**
150 * Start to stream textures to the given |listener|. If you need to change lis tener, you need to 138 * Start to stream textures to the given |listener|. If you need to change lis tener, you need to
151 * call stopListening() first. 139 * call stopListening() first.
152 */ 140 */
153 public void startListening(final OnTextureFrameAvailableListener listener) { 141 public void startListening(final OnTextureFrameAvailableListener listener) {
154 if (this.listener != null || this.pendingListener != null) { 142 if (this.listener != null || this.pendingListener != null) {
155 throw new IllegalStateException("SurfaceTextureHelper listener has already been set."); 143 throw new IllegalStateException("SurfaceTextureHelper listener has already been set.");
156 } 144 }
157 this.pendingListener = listener; 145 this.pendingListener = listener;
158 handler.post(setListenerRunnable); 146 handler.post(setListenerRunnable);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 @Override 212 @Override
225 public void run() { 213 public void run() {
226 isQuitting = true; 214 isQuitting = true;
227 if (!isTextureInUse) { 215 if (!isTextureInUse) {
228 release(); 216 release();
229 } 217 }
230 } 218 }
231 }); 219 });
232 } 220 }
233 221
234 public void textureToYUV( 222 public void textureToYUV(final ByteBuffer buf, final int width, final int heig ht,
235 ByteBuffer buf, int width, int height, int stride, int textureId, float[] transformMatrix) { 223 final int stride, final int textureId, final float[] transformMatrix) {
236 if (textureId != oesTextureId) 224 if (textureId != oesTextureId) {
237 throw new IllegalStateException("textureToByteBuffer called with unexpecte d textureId"); 225 throw new IllegalStateException("textureToByteBuffer called with unexpecte d textureId");
226 }
238 227
239 getYuvConverter().convert(buf, width, height, stride, textureId, transformMa trix); 228 ThreadUtils.invokeAtFrontUninterruptibly(handler, new Runnable() {
229 @Override
230 public void run() {
231 if (yuvConverter == null) {
232 yuvConverter = new YuvConverter();
233 }
234 yuvConverter.convert(buf, width, height, stride, textureId, transformMat rix);
235 }
236 });
240 } 237 }
241 238
242 private void updateTexImage() { 239 private void updateTexImage() {
243 // SurfaceTexture.updateTexImage apparently can compete and deadlock with eg lSwapBuffers, 240 // SurfaceTexture.updateTexImage apparently can compete and deadlock with eg lSwapBuffers,
244 // as observed on Nexus 5. Therefore, synchronize it with the EGL functions. 241 // as observed on Nexus 5. Therefore, synchronize it with the EGL functions.
245 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=5702 for more inf o. 242 // See https://bugs.chromium.org/p/webrtc/issues/detail?id=5702 for more inf o.
246 synchronized (EglBase.lock) { 243 synchronized (EglBase.lock) {
247 surfaceTexture.updateTexImage(); 244 surfaceTexture.updateTexImage();
248 } 245 }
249 } 246 }
(...skipping 18 matching lines...) Expand all
268 listener.onTextureFrameAvailable(oesTextureId, transformMatrix, timestampNs) ; 265 listener.onTextureFrameAvailable(oesTextureId, transformMatrix, timestampNs) ;
269 } 266 }
270 267
271 private void release() { 268 private void release() {
272 if (handler.getLooper().getThread() != Thread.currentThread()) { 269 if (handler.getLooper().getThread() != Thread.currentThread()) {
273 throw new IllegalStateException("Wrong thread."); 270 throw new IllegalStateException("Wrong thread.");
274 } 271 }
275 if (isTextureInUse || !isQuitting) { 272 if (isTextureInUse || !isQuitting) {
276 throw new IllegalStateException("Unexpected release."); 273 throw new IllegalStateException("Unexpected release.");
277 } 274 }
278 synchronized (this) { 275 if (yuvConverter != null) {
279 if (yuvConverter != null) 276 yuvConverter.release();
280 yuvConverter.release();
281 } 277 }
282 GLES20.glDeleteTextures(1, new int[] {oesTextureId}, 0); 278 GLES20.glDeleteTextures(1, new int[] {oesTextureId}, 0);
283 surfaceTexture.release(); 279 surfaceTexture.release();
284 eglBase.release(); 280 eglBase.release();
285 handler.getLooper().quit(); 281 handler.getLooper().quit();
286 } 282 }
287 } 283 }
OLDNEW
« no previous file with comments | « no previous file | webrtc/api/android/java/src/org/webrtc/VideoFileRenderer.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698