| 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 |
| 11 package org.appspot.apprtc; | 11 package org.appspot.apprtc; |
| 12 | 12 |
| 13 import android.widget.SeekBar; | 13 import android.widget.SeekBar; |
| 14 import android.widget.TextView; | 14 import android.widget.TextView; |
| 15 | |
| 16 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; | |
| 17 | |
| 18 import java.util.Arrays; | 15 import java.util.Arrays; |
| 19 import java.util.Collections; | 16 import java.util.Collections; |
| 20 import java.util.Comparator; | 17 import java.util.Comparator; |
| 21 import java.util.List; | 18 import java.util.List; |
| 19 import org.webrtc.CameraEnumerationAndroid.CaptureFormat; |
| 22 | 20 |
| 23 /** | 21 /** |
| 24 * Control capture format based on a seekbar listener. | 22 * Control capture format based on a seekbar listener. |
| 25 */ | 23 */ |
| 26 public class CaptureQualityController implements SeekBar.OnSeekBarChangeListener
{ | 24 public class CaptureQualityController implements SeekBar.OnSeekBarChangeListener
{ |
| 27 private final List<CaptureFormat> formats = | 25 private final List<CaptureFormat> formats = |
| 28 Arrays.asList(new CaptureFormat(1280, 720, 0, 30000), new CaptureFormat(96
0, 540, 0, 30000), | 26 Arrays.asList(new CaptureFormat(1280, 720, 0, 30000), new CaptureFormat(96
0, 540, 0, 30000), |
| 29 new CaptureFormat(640, 480, 0, 30000), new CaptureFormat(480, 360, 0,
30000), | 27 new CaptureFormat(640, 480, 0, 30000), new CaptureFormat(480, 360, 0,
30000), |
| 30 new CaptureFormat(320, 240, 0, 30000), new CaptureFormat(256, 144, 0,
30000)); | 28 new CaptureFormat(320, 240, 0, 30000), new CaptureFormat(256, 144, 0,
30000)); |
| 31 // Prioritize framerate below this threshold and resolution above the threshol
d. | 29 // Prioritize framerate below this threshold and resolution above the threshol
d. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 final double kExpConstant = 3.0; | 81 final double kExpConstant = 3.0; |
| 84 bandwidthFraction = | 82 bandwidthFraction = |
| 85 (Math.exp(kExpConstant * bandwidthFraction) - 1) / (Math.exp(kExpConstan
t) - 1); | 83 (Math.exp(kExpConstant * bandwidthFraction) - 1) / (Math.exp(kExpConstan
t) - 1); |
| 86 targetBandwidth = bandwidthFraction * maxCaptureBandwidth; | 84 targetBandwidth = bandwidthFraction * maxCaptureBandwidth; |
| 87 | 85 |
| 88 // Choose the best format given a target bandwidth. | 86 // Choose the best format given a target bandwidth. |
| 89 final CaptureFormat bestFormat = Collections.max(formats, compareFormats); | 87 final CaptureFormat bestFormat = Collections.max(formats, compareFormats); |
| 90 width = bestFormat.width; | 88 width = bestFormat.width; |
| 91 height = bestFormat.height; | 89 height = bestFormat.height; |
| 92 framerate = calculateFramerate(targetBandwidth, bestFormat); | 90 framerate = calculateFramerate(targetBandwidth, bestFormat); |
| 93 captureFormatText.setText(width + "x" + height + " @ " + framerate + "fps"); | 91 captureFormatText.setText( |
| 92 String.format(captureFormatText.getContext().getString(R.string.format_d
escription), width, |
| 93 height, framerate)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 @Override | 96 @Override |
| 97 public void onStartTrackingTouch(SeekBar seekBar) {} | 97 public void onStartTrackingTouch(SeekBar seekBar) {} |
| 98 | 98 |
| 99 @Override | 99 @Override |
| 100 public void onStopTrackingTouch(SeekBar seekBar) { | 100 public void onStopTrackingTouch(SeekBar seekBar) { |
| 101 callEvents.onCaptureFormatChange(width, height, framerate); | 101 callEvents.onCaptureFormatChange(width, height, framerate); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // Return the highest frame rate possible based on bandwidth and format. | 104 // Return the highest frame rate possible based on bandwidth and format. |
| 105 private int calculateFramerate(double bandwidth, CaptureFormat format) { | 105 private int calculateFramerate(double bandwidth, CaptureFormat format) { |
| 106 return (int) Math.round( | 106 return (int) Math.round( |
| 107 Math.min(format.framerate.max, (int) Math.round(bandwidth / (format.widt
h * format.height))) | 107 Math.min(format.framerate.max, (int) Math.round(bandwidth / (format.widt
h * format.height))) |
| 108 / 1000.0); | 108 / 1000.0); |
| 109 } | 109 } |
| 110 } | 110 } |
| OLD | NEW |