OLD | NEW |
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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 import java.util.ArrayList; | 30 import java.util.ArrayList; |
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.opengles.GL10; | 34 import javax.microedition.khronos.opengles.GL10; |
35 | 35 |
36 import android.annotation.SuppressLint; | 36 import android.annotation.SuppressLint; |
37 import android.graphics.Point; | 37 import android.graphics.Point; |
38 import android.graphics.Rect; | 38 import android.graphics.Rect; |
39 import android.graphics.SurfaceTexture; | |
40 import android.opengl.EGL14; | 39 import android.opengl.EGL14; |
41 import android.opengl.EGLContext; | 40 import android.opengl.EGLContext; |
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. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 long now = System.nanoTime(); | 238 long now = System.nanoTime(); |
240 | 239 |
241 final boolean isNewFrame; | 240 final boolean isNewFrame; |
242 synchronized (pendingFrameLock) { | 241 synchronized (pendingFrameLock) { |
243 isNewFrame = (pendingFrame != null); | 242 isNewFrame = (pendingFrame != null); |
244 if (isNewFrame && startTimeNs == -1) { | 243 if (isNewFrame && startTimeNs == -1) { |
245 startTimeNs = now; | 244 startTimeNs = now; |
246 } | 245 } |
247 | 246 |
248 if (isNewFrame) { | 247 if (isNewFrame) { |
| 248 rotatedSamplingMatrix = RendererCommon.rotateTextureMatrix( |
| 249 pendingFrame.samplingMatrix, pendingFrame.rotationDegree); |
249 if (pendingFrame.yuvFrame) { | 250 if (pendingFrame.yuvFrame) { |
250 rendererType = RendererType.RENDERER_YUV; | 251 rendererType = RendererType.RENDERER_YUV; |
251 drawer.uploadYuvData(yuvTextures, pendingFrame.width, pendingFrame.h
eight, | 252 drawer.uploadYuvData(yuvTextures, pendingFrame.width, pendingFrame.h
eight, |
252 pendingFrame.yuvStrides, pendingFrame.yuvPlanes); | 253 pendingFrame.yuvStrides, pendingFrame.yuvPlanes); |
253 // The convention in WebRTC is that the first element in a ByteBuffe
r corresponds to the | |
254 // top-left corner of the image, but in glTexImage2D() the first ele
ment corresponds to | |
255 // the bottom-left corner. We correct this discrepancy by setting a
vertical flip as | |
256 // sampling matrix. | |
257 final float[] samplingMatrix = RendererCommon.verticalFlipMatrix(); | |
258 rotatedSamplingMatrix = | |
259 RendererCommon.rotateTextureMatrix(samplingMatrix, pendingFrame.
rotationDegree); | |
260 } else { | 254 } else { |
261 rendererType = RendererType.RENDERER_TEXTURE; | 255 rendererType = RendererType.RENDERER_TEXTURE; |
262 // External texture rendering. Update texture image to latest and ma
ke a deep copy of | 256 // External texture rendering. Make a deep copy of the external text
ure. |
263 // the external texture. | |
264 // TODO(magjed): Move updateTexImage() to the video source instead. | |
265 final SurfaceTexture surfaceTexture = (SurfaceTexture) pendingFrame.
textureObject; | |
266 surfaceTexture.updateTexImage(); | |
267 final float[] samplingMatrix = new float[16]; | |
268 surfaceTexture.getTransformMatrix(samplingMatrix); | |
269 rotatedSamplingMatrix = | |
270 RendererCommon.rotateTextureMatrix(samplingMatrix, pendingFrame.
rotationDegree); | |
271 | |
272 // Reallocate offscreen texture if necessary. | 257 // Reallocate offscreen texture if necessary. |
273 textureCopy.setSize(pendingFrame.rotatedWidth(), pendingFrame.rotate
dHeight()); | 258 textureCopy.setSize(pendingFrame.rotatedWidth(), pendingFrame.rotate
dHeight()); |
274 | 259 |
275 // Bind our offscreen framebuffer. | 260 // Bind our offscreen framebuffer. |
276 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, textureCopy.getFrame
BufferId()); | 261 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, textureCopy.getFrame
BufferId()); |
277 GlUtil.checkNoGLES2Error("glBindFramebuffer"); | 262 GlUtil.checkNoGLES2Error("glBindFramebuffer"); |
278 | 263 |
279 // Copy the OES texture content. This will also normalize the sampli
ng matrix. | 264 // Copy the OES texture content. This will also normalize the sampli
ng matrix. |
280 GLES20.glViewport(0, 0, textureCopy.getWidth(), textureCopy.getHeig
ht()); | 265 GLES20.glViewport(0, 0, textureCopy.getWidth(), textureCopy.getHeig
ht()); |
281 drawer.drawOes(pendingFrame.textureId, rotatedSamplingMatrix); | 266 drawer.drawOes(pendingFrame.textureId, rotatedSamplingMatrix); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 GLES20.glViewport(0, 0, screenWidth, screenHeight); | 646 GLES20.glViewport(0, 0, screenWidth, screenHeight); |
662 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 647 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
663 synchronized (yuvImageRenderers) { | 648 synchronized (yuvImageRenderers) { |
664 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) { | 649 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) { |
665 yuvImageRenderer.draw(drawer); | 650 yuvImageRenderer.draw(drawer); |
666 } | 651 } |
667 } | 652 } |
668 } | 653 } |
669 | 654 |
670 } | 655 } |
OLD | NEW |