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 MaxBandwidthFilter::MaxBandwidthFilter() | 17 MaxBandwidthFilter::MaxBandwidthFilter() |
18 : bandwidth_last_round_bytes_per_ms_(0), | 18 : bandwidth_last_round_bytes_per_ms_(0), |
19 round_bandwidth_updated_(0), | 19 max_bandwidth_estimate_bps_(0), |
20 max_bandwidth_estimate_bytes_per_ms_(0), | |
21 rounds_without_growth_(0) {} | 20 rounds_without_growth_(0) {} |
22 | 21 |
23 MaxBandwidthFilter::~MaxBandwidthFilter() {} | 22 MaxBandwidthFilter::~MaxBandwidthFilter() {} |
24 | 23 |
25 // Rounds are units for packets rtt_time, after packet has been acknowledged, | 24 // Rounds are units for packets rtt_time, after packet has been acknowledged, |
26 // one round has passed from its send time. | 25 // one round has passed from its send time. |
27 void MaxBandwidthFilter::AddBandwidthSample(int64_t sample_bytes_per_ms, | 26 void MaxBandwidthFilter::AddBandwidthSample(int64_t sample_bps, |
28 int64_t round, | 27 int64_t round, |
29 size_t filter_size_round) { | 28 size_t filter_size_round) { |
30 if (round - round_bandwidth_updated_ >= filter_size_round || | 29 if (bandwidth_samples_[0].first == 0 || |
31 sample_bytes_per_ms >= max_bandwidth_estimate_bytes_per_ms_) { | 30 sample_bps >= bandwidth_samples_[0].first || |
32 max_bandwidth_estimate_bytes_per_ms_ = sample_bytes_per_ms; | 31 round - bandwidth_samples_[2].second >= filter_size_round) |
33 round_bandwidth_updated_ = round; | 32 bandwidth_samples_[0] = bandwidth_samples_[1] = |
| 33 bandwidth_samples_[2] = {sample_bps, round}; |
| 34 if (sample_bps >= bandwidth_samples_[1].first) { |
| 35 bandwidth_samples_[1] = {sample_bps, round}; |
| 36 bandwidth_samples_[2] = bandwidth_samples_[1]; |
| 37 } else { |
| 38 if (sample_bps >= bandwidth_samples_[1].first) |
| 39 bandwidth_samples_[2] = {sample_bps, round}; |
34 } | 40 } |
| 41 if (round - bandwidth_samples_[0].second >= filter_size_round) { |
| 42 bandwidth_samples_[0] = bandwidth_samples_[1]; |
| 43 bandwidth_samples_[1] = bandwidth_samples_[2]; |
| 44 bandwidth_samples_[2] = {sample_bps, round}; |
| 45 if (round - bandwidth_samples_[0].second >= filter_size_round) { |
| 46 bandwidth_samples_[0] = bandwidth_samples_[1]; |
| 47 bandwidth_samples_[1] = bandwidth_samples_[2]; |
| 48 } |
| 49 max_bandwidth_estimate_bps_ = bandwidth_samples_[0].first; |
| 50 return; |
| 51 } |
| 52 if (bandwidth_samples_[1].first == bandwidth_samples_[0].first && |
| 53 round - bandwidth_samples_[1].second > filter_size_round / 4) { |
| 54 bandwidth_samples_[2] = bandwidth_samples_[1] = {sample_bps, round}; |
| 55 max_bandwidth_estimate_bps_ = bandwidth_samples_[0].first; |
| 56 return; |
| 57 } |
| 58 if (bandwidth_samples_[2].first == bandwidth_samples_[1].first && |
| 59 round - bandwidth_samples_[2].second > filter_size_round / 2) |
| 60 bandwidth_samples_[2] = {sample_bps, round}; |
| 61 max_bandwidth_estimate_bps_ = bandwidth_samples_[0].first; |
35 } | 62 } |
36 | 63 |
37 bool MaxBandwidthFilter::FullBandwidthReached(float growth_target, | 64 bool MaxBandwidthFilter::FullBandwidthReached(float growth_target, |
38 int max_rounds_without_growth) { | 65 int max_rounds_without_growth) { |
39 // Minimal bandwidth necessary to assume that better bandwidth can still be | 66 // Minimal bandwidth necessary to assume that better bandwidth can still be |
40 // found and full bandwidth is not reached. | 67 // found and full bandwidth is not reached. |
41 int64_t minimal_bandwidth = | 68 int64_t minimal_bandwidth = |
42 bandwidth_last_round_bytes_per_ms_ * growth_target; | 69 bandwidth_last_round_bytes_per_ms_ * growth_target; |
43 if (max_bandwidth_estimate_bytes_per_ms_ >= minimal_bandwidth) { | 70 if (max_bandwidth_estimate_bps_ >= minimal_bandwidth) { |
44 bandwidth_last_round_bytes_per_ms_ = max_bandwidth_estimate_bytes_per_ms_; | 71 bandwidth_last_round_bytes_per_ms_ = max_bandwidth_estimate_bps_; |
45 rounds_without_growth_ = 0; | 72 rounds_without_growth_ = 0; |
46 return false; | 73 return false; |
47 } | 74 } |
48 rounds_without_growth_++; | 75 rounds_without_growth_++; |
49 return rounds_without_growth_ >= max_rounds_without_growth; | 76 return rounds_without_growth_ >= max_rounds_without_growth; |
50 } | 77 } |
51 } // namespace bwe | 78 } // namespace bwe |
52 } // namespace testing | 79 } // namespace testing |
53 } // namespace webrtc | 80 } // namespace webrtc |
OLD | NEW |