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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 long now = System.nanoTime(); | 237 long now = System.nanoTime(); |
238 | 238 |
239 final boolean isNewFrame; | 239 final boolean isNewFrame; |
240 synchronized (pendingFrameLock) { | 240 synchronized (pendingFrameLock) { |
241 isNewFrame = (pendingFrame != null); | 241 isNewFrame = (pendingFrame != null); |
242 if (isNewFrame && startTimeNs == -1) { | 242 if (isNewFrame && startTimeNs == -1) { |
243 startTimeNs = now; | 243 startTimeNs = now; |
244 } | 244 } |
245 | 245 |
246 if (isNewFrame) { | 246 if (isNewFrame) { |
| 247 rotatedSamplingMatrix = RendererCommon.rotateTextureMatrix( |
| 248 pendingFrame.samplingMatrix, pendingFrame.rotationDegree); |
247 if (pendingFrame.yuvFrame) { | 249 if (pendingFrame.yuvFrame) { |
248 rendererType = RendererType.RENDERER_YUV; | 250 rendererType = RendererType.RENDERER_YUV; |
249 drawer.uploadYuvData(yuvTextures, pendingFrame.width, pendingFrame.h
eight, | 251 drawer.uploadYuvData(yuvTextures, pendingFrame.width, pendingFrame.h
eight, |
250 pendingFrame.yuvStrides, pendingFrame.yuvPlanes); | 252 pendingFrame.yuvStrides, pendingFrame.yuvPlanes); |
251 // The convention in WebRTC is that the first element in a ByteBuffe
r corresponds to the | |
252 // top-left corner of the image, but in glTexImage2D() the first ele
ment corresponds to | |
253 // the bottom-left corner. We correct this discrepancy by setting a
vertical flip as | |
254 // sampling matrix. | |
255 final float[] samplingMatrix = RendererCommon.verticalFlipMatrix(); | |
256 rotatedSamplingMatrix = | |
257 RendererCommon.rotateTextureMatrix(samplingMatrix, pendingFrame.
rotationDegree); | |
258 } else { | 253 } else { |
259 rendererType = RendererType.RENDERER_TEXTURE; | 254 rendererType = RendererType.RENDERER_TEXTURE; |
260 // External texture rendering. Update texture image to latest and ma
ke a deep copy of | 255 // External texture rendering. Make a deep copy of the external text
ure. |
261 // the external texture. | |
262 // TODO(magjed): Move updateTexImage() to the video source instead. | |
263 final SurfaceTexture surfaceTexture = (SurfaceTexture) pendingFrame.
textureObject; | |
264 surfaceTexture.updateTexImage(); | |
265 final float[] samplingMatrix = new float[16]; | |
266 surfaceTexture.getTransformMatrix(samplingMatrix); | |
267 rotatedSamplingMatrix = | |
268 RendererCommon.rotateTextureMatrix(samplingMatrix, pendingFrame.
rotationDegree); | |
269 | |
270 // Reallocate offscreen texture if necessary. | 256 // Reallocate offscreen texture if necessary. |
271 textureCopy.setSize(pendingFrame.rotatedWidth(), pendingFrame.rotate
dHeight()); | 257 textureCopy.setSize(pendingFrame.rotatedWidth(), pendingFrame.rotate
dHeight()); |
272 | 258 |
273 // Bind our offscreen framebuffer. | 259 // Bind our offscreen framebuffer. |
274 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, textureCopy.getFrame
BufferId()); | 260 GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, textureCopy.getFrame
BufferId()); |
275 GlUtil.checkNoGLES2Error("glBindFramebuffer"); | 261 GlUtil.checkNoGLES2Error("glBindFramebuffer"); |
276 | 262 |
277 // Copy the OES texture content. This will also normalize the sampli
ng matrix. | 263 // Copy the OES texture content. This will also normalize the sampli
ng matrix. |
278 GLES20.glViewport(0, 0, textureCopy.getWidth(), textureCopy.getHeig
ht()); | 264 GLES20.glViewport(0, 0, textureCopy.getWidth(), textureCopy.getHeig
ht()); |
279 drawer.drawOes(pendingFrame.textureId, rotatedSamplingMatrix); | 265 drawer.drawOes(pendingFrame.textureId, rotatedSamplingMatrix); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 GLES20.glViewport(0, 0, screenWidth, screenHeight); | 616 GLES20.glViewport(0, 0, screenWidth, screenHeight); |
631 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); | 617 GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); |
632 synchronized (yuvImageRenderers) { | 618 synchronized (yuvImageRenderers) { |
633 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) { | 619 for (YuvImageRenderer yuvImageRenderer : yuvImageRenderers) { |
634 yuvImageRenderer.draw(drawer); | 620 yuvImageRenderer.draw(drawer); |
635 } | 621 } |
636 } | 622 } |
637 } | 623 } |
638 | 624 |
639 } | 625 } |
OLD | NEW |