Index: webrtc/sdk/android/src/java/org/webrtc/Camera2Session.java |
diff --git a/webrtc/sdk/android/src/java/org/webrtc/Camera2Session.java b/webrtc/sdk/android/src/java/org/webrtc/Camera2Session.java |
index 8de5be0eebef48b3cea295d1903abf9c3b105e0f..243b41d649357ddf7de485bba15e2c5c363e8a1b 100644 |
--- a/webrtc/sdk/android/src/java/org/webrtc/Camera2Session.java |
+++ b/webrtc/sdk/android/src/java/org/webrtc/Camera2Session.java |
@@ -12,6 +12,7 @@ package org.webrtc; |
import android.annotation.TargetApi; |
import android.content.Context; |
+import android.graphics.Matrix; |
import android.graphics.SurfaceTexture; |
import android.hardware.camera2.CameraAccessException; |
import android.hardware.camera2.CameraCaptureSession; |
@@ -213,20 +214,29 @@ class Camera2Session implements CameraSession { |
camera2StartTimeMsHistogram.addSample(startTimeMs); |
} |
+ Matrix frameMatrix = |
+ RendererCommon.convertMatrixToAndroidGraphicsMatrix(transformMatrix); |
+ |
int rotation = getFrameOrientation(); |
if (isCameraFrontFacing) { |
// Undo the mirror that the OS "helps" us with. |
// http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int) |
- transformMatrix = RendererCommon.multiplyMatrices( |
- transformMatrix, RendererCommon.horizontalFlipMatrix()); |
+ frameMatrix.preTranslate(1f, 0f); |
+ frameMatrix.preScale(-1f, 1f); |
} |
- // Undo camera orientation - we report it as rotation instead. |
- transformMatrix = |
- RendererCommon.rotateTextureMatrix(transformMatrix, -cameraOrientation); |
- |
- events.onTextureFrameCaptured(Camera2Session.this, captureFormat.width, |
- captureFormat.height, oesTextureId, transformMatrix, rotation, timestampNs); |
+ // Undo camera orientation - we report it as rotation instead. We have to shift the |
+ // origin for the rotation. |
+ frameMatrix.preTranslate(0.5f, 0.5f); |
+ frameMatrix.preRotate(-cameraOrientation); |
+ frameMatrix.preTranslate(-0.5f, -0.5f); |
+ |
+ VideoFrame.Buffer buffer = surfaceTextureHelper.createTextureBuffer( |
+ captureFormat.width, captureFormat.height, |
+ RendererCommon.convertMatrixFromAndroidGraphicsMatrix(frameMatrix)); |
+ final VideoFrame frame = new VideoFrame(buffer, rotation, timestampNs, frameMatrix); |
+ events.onFrameCaptured(Camera2Session.this, frame); |
+ frame.release(); |
} |
}); |
Logging.d(TAG, "Camera device successfully started."); |