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..b74aaa0035abfcc2cea95d95c68d14d33a6e408a 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; |
@@ -44,6 +45,8 @@ class Camera2Session implements CameraSession { |
private static enum SessionState { RUNNING, STOPPED } |
+ private final boolean videoFrameEmitTrialEnabled; |
+ |
private final Handler cameraThreadHandler; |
private final CreateSessionCallback callback; |
private final Events events; |
@@ -225,8 +228,17 @@ class Camera2Session implements CameraSession { |
transformMatrix = |
RendererCommon.rotateTextureMatrix(transformMatrix, -cameraOrientation); |
- events.onTextureFrameCaptured(Camera2Session.this, captureFormat.width, |
- captureFormat.height, oesTextureId, transformMatrix, rotation, timestampNs); |
+ if (videoFrameEmitTrialEnabled) { |
+ VideoFrame.Buffer buffer = surfaceTextureHelper.createTextureBuffer( |
+ captureFormat.width, captureFormat.height, |
+ RendererCommon.convertMatrixToAndroidGraphicsMatrix(transformMatrix)); |
+ final VideoFrame frame = new VideoFrame(buffer, rotation, timestampNs); |
+ events.onFrameCaptured(Camera2Session.this, frame); |
+ frame.release(); |
+ } else { |
+ events.onTextureFrameCaptured(Camera2Session.this, captureFormat.width, |
+ captureFormat.height, oesTextureId, transformMatrix, rotation, timestampNs); |
+ } |
} |
}); |
Logging.d(TAG, "Camera device successfully started."); |
@@ -301,6 +313,9 @@ class Camera2Session implements CameraSession { |
CameraManager cameraManager, SurfaceTextureHelper surfaceTextureHelper, |
MediaRecorder mediaRecorder, String cameraId, int width, int height, int framerate) { |
Logging.d(TAG, "Create new camera2 session on camera " + cameraId); |
+ videoFrameEmitTrialEnabled = |
+ PeerConnectionFactory.fieldTrialsFindFullName(PeerConnectionFactory.VIDEO_FRAME_EMIT_TRIAL) |
+ .equals(PeerConnectionFactory.TRIAL_ENABLED); |
constructionTimeNs = System.nanoTime(); |