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

Side by Side Diff: webrtc/api/java/android/org/webrtc/CameraEnumerationAndroid.java

Issue 2021233002: Revert of Android: Change camera fps range selection (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « webrtc/androidjunit/src/org/webrtc/CameraEnumerationTest.java ('k') | webrtc/webrtc_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 private static abstract class ClosestComparator<T> implements Comparator<T> { 174 private static abstract class ClosestComparator<T> implements Comparator<T> {
175 // Difference between supported and requested parameter. 175 // Difference between supported and requested parameter.
176 abstract int diff(T supportedParameter); 176 abstract int diff(T supportedParameter);
177 177
178 @Override 178 @Override
179 public int compare(T t1, T t2) { 179 public int compare(T t1, T t2) {
180 return diff(t1) - diff(t2); 180 return diff(t1) - diff(t2);
181 } 181 }
182 } 182 }
183 183
184 // Prefer a fps range with an upper bound close to |framerate|. Also prefer a fps range with a low
185 // lower bound, to allow the framerate to fluctuate based on lightning conditi ons.
186 public static CaptureFormat.FramerateRange getClosestSupportedFramerateRange( 184 public static CaptureFormat.FramerateRange getClosestSupportedFramerateRange(
187 List<CaptureFormat.FramerateRange> supportedFramerates, final int requeste dFps) { 185 List<CaptureFormat.FramerateRange> supportedFramerates, final int requeste dFps) {
188 return Collections.min(supportedFramerates, 186 return Collections.min(supportedFramerates,
189 new ClosestComparator<CaptureFormat.FramerateRange>() { 187 new ClosestComparator<CaptureFormat.FramerateRange>() {
190 // Progressive penalty if the upper bound is further away than |MAX_FP S_DIFF_THRESHOLD| 188 private static final int MAX_FPS_WEIGHT = 10;
191 // from requested.
192 private static final int MAX_FPS_DIFF_THRESHOLD = 5000;
193 private static final int MAX_FPS_LOW_DIFF_WEIGHT = 1;
194 private static final int MAX_FPS_HIGH_DIFF_WEIGHT = 3;
195
196 // Progressive penalty if the lower bound is bigger than |MIN_FPS_THRE SHOLD|.
197 private static final int MIN_FPS_THRESHOLD = 8000;
198 private static final int MIN_FPS_LOW_VALUE_WEIGHT = 1;
199 private static final int MIN_FPS_HIGH_VALUE_WEIGHT = 4;
200
201 // Use one weight for small |value| less than |threshold|, and another weight above.
202 private int progressivePenalty(int value, int threshold, int lowWeight , int highWeight) {
203 return (value < threshold)
204 ? value * lowWeight
205 : threshold * lowWeight + (value - threshold) * highWeight;
206 }
207 189
208 @Override 190 @Override
209 int diff(CaptureFormat.FramerateRange range) { 191 int diff(CaptureFormat.FramerateRange range) {
210 final int minFpsError = progressivePenalty(range.min, 192 return range.min + MAX_FPS_WEIGHT * abs(requestedFps * 1000 - range. max);
211 MIN_FPS_THRESHOLD, MIN_FPS_LOW_VALUE_WEIGHT, MIN_FPS_HIGH_VALUE_ WEIGHT);
212 final int maxFpsError = progressivePenalty(Math.abs(requestedFps * 1 000 - range.max),
213 MAX_FPS_DIFF_THRESHOLD, MAX_FPS_LOW_DIFF_WEIGHT, MAX_FPS_HIGH_DI FF_WEIGHT);
214 return minFpsError + maxFpsError;
215 } 193 }
216 }); 194 });
217 } 195 }
218 196
219 public static android.hardware.Camera.Size getClosestSupportedSize( 197 public static android.hardware.Camera.Size getClosestSupportedSize(
220 List<android.hardware.Camera.Size> supportedSizes, final int requestedWidt h, 198 List<android.hardware.Camera.Size> supportedSizes, final int requestedWidt h,
221 final int requestedHeight) { 199 final int requestedHeight) {
222 return Collections.min(supportedSizes, 200 return Collections.min(supportedSizes,
223 new ClosestComparator<android.hardware.Camera.Size>() { 201 new ClosestComparator<android.hardware.Camera.Size>() {
224 @Override int diff(android.hardware.Camera.Size size) { 202 @Override int diff(android.hardware.Camera.Size size) {
(...skipping 10 matching lines...) Expand all
235 if (info.facing == facing) { 213 if (info.facing == facing) {
236 return getDeviceName(i); 214 return getDeviceName(i);
237 } 215 }
238 } catch (Exception e) { 216 } catch (Exception e) {
239 Logging.e(TAG, "getCameraInfo() failed on index " + i, e); 217 Logging.e(TAG, "getCameraInfo() failed on index " + i, e);
240 } 218 }
241 } 219 }
242 return null; 220 return null;
243 } 221 }
244 } 222 }
OLDNEW
« no previous file with comments | « webrtc/androidjunit/src/org/webrtc/CameraEnumerationTest.java ('k') | webrtc/webrtc_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698