OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 15 matching lines...) Expand all Loading... |
26 constexpr int kProbeDeltasPerCluster = 5; | 26 constexpr int kProbeDeltasPerCluster = 5; |
27 | 27 |
28 // Maximum waiting time from the time of initiating probing to getting | 28 // Maximum waiting time from the time of initiating probing to getting |
29 // the measured results back. | 29 // the measured results back. |
30 constexpr int64_t kMaxWaitingTimeForProbingResultMs = 1000; | 30 constexpr int64_t kMaxWaitingTimeForProbingResultMs = 1000; |
31 | 31 |
32 // Value of |min_bitrate_to_probe_further_bps_| that indicates | 32 // Value of |min_bitrate_to_probe_further_bps_| that indicates |
33 // further probing is disabled. | 33 // further probing is disabled. |
34 constexpr int kExponentialProbingDisabled = 0; | 34 constexpr int kExponentialProbingDisabled = 0; |
35 | 35 |
36 // A limit to prevent probing at excessive bitrates. | 36 // Default probing bitrate limit. Applied only when the application didn't |
37 constexpr int kMaxProbingBitrateBps = 10000000; | 37 // specify max bitrate. |
| 38 constexpr int kDefaultMaxProbingBitrateBps = 100000000; |
38 | 39 |
39 // This is a limit on how often probing can be done when there is a BW | 40 // This is a limit on how often probing can be done when there is a BW |
40 // drop detected in ALR region. | 41 // drop detected in ALR region. |
41 constexpr int kAlrProbingIntervalLimitMs = 5000; | 42 constexpr int kAlrProbingIntervalLimitMs = 5000; |
42 | 43 |
43 } // namespace | 44 } // namespace |
44 | 45 |
45 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) | 46 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) |
46 : pacer_(pacer), | 47 : pacer_(pacer), |
47 clock_(clock), | 48 clock_(clock), |
48 state_(State::kInit), | 49 state_(State::kInit), |
49 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), | 50 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), |
50 time_last_probing_initiated_ms_(0), | 51 time_last_probing_initiated_ms_(0), |
51 estimated_bitrate_bps_(0), | 52 estimated_bitrate_bps_(0), |
52 max_bitrate_bps_(0), | 53 max_bitrate_bps_(0), |
53 last_alr_probing_time_(clock_->TimeInMilliseconds()) {} | 54 last_alr_probing_time_(clock_->TimeInMilliseconds()) {} |
54 | 55 |
55 void ProbeController::SetBitrates(int min_bitrate_bps, | 56 void ProbeController::SetBitrates(int min_bitrate_bps, |
56 int start_bitrate_bps, | 57 int start_bitrate_bps, |
57 int max_bitrate_bps) { | 58 int max_bitrate_bps) { |
58 rtc::CritScope cs(&critsect_); | 59 rtc::CritScope cs(&critsect_); |
59 if (state_ == State::kInit) { | 60 if (state_ == State::kInit) { |
60 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | 61 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of |
61 // 1.2 Mbps to continue probing. | 62 // 1.2 Mbps to continue probing. |
62 InitiateProbing({3 * start_bitrate_bps, 6 * start_bitrate_bps}, | 63 InitiateProbing({3 * start_bitrate_bps, 6 * start_bitrate_bps}, |
63 4 * start_bitrate_bps); | 64 4 * start_bitrate_bps); |
64 } | 65 } |
65 | 66 |
| 67 int old_max_bitrate_bps = max_bitrate_bps_; |
| 68 max_bitrate_bps_ = max_bitrate_bps; |
| 69 |
66 // Only do probing if: | 70 // Only do probing if: |
67 // we are mid-call, which we consider to be if | 71 // we are mid-call, which we consider to be if |
68 // exponential probing is not active and | 72 // exponential probing is not active and |
69 // |estimated_bitrate_bps_| is valid (> 0) and | 73 // |estimated_bitrate_bps_| is valid (> 0) and |
70 // the current bitrate is lower than the new |max_bitrate_bps|, and | 74 // the current bitrate is lower than the new |max_bitrate_bps|, and |
71 // we actually want to increase the |max_bitrate_bps_|. | 75 // |max_bitrate_bps_| was increased. |
72 if (state_ != State::kWaitingForProbingResult && | 76 if (state_ != State::kWaitingForProbingResult && |
73 estimated_bitrate_bps_ != 0 && estimated_bitrate_bps_ < max_bitrate_bps && | 77 estimated_bitrate_bps_ != 0 && |
74 max_bitrate_bps > max_bitrate_bps_) { | 78 estimated_bitrate_bps_ < old_max_bitrate_bps && |
| 79 max_bitrate_bps_ > old_max_bitrate_bps) { |
75 InitiateProbing({max_bitrate_bps}, kExponentialProbingDisabled); | 80 InitiateProbing({max_bitrate_bps}, kExponentialProbingDisabled); |
76 } | 81 } |
77 max_bitrate_bps_ = max_bitrate_bps; | |
78 } | 82 } |
79 | 83 |
80 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { | 84 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { |
81 rtc::CritScope cs(&critsect_); | 85 rtc::CritScope cs(&critsect_); |
82 if (state_ == State::kWaitingForProbingResult) { | 86 if (state_ == State::kWaitingForProbingResult) { |
83 if ((clock_->TimeInMilliseconds() - time_last_probing_initiated_ms_) > | 87 if ((clock_->TimeInMilliseconds() - time_last_probing_initiated_ms_) > |
84 kMaxWaitingTimeForProbingResultMs) { | 88 kMaxWaitingTimeForProbingResultMs) { |
85 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; | 89 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; |
86 state_ = State::kProbingComplete; | 90 state_ = State::kProbingComplete; |
87 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | 91 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // drop due to exogenous event. | 128 // drop due to exogenous event. |
125 } | 129 } |
126 estimated_bitrate_bps_ = bitrate_bps; | 130 estimated_bitrate_bps_ = bitrate_bps; |
127 } | 131 } |
128 | 132 |
129 void ProbeController::InitiateProbing( | 133 void ProbeController::InitiateProbing( |
130 std::initializer_list<int> bitrates_to_probe, | 134 std::initializer_list<int> bitrates_to_probe, |
131 int min_bitrate_to_probe_further_bps) { | 135 int min_bitrate_to_probe_further_bps) { |
132 bool first_cluster = true; | 136 bool first_cluster = true; |
133 for (int bitrate : bitrates_to_probe) { | 137 for (int bitrate : bitrates_to_probe) { |
134 bitrate = std::min(bitrate, kMaxProbingBitrateBps); | 138 int max_probe_bitrate_bps = |
| 139 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; |
| 140 bitrate = std::min(bitrate, max_probe_bitrate_bps); |
135 if (first_cluster) { | 141 if (first_cluster) { |
136 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); | 142 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); |
137 first_cluster = false; | 143 first_cluster = false; |
138 } else { | 144 } else { |
139 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); | 145 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); |
140 } | 146 } |
141 } | 147 } |
142 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; | 148 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; |
143 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); | 149 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); |
144 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) | 150 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) |
145 state_ = State::kProbingComplete; | 151 state_ = State::kProbingComplete; |
146 else | 152 else |
147 state_ = State::kWaitingForProbingResult; | 153 state_ = State::kWaitingForProbingResult; |
148 } | 154 } |
149 | 155 |
150 } // namespace webrtc | 156 } // namespace webrtc |
OLD | NEW |