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 12 matching lines...) Expand all Loading... |
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.content.res.Resources.NotFoundException; | 31 import android.content.res.Resources.NotFoundException; |
32 import android.graphics.Point; | 32 import android.graphics.Point; |
| 33 import android.graphics.SurfaceTexture; |
33 import android.opengl.GLES20; | 34 import android.opengl.GLES20; |
| 35 import android.opengl.Matrix; |
34 import android.os.Handler; | 36 import android.os.Handler; |
35 import android.os.HandlerThread; | 37 import android.os.HandlerThread; |
36 import android.util.AttributeSet; | 38 import android.util.AttributeSet; |
37 import android.view.SurfaceHolder; | 39 import android.view.SurfaceHolder; |
38 import android.view.SurfaceView; | 40 import android.view.SurfaceView; |
39 | 41 |
40 import org.webrtc.Logging; | 42 import org.webrtc.Logging; |
41 | 43 |
42 import java.util.concurrent.CountDownLatch; | 44 import java.util.concurrent.CountDownLatch; |
43 | 45 |
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 final VideoRenderer.I420Frame frame; | 450 final VideoRenderer.I420Frame frame; |
449 synchronized (frameLock) { | 451 synchronized (frameLock) { |
450 if (pendingFrame == null) { | 452 if (pendingFrame == null) { |
451 return; | 453 return; |
452 } | 454 } |
453 frame = pendingFrame; | 455 frame = pendingFrame; |
454 pendingFrame = null; | 456 pendingFrame = null; |
455 } | 457 } |
456 | 458 |
457 final long startTimeNs = System.nanoTime(); | 459 final long startTimeNs = System.nanoTime(); |
| 460 final float[] samplingMatrix; |
| 461 if (frame.yuvFrame) { |
| 462 // The convention in WebRTC is that the first element in a ByteBuffer corr
esponds to the |
| 463 // top-left corner of the image, but in glTexImage2D() the first element c
orresponds to the |
| 464 // bottom-left corner. We correct this discrepancy by setting a vertical f
lip as sampling |
| 465 // matrix. |
| 466 samplingMatrix = RendererCommon.verticalFlipMatrix(); |
| 467 } else { |
| 468 // TODO(magjed): Move updateTexImage() to the video source instead. |
| 469 SurfaceTexture surfaceTexture = (SurfaceTexture) frame.textureObject; |
| 470 surfaceTexture.updateTexImage(); |
| 471 samplingMatrix = new float[16]; |
| 472 surfaceTexture.getTransformMatrix(samplingMatrix); |
| 473 } |
| 474 |
458 final float[] texMatrix; | 475 final float[] texMatrix; |
459 synchronized (layoutLock) { | 476 synchronized (layoutLock) { |
460 final float[] rotatedSamplingMatrix = | 477 final float[] rotatedSamplingMatrix = |
461 RendererCommon.rotateTextureMatrix(frame.samplingMatrix, frame.rotatio
nDegree); | 478 RendererCommon.rotateTextureMatrix(samplingMatrix, frame.rotationDegre
e); |
462 final float[] layoutMatrix = RendererCommon.getLayoutMatrix( | 479 final float[] layoutMatrix = RendererCommon.getLayoutMatrix( |
463 mirror, frameAspectRatio(), (float) layoutWidth / layoutHeight); | 480 mirror, frameAspectRatio(), (float) layoutWidth / layoutHeight); |
464 texMatrix = RendererCommon.multiplyMatrices(rotatedSamplingMatrix, layoutM
atrix); | 481 texMatrix = RendererCommon.multiplyMatrices(rotatedSamplingMatrix, layoutM
atrix); |
465 } | 482 } |
466 | 483 |
467 GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); | 484 GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); |
468 // TODO(magjed): glClear() shouldn't be necessary since every pixel is cover
ed anyway, but it's | 485 // TODO(magjed): glClear() shouldn't be necessary since every pixel is cover
ed anyway, but it's |
469 // a workaround for bug 5147. Performance will be slightly worse. | 486 // a workaround for bug 5147. Performance will be slightly worse. |
470 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 487 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
471 if (frame.yuvFrame) { | 488 if (frame.yuvFrame) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 if (framesReceived > 0 && framesRendered > 0) { | 553 if (framesReceived > 0 && framesRendered > 0) { |
537 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs; | 554 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs; |
538 Logging.d(TAG, getResourceName() + "Duration: " + (int) (timeSinceFirstF
rameNs / 1e6) + | 555 Logging.d(TAG, getResourceName() + "Duration: " + (int) (timeSinceFirstF
rameNs / 1e6) + |
539 " ms. FPS: " + (float) framesRendered * 1e9 / timeSinceFirstFrameNs)
; | 556 " ms. FPS: " + (float) framesRendered * 1e9 / timeSinceFirstFrameNs)
; |
540 Logging.d(TAG, getResourceName() + "Average render time: " | 557 Logging.d(TAG, getResourceName() + "Average render time: " |
541 + (int) (renderTimeNs / (1000 * framesRendered)) + " us."); | 558 + (int) (renderTimeNs / (1000 * framesRendered)) + " us."); |
542 } | 559 } |
543 } | 560 } |
544 } | 561 } |
545 } | 562 } |
OLD | NEW |