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

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

Issue 1422963003: Android MediaCodecVideoDecoder: Manage lifetime of texture frames (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added frame dropping. 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 2015 Google Inc. 3 * Copyright 2015 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 11 matching lines...) Expand all
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 package org.webrtc; 28 package org.webrtc;
29 29
30 import android.content.Context; 30 import android.content.Context;
31 import android.graphics.Point; 31 import android.graphics.Point;
32 import android.graphics.SurfaceTexture; 32 import android.graphics.SurfaceTexture;
magjed_webrtc 2015/11/09 16:30:52 This import is unnecessary now - remove it.
perkj_webrtc 2015/11/09 16:53:50 Done.
33 import android.opengl.GLES20; 33 import android.opengl.GLES20;
34 import android.opengl.Matrix; 34 import android.opengl.Matrix;
35 import android.os.Handler; 35 import android.os.Handler;
36 import android.os.HandlerThread; 36 import android.os.HandlerThread;
37 import android.util.AttributeSet; 37 import android.util.AttributeSet;
38 import android.view.SurfaceHolder; 38 import android.view.SurfaceHolder;
39 import android.view.SurfaceView; 39 import android.view.SurfaceView;
40 40
41 import org.webrtc.Logging; 41 import org.webrtc.Logging;
42 42
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 final VideoRenderer.I420Frame frame; 431 final VideoRenderer.I420Frame frame;
432 synchronized (frameLock) { 432 synchronized (frameLock) {
433 if (pendingFrame == null) { 433 if (pendingFrame == null) {
434 return; 434 return;
435 } 435 }
436 frame = pendingFrame; 436 frame = pendingFrame;
437 pendingFrame = null; 437 pendingFrame = null;
438 } 438 }
439 439
440 final long startTimeNs = System.nanoTime(); 440 final long startTimeNs = System.nanoTime();
441 final float[] samplingMatrix;
442 if (frame.yuvFrame) {
443 // The convention in WebRTC is that the first element in a ByteBuffer corr esponds to the
444 // top-left corner of the image, but in glTexImage2D() the first element c orresponds to the
445 // bottom-left corner. We correct this discrepancy by setting a vertical f lip as sampling
446 // matrix.
447 samplingMatrix = RendererCommon.verticalFlipMatrix();
448 } else {
449 // TODO(magjed): Move updateTexImage() to the video source instead.
450 SurfaceTexture surfaceTexture = (SurfaceTexture) frame.textureObject;
451 surfaceTexture.updateTexImage();
452 samplingMatrix = new float[16];
453 surfaceTexture.getTransformMatrix(samplingMatrix);
454 }
455
456 final float[] texMatrix; 441 final float[] texMatrix;
457 synchronized (layoutLock) { 442 synchronized (layoutLock) {
458 final float[] rotatedSamplingMatrix = 443 final float[] rotatedSamplingMatrix =
459 RendererCommon.rotateTextureMatrix(samplingMatrix, frame.rotationDegre e); 444 RendererCommon.rotateTextureMatrix(frame.samplingMatrix, frame.rotatio nDegree);
460 final float[] layoutMatrix = RendererCommon.getLayoutMatrix( 445 final float[] layoutMatrix = RendererCommon.getLayoutMatrix(
461 mirror, frameAspectRatio(), (float) layoutWidth / layoutHeight); 446 mirror, frameAspectRatio(), (float) layoutWidth / layoutHeight);
462 texMatrix = RendererCommon.multiplyMatrices(rotatedSamplingMatrix, layoutM atrix); 447 texMatrix = RendererCommon.multiplyMatrices(rotatedSamplingMatrix, layoutM atrix);
463 } 448 }
464 449
465 GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); 450 GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight);
466 if (frame.yuvFrame) { 451 if (frame.yuvFrame) {
467 // Make sure YUV textures are allocated. 452 // Make sure YUV textures are allocated.
468 if (yuvTextures == null) { 453 if (yuvTextures == null) {
469 yuvTextures = new int[3]; 454 yuvTextures = new int[3];
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 if (framesReceived > 0 && framesRendered > 0) { 517 if (framesReceived > 0 && framesRendered > 0) {
533 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs; 518 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs;
534 Logging.d(TAG, "Duration: " + (int) (timeSinceFirstFrameNs / 1e6) + 519 Logging.d(TAG, "Duration: " + (int) (timeSinceFirstFrameNs / 1e6) +
535 " ms. FPS: " + (float) framesRendered * 1e9 / timeSinceFirstFrameNs) ; 520 " ms. FPS: " + (float) framesRendered * 1e9 / timeSinceFirstFrameNs) ;
536 Logging.d(TAG, "Average render time: " 521 Logging.d(TAG, "Average render time: "
537 + (int) (renderTimeNs / (1000 * framesRendered)) + " us."); 522 + (int) (renderTimeNs / (1000 * framesRendered)) + " us.");
538 } 523 }
539 } 524 }
540 } 525 }
541 } 526 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698