OLD | NEW |
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 Loading... |
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; | |
33 import android.opengl.GLES20; | 32 import android.opengl.GLES20; |
34 import android.opengl.Matrix; | |
35 import android.os.Handler; | 33 import android.os.Handler; |
36 import android.os.HandlerThread; | 34 import android.os.HandlerThread; |
37 import android.util.AttributeSet; | 35 import android.util.AttributeSet; |
38 import android.view.SurfaceHolder; | 36 import android.view.SurfaceHolder; |
39 import android.view.SurfaceView; | 37 import android.view.SurfaceView; |
40 | 38 |
41 import org.webrtc.Logging; | 39 import org.webrtc.Logging; |
42 | 40 |
43 import java.util.concurrent.CountDownLatch; | 41 import java.util.concurrent.CountDownLatch; |
44 | 42 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 final VideoRenderer.I420Frame frame; | 429 final VideoRenderer.I420Frame frame; |
432 synchronized (frameLock) { | 430 synchronized (frameLock) { |
433 if (pendingFrame == null) { | 431 if (pendingFrame == null) { |
434 return; | 432 return; |
435 } | 433 } |
436 frame = pendingFrame; | 434 frame = pendingFrame; |
437 pendingFrame = null; | 435 pendingFrame = null; |
438 } | 436 } |
439 | 437 |
440 final long startTimeNs = System.nanoTime(); | 438 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; | 439 final float[] texMatrix; |
457 synchronized (layoutLock) { | 440 synchronized (layoutLock) { |
458 final float[] rotatedSamplingMatrix = | 441 final float[] rotatedSamplingMatrix = |
459 RendererCommon.rotateTextureMatrix(samplingMatrix, frame.rotationDegre
e); | 442 RendererCommon.rotateTextureMatrix(frame.samplingMatrix, frame.rotatio
nDegree); |
460 final float[] layoutMatrix = RendererCommon.getLayoutMatrix( | 443 final float[] layoutMatrix = RendererCommon.getLayoutMatrix( |
461 mirror, frameAspectRatio(), (float) layoutWidth / layoutHeight); | 444 mirror, frameAspectRatio(), (float) layoutWidth / layoutHeight); |
462 texMatrix = RendererCommon.multiplyMatrices(rotatedSamplingMatrix, layoutM
atrix); | 445 texMatrix = RendererCommon.multiplyMatrices(rotatedSamplingMatrix, layoutM
atrix); |
463 } | 446 } |
464 | 447 |
465 GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); | 448 GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); |
466 if (frame.yuvFrame) { | 449 if (frame.yuvFrame) { |
467 // Make sure YUV textures are allocated. | 450 // Make sure YUV textures are allocated. |
468 if (yuvTextures == null) { | 451 if (yuvTextures == null) { |
469 yuvTextures = new int[3]; | 452 yuvTextures = new int[3]; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 if (framesReceived > 0 && framesRendered > 0) { | 515 if (framesReceived > 0 && framesRendered > 0) { |
533 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs; | 516 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs; |
534 Logging.d(TAG, "Duration: " + (int) (timeSinceFirstFrameNs / 1e6) + | 517 Logging.d(TAG, "Duration: " + (int) (timeSinceFirstFrameNs / 1e6) + |
535 " ms. FPS: " + (float) framesRendered * 1e9 / timeSinceFirstFrameNs)
; | 518 " ms. FPS: " + (float) framesRendered * 1e9 / timeSinceFirstFrameNs)
; |
536 Logging.d(TAG, "Average render time: " | 519 Logging.d(TAG, "Average render time: " |
537 + (int) (renderTimeNs / (1000 * framesRendered)) + " us."); | 520 + (int) (renderTimeNs / (1000 * framesRendered)) + " us."); |
538 } | 521 } |
539 } | 522 } |
540 } | 523 } |
541 } | 524 } |
OLD | NEW |