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

Side by Side Diff: webrtc/sdk/android/api/org/webrtc/CameraVideoCapturer.java

Issue 2821373003: Android: Move CameraStatistics from API to src (Closed)
Patch Set: Created 3 years, 8 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
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // Invoked on failure, e.g. camera is stopped or only one camera available. 52 // Invoked on failure, e.g. camera is stopped or only one camera available.
53 void onCameraSwitchError(String errorDescription); 53 void onCameraSwitchError(String errorDescription);
54 } 54 }
55 55
56 /** 56 /**
57 * Switch camera to the next valid camera id. This can only be called while th e camera is running. 57 * Switch camera to the next valid camera id. This can only be called while th e camera is running.
58 * This function can be called from any thread. 58 * This function can be called from any thread.
59 */ 59 */
60 void switchCamera(CameraSwitchHandler switchEventsHandler); 60 void switchCamera(CameraSwitchHandler switchEventsHandler);
61
62 /**
63 * Helper class to log framerate and detect if the camera freezes. It will run periodic callbacks
64 * on the SurfaceTextureHelper thread passed in the ctor, and should only be o perated from that
65 * thread.
66 */
67 public static class CameraStatistics {
68 private final static String TAG = "CameraStatistics";
69 private final static int CAMERA_OBSERVER_PERIOD_MS = 2000;
70 private final static int CAMERA_FREEZE_REPORT_TIMOUT_MS = 4000;
71
72 private final SurfaceTextureHelper surfaceTextureHelper;
73 private final CameraEventsHandler eventsHandler;
74 private int frameCount;
75 private int freezePeriodCount;
76 // Camera observer - monitors camera framerate. Observer is executed on came ra thread.
77 private final Runnable cameraObserver = new Runnable() {
78 @Override
79 public void run() {
80 final int cameraFps = Math.round(frameCount * 1000.0f / CAMERA_OBSERVER_ PERIOD_MS);
81 Logging.d(TAG, "Camera fps: " + cameraFps + ".");
82 if (frameCount == 0) {
83 ++freezePeriodCount;
84 if (CAMERA_OBSERVER_PERIOD_MS * freezePeriodCount >= CAMERA_FREEZE_REP ORT_TIMOUT_MS
85 && eventsHandler != null) {
86 Logging.e(TAG, "Camera freezed.");
87 if (surfaceTextureHelper.isTextureInUse()) {
88 // This can only happen if we are capturing to textures.
89 eventsHandler.onCameraFreezed("Camera failure. Client must return video buffers.");
90 } else {
91 eventsHandler.onCameraFreezed("Camera failure.");
92 }
93 return;
94 }
95 } else {
96 freezePeriodCount = 0;
97 }
98 frameCount = 0;
99 surfaceTextureHelper.getHandler().postDelayed(this, CAMERA_OBSERVER_PERI OD_MS);
100 }
101 };
102
103 public CameraStatistics(
104 SurfaceTextureHelper surfaceTextureHelper, CameraEventsHandler eventsHan dler) {
105 if (surfaceTextureHelper == null) {
106 throw new IllegalArgumentException("SurfaceTextureHelper is null");
107 }
108 this.surfaceTextureHelper = surfaceTextureHelper;
109 this.eventsHandler = eventsHandler;
110 this.frameCount = 0;
111 this.freezePeriodCount = 0;
112 surfaceTextureHelper.getHandler().postDelayed(cameraObserver, CAMERA_OBSER VER_PERIOD_MS);
113 }
114
115 private void checkThread() {
116 if (Thread.currentThread() != surfaceTextureHelper.getHandler().getLooper( ).getThread()) {
117 throw new IllegalStateException("Wrong thread");
118 }
119 }
120
121 public void addFrame() {
122 checkThread();
123 ++frameCount;
124 }
125
126 public void release() {
127 surfaceTextureHelper.getHandler().removeCallbacks(cameraObserver);
128 }
129 }
130 } 61 }
OLDNEW
« no previous file with comments | « webrtc/sdk/android/BUILD.gn ('k') | webrtc/sdk/android/src/java/org/webrtc/CameraStatistics.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698