| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2011 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 #include "webrtc/base/bandwidthsmoother.h" | 11 #include "webrtc/base/bandwidthsmoother.h" |
| 12 | 12 |
| 13 #include <limits.h> | 13 #include <limits.h> |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 | 15 |
| 16 namespace rtc { | 16 namespace rtc { |
| 17 | 17 |
| 18 BandwidthSmoother::BandwidthSmoother(int initial_bandwidth_guess, | 18 BandwidthSmoother::BandwidthSmoother(int initial_bandwidth_guess, |
| 19 uint32 time_between_increase, | 19 uint32_t time_between_increase, |
| 20 double percent_increase, | 20 double percent_increase, |
| 21 size_t samples_count_to_average, | 21 size_t samples_count_to_average, |
| 22 double min_sample_count_percent) | 22 double min_sample_count_percent) |
| 23 : time_between_increase_(time_between_increase), | 23 : time_between_increase_(time_between_increase), |
| 24 percent_increase_(std::max(1.0, percent_increase)), | 24 percent_increase_(std::max(1.0, percent_increase)), |
| 25 time_at_last_change_(0), | 25 time_at_last_change_(0), |
| 26 bandwidth_estimation_(initial_bandwidth_guess), | 26 bandwidth_estimation_(initial_bandwidth_guess), |
| 27 accumulator_(samples_count_to_average), | 27 accumulator_(samples_count_to_average), |
| 28 min_sample_count_percent_( | 28 min_sample_count_percent_( |
| 29 std::min(1.0, std::max(0.0, min_sample_count_percent))) { | 29 std::min(1.0, std::max(0.0, min_sample_count_percent))) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 BandwidthSmoother::~BandwidthSmoother() = default; | 32 BandwidthSmoother::~BandwidthSmoother() = default; |
| 33 | 33 |
| 34 // Samples a new bandwidth measurement | 34 // Samples a new bandwidth measurement |
| 35 // returns true if the bandwidth estimation changed | 35 // returns true if the bandwidth estimation changed |
| 36 bool BandwidthSmoother::Sample(uint32 sample_time, int bandwidth) { | 36 bool BandwidthSmoother::Sample(uint32_t sample_time, int bandwidth) { |
| 37 if (bandwidth < 0) { | 37 if (bandwidth < 0) { |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 | 40 |
| 41 accumulator_.AddSample(bandwidth); | 41 accumulator_.AddSample(bandwidth); |
| 42 | 42 |
| 43 if (accumulator_.count() < static_cast<size_t>( | 43 if (accumulator_.count() < static_cast<size_t>( |
| 44 accumulator_.max_count() * min_sample_count_percent_)) { | 44 accumulator_.max_count() * min_sample_count_percent_)) { |
| 45 // We have not collected enough samples yet. | 45 // We have not collected enough samples yet. |
| 46 return false; | 46 return false; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 77 } else { | 77 } else { |
| 78 bandwidth_estimation_ = increase_threshold; | 78 bandwidth_estimation_ = increase_threshold; |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 // Else don't make a change. | 81 // Else don't make a change. |
| 82 | 82 |
| 83 return old_bandwidth_estimation != bandwidth_estimation_; | 83 return old_bandwidth_estimation != bandwidth_estimation_; |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace rtc | 86 } // namespace rtc |
| OLD | NEW |