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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 } |
OLD | NEW |