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 #include "webrtc/call/congestion_controller.h" | 11 #include "webrtc/call/congestion_controller.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
18 #include "webrtc/base/socket.h" | 18 #include "webrtc/base/socket.h" |
19 #include "webrtc/base/thread_annotations.h" | 19 #include "webrtc/base/thread_annotations.h" |
20 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 20 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
21 #include "webrtc/modules/pacing/paced_sender.h" | 21 #include "webrtc/modules/pacing/paced_sender.h" |
22 #include "webrtc/modules/pacing/packet_router.h" | 22 #include "webrtc/modules/pacing/packet_router.h" |
23 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" | 23 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" |
24 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" | 24 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" |
25 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" | 25 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" |
26 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" | 26 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
27 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h" | 27 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h" |
28 #include "webrtc/modules/utility/include/process_thread.h" | 28 #include "webrtc/modules/utility/include/process_thread.h" |
29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 29 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
30 #include "webrtc/video/call_stats.h" | |
31 #include "webrtc/video/payload_router.h" | 30 #include "webrtc/video/payload_router.h" |
32 | 31 |
33 namespace webrtc { | 32 namespace webrtc { |
34 namespace { | 33 namespace { |
35 | 34 |
36 static const uint32_t kTimeOffsetSwitchThreshold = 30; | 35 static const uint32_t kTimeOffsetSwitchThreshold = 30; |
37 | 36 |
38 class WrappingBitrateEstimator : public RemoteBitrateEstimator { | 37 class WrappingBitrateEstimator : public RemoteBitrateEstimator { |
39 public: | 38 public: |
40 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock) | 39 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock) |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 uint32_t packets_since_absolute_send_time_; | 132 uint32_t packets_since_absolute_send_time_; |
134 int min_bitrate_bps_; | 133 int min_bitrate_bps_; |
135 | 134 |
136 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); | 135 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); |
137 }; | 136 }; |
138 | 137 |
139 } // namespace | 138 } // namespace |
140 | 139 |
141 CongestionController::CongestionController( | 140 CongestionController::CongestionController( |
142 Clock* clock, | 141 Clock* clock, |
143 ProcessThread* process_thread, | |
144 CallStats* call_stats, | |
145 BitrateObserver* bitrate_observer, | 142 BitrateObserver* bitrate_observer, |
146 RemoteBitrateObserver* remote_bitrate_observer) | 143 RemoteBitrateObserver* remote_bitrate_observer) |
147 : clock_(clock), | 144 : clock_(clock), |
148 packet_router_(new PacketRouter()), | 145 packet_router_(new PacketRouter()), |
149 pacer_(new PacedSender(clock_, | 146 pacer_(new PacedSender(clock_, |
150 packet_router_.get(), | 147 packet_router_.get(), |
151 BitrateController::kDefaultStartBitrateKbps, | 148 BitrateController::kDefaultStartBitrateKbps, |
152 PacedSender::kDefaultPaceMultiplier * | 149 PacedSender::kDefaultPaceMultiplier * |
153 BitrateController::kDefaultStartBitrateKbps, | 150 BitrateController::kDefaultStartBitrateKbps, |
154 0)), | 151 0)), |
155 remote_bitrate_estimator_( | 152 remote_bitrate_estimator_( |
156 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), | 153 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)), |
157 remote_estimator_proxy_( | 154 remote_estimator_proxy_( |
158 new RemoteEstimatorProxy(clock_, packet_router_.get())), | 155 new RemoteEstimatorProxy(clock_, packet_router_.get())), |
159 process_thread_(process_thread), | |
160 call_stats_(call_stats), | |
161 pacer_thread_(ProcessThread::Create("PacerThread")), | 156 pacer_thread_(ProcessThread::Create("PacerThread")), |
162 // Constructed last as this object calls the provided callback on | 157 // Constructed last as this object calls the provided callback on |
163 // construction. | 158 // construction. |
164 bitrate_controller_( | 159 bitrate_controller_( |
165 BitrateController::CreateBitrateController(clock_, bitrate_observer)), | 160 BitrateController::CreateBitrateController(clock_, bitrate_observer)), |
161 transport_feedback_adapter_( | |
162 new TransportFeedbackAdapter(bitrate_controller_.get(), clock_)), | |
166 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) { | 163 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) { |
167 call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get()); | 164 transport_feedback_adapter_->SetBitrateEstimator( |
168 | 165 new RemoteBitrateEstimatorAbsSendTime(transport_feedback_adapter_.get(), |
166 clock_)); | |
167 transport_feedback_adapter_->GetBitrateEstimator()->SetMinBitrate( | |
168 min_bitrate_bps_); | |
169 pacer_thread_->RegisterModule(pacer_.get()); | 169 pacer_thread_->RegisterModule(pacer_.get()); |
170 pacer_thread_->RegisterModule(remote_estimator_proxy_.get()); | 170 pacer_thread_->RegisterModule(remote_estimator_proxy_.get()); |
171 pacer_thread_->Start(); | 171 pacer_thread_->Start(); |
172 | |
173 process_thread_->RegisterModule(remote_bitrate_estimator_.get()); | |
174 process_thread_->RegisterModule(bitrate_controller_.get()); | |
175 } | 172 } |
176 | 173 |
177 CongestionController::~CongestionController() { | 174 CongestionController::~CongestionController() { |
178 pacer_thread_->Stop(); | 175 pacer_thread_->Stop(); |
179 pacer_thread_->DeRegisterModule(pacer_.get()); | 176 pacer_thread_->DeRegisterModule(pacer_.get()); |
180 pacer_thread_->DeRegisterModule(remote_estimator_proxy_.get()); | 177 pacer_thread_->DeRegisterModule(remote_estimator_proxy_.get()); |
181 process_thread_->DeRegisterModule(bitrate_controller_.get()); | |
182 process_thread_->DeRegisterModule(remote_bitrate_estimator_.get()); | |
183 call_stats_->DeregisterStatsObserver(remote_bitrate_estimator_.get()); | |
184 if (transport_feedback_adapter_.get()) | |
185 call_stats_->DeregisterStatsObserver(transport_feedback_adapter_.get()); | |
186 } | 178 } |
187 | 179 |
188 | 180 |
189 void CongestionController::SetBweBitrates(int min_bitrate_bps, | 181 void CongestionController::SetBweBitrates(int min_bitrate_bps, |
190 int start_bitrate_bps, | 182 int start_bitrate_bps, |
191 int max_bitrate_bps) { | 183 int max_bitrate_bps) { |
184 RTC_DCHECK(config_thread_checker_.CalledOnValidThread()); | |
the sun
2016/02/17 13:50:55
Is this thread checker under used?
stefan-webrtc
2016/02/17 14:14:27
Unfortunately not, but it might be that it can be
| |
192 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, | 185 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps, |
193 // and that we don't try to set the min bitrate to 0 from any applications. | 186 // and that we don't try to set the min bitrate to 0 from any applications. |
194 // The congestion controller should allow a min bitrate of 0. | 187 // The congestion controller should allow a min bitrate of 0. |
195 const int kMinBitrateBps = 10000; | 188 const int kMinBitrateBps = 10000; |
196 if (min_bitrate_bps < kMinBitrateBps) | 189 if (min_bitrate_bps < kMinBitrateBps) |
197 min_bitrate_bps = kMinBitrateBps; | 190 min_bitrate_bps = kMinBitrateBps; |
198 if (max_bitrate_bps > 0) | 191 if (max_bitrate_bps > 0) |
199 max_bitrate_bps = std::max(min_bitrate_bps, max_bitrate_bps); | 192 max_bitrate_bps = std::max(min_bitrate_bps, max_bitrate_bps); |
200 if (start_bitrate_bps > 0) { | 193 if (start_bitrate_bps > 0) { |
201 start_bitrate_bps = std::max(min_bitrate_bps, start_bitrate_bps); | 194 start_bitrate_bps = std::max(min_bitrate_bps, start_bitrate_bps); |
202 bitrate_controller_->SetStartBitrate(start_bitrate_bps); | 195 bitrate_controller_->SetStartBitrate(start_bitrate_bps); |
203 } | 196 } |
204 bitrate_controller_->SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps); | 197 bitrate_controller_->SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps); |
205 if (remote_bitrate_estimator_.get()) | 198 if (remote_bitrate_estimator_) |
206 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); | 199 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); |
207 if (transport_feedback_adapter_.get()) | |
208 transport_feedback_adapter_->GetBitrateEstimator()->SetMinBitrate( | |
209 min_bitrate_bps); | |
210 min_bitrate_bps_ = min_bitrate_bps; | 200 min_bitrate_bps_ = min_bitrate_bps; |
201 transport_feedback_adapter_->GetBitrateEstimator()->SetMinBitrate( | |
202 min_bitrate_bps_); | |
211 } | 203 } |
212 | 204 |
213 BitrateController* CongestionController::GetBitrateController() const { | 205 BitrateController* CongestionController::GetBitrateController() const { |
214 return bitrate_controller_.get(); | 206 return bitrate_controller_.get(); |
215 } | 207 } |
216 | 208 |
217 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( | 209 RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator( |
218 bool send_side_bwe) const { | 210 bool send_side_bwe) const { |
219 | 211 if (send_side_bwe) { |
220 if (send_side_bwe) | |
221 return remote_estimator_proxy_.get(); | 212 return remote_estimator_proxy_.get(); |
222 else | 213 } else { |
pbos-webrtc
2016/02/17 13:37:21
remove else and just return
| |
223 return remote_bitrate_estimator_.get(); | 214 return remote_bitrate_estimator_.get(); |
215 } | |
224 } | 216 } |
225 | 217 |
226 TransportFeedbackObserver* | 218 TransportFeedbackObserver* |
227 CongestionController::GetTransportFeedbackObserver() { | 219 CongestionController::GetTransportFeedbackObserver() { |
228 if (transport_feedback_adapter_.get() == nullptr) { | 220 RTC_DCHECK(config_thread_checker_.CalledOnValidThread()); |
229 transport_feedback_adapter_.reset(new TransportFeedbackAdapter( | |
230 bitrate_controller_.get(), clock_, process_thread_)); | |
231 transport_feedback_adapter_->SetBitrateEstimator( | |
232 new RemoteBitrateEstimatorAbsSendTime(transport_feedback_adapter_.get(), | |
233 clock_)); | |
234 transport_feedback_adapter_->GetBitrateEstimator()->SetMinBitrate( | |
235 min_bitrate_bps_); | |
236 call_stats_->RegisterStatsObserver(transport_feedback_adapter_.get()); | |
237 } | |
238 return transport_feedback_adapter_.get(); | 221 return transport_feedback_adapter_.get(); |
239 } | 222 } |
240 | 223 |
241 void CongestionController::UpdatePacerBitrate(int bitrate_kbps, | 224 void CongestionController::UpdatePacerBitrate(int bitrate_kbps, |
242 int max_bitrate_kbps, | 225 int max_bitrate_kbps, |
243 int min_bitrate_kbps) { | 226 int min_bitrate_kbps) { |
244 pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps); | 227 pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps); |
245 } | 228 } |
246 | 229 |
247 int64_t CongestionController::GetPacerQueuingDelayMs() const { | 230 int64_t CongestionController::GetPacerQueuingDelayMs() const { |
248 return pacer_->QueueInMs(); | 231 return pacer_->QueueInMs(); |
249 } | 232 } |
250 | 233 |
251 void CongestionController::SignalNetworkState(NetworkState state) { | 234 void CongestionController::SignalNetworkState(NetworkState state) { |
252 if (state == kNetworkUp) { | 235 if (state == kNetworkUp) { |
253 pacer_->Resume(); | 236 pacer_->Resume(); |
254 } else { | 237 } else { |
255 pacer_->Pause(); | 238 pacer_->Pause(); |
256 } | 239 } |
257 } | 240 } |
258 | 241 |
259 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { | 242 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { |
260 if (transport_feedback_adapter_) { | 243 transport_feedback_adapter_->OnSentPacket(sent_packet.packet_id, |
261 transport_feedback_adapter_->OnSentPacket(sent_packet.packet_id, | 244 sent_packet.send_time_ms); |
262 sent_packet.send_time_ms); | |
263 } | |
264 } | 245 } |
246 | |
247 void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | |
248 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | |
249 transport_feedback_adapter_->OnRttUpdate(avg_rtt_ms, max_rtt_ms); | |
250 } | |
251 | |
252 int64_t CongestionController::TimeUntilNextProcess() { | |
253 return std::min(bitrate_controller_->TimeUntilNextProcess(), | |
254 remote_bitrate_estimator_->TimeUntilNextProcess()); | |
255 } | |
256 | |
257 int32_t CongestionController::Process() { | |
258 bitrate_controller_->Process(); | |
259 remote_bitrate_estimator_->Process(); | |
260 return 0; | |
261 } | |
262 | |
265 } // namespace webrtc | 263 } // namespace webrtc |
OLD | NEW |