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

Side by Side Diff: talk/app/webrtc/java/android/org/webrtc/VideoRendererGui.java

Issue 1422963003: Android MediaCodecVideoDecoder: Manage lifetime of texture frames (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed magjeds comments. Created 5 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 20 matching lines...) Expand all
31 import java.util.concurrent.CountDownLatch; 31 import java.util.concurrent.CountDownLatch;
32 32
33 import javax.microedition.khronos.egl.EGLConfig; 33 import javax.microedition.khronos.egl.EGLConfig;
34 import javax.microedition.khronos.egl.EGL10; 34 import javax.microedition.khronos.egl.EGL10;
35 import javax.microedition.khronos.egl.EGLContext; 35 import javax.microedition.khronos.egl.EGLContext;
36 import javax.microedition.khronos.opengles.GL10; 36 import javax.microedition.khronos.opengles.GL10;
37 37
38 import android.annotation.SuppressLint; 38 import android.annotation.SuppressLint;
39 import android.graphics.Point; 39 import android.graphics.Point;
40 import android.graphics.Rect; 40 import android.graphics.Rect;
41 import android.graphics.SurfaceTexture;
42 import android.opengl.GLES20; 41 import android.opengl.GLES20;
43 import android.opengl.GLSurfaceView; 42 import android.opengl.GLSurfaceView;
44 43
45 import org.webrtc.Logging; 44 import org.webrtc.Logging;
46 import org.webrtc.VideoRenderer.I420Frame; 45 import org.webrtc.VideoRenderer.I420Frame;
47 46
48 /** 47 /**
49 * Efficiently renders YUV frames using the GPU for CSC. 48 * Efficiently renders YUV frames using the GPU for CSC.
50 * Clients will want first to call setView() to pass GLSurfaceView 49 * Clients will want first to call setView() to pass GLSurfaceView
51 * and then for each video stream either create instance of VideoRenderer using 50 * and then for each video stream either create instance of VideoRenderer using
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 long now = System.nanoTime(); 233 long now = System.nanoTime();
235 234
236 final boolean isNewFrame; 235 final boolean isNewFrame;
237 synchronized (pendingFrameLock) { 236 synchronized (pendingFrameLock) {
238 isNewFrame = (pendingFrame != null); 237 isNewFrame = (pendingFrame != null);
239 if (isNewFrame && startTimeNs == -1) { 238 if (isNewFrame && startTimeNs == -1) {
240 startTimeNs = now; 239 startTimeNs = now;
241 } 240 }
242 241
243 if (isNewFrame) { 242 if (isNewFrame) {
243 rotatedSamplingMatrix = RendererCommon.rotateTextureMatrix(
244 pendingFrame.samplingMatrix, pendingFrame.rotationDegree);
244 if (pendingFrame.yuvFrame) { 245 if (pendingFrame.yuvFrame) {
245 rendererType = RendererType.RENDERER_YUV; 246 rendererType = RendererType.RENDERER_YUV;
246 drawer.uploadYuvData(yuvTextures, pendingFrame.width, pendingFrame.h eight, 247 drawer.uploadYuvData(yuvTextures, pendingFrame.width, pendingFrame.h eight,
247 pendingFrame.yuvStrides, pendingFrame.yuvPlanes); 248 pendingFrame.yuvStrides, pendingFrame.yuvPlanes);
248 // The convention in WebRTC is that the first element in a ByteBuffe r corresponds to the
249 // top-left corner of the image, but in glTexImage2D() the first ele ment corresponds to
250 // the bottom-left corner. We correct this discrepancy by setting a vertical flip as
251 // sampling matrix.
252 final float[] samplingMatrix = RendererCommon.verticalFlipMatrix();
253 rotatedSamplingMatrix =
254 RendererCommon.rotateTextureMatrix(samplingMatrix, pendingFrame. rotationDegree);
255 } else { 249 } else {
256 rendererType = RendererType.RENDERER_TEXTURE; 250 rendererType = RendererType.RENDERER_TEXTURE;
257 // External texture rendering. Update texture image to latest and ma ke a deep copy of 251 // External texture rendering. Make a deep copy of the external text ure.
258 // the external texture.
259 // TODO(magjed): Move updateTexImage() to the video source instead.
260 final SurfaceTexture surfaceTexture = (SurfaceTexture) pendingFrame. textureObject;
261 surfaceTexture.updateTexImage();
262 final float[] samplingMatrix = new float[16];
263 surfaceTexture.getTransformMatrix(samplingMatrix);
264 rotatedSamplingMatrix =
265 RendererCommon.rotateTextureMatrix(samplingMatrix, pendingFrame. rotationDegree);
266
267 // Reallocate offscreen texture if necessary. 252 // Reallocate offscreen texture if necessary.
268 textureCopy.setSize(pendingFrame.rotatedWidth(), pendingFrame.rotate dHeight()); 253 textureCopy.setSize(pendingFrame.rotatedWidth(), pendingFrame.rotate dHeight());
269 254
270 // Bind our offscreen framebuffer. 255 // Bind our offscreen framebuffer.
271 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, textureCopy.getFrame BufferId()); 256 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, textureCopy.getFrame BufferId());
272 GlUtil.checkNoGLES2Error("glBindFramebuffer"); 257 GlUtil.checkNoGLES2Error("glBindFramebuffer");
273 258
274 // Copy the OES texture content. This will also normalize the sampli ng matrix. 259 // Copy the OES texture content. This will also normalize the sampli ng matrix.
275 GLES20.glViewport(0, 0, textureCopy.getWidth(), textureCopy.getHeig ht()); 260 GLES20.glViewport(0, 0, textureCopy.getWidth(), textureCopy.getHeig ht());
276 drawer.drawOes(pendingFrame.textureId, rotatedSamplingMatrix); 261 drawer.drawOes(pendingFrame.textureId, rotatedSamplingMatrix);
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 GLES20.glViewport(0, 0, screenWidth, screenHeight); 639 GLES20.glViewport(0, 0, screenWidth, screenHeight);
655 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); 640 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
656 synchronized (yuvImageRenderers) { 641 synchronized (yuvImageRenderers) {
657 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) { 642 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) {
658 yuvImageRenderer.draw(drawer); 643 yuvImageRenderer.draw(drawer);
659 } 644 }
660 } 645 }
661 } 646 }
662 647
663 } 648 }
OLDNEW
« no previous file with comments | « talk/app/webrtc/java/android/org/webrtc/SurfaceViewRenderer.java ('k') | talk/app/webrtc/java/jni/androidmediadecoder_jni.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698