| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 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 | 11 |
| 12 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/max_bandwidth_
filter.h" | 12 #include "webrtc/modules/remote_bitrate_estimator/test/estimators/max_bandwidth_
filter.h" |
| 13 | 13 |
| 14 namespace webrtc { | 14 namespace webrtc { |
| 15 namespace testing { | 15 namespace testing { |
| 16 namespace bwe { | 16 namespace bwe { |
| 17 |
| 18 const size_t MaxBandwidthFilter::kBandwidthWindowFilterSize; |
| 19 |
| 17 MaxBandwidthFilter::MaxBandwidthFilter() | 20 MaxBandwidthFilter::MaxBandwidthFilter() |
| 18 : bandwidth_last_round_bytes_per_ms_(0), | 21 : bandwidth_last_round_bytes_per_ms_(0), |
| 19 max_bandwidth_estimate_bps_(0), | 22 max_bandwidth_estimate_bps_(0), |
| 20 rounds_without_growth_(0) {} | 23 rounds_without_growth_(0) {} |
| 21 | 24 |
| 22 MaxBandwidthFilter::~MaxBandwidthFilter() {} | 25 MaxBandwidthFilter::~MaxBandwidthFilter() {} |
| 23 | 26 |
| 24 // For detailed explanation about implementing bandwidth filter this way visit | 27 // For detailed explanation about implementing bandwidth filter this way visit |
| 25 // "Bbr design" doc. |sample_bps| was measured during |round|. | 28 // "Bbr design" doc. |sample_bps| was measured during |round|. |
| 26 void MaxBandwidthFilter::AddBandwidthSample(int64_t sample_bps, | 29 void MaxBandwidthFilter::AddBandwidthSample(int64_t sample_bps, int64_t round) { |
| 27 int64_t round, | |
| 28 size_t filter_size_round) { | |
| 29 if (bandwidth_samples_[0].first == 0 || | 30 if (bandwidth_samples_[0].first == 0 || |
| 30 sample_bps >= bandwidth_samples_[0].first || | 31 sample_bps >= bandwidth_samples_[0].first || |
| 31 round - bandwidth_samples_[2].second >= filter_size_round) | 32 round - bandwidth_samples_[2].second >= |
| 33 MaxBandwidthFilter::kBandwidthWindowFilterSize) |
| 32 bandwidth_samples_[0] = bandwidth_samples_[1] = | 34 bandwidth_samples_[0] = bandwidth_samples_[1] = |
| 33 bandwidth_samples_[2] = {sample_bps, round}; | 35 bandwidth_samples_[2] = {sample_bps, round}; |
| 34 if (sample_bps >= bandwidth_samples_[1].first) { | 36 if (sample_bps >= bandwidth_samples_[1].first) { |
| 35 bandwidth_samples_[1] = {sample_bps, round}; | 37 bandwidth_samples_[1] = {sample_bps, round}; |
| 36 bandwidth_samples_[2] = bandwidth_samples_[1]; | 38 bandwidth_samples_[2] = bandwidth_samples_[1]; |
| 37 } else { | 39 } else { |
| 38 if (sample_bps >= bandwidth_samples_[2].first) | 40 if (sample_bps >= bandwidth_samples_[2].first) |
| 39 bandwidth_samples_[2] = {sample_bps, round}; | 41 bandwidth_samples_[2] = {sample_bps, round}; |
| 40 } | 42 } |
| 41 if (round - bandwidth_samples_[0].second >= filter_size_round) { | 43 if (round - bandwidth_samples_[0].second >= |
| 44 MaxBandwidthFilter::kBandwidthWindowFilterSize) { |
| 42 bandwidth_samples_[0] = bandwidth_samples_[1]; | 45 bandwidth_samples_[0] = bandwidth_samples_[1]; |
| 43 bandwidth_samples_[1] = bandwidth_samples_[2]; | 46 bandwidth_samples_[1] = bandwidth_samples_[2]; |
| 44 bandwidth_samples_[2] = {sample_bps, round}; | 47 bandwidth_samples_[2] = {sample_bps, round}; |
| 45 if (round - bandwidth_samples_[0].second >= filter_size_round) { | 48 if (round - bandwidth_samples_[0].second >= |
| 49 MaxBandwidthFilter::kBandwidthWindowFilterSize) { |
| 46 bandwidth_samples_[0] = bandwidth_samples_[1]; | 50 bandwidth_samples_[0] = bandwidth_samples_[1]; |
| 47 bandwidth_samples_[1] = bandwidth_samples_[2]; | 51 bandwidth_samples_[1] = bandwidth_samples_[2]; |
| 48 } | 52 } |
| 49 max_bandwidth_estimate_bps_ = bandwidth_samples_[0].first; | 53 max_bandwidth_estimate_bps_ = bandwidth_samples_[0].first; |
| 50 return; | 54 return; |
| 51 } | 55 } |
| 52 if (bandwidth_samples_[1].first == bandwidth_samples_[0].first && | 56 if (bandwidth_samples_[1].first == bandwidth_samples_[0].first && |
| 53 round - bandwidth_samples_[1].second > filter_size_round / 4) { | 57 round - bandwidth_samples_[1].second > |
| 58 MaxBandwidthFilter::kBandwidthWindowFilterSize / 4) { |
| 54 bandwidth_samples_[2] = bandwidth_samples_[1] = {sample_bps, round}; | 59 bandwidth_samples_[2] = bandwidth_samples_[1] = {sample_bps, round}; |
| 55 max_bandwidth_estimate_bps_ = bandwidth_samples_[0].first; | 60 max_bandwidth_estimate_bps_ = bandwidth_samples_[0].first; |
| 56 return; | 61 return; |
| 57 } | 62 } |
| 58 if (bandwidth_samples_[2].first == bandwidth_samples_[1].first && | 63 if (bandwidth_samples_[2].first == bandwidth_samples_[1].first && |
| 59 round - bandwidth_samples_[2].second > filter_size_round / 2) | 64 round - bandwidth_samples_[2].second > |
| 65 MaxBandwidthFilter::kBandwidthWindowFilterSize / 2) |
| 60 bandwidth_samples_[2] = {sample_bps, round}; | 66 bandwidth_samples_[2] = {sample_bps, round}; |
| 61 max_bandwidth_estimate_bps_ = bandwidth_samples_[0].first; | 67 max_bandwidth_estimate_bps_ = bandwidth_samples_[0].first; |
| 62 } | 68 } |
| 63 | 69 |
| 64 bool MaxBandwidthFilter::FullBandwidthReached(float growth_target, | 70 bool MaxBandwidthFilter::FullBandwidthReached(float growth_target, |
| 65 int max_rounds_without_growth) { | 71 int max_rounds_without_growth) { |
| 66 // Minimal bandwidth necessary to assume that better bandwidth can still be | 72 // Minimal bandwidth necessary to assume that better bandwidth can still be |
| 67 // found and full bandwidth is not reached. | 73 // found and full bandwidth is not reached. |
| 68 int64_t minimal_bandwidth = | 74 int64_t minimal_bandwidth = |
| 69 bandwidth_last_round_bytes_per_ms_ * growth_target; | 75 bandwidth_last_round_bytes_per_ms_ * growth_target; |
| 70 if (max_bandwidth_estimate_bps_ >= minimal_bandwidth) { | 76 if (max_bandwidth_estimate_bps_ >= minimal_bandwidth) { |
| 71 bandwidth_last_round_bytes_per_ms_ = max_bandwidth_estimate_bps_; | 77 bandwidth_last_round_bytes_per_ms_ = max_bandwidth_estimate_bps_; |
| 72 rounds_without_growth_ = 0; | 78 rounds_without_growth_ = 0; |
| 73 return false; | 79 return false; |
| 74 } | 80 } |
| 75 rounds_without_growth_++; | 81 rounds_without_growth_++; |
| 76 return rounds_without_growth_ >= max_rounds_without_growth; | 82 return rounds_without_growth_ >= max_rounds_without_growth; |
| 77 } | 83 } |
| 78 } // namespace bwe | 84 } // namespace bwe |
| 79 } // namespace testing | 85 } // namespace testing |
| 80 } // namespace webrtc | 86 } // namespace webrtc |
| OLD | NEW |