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

Unified Diff: webrtc/sdk/android/src/java/org/webrtc/Camera1Session.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/Camera1Session.java
diff --git a/webrtc/sdk/android/src/java/org/webrtc/Camera1Session.java b/webrtc/sdk/android/src/java/org/webrtc/Camera1Session.java
index d1950690c34f7f1b10a413e6ab1ca17a42621088..39974ca8d921649d76b223efa7c98bb637d670c8 100644
--- a/webrtc/sdk/android/src/java/org/webrtc/Camera1Session.java
+++ b/webrtc/sdk/android/src/java/org/webrtc/Camera1Session.java
@@ -18,7 +18,9 @@ import android.view.Surface;
import android.view.WindowManager;
import java.io.IOException;
import java.nio.ByteBuffer;
+import java.util.HashMap;
magjed_webrtc 2017/08/22 08:53:08 This is unused.
sakal 2017/08/22 11:45:30 Done.
import java.util.List;
+import java.util.Map;
magjed_webrtc 2017/08/22 08:53:08 This is unused.
sakal 2017/08/22 11:45:30 Done.
import java.util.concurrent.TimeUnit;
import org.webrtc.CameraEnumerationAndroid.CaptureFormat;
@@ -36,6 +38,8 @@ class Camera1Session implements CameraSession {
private static enum SessionState { RUNNING, STOPPED }
+ private final boolean videoFrameEmitTrialEnabled;
+
private final Handler cameraThreadHandler;
private final Events events;
private final boolean captureToTexture;
@@ -85,7 +89,6 @@ class Camera1Session implements CameraSession {
updateCameraParameters(camera, parameters, captureFormat, pictureSize, captureToTexture);
- // Initialize the capture buffers.
if (!captureToTexture) {
final int frameSize = captureFormat.frameSize();
for (int i = 0; i < NUMBER_OF_CAPTURE_BUFFERS; ++i) {
@@ -151,6 +154,9 @@ class Camera1Session implements CameraSession {
android.hardware.Camera camera, android.hardware.Camera.CameraInfo info,
CaptureFormat captureFormat, long constructionTimeNs) {
Logging.d(TAG, "Create new camera1 session on camera " + cameraId);
+ videoFrameEmitTrialEnabled =
+ PeerConnectionFactory.fieldTrialsFindFullName(PeerConnectionFactory.VIDEO_FRAME_EMIT_TRIAL)
+ .equals(PeerConnectionFactory.TRIAL_ENABLED);
this.cameraThreadHandler = new Handler();
this.events = events;
@@ -267,8 +273,17 @@ class Camera1Session implements CameraSession {
transformMatrix = RendererCommon.multiplyMatrices(
transformMatrix, RendererCommon.horizontalFlipMatrix());
}
- events.onTextureFrameCaptured(Camera1Session.this, captureFormat.width,
- captureFormat.height, oesTextureId, transformMatrix, rotation, timestampNs);
+ if (videoFrameEmitTrialEnabled) {
+ final VideoFrame.Buffer buffer =
+ surfaceTextureHelper.createTextureBuffer(captureFormat.width, captureFormat.height,
+ RendererCommon.convertMatrixToAndroidGraphicsMatrix(transformMatrix));
+ final VideoFrame frame = new VideoFrame(buffer, rotation, timestampNs);
+ events.onFrameCaptured(Camera1Session.this, frame);
+ frame.release();
+ } else {
+ events.onTextureFrameCaptured(Camera1Session.this, captureFormat.width,
+ captureFormat.height, oesTextureId, transformMatrix, rotation, timestampNs);
+ }
}
});
}
@@ -276,7 +291,7 @@ class Camera1Session implements CameraSession {
private void listenForBytebufferFrames() {
camera.setPreviewCallbackWithBuffer(new android.hardware.Camera.PreviewCallback() {
@Override
- public void onPreviewFrame(byte[] data, android.hardware.Camera callbackCamera) {
+ public void onPreviewFrame(final byte[] data, android.hardware.Camera callbackCamera) {
checkIsOnCameraThread();
if (callbackCamera != camera) {
@@ -298,9 +313,22 @@ class Camera1Session implements CameraSession {
firstFrameReported = true;
}
- events.onByteBufferFrameCaptured(Camera1Session.this, data, captureFormat.width,
- captureFormat.height, getFrameOrientation(), captureTimeNs);
- camera.addCallbackBuffer(data);
+ if (videoFrameEmitTrialEnabled) {
+ VideoFrame.Buffer frameBuffer = new NV21Buffer(data, captureFormat.width,
+ captureFormat.height, () -> cameraThreadHandler.post(() -> {
+ if (state == SessionState.RUNNING) {
+ camera.addCallbackBuffer(data);
+ }
+ }));
+ final VideoFrame frame =
+ new VideoFrame(frameBuffer, getFrameOrientation(), captureTimeNs);
+ events.onFrameCaptured(Camera1Session.this, frame);
+ frame.release();
+ } else {
+ events.onByteBufferFrameCaptured(Camera1Session.this, data, captureFormat.width,
+ captureFormat.height, getFrameOrientation(), captureTimeNs);
+ camera.addCallbackBuffer(data);
+ }
}
});
}
@@ -340,4 +368,6 @@ class Camera1Session implements CameraSession {
throw new IllegalStateException("Wrong thread");
}
}
+
+ private static native void nativeNV21ToI420(int width, int height, byte[] src, ByteBuffer dst);
magjed_webrtc 2017/08/22 08:53:08 This is not used?
sakal 2017/08/22 11:45:30 Done.
}

Powered by Google App Engine
This is Rietveld 408576698