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

Side by Side Diff: webrtc/examples/androidapp/src/org/appspot/apprtc/CaptureQualityController.java

Issue 2010763003: Android: Add FramerateRange class (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Make constant static 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/api/java/jni/androidvideocapturer_jni.cc ('k') | no next file » | 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 height = 0; 70 height = 0;
71 framerate = 0; 71 framerate = 0;
72 captureFormatText.setText(R.string.muted); 72 captureFormatText.setText(R.string.muted);
73 return; 73 return;
74 } 74 }
75 75
76 // Extract max bandwidth (in millipixels / second). 76 // Extract max bandwidth (in millipixels / second).
77 long maxCaptureBandwidth = java.lang.Long.MIN_VALUE; 77 long maxCaptureBandwidth = java.lang.Long.MIN_VALUE;
78 for (CaptureFormat format : formats) { 78 for (CaptureFormat format : formats) {
79 maxCaptureBandwidth = Math.max(maxCaptureBandwidth, 79 maxCaptureBandwidth = Math.max(maxCaptureBandwidth,
80 (long) format.width * format.height * format.maxFramerate); 80 (long) format.width * format.height * format.framerate.max);
81 } 81 }
82 82
83 // Fraction between 0 and 1. 83 // Fraction between 0 and 1.
84 double bandwidthFraction = (double) progress / 100.0; 84 double bandwidthFraction = (double) progress / 100.0;
85 // Make a log-scale transformation, still between 0 and 1. 85 // Make a log-scale transformation, still between 0 and 1.
86 final double kExpConstant = 3.0; 86 final double kExpConstant = 3.0;
87 bandwidthFraction = 87 bandwidthFraction =
88 (Math.exp(kExpConstant * bandwidthFraction) - 1) / (Math.exp(kExpConstan t) - 1); 88 (Math.exp(kExpConstant * bandwidthFraction) - 1) / (Math.exp(kExpConstan t) - 1);
89 targetBandwidth = bandwidthFraction * maxCaptureBandwidth; 89 targetBandwidth = bandwidthFraction * maxCaptureBandwidth;
90 90
91 // Choose the best format given a target bandwidth. 91 // Choose the best format given a target bandwidth.
92 final CaptureFormat bestFormat = Collections.max(formats, compareFormats); 92 final CaptureFormat bestFormat = Collections.max(formats, compareFormats);
93 width = bestFormat.width; 93 width = bestFormat.width;
94 height = bestFormat.height; 94 height = bestFormat.height;
95 framerate = calculateFramerate(targetBandwidth, bestFormat); 95 framerate = calculateFramerate(targetBandwidth, bestFormat);
96 captureFormatText.setText(width + "x" + height + " @ " + framerate + "fps"); 96 captureFormatText.setText(width + "x" + height + " @ " + framerate + "fps");
97 } 97 }
98 98
99 @Override 99 @Override
100 public void onStartTrackingTouch(SeekBar seekBar) { 100 public void onStartTrackingTouch(SeekBar seekBar) {
101 } 101 }
102 102
103 @Override 103 @Override
104 public void onStopTrackingTouch(SeekBar seekBar) { 104 public void onStopTrackingTouch(SeekBar seekBar) {
105 callEvents.onCaptureFormatChange(width, height, framerate); 105 callEvents.onCaptureFormatChange(width, height, framerate);
106 } 106 }
107 107
108 // Return the highest frame rate possible based on bandwidth and format. 108 // Return the highest frame rate possible based on bandwidth and format.
109 private int calculateFramerate(double bandwidth, CaptureFormat format) { 109 private int calculateFramerate(double bandwidth, CaptureFormat format) {
110 return (int) Math.round(Math.min(format.maxFramerate, 110 return (int) Math.round(Math.min(format.framerate.max,
111 (int) Math.round(bandwidth / (format.width * format.height))) / 1000.0); 111 (int) Math.round(bandwidth / (format.width * format.height))) / 1000.0);
112 } 112 }
113 } 113 }
114 114
OLDNEW
« no previous file with comments | « webrtc/api/java/jni/androidvideocapturer_jni.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698