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

Side by Side 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: Fix error. Created 3 years, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 package org.webrtc; 11 package org.webrtc;
12 12
13 import android.annotation.TargetApi; 13 import android.annotation.TargetApi;
14 import android.content.Context; 14 import android.content.Context;
15 import android.graphics.Matrix;
15 import android.graphics.SurfaceTexture; 16 import android.graphics.SurfaceTexture;
16 import android.hardware.camera2.CameraAccessException; 17 import android.hardware.camera2.CameraAccessException;
17 import android.hardware.camera2.CameraCaptureSession; 18 import android.hardware.camera2.CameraCaptureSession;
18 import android.hardware.camera2.CameraCharacteristics; 19 import android.hardware.camera2.CameraCharacteristics;
19 import android.hardware.camera2.CameraDevice; 20 import android.hardware.camera2.CameraDevice;
20 import android.hardware.camera2.CameraManager; 21 import android.hardware.camera2.CameraManager;
21 import android.hardware.camera2.CameraMetadata; 22 import android.hardware.camera2.CameraMetadata;
22 import android.hardware.camera2.CaptureFailure; 23 import android.hardware.camera2.CaptureFailure;
23 import android.hardware.camera2.CaptureRequest; 24 import android.hardware.camera2.CaptureRequest;
24 import android.media.MediaRecorder; 25 import android.media.MediaRecorder;
(...skipping 12 matching lines...) Expand all
37 38
38 private static final Histogram camera2StartTimeMsHistogram = 39 private static final Histogram camera2StartTimeMsHistogram =
39 Histogram.createCounts("WebRTC.Android.Camera2.StartTimeMs", 1, 10000, 50) ; 40 Histogram.createCounts("WebRTC.Android.Camera2.StartTimeMs", 1, 10000, 50) ;
40 private static final Histogram camera2StopTimeMsHistogram = 41 private static final Histogram camera2StopTimeMsHistogram =
41 Histogram.createCounts("WebRTC.Android.Camera2.StopTimeMs", 1, 10000, 50); 42 Histogram.createCounts("WebRTC.Android.Camera2.StopTimeMs", 1, 10000, 50);
42 private static final Histogram camera2ResolutionHistogram = Histogram.createEn umeration( 43 private static final Histogram camera2ResolutionHistogram = Histogram.createEn umeration(
43 "WebRTC.Android.Camera2.Resolution", CameraEnumerationAndroid.COMMON_RESOL UTIONS.size()); 44 "WebRTC.Android.Camera2.Resolution", CameraEnumerationAndroid.COMMON_RESOL UTIONS.size());
44 45
45 private static enum SessionState { RUNNING, STOPPED } 46 private static enum SessionState { RUNNING, STOPPED }
46 47
48 private final boolean videoFrameEmitTrialEnabled;
49
47 private final Handler cameraThreadHandler; 50 private final Handler cameraThreadHandler;
48 private final CreateSessionCallback callback; 51 private final CreateSessionCallback callback;
49 private final Events events; 52 private final Events events;
50 private final Context applicationContext; 53 private final Context applicationContext;
51 private final CameraManager cameraManager; 54 private final CameraManager cameraManager;
52 private final SurfaceTextureHelper surfaceTextureHelper; 55 private final SurfaceTextureHelper surfaceTextureHelper;
53 private final Surface mediaRecorderSurface; 56 private final Surface mediaRecorderSurface;
54 private final String cameraId; 57 private final String cameraId;
55 private final int width; 58 private final int width;
56 private final int height; 59 private final int height;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 // Undo the mirror that the OS "helps" us with. 221 // Undo the mirror that the OS "helps" us with.
219 // http://developer.android.com/reference/android/hardware/Camer a.html#setDisplayOrientation(int) 222 // http://developer.android.com/reference/android/hardware/Camer a.html#setDisplayOrientation(int)
220 transformMatrix = RendererCommon.multiplyMatrices( 223 transformMatrix = RendererCommon.multiplyMatrices(
221 transformMatrix, RendererCommon.horizontalFlipMatrix()); 224 transformMatrix, RendererCommon.horizontalFlipMatrix());
222 } 225 }
223 226
224 // Undo camera orientation - we report it as rotation instead. 227 // Undo camera orientation - we report it as rotation instead.
225 transformMatrix = 228 transformMatrix =
226 RendererCommon.rotateTextureMatrix(transformMatrix, -cameraOri entation); 229 RendererCommon.rotateTextureMatrix(transformMatrix, -cameraOri entation);
227 230
228 events.onTextureFrameCaptured(Camera2Session.this, captureFormat.w idth, 231 if (videoFrameEmitTrialEnabled) {
229 captureFormat.height, oesTextureId, transformMatrix, rotation, timestampNs); 232 VideoFrame.Buffer buffer = surfaceTextureHelper.createTextureBuf fer(
233 captureFormat.width, captureFormat.height,
234 RendererCommon.convertMatrixToAndroidGraphicsMatrix(transfor mMatrix));
235 final VideoFrame frame = new VideoFrame(buffer, rotation, timest ampNs);
236 events.onFrameCaptured(Camera2Session.this, frame);
237 frame.release();
238 } else {
239 events.onTextureFrameCaptured(Camera2Session.this, captureFormat .width,
240 captureFormat.height, oesTextureId, transformMatrix, rotatio n, timestampNs);
241 }
230 } 242 }
231 }); 243 });
232 Logging.d(TAG, "Camera device successfully started."); 244 Logging.d(TAG, "Camera device successfully started.");
233 callback.onDone(Camera2Session.this); 245 callback.onDone(Camera2Session.this);
234 } 246 }
235 247
236 // Prefers optical stabilization over software stabilization if available. O nly enables one of 248 // Prefers optical stabilization over software stabilization if available. O nly enables one of
237 // the stabilization modes at a time because having both enabled can cause s trange results. 249 // the stabilization modes at a time because having both enabled can cause s trange results.
238 private void chooseStabilizationMode(CaptureRequest.Builder captureRequestBu ilder) { 250 private void chooseStabilizationMode(CaptureRequest.Builder captureRequestBu ilder) {
239 final int[] availableOpticalStabilization = cameraCharacteristics.get( 251 final int[] availableOpticalStabilization = cameraCharacteristics.get(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecorder, St ring cameraId, 306 SurfaceTextureHelper surfaceTextureHelper, MediaRecorder mediaRecorder, St ring cameraId,
295 int width, int height, int framerate) { 307 int width, int height, int framerate) {
296 new Camera2Session(callback, events, applicationContext, cameraManager, surf aceTextureHelper, 308 new Camera2Session(callback, events, applicationContext, cameraManager, surf aceTextureHelper,
297 mediaRecorder, cameraId, width, height, framerate); 309 mediaRecorder, cameraId, width, height, framerate);
298 } 310 }
299 311
300 private Camera2Session(CreateSessionCallback callback, Events events, Context applicationContext, 312 private Camera2Session(CreateSessionCallback callback, Events events, Context applicationContext,
301 CameraManager cameraManager, SurfaceTextureHelper surfaceTextureHelper, 313 CameraManager cameraManager, SurfaceTextureHelper surfaceTextureHelper,
302 MediaRecorder mediaRecorder, String cameraId, int width, int height, int f ramerate) { 314 MediaRecorder mediaRecorder, String cameraId, int width, int height, int f ramerate) {
303 Logging.d(TAG, "Create new camera2 session on camera " + cameraId); 315 Logging.d(TAG, "Create new camera2 session on camera " + cameraId);
316 videoFrameEmitTrialEnabled =
317 PeerConnectionFactory.fieldTrialsFindFullName(PeerConnectionFactory.VIDE O_FRAME_EMIT_TRIAL)
318 .equals(PeerConnectionFactory.TRIAL_ENABLED);
304 319
305 constructionTimeNs = System.nanoTime(); 320 constructionTimeNs = System.nanoTime();
306 321
307 this.cameraThreadHandler = new Handler(); 322 this.cameraThreadHandler = new Handler();
308 this.callback = callback; 323 this.callback = callback;
309 this.events = events; 324 this.events = events;
310 this.applicationContext = applicationContext; 325 this.applicationContext = applicationContext;
311 this.cameraManager = cameraManager; 326 this.cameraManager = cameraManager;
312 this.surfaceTextureHelper = surfaceTextureHelper; 327 this.surfaceTextureHelper = surfaceTextureHelper;
313 this.mediaRecorderSurface = (mediaRecorder != null) ? mediaRecorder.getSurfa ce() : null; 328 this.mediaRecorderSurface = (mediaRecorder != null) ? mediaRecorder.getSurfa ce() : null;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 } 471 }
457 return (cameraOrientation + rotation) % 360; 472 return (cameraOrientation + rotation) % 360;
458 } 473 }
459 474
460 private void checkIsOnCameraThread() { 475 private void checkIsOnCameraThread() {
461 if (Thread.currentThread() != cameraThreadHandler.getLooper().getThread()) { 476 if (Thread.currentThread() != cameraThreadHandler.getLooper().getThread()) {
462 throw new IllegalStateException("Wrong thread"); 477 throw new IllegalStateException("Wrong thread");
463 } 478 }
464 } 479 }
465 } 480 }
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/java/org/webrtc/Camera1Session.java ('k') | webrtc/sdk/android/src/java/org/webrtc/CameraCapturer.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698