Chromium Code Reviews| 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 <vector> | |
| 14 | |
| 13 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
| 17 #include "webrtc/base/socket.h" | |
| 15 #include "webrtc/base/thread_annotations.h" | 18 #include "webrtc/base/thread_annotations.h" |
| 16 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 19 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 17 #include "webrtc/modules/pacing/paced_sender.h" | 20 #include "webrtc/modules/pacing/paced_sender.h" |
| 18 #include "webrtc/modules/pacing/packet_router.h" | 21 #include "webrtc/modules/pacing/packet_router.h" |
| 19 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" | 22 #include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h" |
| 20 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" | 23 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_s end_time.h" |
| 21 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" | 24 #include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_singl e_stream.h" |
| 22 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" | 25 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
| 23 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h" | 26 #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h" |
| 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | |
| 25 #include "webrtc/modules/utility/include/process_thread.h" | 27 #include "webrtc/modules/utility/include/process_thread.h" |
| 26 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 28 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 27 #include "webrtc/video/call_stats.h" | 29 #include "webrtc/video/call_stats.h" |
| 28 #include "webrtc/video/payload_router.h" | 30 #include "webrtc/video/payload_router.h" |
| 29 #include "webrtc/video/vie_encoder.h" | |
| 30 #include "webrtc/video/vie_remb.h" | |
| 31 #include "webrtc/voice_engine/include/voe_video_sync.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) |
| 41 : observer_(observer), | 40 : observer_(observer), |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 rtc::scoped_ptr<RemoteBitrateEstimator> rbe_; | 135 rtc::scoped_ptr<RemoteBitrateEstimator> rbe_; |
| 137 bool using_absolute_send_time_; | 136 bool using_absolute_send_time_; |
| 138 uint32_t packets_since_absolute_send_time_; | 137 uint32_t packets_since_absolute_send_time_; |
| 139 int min_bitrate_bps_; | 138 int min_bitrate_bps_; |
| 140 | 139 |
| 141 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); | 140 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); |
| 142 }; | 141 }; |
| 143 | 142 |
| 144 } // namespace | 143 } // namespace |
| 145 | 144 |
| 146 CongestionController::CongestionController(ProcessThread* process_thread, | 145 CongestionController::CongestionController( |
| 147 CallStats* call_stats, | 146 Clock* clock, |
|
the sun
2016/02/05 15:12:37
Store clock in a field and use instead of GetRealT
stefan-webrtc
2016/02/07 18:29:27
Good suggestion, I don't know why I didn't do that
| |
| 148 BitrateObserver* bitrate_observer) | 147 ProcessThread* process_thread, |
| 149 : remb_(new VieRemb(Clock::GetRealTimeClock())), | 148 CallStats* call_stats, |
| 150 packet_router_(new PacketRouter()), | 149 BitrateObserver* bitrate_observer, |
| 151 pacer_(new PacedSender(Clock::GetRealTimeClock(), | 150 RemoteBitrateObserver* remote_bitrate_observer) |
| 151 : packet_router_(new PacketRouter()), | |
| 152 pacer_(new PacedSender(clock, | |
| 152 packet_router_.get(), | 153 packet_router_.get(), |
| 153 BitrateController::kDefaultStartBitrateKbps, | 154 BitrateController::kDefaultStartBitrateKbps, |
| 154 PacedSender::kDefaultPaceMultiplier * | 155 PacedSender::kDefaultPaceMultiplier * |
| 155 BitrateController::kDefaultStartBitrateKbps, | 156 BitrateController::kDefaultStartBitrateKbps, |
| 156 0)), | 157 0)), |
| 157 remote_bitrate_estimator_( | 158 remote_bitrate_estimator_( |
| 158 new WrappingBitrateEstimator(remb_.get(), Clock::GetRealTimeClock())), | 159 new WrappingBitrateEstimator(remote_bitrate_observer, |
| 160 Clock::GetRealTimeClock())), | |
| 159 remote_estimator_proxy_( | 161 remote_estimator_proxy_( |
| 160 new RemoteEstimatorProxy(Clock::GetRealTimeClock(), | 162 new RemoteEstimatorProxy(Clock::GetRealTimeClock(), |
| 161 packet_router_.get())), | 163 packet_router_.get())), |
| 162 process_thread_(process_thread), | 164 process_thread_(process_thread), |
| 163 call_stats_(call_stats), | 165 call_stats_(call_stats), |
| 164 pacer_thread_(ProcessThread::Create("PacerThread")), | 166 pacer_thread_(ProcessThread::Create("PacerThread")), |
| 165 // Constructed last as this object calls the provided callback on | 167 // Constructed last as this object calls the provided callback on |
| 166 // construction. | 168 // construction. |
| 167 bitrate_controller_( | 169 bitrate_controller_( |
| 168 BitrateController::CreateBitrateController(Clock::GetRealTimeClock(), | 170 BitrateController::CreateBitrateController(clock, bitrate_observer)), |
| 169 bitrate_observer)), | |
| 170 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) { | 171 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) { |
| 171 call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get()); | 172 call_stats_->RegisterStatsObserver(remote_bitrate_estimator_.get()); |
| 172 | 173 |
| 173 pacer_thread_->RegisterModule(pacer_.get()); | 174 pacer_thread_->RegisterModule(pacer_.get()); |
| 174 pacer_thread_->RegisterModule(remote_estimator_proxy_.get()); | 175 pacer_thread_->RegisterModule(remote_estimator_proxy_.get()); |
| 175 pacer_thread_->Start(); | 176 pacer_thread_->Start(); |
| 176 | 177 |
| 177 process_thread->RegisterModule(remote_bitrate_estimator_.get()); | 178 process_thread_->RegisterModule(remote_bitrate_estimator_.get()); |
| 178 process_thread->RegisterModule(bitrate_controller_.get()); | 179 process_thread_->RegisterModule(bitrate_controller_.get()); |
| 179 } | 180 } |
| 180 | 181 |
| 181 CongestionController::~CongestionController() { | 182 CongestionController::~CongestionController() { |
| 182 pacer_thread_->Stop(); | 183 pacer_thread_->Stop(); |
| 183 pacer_thread_->DeRegisterModule(pacer_.get()); | 184 pacer_thread_->DeRegisterModule(pacer_.get()); |
| 184 pacer_thread_->DeRegisterModule(remote_estimator_proxy_.get()); | 185 pacer_thread_->DeRegisterModule(remote_estimator_proxy_.get()); |
| 185 process_thread_->DeRegisterModule(bitrate_controller_.get()); | 186 process_thread_->DeRegisterModule(bitrate_controller_.get()); |
| 186 process_thread_->DeRegisterModule(remote_bitrate_estimator_.get()); | 187 process_thread_->DeRegisterModule(remote_bitrate_estimator_.get()); |
| 187 call_stats_->DeregisterStatsObserver(remote_bitrate_estimator_.get()); | 188 call_stats_->DeregisterStatsObserver(remote_bitrate_estimator_.get()); |
| 188 if (transport_feedback_adapter_.get()) | 189 if (transport_feedback_adapter_.get()) |
| 189 call_stats_->DeregisterStatsObserver(transport_feedback_adapter_.get()); | 190 call_stats_->DeregisterStatsObserver(transport_feedback_adapter_.get()); |
| 190 RTC_DCHECK(!remb_->InUse()); | |
| 191 RTC_DCHECK(encoders_.empty()); | |
| 192 } | 191 } |
| 193 | 192 |
| 194 void CongestionController::AddEncoder(ViEEncoder* encoder) { | |
| 195 rtc::CritScope lock(&encoder_crit_); | |
| 196 encoders_.push_back(encoder); | |
| 197 } | |
| 198 | |
| 199 void CongestionController::RemoveEncoder(ViEEncoder* encoder) { | |
| 200 rtc::CritScope lock(&encoder_crit_); | |
| 201 for (auto it = encoders_.begin(); it != encoders_.end(); ++it) { | |
| 202 if (*it == encoder) { | |
| 203 encoders_.erase(it); | |
| 204 return; | |
| 205 } | |
| 206 } | |
| 207 } | |
| 208 | 193 |
| 209 void CongestionController::SetBweBitrates(int min_bitrate_bps, | 194 void CongestionController::SetBweBitrates(int min_bitrate_bps, |
| 210 int start_bitrate_bps, | 195 int start_bitrate_bps, |
| 211 int max_bitrate_bps) { | 196 int max_bitrate_bps) { |
| 212 if (start_bitrate_bps > 0) | 197 if (start_bitrate_bps > 0) |
| 213 bitrate_controller_->SetStartBitrate(start_bitrate_bps); | 198 bitrate_controller_->SetStartBitrate(start_bitrate_bps); |
| 214 bitrate_controller_->SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps); | 199 bitrate_controller_->SetMinMaxBitrate(min_bitrate_bps, max_bitrate_bps); |
| 215 if (remote_bitrate_estimator_.get()) | 200 if (remote_bitrate_estimator_.get()) |
| 216 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); | 201 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps); |
| 217 if (transport_feedback_adapter_.get()) | 202 if (transport_feedback_adapter_.get()) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 void CongestionController::UpdatePacerBitrate(int bitrate_kbps, | 236 void CongestionController::UpdatePacerBitrate(int bitrate_kbps, |
| 252 int max_bitrate_kbps, | 237 int max_bitrate_kbps, |
| 253 int min_bitrate_kbps) { | 238 int min_bitrate_kbps) { |
| 254 pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps); | 239 pacer_->UpdateBitrate(bitrate_kbps, max_bitrate_kbps, min_bitrate_kbps); |
| 255 } | 240 } |
| 256 | 241 |
| 257 int64_t CongestionController::GetPacerQueuingDelayMs() const { | 242 int64_t CongestionController::GetPacerQueuingDelayMs() const { |
| 258 return pacer_->QueueInMs(); | 243 return pacer_->QueueInMs(); |
| 259 } | 244 } |
| 260 | 245 |
| 261 // TODO(mflodman): Move out of this class. | |
| 262 void CongestionController::SetChannelRembStatus(bool sender, | |
| 263 bool receiver, | |
| 264 RtpRtcp* rtp_module) { | |
| 265 rtp_module->SetREMBStatus(sender || receiver); | |
| 266 if (sender) { | |
| 267 remb_->AddRembSender(rtp_module); | |
| 268 } else { | |
| 269 remb_->RemoveRembSender(rtp_module); | |
| 270 } | |
| 271 if (receiver) { | |
| 272 remb_->AddReceiveChannel(rtp_module); | |
| 273 } else { | |
| 274 remb_->RemoveReceiveChannel(rtp_module); | |
| 275 } | |
| 276 } | |
| 277 | |
| 278 void CongestionController::SignalNetworkState(NetworkState state) { | 246 void CongestionController::SignalNetworkState(NetworkState state) { |
| 279 if (state == kNetworkUp) { | 247 if (state == kNetworkUp) { |
| 280 pacer_->Resume(); | 248 pacer_->Resume(); |
| 281 } else { | 249 } else { |
| 282 pacer_->Pause(); | 250 pacer_->Pause(); |
| 283 } | 251 } |
| 284 } | 252 } |
| 285 | 253 |
| 286 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { | 254 void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) { |
| 287 if (transport_feedback_adapter_) { | 255 if (transport_feedback_adapter_) { |
| 288 transport_feedback_adapter_->OnSentPacket(sent_packet.packet_id, | 256 transport_feedback_adapter_->OnSentPacket(sent_packet.packet_id, |
| 289 sent_packet.send_time_ms); | 257 sent_packet.send_time_ms); |
| 290 } | 258 } |
| 291 } | 259 } |
| 292 } // namespace webrtc | 260 } // namespace webrtc |
| OLD | NEW |