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 28 matching lines...) Loading... | |
39 | 39 |
40 // 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 |
41 // drop detected in ALR region. | 41 // drop detected in ALR region. |
42 constexpr int kAlrProbingIntervalLimitMs = 5000; | 42 constexpr int kAlrProbingIntervalLimitMs = 5000; |
43 | 43 |
44 } // namespace | 44 } // namespace |
45 | 45 |
46 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) | 46 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) |
47 : pacer_(pacer), | 47 : pacer_(pacer), |
48 clock_(clock), | 48 clock_(clock), |
49 network_state_(kNetworkUp), | |
49 state_(State::kInit), | 50 state_(State::kInit), |
50 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), | 51 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), |
51 time_last_probing_initiated_ms_(0), | 52 time_last_probing_initiated_ms_(0), |
52 estimated_bitrate_bps_(0), | 53 estimated_bitrate_bps_(0), |
54 start_bitrate_bps_(0), | |
53 max_bitrate_bps_(0), | 55 max_bitrate_bps_(0), |
54 last_alr_probing_time_(clock_->TimeInMilliseconds()) {} | 56 last_alr_probing_time_(clock_->TimeInMilliseconds()) {} |
55 | 57 |
56 void ProbeController::SetBitrates(int min_bitrate_bps, | 58 void ProbeController::SetBitrates(int min_bitrate_bps, |
57 int start_bitrate_bps, | 59 int start_bitrate_bps, |
58 int max_bitrate_bps) { | 60 int max_bitrate_bps) { |
59 rtc::CritScope cs(&critsect_); | 61 rtc::CritScope cs(&critsect_); |
60 if (state_ == State::kInit) { | 62 |
61 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | 63 start_bitrate_bps_ = |
philipel
2016/11/08 09:48:18
min_bitrate_bps <= start_bitrate_bps <= max_bitrat
Sergey Ulanov
2016/11/08 16:26:01
This function is called with with start_bitrate_bp
| |
62 // 1.2 Mbps to continue probing. | 64 start_bitrate_bps > 0 ? start_bitrate_bps : min_bitrate_bps; |
63 InitiateProbing({3 * start_bitrate_bps, 6 * start_bitrate_bps}, | |
64 4 * start_bitrate_bps); | |
65 } | |
66 | 65 |
67 int old_max_bitrate_bps = max_bitrate_bps_; | 66 int old_max_bitrate_bps = max_bitrate_bps_; |
68 max_bitrate_bps_ = max_bitrate_bps; | 67 max_bitrate_bps_ = max_bitrate_bps; |
69 | 68 |
70 // Only do probing if: | 69 switch (state_) { |
71 // we are mid-call, which we consider to be if | 70 case State::kInit: |
72 // exponential probing is not active and | 71 if (network_state_ == kNetworkUp) |
73 // |estimated_bitrate_bps_| is valid (> 0) and | 72 InitiateExponentialProbing(); |
74 // the current bitrate is lower than the new |max_bitrate_bps|, and | 73 break; |
75 // |max_bitrate_bps_| was increased. | 74 |
76 if (state_ != State::kWaitingForProbingResult && | 75 case State::kWaitingForProbingResult: |
77 estimated_bitrate_bps_ != 0 && | 76 break; |
78 estimated_bitrate_bps_ < old_max_bitrate_bps && | 77 |
79 max_bitrate_bps_ > old_max_bitrate_bps) { | 78 case State::kProbingComplete: |
80 InitiateProbing({max_bitrate_bps}, kExponentialProbingDisabled); | 79 // Initiate probing when |max_bitrate_| was increased mid-call. |
80 if (estimated_bitrate_bps_ != 0 && | |
81 estimated_bitrate_bps_ < old_max_bitrate_bps && | |
82 max_bitrate_bps_ > old_max_bitrate_bps) { | |
83 InitiateProbing({max_bitrate_bps}, kExponentialProbingDisabled); | |
84 } | |
85 break; | |
81 } | 86 } |
82 } | 87 } |
83 | 88 |
89 void ProbeController::OnNetworkStateChanged(NetworkState state) { | |
philipel
2016/11/08 09:48:18
Maybe rename |state| to |network_state|, slightly
Sergey Ulanov
2016/11/08 16:26:01
Done.
| |
90 rtc::CritScope cs(&critsect_); | |
91 network_state_ = state; | |
92 if (network_state_ == kNetworkUp && state_ == State::kInit) | |
93 InitiateExponentialProbing(); | |
94 } | |
95 | |
96 void ProbeController::InitiateExponentialProbing() { | |
97 RTC_DCHECK(network_state_ == kNetworkUp); | |
98 RTC_DCHECK(state_ == State::kInit); | |
99 RTC_DCHECK_GT(start_bitrate_bps_, 0); | |
100 | |
101 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | |
102 // 1.2 Mbps to continue probing. | |
103 InitiateProbing({3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, | |
104 4 * start_bitrate_bps_); | |
105 } | |
106 | |
84 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { | 107 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { |
85 rtc::CritScope cs(&critsect_); | 108 rtc::CritScope cs(&critsect_); |
86 if (state_ == State::kWaitingForProbingResult) { | 109 if (state_ == State::kWaitingForProbingResult) { |
87 if ((clock_->TimeInMilliseconds() - time_last_probing_initiated_ms_) > | 110 if ((clock_->TimeInMilliseconds() - time_last_probing_initiated_ms_) > |
88 kMaxWaitingTimeForProbingResultMs) { | 111 kMaxWaitingTimeForProbingResultMs) { |
89 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; | 112 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; |
90 state_ = State::kProbingComplete; | 113 state_ = State::kProbingComplete; |
91 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | 114 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
92 } else { | 115 } else { |
93 // Continue probing if probing results indicate channel has greater | 116 // Continue probing if probing results indicate channel has greater |
(...skipping 53 matching lines...) Loading... | |
147 } | 170 } |
148 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; | 171 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; |
149 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); | 172 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); |
150 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) | 173 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) |
151 state_ = State::kProbingComplete; | 174 state_ = State::kProbingComplete; |
152 else | 175 else |
153 state_ = State::kWaitingForProbingResult; | 176 state_ = State::kWaitingForProbingResult; |
154 } | 177 } |
155 | 178 |
156 } // namespace webrtc | 179 } // namespace webrtc |
OLD | NEW |