Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Unified Diff: webrtc/sdk/android/src/java/org/webrtc/Camera2Session.java

Issue 2984633002: Add a field trial to produce VideoFrames in camera capturers. (Closed)
Patch Set: Rebase Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..61bfe495816bdb7237e7029e5f4ed557dc05d1ca 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;
@@ -213,20 +216,35 @@ 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);
magjed_webrtc 2017/08/22 08:53:08 Revert these changes just to be safe and perform t
sakal 2017/08/22 11:45:30 Done.
+ frameMatrix.preRotate(-cameraOrientation);
+ frameMatrix.preTranslate(-0.5f, -0.5f);
+
+ if (videoFrameEmitTrialEnabled) {
+ VideoFrame.Buffer buffer = surfaceTextureHelper.createTextureBuffer(
+ captureFormat.width, captureFormat.height, frameMatrix);
+ 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,
+ RendererCommon.convertMatrixFromAndroidGraphicsMatrix(frameMatrix), rotation,
+ timestampNs);
+ }
}
});
Logging.d(TAG, "Camera device successfully started.");
@@ -301,6 +319,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();

Powered by Google App Engine
This is Rietveld 408576698