OLD | NEW |
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 private final Comparator<CaptureFormat> compareFormats = new Comparator<Captur
eFormat>() { | 49 private final Comparator<CaptureFormat> compareFormats = new Comparator<Captur
eFormat>() { |
50 @Override | 50 @Override |
51 public int compare(CaptureFormat first, CaptureFormat second) { | 51 public int compare(CaptureFormat first, CaptureFormat second) { |
52 int firstFps = calculateFramerate(targetBandwidth, first); | 52 int firstFps = calculateFramerate(targetBandwidth, first); |
53 int secondFps = calculateFramerate(targetBandwidth, second); | 53 int secondFps = calculateFramerate(targetBandwidth, second); |
54 | 54 |
55 if (firstFps >= FRAMERATE_THRESHOLD && secondFps >= FRAMERATE_THRESHOLD | 55 if (firstFps >= FRAMERATE_THRESHOLD && secondFps >= FRAMERATE_THRESHOLD |
56 || firstFps == secondFps) { | 56 || firstFps == secondFps) { |
57 // Compare resolution. | 57 // Compare resolution. |
58 return first.width * first.height - second.width * second.height; | 58 return first.size.width * first.size.height - second.size.width * second
.size.height; |
59 } else { | 59 } else { |
60 // Compare fps. | 60 // Compare fps. |
61 return firstFps - secondFps; | 61 return firstFps - secondFps; |
62 } | 62 } |
63 } | 63 } |
64 }; | 64 }; |
65 | 65 |
66 @Override | 66 @Override |
67 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{ | 67 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
{ |
68 if (progress == 0) { | 68 if (progress == 0) { |
69 width = 0; | 69 width = 0; |
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.size.width * format.size.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.size.width; |
94 height = bestFormat.height; | 94 height = bestFormat.size.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.size.width * format.size.height)))
/ 1000.0); |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
OLD | NEW |