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 | |
90 BitrateControllerImpl::BitrateControllerImpl(Clock* clock, | 86 BitrateControllerImpl::BitrateControllerImpl(Clock* clock, |
91 BitrateObserver* observer) | 87 BitrateObserver* observer) |
92 : clock_(clock), | 88 : clock_(clock), |
93 observer_(observer), | 89 observer_(observer), |
94 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), | 90 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), |
95 bandwidth_estimation_(), | 91 bandwidth_estimation_(), |
96 reserved_bitrate_bps_(0), | 92 reserved_bitrate_bps_(0), |
97 last_bitrate_bps_(0), | 93 last_bitrate_bps_(0), |
98 last_fraction_loss_(0), | 94 last_fraction_loss_(0), |
99 last_rtt_ms_(0), | 95 last_rtt_ms_(0), |
100 last_reserved_bitrate_bps_(0) { | 96 last_reserved_bitrate_bps_(0) { |
101 // This calls the observer_ if set, which means that the observer provided by | 97 // This calls the observer_, which means that the observer provided by the |
102 // the user must be ready to accept a bitrate update when it constructs the | 98 // user must be ready to accept a bitrate update when it constructs the |
103 // controller. We do this to avoid having to keep synchronized initial values | 99 // controller. We do this to avoid having to keep synchronized initial values |
104 // in both the controller and the allocator. | 100 // in both the controller and the allocator. |
105 MaybeTriggerOnNetworkChanged(); | 101 MaybeTriggerOnNetworkChanged(); |
106 } | 102 } |
107 | 103 |
108 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { | 104 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { |
109 return new RtcpBandwidthObserverImpl(this); | 105 return new RtcpBandwidthObserverImpl(this); |
110 } | 106 } |
111 | 107 |
112 void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) { | 108 void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 int64_t now_ms) { | 192 int64_t now_ms) { |
197 { | 193 { |
198 rtc::CritScope cs(&critsect_); | 194 rtc::CritScope cs(&critsect_); |
199 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt, | 195 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt, |
200 number_of_packets, now_ms); | 196 number_of_packets, now_ms); |
201 } | 197 } |
202 MaybeTriggerOnNetworkChanged(); | 198 MaybeTriggerOnNetworkChanged(); |
203 } | 199 } |
204 | 200 |
205 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { | 201 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { |
206 if (!observer_) | 202 uint32_t bitrate; |
207 return; | |
208 | |
209 uint32_t bitrate_bps; | |
210 uint8_t fraction_loss; | 203 uint8_t fraction_loss; |
211 int64_t rtt; | 204 int64_t rtt; |
212 | 205 if (GetNetworkParameters(&bitrate, &fraction_loss, &rtt)) |
213 if (GetNetworkParameters(&bitrate_bps, &fraction_loss, &rtt)) | 206 observer_->OnNetworkChanged(bitrate, fraction_loss, rtt); |
214 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); | |
215 } | 207 } |
216 | 208 |
217 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, | 209 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, |
218 uint8_t* fraction_loss, | 210 uint8_t* fraction_loss, |
219 int64_t* rtt) { | 211 int64_t* rtt) { |
220 rtc::CritScope cs(&critsect_); | 212 rtc::CritScope cs(&critsect_); |
221 int current_bitrate; | 213 int current_bitrate; |
222 bandwidth_estimation_.CurrentEstimate(¤t_bitrate, fraction_loss, rtt); | 214 bandwidth_estimation_.CurrentEstimate(¤t_bitrate, fraction_loss, rtt); |
223 *bitrate = current_bitrate; | 215 *bitrate = current_bitrate; |
224 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_); | 216 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_); |
(...skipping 21 matching lines...) Expand all Loading... |
246 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); | 238 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); |
247 if (bitrate > 0) { | 239 if (bitrate > 0) { |
248 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); | 240 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); |
249 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); | 241 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); |
250 *bandwidth = bitrate; | 242 *bandwidth = bitrate; |
251 return true; | 243 return true; |
252 } | 244 } |
253 return false; | 245 return false; |
254 } | 246 } |
255 } // namespace webrtc | 247 } // namespace webrtc |
OLD | NEW |