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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 final VideoRenderer.I420Frame frame; | 425 final VideoRenderer.I420Frame frame; |
426 synchronized (frameLock) { | 426 synchronized (frameLock) { |
427 if (pendingFrame == null) { | 427 if (pendingFrame == null) { |
428 return; | 428 return; |
429 } | 429 } |
430 frame = pendingFrame; | 430 frame = pendingFrame; |
431 pendingFrame = null; | 431 pendingFrame = null; |
432 } | 432 } |
433 | 433 |
434 final long startTimeNs = System.nanoTime(); | 434 final long startTimeNs = System.nanoTime(); |
435 final float[] samplingMatrix; | |
436 if (frame.yuvFrame) { | |
437 // The convention in WebRTC is that the first element in a ByteBuffer corr
esponds to the | |
438 // top-left corner of the image, but in glTexImage2D() the first element c
orresponds to the | |
439 // bottom-left corner. We correct this discrepancy by setting a vertical f
lip as sampling | |
440 // matrix. | |
441 samplingMatrix = RendererCommon.verticalFlipMatrix(); | |
442 } else { | |
443 // TODO(magjed): Move updateTexImage() to the video source instead. | |
444 SurfaceTexture surfaceTexture = (SurfaceTexture) frame.textureObject; | |
445 surfaceTexture.updateTexImage(); | |
446 samplingMatrix = new float[16]; | |
447 surfaceTexture.getTransformMatrix(samplingMatrix); | |
448 } | |
449 | |
450 final float[] texMatrix; | 435 final float[] texMatrix; |
451 synchronized (layoutLock) { | 436 synchronized (layoutLock) { |
452 final float[] rotatedSamplingMatrix = | 437 final float[] rotatedSamplingMatrix = |
453 RendererCommon.rotateTextureMatrix(samplingMatrix, frame.rotationDegre
e); | 438 RendererCommon.rotateTextureMatrix(frame.samplingMatrix, frame.rotatio
nDegree); |
454 final float[] layoutMatrix = RendererCommon.getLayoutMatrix( | 439 final float[] layoutMatrix = RendererCommon.getLayoutMatrix( |
455 mirror, frameAspectRatio(), (float) layoutWidth / layoutHeight); | 440 mirror, frameAspectRatio(), (float) layoutWidth / layoutHeight); |
456 texMatrix = RendererCommon.multiplyMatrices(rotatedSamplingMatrix, layoutM
atrix); | 441 texMatrix = RendererCommon.multiplyMatrices(rotatedSamplingMatrix, layoutM
atrix); |
457 } | 442 } |
458 | 443 |
459 GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); | 444 GLES20.glViewport(0, 0, surfaceWidth, surfaceHeight); |
460 if (frame.yuvFrame) { | 445 if (frame.yuvFrame) { |
461 // Make sure YUV textures are allocated. | 446 // Make sure YUV textures are allocated. |
462 if (yuvTextures == null) { | 447 if (yuvTextures == null) { |
463 yuvTextures = new int[3]; | 448 yuvTextures = new int[3]; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 if (framesReceived > 0 && framesRendered > 0) { | 511 if (framesReceived > 0 && framesRendered > 0) { |
527 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs; | 512 final long timeSinceFirstFrameNs = System.nanoTime() - firstFrameTimeNs; |
528 Logging.d(TAG, "Duration: " + (int) (timeSinceFirstFrameNs / 1e6) + | 513 Logging.d(TAG, "Duration: " + (int) (timeSinceFirstFrameNs / 1e6) + |
529 " ms. FPS: " + (float) framesRendered * 1e9 / timeSinceFirstFrameNs)
; | 514 " ms. FPS: " + (float) framesRendered * 1e9 / timeSinceFirstFrameNs)
; |
530 Logging.d(TAG, "Average render time: " | 515 Logging.d(TAG, "Average render time: " |
531 + (int) (renderTimeNs / (1000 * framesRendered)) + " us."); | 516 + (int) (renderTimeNs / (1000 * framesRendered)) + " us."); |
532 } | 517 } |
533 } | 518 } |
534 } | 519 } |
535 } | 520 } |
OLD | NEW |