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 */ |
11 | 11 |
12 #include "webrtc/modules/bitrate_controller/bitrate_controller_impl.h" | 12 #include "webrtc/modules/bitrate_controller/bitrate_controller_impl.h" |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
15 #include <map> | 15 #include <map> |
16 #include <utility> | 16 #include <utility> |
17 | 17 |
18 #include "webrtc/base/checks.h" | |
19 #include "webrtc/base/logging.h" | |
18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
19 | 21 |
20 namespace webrtc { | 22 namespace webrtc { |
21 | 23 |
22 class BitrateControllerImpl::RtcpBandwidthObserverImpl | 24 class BitrateControllerImpl::RtcpBandwidthObserverImpl |
23 : public RtcpBandwidthObserver { | 25 : public RtcpBandwidthObserver { |
24 public: | 26 public: |
25 explicit RtcpBandwidthObserverImpl(BitrateControllerImpl* owner) | 27 explicit RtcpBandwidthObserverImpl(BitrateControllerImpl* owner) |
26 : owner_(owner) { | 28 : owner_(owner) { |
27 } | 29 } |
(...skipping 48 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_; | 78 std::map<uint32_t, uint32_t> ssrc_to_last_received_extended_high_seq_num_; |
77 BitrateControllerImpl* owner_; | 79 BitrateControllerImpl* owner_; |
78 }; | 80 }; |
79 | 81 |
80 BitrateController* BitrateController::CreateBitrateController( | 82 BitrateController* BitrateController::CreateBitrateController( |
81 Clock* clock, | 83 Clock* clock, |
82 BitrateObserver* observer) { | 84 BitrateObserver* observer) { |
83 return new BitrateControllerImpl(clock, observer); | 85 return new BitrateControllerImpl(clock, observer); |
84 } | 86 } |
85 | 87 |
88 BitrateController* BitrateController::CreateBitrateController(Clock* clock) { | |
89 return new BitrateControllerImpl(clock, nullptr); | |
90 } | |
91 | |
86 BitrateControllerImpl::BitrateControllerImpl(Clock* clock, | 92 BitrateControllerImpl::BitrateControllerImpl(Clock* clock, |
87 BitrateObserver* observer) | 93 BitrateObserver* observer) |
88 : clock_(clock), | 94 : clock_(clock), |
89 observer_(observer), | 95 observer_(observer), |
90 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), | 96 last_bitrate_update_ms_(clock_->TimeInMilliseconds()), |
91 bandwidth_estimation_(), | 97 bandwidth_estimation_(), |
92 reserved_bitrate_bps_(0), | 98 reserved_bitrate_bps_(0), |
93 last_bitrate_bps_(0), | 99 last_bitrate_bps_(0), |
94 last_fraction_loss_(0), | 100 last_fraction_loss_(0), |
95 last_rtt_ms_(0), | 101 last_rtt_ms_(0), |
96 last_reserved_bitrate_bps_(0) { | 102 last_reserved_bitrate_bps_(0) { |
97 // This calls the observer_, which means that the observer provided by the | 103 // TODO(perkj): BitrateObserver has been deprecated and is not used in WebRTC. |
98 // user must be ready to accept a bitrate update when it constructs the | 104 // This is left for code that is not yet updated. |
stefan-webrtc
2016/05/02 12:56:47
Maybe move this to the .h file by the observer poi
perkj_webrtc
2016/05/02 14:45:35
Done.
| |
105 // This calls the observer_ if set, which means that the observer provided by | |
106 // 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 | 107 // controller. We do this to avoid having to keep synchronized initial values |
100 // in both the controller and the allocator. | 108 // in both the controller and the allocator. |
101 MaybeTriggerOnNetworkChanged(); | 109 MaybeTriggerOnNetworkChanged(); |
102 } | 110 } |
103 | 111 |
104 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { | 112 RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { |
105 return new RtcpBandwidthObserverImpl(this); | 113 return new RtcpBandwidthObserverImpl(this); |
106 } | 114 } |
107 | 115 |
108 void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) { | 116 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) { | 200 int64_t now_ms) { |
193 { | 201 { |
194 rtc::CritScope cs(&critsect_); | 202 rtc::CritScope cs(&critsect_); |
195 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt, | 203 bandwidth_estimation_.UpdateReceiverBlock(fraction_loss, rtt, |
196 number_of_packets, now_ms); | 204 number_of_packets, now_ms); |
197 } | 205 } |
198 MaybeTriggerOnNetworkChanged(); | 206 MaybeTriggerOnNetworkChanged(); |
199 } | 207 } |
200 | 208 |
201 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { | 209 void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { |
202 uint32_t bitrate; | 210 if (!observer_) |
211 return; | |
212 | |
213 uint32_t bitrate_bps; | |
203 uint8_t fraction_loss; | 214 uint8_t fraction_loss; |
204 int64_t rtt; | 215 int64_t rtt; |
205 if (GetNetworkParameters(&bitrate, &fraction_loss, &rtt)) | 216 |
206 observer_->OnNetworkChanged(bitrate, fraction_loss, rtt); | 217 if (GetNetworkParameters(&bitrate_bps, &fraction_loss, &rtt)) { |
218 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); | |
219 } | |
207 } | 220 } |
208 | 221 |
209 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, | 222 bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, |
210 uint8_t* fraction_loss, | 223 uint8_t* fraction_loss, |
211 int64_t* rtt) { | 224 int64_t* rtt) { |
212 rtc::CritScope cs(&critsect_); | 225 rtc::CritScope cs(&critsect_); |
213 int current_bitrate; | 226 int current_bitrate; |
214 bandwidth_estimation_.CurrentEstimate(¤t_bitrate, fraction_loss, rtt); | 227 bandwidth_estimation_.CurrentEstimate(¤t_bitrate, fraction_loss, rtt); |
215 *bitrate = current_bitrate; | 228 *bitrate = current_bitrate; |
216 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_); | 229 *bitrate -= std::min(*bitrate, reserved_bitrate_bps_); |
217 *bitrate = | 230 *bitrate = |
218 std::max<uint32_t>(*bitrate, bandwidth_estimation_.GetMinBitrate()); | 231 std::max<uint32_t>(*bitrate, bandwidth_estimation_.GetMinBitrate()); |
219 | 232 |
220 bool new_bitrate = false; | 233 bool new_bitrate = false; |
221 if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ || | 234 if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ || |
222 *rtt != last_rtt_ms_ || | 235 *rtt != last_rtt_ms_ || |
223 last_reserved_bitrate_bps_ != reserved_bitrate_bps_) { | 236 last_reserved_bitrate_bps_ != reserved_bitrate_bps_) { |
224 last_bitrate_bps_ = *bitrate; | 237 last_bitrate_bps_ = *bitrate; |
225 last_fraction_loss_ = *fraction_loss; | 238 last_fraction_loss_ = *fraction_loss; |
226 last_rtt_ms_ = *rtt; | 239 last_rtt_ms_ = *rtt; |
227 last_reserved_bitrate_bps_ = reserved_bitrate_bps_; | 240 last_reserved_bitrate_bps_ = reserved_bitrate_bps_; |
228 new_bitrate = true; | 241 new_bitrate = true; |
229 } | 242 } |
243 | |
230 return new_bitrate; | 244 return new_bitrate; |
231 } | 245 } |
232 | 246 |
233 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { | 247 bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { |
234 rtc::CritScope cs(&critsect_); | 248 rtc::CritScope cs(&critsect_); |
235 int bitrate; | 249 int bitrate; |
236 uint8_t fraction_loss; | 250 uint8_t fraction_loss; |
237 int64_t rtt; | 251 int64_t rtt; |
238 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); | 252 bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); |
239 if (bitrate > 0) { | 253 if (bitrate > 0) { |
240 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); | 254 bitrate = bitrate - std::min<int>(bitrate, reserved_bitrate_bps_); |
241 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); | 255 bitrate = std::max(bitrate, bandwidth_estimation_.GetMinBitrate()); |
242 *bandwidth = bitrate; | 256 *bandwidth = bitrate; |
243 return true; | 257 return true; |
244 } | 258 } |
245 return false; | 259 return false; |
246 } | 260 } |
247 } // namespace webrtc | 261 } // namespace webrtc |
OLD | NEW |