blob: c836f40f5e7187f242e828dc4b64c4e1e7ca3652 [file] [log] [blame]
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Stefan Holmer80e12072016-02-23 13:30:42 +010011#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000012
Stefan Holmer62a5ccd2016-02-16 17:07:21 +010013#include <algorithm>
kwiberg22feaa32016-03-17 09:17:43 -070014#include <memory>
Stefan Holmer58c664c2016-02-08 14:31:30 +010015#include <vector>
16
stefan@webrtc.orga50e6f02015-03-09 10:06:40 +000017#include "webrtc/base/checks.h"
kwiberg4485ffb2016-04-26 08:14:39 -070018#include "webrtc/base/constructormagic.h"
Peter Boström7c704b82015-12-04 16:13:05 +010019#include "webrtc/base/logging.h"
Stefan Holmer58c664c2016-02-08 14:31:30 +010020#include "webrtc/base/socket.h"
pbos@webrtc.org38344ed2014-09-24 06:05:00 +000021#include "webrtc/base/thread_annotations.h"
mflodman0e7e2592015-11-12 21:02:42 -080022#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
philipel863a8262016-06-17 09:21:34 -070023#include "webrtc/modules/congestion_controller/delay_based_bwe.h"
sprang867fb522015-08-03 04:38:41 -070024#include "webrtc/modules/remote_bitrate_estimator/include/send_time_history.h"
Erik Språng468e62a2015-07-06 10:50:47 +020025#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_abs_send_time.h"
26#include "webrtc/modules/remote_bitrate_estimator/remote_bitrate_estimator_single_stream.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010027#include "webrtc/modules/utility/include/process_thread.h"
Henrik Kjellander98f53512015-10-28 18:17:40 +010028#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
Peter Boström7623ce42015-12-09 12:13:30 +010029#include "webrtc/video/payload_router.h"
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000030
31namespace webrtc {
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000032namespace {
33
pbos@webrtc.org5ab75672013-12-16 12:24:44 +000034static const uint32_t kTimeOffsetSwitchThreshold = 30;
35
honghaiz059e1832016-06-24 11:03:55 -070036// Makes sure that the bitrate and the min, max values are in valid range.
37static void ClampBitrates(int* bitrate_bps,
38 int* min_bitrate_bps,
39 int* max_bitrate_bps) {
40 // TODO(holmer): We should make sure the default bitrates are set to 10 kbps,
41 // and that we don't try to set the min bitrate to 0 from any applications.
42 // The congestion controller should allow a min bitrate of 0.
43 const int kMinBitrateBps = 10000;
44 if (*min_bitrate_bps < kMinBitrateBps)
45 *min_bitrate_bps = kMinBitrateBps;
46 if (*max_bitrate_bps > 0)
47 *max_bitrate_bps = std::max(*min_bitrate_bps, *max_bitrate_bps);
48 if (*bitrate_bps > 0)
49 *bitrate_bps = std::max(*min_bitrate_bps, *bitrate_bps);
50}
51
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000052class WrappingBitrateEstimator : public RemoteBitrateEstimator {
53 public:
pbosef35f062015-07-27 08:37:06 -070054 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock)
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000055 : observer_(observer),
56 clock_(clock),
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000057 crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
stefan4fbd1452015-09-28 03:57:14 -070058 rbe_(new RemoteBitrateEstimatorSingleStream(observer_, clock_)),
pbos@webrtc.org5ab75672013-12-16 12:24:44 +000059 using_absolute_send_time_(false),
stefan4fbd1452015-09-28 03:57:14 -070060 packets_since_absolute_send_time_(0),
61 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps) {}
andresp@webrtc.org1295dc62014-07-02 13:23:19 +000062
63 virtual ~WrappingBitrateEstimator() {}
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000064
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000065 void IncomingPacket(int64_t arrival_time_ms,
66 size_t payload_size,
pbos2169d8b2016-06-20 11:53:02 -070067 const RTPHeader& header) override {
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000068 CriticalSectionScoped cs(crit_sect_.get());
stefan@webrtc.orga16147c2014-03-25 10:37:31 +000069 PickEstimatorFromHeader(header);
pbos2169d8b2016-06-20 11:53:02 -070070 rbe_->IncomingPacket(arrival_time_ms, payload_size, header);
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000071 }
72
pbosa26ac922016-02-25 04:50:01 -080073 void Process() override {
andresp@webrtc.org1295dc62014-07-02 13:23:19 +000074 CriticalSectionScoped cs(crit_sect_.get());
pbosa26ac922016-02-25 04:50:01 -080075 rbe_->Process();
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000076 }
77
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000078 int64_t TimeUntilNextProcess() override {
andresp@webrtc.org1295dc62014-07-02 13:23:19 +000079 CriticalSectionScoped cs(crit_sect_.get());
80 return rbe_->TimeUntilNextProcess();
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000081 }
82
stefan2328a942015-08-07 04:27:51 -070083 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override {
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000084 CriticalSectionScoped cs(crit_sect_.get());
stefan2328a942015-08-07 04:27:51 -070085 rbe_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000086 }
87
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000088 void RemoveStream(unsigned int ssrc) override {
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000089 CriticalSectionScoped cs(crit_sect_.get());
90 rbe_->RemoveStream(ssrc);
91 }
92
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000093 bool LatestEstimate(std::vector<unsigned int>* ssrcs,
94 unsigned int* bitrate_bps) const override {
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +000095 CriticalSectionScoped cs(crit_sect_.get());
96 return rbe_->LatestEstimate(ssrcs, bitrate_bps);
97 }
98
nisseef8b61e2016-04-29 06:09:15 -070099 void SetMinBitrate(int min_bitrate_bps) override {
stefan4fbd1452015-09-28 03:57:14 -0700100 CriticalSectionScoped cs(crit_sect_.get());
101 rbe_->SetMinBitrate(min_bitrate_bps);
102 min_bitrate_bps_ = min_bitrate_bps;
103 }
104
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +0000105 private:
stefan@webrtc.orga16147c2014-03-25 10:37:31 +0000106 void PickEstimatorFromHeader(const RTPHeader& header)
107 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_.get()) {
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000108 if (header.extension.hasAbsoluteSendTime) {
109 // If we see AST in header, switch RBE strategy immediately.
110 if (!using_absolute_send_time_) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000111 LOG(LS_INFO) <<
112 "WrappingBitrateEstimator: Switching to absolute send time RBE.";
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000113 using_absolute_send_time_ = true;
stefan@webrtc.orga16147c2014-03-25 10:37:31 +0000114 PickEstimator();
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000115 }
116 packets_since_absolute_send_time_ = 0;
117 } else {
118 // When we don't see AST, wait for a few packets before going back to TOF.
119 if (using_absolute_send_time_) {
120 ++packets_since_absolute_send_time_;
121 if (packets_since_absolute_send_time_ >= kTimeOffsetSwitchThreshold) {
mflodman@webrtc.org5574dac2014-04-07 10:56:31 +0000122 LOG(LS_INFO) << "WrappingBitrateEstimator: Switching to transmission "
123 << "time offset RBE.";
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000124 using_absolute_send_time_ = false;
stefan@webrtc.orga16147c2014-03-25 10:37:31 +0000125 PickEstimator();
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000126 }
127 }
128 }
129 }
130
stefan@webrtc.orga16147c2014-03-25 10:37:31 +0000131 // Instantiate RBE for Time Offset or Absolute Send Time extensions.
132 void PickEstimator() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_.get()) {
stefan@webrtc.orga16147c2014-03-25 10:37:31 +0000133 if (using_absolute_send_time_) {
stefan1112b2b2016-04-14 08:08:15 -0700134 rbe_.reset(new RemoteBitrateEstimatorAbsSendTime(observer_));
stefan@webrtc.orga16147c2014-03-25 10:37:31 +0000135 } else {
stefan4fbd1452015-09-28 03:57:14 -0700136 rbe_.reset(new RemoteBitrateEstimatorSingleStream(observer_, clock_));
stefan@webrtc.orga16147c2014-03-25 10:37:31 +0000137 }
stefan4fbd1452015-09-28 03:57:14 -0700138 rbe_->SetMinBitrate(min_bitrate_bps_);
stefan@webrtc.orga16147c2014-03-25 10:37:31 +0000139 }
140
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +0000141 RemoteBitrateObserver* observer_;
Stefan Holmer58c664c2016-02-08 14:31:30 +0100142 Clock* const clock_;
kwiberg22feaa32016-03-17 09:17:43 -0700143 std::unique_ptr<CriticalSectionWrapper> crit_sect_;
144 std::unique_ptr<RemoteBitrateEstimator> rbe_;
pbos@webrtc.org5ab75672013-12-16 12:24:44 +0000145 bool using_absolute_send_time_;
146 uint32_t packets_since_absolute_send_time_;
stefan4fbd1452015-09-28 03:57:14 -0700147 int min_bitrate_bps_;
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +0000148
henrikg3c089d72015-09-16 05:37:44 -0700149 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator);
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +0000150};
sprang867fb522015-08-03 04:38:41 -0700151
solenberg@webrtc.orga6db54d2013-05-27 16:02:56 +0000152} // namespace
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000153
Stefan Holmer58c664c2016-02-08 14:31:30 +0100154CongestionController::CongestionController(
155 Clock* clock,
ivoc9e03c3b2016-06-30 00:59:43 -0700156 BitrateObserver* bitrate_observer,
157 RemoteBitrateObserver* remote_bitrate_observer)
158 : clock_(clock),
159 observer_(nullptr),
160 packet_router_(new PacketRouter()),
161 pacer_(new PacedSender(clock_, packet_router_.get())),
162 remote_bitrate_estimator_(
163 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
164 bitrate_controller_(
165 BitrateController::CreateBitrateController(clock_, bitrate_observer)),
166 remote_estimator_proxy_(clock_, packet_router_.get()),
167 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
168 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
169 last_reported_bitrate_bps_(0),
170 last_reported_fraction_loss_(0),
171 last_reported_rtt_(0),
172 network_state_(kNetworkUp) {
173 Init();
174}
175
176CongestionController::CongestionController(
177 Clock* clock,
perkjec81bcd2016-05-11 06:01:13 -0700178 Observer* observer,
ivoc9e03c3b2016-06-30 00:59:43 -0700179 RemoteBitrateObserver* remote_bitrate_observer)
perkjec81bcd2016-05-11 06:01:13 -0700180 : clock_(clock),
181 observer_(observer),
182 packet_router_(new PacketRouter()),
perkjfea93092016-05-14 00:58:48 -0700183 pacer_(new PacedSender(clock_, packet_router_.get())),
perkjec81bcd2016-05-11 06:01:13 -0700184 remote_bitrate_estimator_(
185 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
ivoc9e03c3b2016-06-30 00:59:43 -0700186 bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
perkjec81bcd2016-05-11 06:01:13 -0700187 remote_estimator_proxy_(clock_, packet_router_.get()),
188 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
189 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
perkjfea93092016-05-14 00:58:48 -0700190 last_reported_bitrate_bps_(0),
191 last_reported_fraction_loss_(0),
192 last_reported_rtt_(0),
193 network_state_(kNetworkUp) {
perkjec81bcd2016-05-11 06:01:13 -0700194 Init();
195}
196
197CongestionController::CongestionController(
198 Clock* clock,
199 Observer* observer,
200 RemoteBitrateObserver* remote_bitrate_observer,
201 std::unique_ptr<PacketRouter> packet_router,
202 std::unique_ptr<PacedSender> pacer)
203 : clock_(clock),
204 observer_(observer),
205 packet_router_(std::move(packet_router)),
206 pacer_(std::move(pacer)),
Erik Språng6b8d3552015-09-24 15:06:57 +0200207 remote_bitrate_estimator_(
Stefan Holmer58c664c2016-02-08 14:31:30 +0100208 new WrappingBitrateEstimator(remote_bitrate_observer, clock_)),
Stefan Holmere5904162015-03-26 11:11:06 +0100209 // Constructed last as this object calls the provided callback on
210 // construction.
ivoc9e03c3b2016-06-30 00:59:43 -0700211 bitrate_controller_(BitrateController::CreateBitrateController(clock_)),
perkjec81bcd2016-05-11 06:01:13 -0700212 remote_estimator_proxy_(clock_, packet_router_.get()),
Stefan Holmer789ba922016-02-17 15:52:17 +0100213 transport_feedback_adapter_(bitrate_controller_.get(), clock_),
perkjec81bcd2016-05-11 06:01:13 -0700214 min_bitrate_bps_(RemoteBitrateEstimator::kDefaultMinBitrateBps),
perkjfea93092016-05-14 00:58:48 -0700215 last_reported_bitrate_bps_(0),
216 last_reported_fraction_loss_(0),
217 last_reported_rtt_(0),
218 network_state_(kNetworkUp) {
perkjec81bcd2016-05-11 06:01:13 -0700219 Init();
220}
221
222CongestionController::~CongestionController() {}
223
224void CongestionController::Init() {
Stefan Holmer789ba922016-02-17 15:52:17 +0100225 transport_feedback_adapter_.SetBitrateEstimator(
philipel863a8262016-06-17 09:21:34 -0700226 new DelayBasedBwe(&transport_feedback_adapter_));
Stefan Holmer789ba922016-02-17 15:52:17 +0100227 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
228 min_bitrate_bps_);
perkje30c2722016-05-09 04:57:11 -0700229}
230
mflodman0c478b32015-10-21 15:52:16 +0200231void CongestionController::SetBweBitrates(int min_bitrate_bps,
232 int start_bitrate_bps,
233 int max_bitrate_bps) {
honghaiz059e1832016-06-24 11:03:55 -0700234 ClampBitrates(&start_bitrate_bps, &min_bitrate_bps, &max_bitrate_bps);
philipelc6957c72016-04-28 15:52:49 +0200235 bitrate_controller_->SetBitrates(start_bitrate_bps,
236 min_bitrate_bps,
237 max_bitrate_bps);
238
Stefan Holmer789ba922016-02-17 15:52:17 +0100239 if (remote_bitrate_estimator_)
stefan4fbd1452015-09-28 03:57:14 -0700240 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
stefan4fbd1452015-09-28 03:57:14 -0700241 min_bitrate_bps_ = min_bitrate_bps;
Stefan Holmer789ba922016-02-17 15:52:17 +0100242 transport_feedback_adapter_.GetBitrateEstimator()->SetMinBitrate(
243 min_bitrate_bps_);
perkjec81bcd2016-05-11 06:01:13 -0700244 MaybeTriggerOnNetworkChanged();
stefan4fbd1452015-09-28 03:57:14 -0700245}
246
honghaiz059e1832016-06-24 11:03:55 -0700247void CongestionController::ResetBweAndBitrates(int bitrate_bps,
248 int min_bitrate_bps,
249 int max_bitrate_bps) {
250 ClampBitrates(&bitrate_bps, &min_bitrate_bps, &max_bitrate_bps);
251 // TODO(honghaiz): Recreate this object once the bitrate controller is
252 // no longer exposed outside CongestionController.
253 bitrate_controller_->ResetBitrates(bitrate_bps, min_bitrate_bps,
254 max_bitrate_bps);
255 min_bitrate_bps_ = min_bitrate_bps;
256 // TODO(honghaiz): Recreate this object once the remote bitrate estimator is
257 // no longer exposed outside CongestionController.
258 if (remote_bitrate_estimator_)
259 remote_bitrate_estimator_->SetMinBitrate(min_bitrate_bps);
260
261 RemoteBitrateEstimator* rbe =
262 new RemoteBitrateEstimatorAbsSendTime(&transport_feedback_adapter_);
263 transport_feedback_adapter_.SetBitrateEstimator(rbe);
264 rbe->SetMinBitrate(min_bitrate_bps);
265 // TODO(holmer): Trigger a new probe once mid-call probing is implemented.
266 MaybeTriggerOnNetworkChanged();
267}
268
mflodman0c478b32015-10-21 15:52:16 +0200269BitrateController* CongestionController::GetBitrateController() const {
bjornv@webrtc.orgcb89c6f2012-06-05 12:25:35 +0000270 return bitrate_controller_.get();
stefan@webrtc.orgf7288142012-06-05 10:44:00 +0000271}
272
mflodman0c478b32015-10-21 15:52:16 +0200273RemoteBitrateEstimator* CongestionController::GetRemoteBitrateEstimator(
Stefan Holmer789ba922016-02-17 15:52:17 +0100274 bool send_side_bwe) {
275 if (send_side_bwe) {
276 return &remote_estimator_proxy_;
277 } else {
mflodmana20de202015-10-18 22:08:19 -0700278 return remote_bitrate_estimator_.get();
Stefan Holmer789ba922016-02-17 15:52:17 +0100279 }
stefan@webrtc.org9354cc92012-06-07 08:10:14 +0000280}
281
mflodman0c478b32015-10-21 15:52:16 +0200282TransportFeedbackObserver*
283CongestionController::GetTransportFeedbackObserver() {
Stefan Holmer789ba922016-02-17 15:52:17 +0100284 return &transport_feedback_adapter_;
mflodman949c2f02015-10-16 02:31:11 -0700285}
286
perkj71ee44c2016-06-15 00:47:53 -0700287void CongestionController::SetAllocatedSendBitrateLimits(
288 int min_send_bitrate_bps,
289 int max_padding_bitrate_bps) {
290 pacer_->SetSendBitrateLimits(min_send_bitrate_bps, max_padding_bitrate_bps);
mflodman0e7e2592015-11-12 21:02:42 -0800291}
292
mflodman0c478b32015-10-21 15:52:16 +0200293int64_t CongestionController::GetPacerQueuingDelayMs() const {
Stefan Holmere5904162015-03-26 11:11:06 +0100294 return pacer_->QueueInMs();
295}
296
mflodman0c478b32015-10-21 15:52:16 +0200297void CongestionController::SignalNetworkState(NetworkState state) {
stefan457a61d2015-10-14 03:12:59 -0700298 if (state == kNetworkUp) {
299 pacer_->Resume();
300 } else {
301 pacer_->Pause();
302 }
perkjfea93092016-05-14 00:58:48 -0700303 {
304 rtc::CritScope cs(&critsect_);
305 network_state_ = state;
306 }
307 MaybeTriggerOnNetworkChanged();
stefan457a61d2015-10-14 03:12:59 -0700308}
309
mflodman0c478b32015-10-21 15:52:16 +0200310void CongestionController::OnSentPacket(const rtc::SentPacket& sent_packet) {
Stefan Holmer789ba922016-02-17 15:52:17 +0100311 transport_feedback_adapter_.OnSentPacket(sent_packet.packet_id,
312 sent_packet.send_time_ms);
stefanc1aeaf02015-10-15 07:26:07 -0700313}
Stefan Holmer789ba922016-02-17 15:52:17 +0100314
315void CongestionController::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) {
316 remote_bitrate_estimator_->OnRttUpdate(avg_rtt_ms, max_rtt_ms);
317 transport_feedback_adapter_.OnRttUpdate(avg_rtt_ms, max_rtt_ms);
318}
319
320int64_t CongestionController::TimeUntilNextProcess() {
321 return std::min(bitrate_controller_->TimeUntilNextProcess(),
322 remote_bitrate_estimator_->TimeUntilNextProcess());
323}
324
pbosa26ac922016-02-25 04:50:01 -0800325void CongestionController::Process() {
Stefan Holmer789ba922016-02-17 15:52:17 +0100326 bitrate_controller_->Process();
327 remote_bitrate_estimator_->Process();
perkjec81bcd2016-05-11 06:01:13 -0700328 MaybeTriggerOnNetworkChanged();
329}
330
331void CongestionController::MaybeTriggerOnNetworkChanged() {
332 // TODO(perkj): |observer_| can be nullptr if the ctor that accepts a
333 // BitrateObserver is used. Remove this check once the ctor is removed.
334 if (!observer_)
335 return;
336
337 uint32_t bitrate_bps;
338 uint8_t fraction_loss;
339 int64_t rtt;
perkjfea93092016-05-14 00:58:48 -0700340 bool estimate_changed = bitrate_controller_->GetNetworkParameters(
perkjec81bcd2016-05-11 06:01:13 -0700341 &bitrate_bps, &fraction_loss, &rtt);
perkjfea93092016-05-14 00:58:48 -0700342 if (estimate_changed)
perkjec81bcd2016-05-11 06:01:13 -0700343 pacer_->SetEstimatedBitrate(bitrate_bps);
perkjfea93092016-05-14 00:58:48 -0700344
345 bitrate_bps = IsNetworkDown() || IsSendQueueFull() ? 0 : bitrate_bps;
346
347 if (HasNetworkParametersToReportChanged(bitrate_bps, fraction_loss, rtt)) {
perkjec81bcd2016-05-11 06:01:13 -0700348 observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt);
349 }
350}
351
perkjfea93092016-05-14 00:58:48 -0700352bool CongestionController::HasNetworkParametersToReportChanged(
353 uint32_t bitrate_bps,
354 uint8_t fraction_loss,
355 int64_t rtt) {
perkjec81bcd2016-05-11 06:01:13 -0700356 rtc::CritScope cs(&critsect_);
perkjfea93092016-05-14 00:58:48 -0700357 bool changed =
358 last_reported_bitrate_bps_ != bitrate_bps ||
359 (bitrate_bps > 0 && (last_reported_fraction_loss_ != fraction_loss ||
360 last_reported_rtt_ != rtt));
361 last_reported_bitrate_bps_ = bitrate_bps;
362 last_reported_fraction_loss_ = fraction_loss;
363 last_reported_rtt_ = rtt;
364 return changed;
365}
366
367bool CongestionController::IsSendQueueFull() const {
368 return pacer_->ExpectedQueueTimeMs() > PacedSender::kMaxQueueLengthMs;
369}
370
371bool CongestionController::IsNetworkDown() const {
372 rtc::CritScope cs(&critsect_);
373 return network_state_ == kNetworkDown;
Stefan Holmer789ba922016-02-17 15:52:17 +0100374}
375
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000376} // namespace webrtc