OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_; | 76 std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_; |
77 BitrateControllerImpl* owner_; | 77 BitrateControllerImpl* owner_; |
78 }; | 78 }; |
79 | 79 |
80 BitrateController* BitrateController::CreateBitrateController( | 80 BitrateController* BitrateController::CreateBitrateController( |
81 Clock* clock, | 81 Clock* clock, |
82 BitrateObserver* observer) { | 82 BitrateObserver* observer) { |
83 return new BitrateControllerImpl(clock, observer); | 83 return new BitrateControllerImpl(clock, observer); |
84 } | 84 } |
85 | 85 |
86 BitrateController* BitrateController::CreateBitrateController(Clock* clock) { | |
87 return new BitrateControllerImpl(clock, nullptr); | |
88 } | |
89 | |
86 BitrateControllerImpl::BitrateControllerImpl(Clock* clock, | 90 BitrateControllerImpl::BitrateControllerImpl(Clock* clock, |
87 BitrateObserver* observer) | 91 BitrateObserver* observer) |
88 : clock_(clock), | 92 : clock_(clock), |
89 observer_(observer), | 93 observer_(observer), |
90 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), | 94 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), |
91 bandwidth_estimation_(), | 95 bandwidth_estimation_(), |
92 reserved_bitrate_bps_(0), | 96 reserved_bitrate_bps_(0), |
93 last_bitrate_bps_(0), | 97 last_bitrate_bps_(0), |
94 last_fraction_loss_(0), | 98 last_fraction_loss_(0), |
95 last_rtt_ms_(0), | 99 last_rtt_ms_(0), |
96 last_reserved_bitrate_bps_(0) { | 100 last_reserved_bitrate_bps_(0) { |
97 // This calls the observer_, which means that the observer provided by the | 101 // This calls the observer_ if set, which means that the observer provided by |
98 // user must be ready to accept a bitrate update when it constructs the | 102 // the user must be ready to accept a bitrate update when it constructs the |
99 // controller. We do this to avoid having to keep synchronized initial values | 103 // controller. We do this to avoid having to keep synchronized initial values |
100 // in both the controller and the allocator. | 104 // in both the controller and the allocator. |
101 MaybeTriggerOnNetworkChanged(); | 105 MaybeTriggerOnNetworkChanged(); |
102 } | 106 } |
103 | 107 |
104 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { | 108 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { |
105 return new RtcpBandwidthObserverImpl(this); | 109 return new RtcpBandwidthObserverImpl(this); |
106 } | 110 } |
107 | 111 |
108 void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) { | 112 void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 int64_t now_ms) { | 196 int64_t now_ms) { |
193 { | 197 { |
194 rtc::CritScope cs(&critsect_); | 198 rtc::CritScope cs(&critsect_); |
195 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt, | 199 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt, |
196 number_of_packets, now_ms); | 200 number_of_packets, now_ms); |
197 } | 201 } |
198 MaybeTriggerOnNetworkChanged(); | 202 MaybeTriggerOnNetworkChanged(); |
199 } | 203 } |
200 | 204 |
201 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { | 205 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { |
202 uint32_t bitrate; | 206 if (!observer_) |
207 return; | |
208 | |
209 uint32_t bitrate_bps; | |
203 uint8_t fraction_loss; | 210 uint8_t fraction_loss; |
204 int64_t rtt; | 211 int64_t rtt; |
205 if (GetNetworkParameters(&bitrate, &fraction_loss, &rtt)) | 212 |
206 observer_->OnNetworkChanged(bitrate, fraction_loss, rtt); | 213 if (GetNetworkParameters(&bitrate_bps, &fraction_loss, &rtt)) { |
stefan-webrtc
2016/05/03 12:21:14
Remove {}
perkj_webrtc
2016/05/03 13:56:00
Done.
| |
214 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); | |
215 } | |
207 } | 216 } |
208 | 217 |
209 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, | 218 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, |
210 uint8_t* fraction_loss, | 219 uint8_t* fraction_loss, |
211 int64_t* rtt) { | 220 int64_t* rtt) { |
212 rtc::CritScope cs(&critsect_); | 221 rtc::CritScope cs(&critsect_); |
213 int current_bitrate; | 222 int current_bitrate; |
214 bandwidth_estimation_.CurrentEstimate(¤t_bitrate, fraction_loss, rtt); | 223 bandwidth_estimation_.CurrentEstimate(¤t_bitrate, fraction_loss, rtt); |
215 *bitrate = current_bitrate; | 224 *bitrate = current_bitrate; |
216 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_); | 225 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_); |
217 *bitrate = | 226 *bitrate = |
218 std::max<uint32_t>(*bitrate, bandwidth_estimation_.GetMinBitrate()); | 227 std::max<uint32_t>(*bitrate, bandwidth_estimation_.GetMinBitrate()); |
219 | 228 |
220 bool new_bitrate = false; | 229 bool new_bitrate = false; |
221 if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ || | 230 if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ || |
222 *rtt != last_rtt_ms_ || | 231 *rtt != last_rtt_ms_ || |
223 last_reserved_bitrate_bps_ != reserved_bitrate_bps_) { | 232 last_reserved_bitrate_bps_ != reserved_bitrate_bps_) { |
224 last_bitrate_bps_ = *bitrate; | 233 last_bitrate_bps_ = *bitrate; |
225 last_fraction_loss_ = *fraction_loss; | 234 last_fraction_loss_ = *fraction_loss; |
226 last_rtt_ms_ = *rtt; | 235 last_rtt_ms_ = *rtt; |
227 last_reserved_bitrate_bps_ = reserved_bitrate_bps_; | 236 last_reserved_bitrate_bps_ = reserved_bitrate_bps_; |
228 new_bitrate = true; | 237 new_bitrate = true; |
229 } | 238 } |
239 | |
230 return new_bitrate; | 240 return new_bitrate; |
231 } | 241 } |
232 | 242 |
233 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { | 243 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { |
234 rtc::CritScope cs(&critsect_); | 244 rtc::CritScope cs(&critsect_); |
235 int bitrate; | 245 int bitrate; |
236 uint8_t fraction_loss; | 246 uint8_t fraction_loss; |
237 int64_t rtt; | 247 int64_t rtt; |
238 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); | 248 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); |
239 if (bitrate > 0) { | 249 if (bitrate > 0) { |
240 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); | 250 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); |
241 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); | 251 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); |
242 *bandwidth = bitrate; | 252 *bandwidth = bitrate; |
243 return true; | 253 return true; |
244 } | 254 } |
245 return false; | 255 return false; |
246 } | 256 } |
247 } // namespace webrtc | 257 } // namespace webrtc |
OLD | NEW |