blob: 1c04c119dffd4e9fe21b37cd1b6e1402ff1a0de7 [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#ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
12#define WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000013
kwiberg84be5112016-04-27 01:19:58 -070014#include <memory>
15
kwiberg4485ffb2016-04-26 08:14:39 -070016#include "webrtc/base/constructormagic.h"
pbos1ba8d392016-05-01 20:18:34 -070017#include "webrtc/common_types.h"
Stefan Holmer789ba922016-02-17 15:52:17 +010018#include "webrtc/modules/include/module.h"
19#include "webrtc/modules/include/module_common_types.h"
20#include "webrtc/modules/pacing/packet_router.h"
perkjec81bcd2016-05-11 06:01:13 -070021#include "webrtc/modules/pacing/paced_sender.h"
Stefan Holmer789ba922016-02-17 15:52:17 +010022#include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h"
23#include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h"
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000024
Stefan Holmer58c664c2016-02-08 14:31:30 +010025namespace rtc {
26struct SentPacket;
27}
28
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000029namespace webrtc {
30
mflodman0e7e2592015-11-12 21:02:42 -080031class BitrateController;
32class BitrateObserver;
Stefan Holmer58c664c2016-02-08 14:31:30 +010033class Clock;
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000034class ProcessThread;
andresp@webrtc.org29b22192013-05-14 12:10:58 +000035class RemoteBitrateEstimator;
Stefan Holmer58c664c2016-02-08 14:31:30 +010036class RemoteBitrateObserver;
mflodman0e7e2592015-11-12 21:02:42 -080037class TransportFeedbackObserver;
stefan@webrtc.orga50e6f02015-03-09 10:06:40 +000038
Stefan Holmer789ba922016-02-17 15:52:17 +010039class CongestionController : public CallStatsObserver, public Module {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000040 public:
perkjec81bcd2016-05-11 06:01:13 -070041 // Observer class for bitrate changes announced due to change in bandwidth
42 // estimate or due to that the send pacer is full. Fraction loss and rtt is
43 // also part of this callback to allow the observer to optimize its settings
44 // for different types of network environments. The bitrate does not include
45 // packet headers and is measured in bits per second.
46 class Observer {
47 public:
48 virtual void OnNetworkChanged(uint32_t bitrate_bps,
49 uint8_t fraction_loss, // 0 - 255.
50 int64_t rtt_ms) = 0;
51
52 protected:
53 virtual ~Observer() {}
54 };
55 // Deprecated
56 // TODO(perkj): Remove once no other clients use this ctor.
Stefan Holmer58c664c2016-02-08 14:31:30 +010057 CongestionController(Clock* clock,
perkj825eb582016-05-04 01:08:05 -070058 BitrateObserver* bitrate_observer,
Stefan Holmer58c664c2016-02-08 14:31:30 +010059 RemoteBitrateObserver* remote_bitrate_observer);
perkjec81bcd2016-05-11 06:01:13 -070060 CongestionController(Clock* clock,
61 Observer* observer,
62 RemoteBitrateObserver* remote_bitrate_observer);
63 CongestionController(Clock* clock,
64 Observer* observer,
65 RemoteBitrateObserver* remote_bitrate_observer,
66 std::unique_ptr<PacketRouter> packet_router,
67 std::unique_ptr<PacedSender> pacer);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010068 virtual ~CongestionController();
Stefan Holmer789ba922016-02-17 15:52:17 +010069
Stefan Holmer3842c5c2016-01-12 13:55:00 +010070 virtual void SetBweBitrates(int min_bitrate_bps,
71 int start_bitrate_bps,
72 int max_bitrate_bps);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010073 virtual void SignalNetworkState(NetworkState state);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010074 virtual BitrateController* GetBitrateController() const;
75 virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator(
Stefan Holmer789ba922016-02-17 15:52:17 +010076 bool send_side_bwe);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010077 virtual int64_t GetPacerQueuingDelayMs() const;
Stefan Holmer789ba922016-02-17 15:52:17 +010078 virtual PacedSender* pacer() { return pacer_.get(); }
perkjec81bcd2016-05-11 06:01:13 -070079 virtual PacketRouter* packet_router() { return packet_router_.get(); }
Stefan Holmer3842c5c2016-01-12 13:55:00 +010080 virtual TransportFeedbackObserver* GetTransportFeedbackObserver();
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +000081
perkj71ee44c2016-06-15 00:47:53 -070082 // SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec
83 // settings.
84 // |min_send_bitrate_bps| is the total minimum send bitrate required by all
85 // sending streams. This is the minimum bitrate the PacedSender will use.
86 // Note that CongestionController::OnNetworkChanged can still be called with
87 // a lower bitrate estimate.
88 // |max_padding_bitrate_bps| is the max bitrate the send streams request for
89 // padding. This can be higher than the current network estimate and tells
90 // the PacedSender how much it should max pad unless there is real packets to
91 // send.
92 void SetAllocatedSendBitrateLimits(int min_send_bitrate_bps,
93 int max_padding_bitrate_bps);
stefan@webrtc.org792f1a12015-03-04 12:24:26 +000094
Stefan Holmer3842c5c2016-01-12 13:55:00 +010095 virtual void OnSentPacket(const rtc::SentPacket& sent_packet);
stefanc1aeaf02015-10-15 07:26:07 -070096
Stefan Holmer789ba922016-02-17 15:52:17 +010097 // Implements CallStatsObserver.
98 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
99
100 // Implements Module.
101 int64_t TimeUntilNextProcess() override;
pbosa26ac922016-02-25 04:50:01 -0800102 void Process() override;
Stefan Holmer789ba922016-02-17 15:52:17 +0100103
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000104 private:
perkjec81bcd2016-05-11 06:01:13 -0700105 void Init();
106 void MaybeTriggerOnNetworkChanged();
perkjec81bcd2016-05-11 06:01:13 -0700107
perkjfea93092016-05-14 00:58:48 -0700108 bool IsSendQueueFull() const;
109 bool IsNetworkDown() const;
110 bool HasNetworkParametersToReportChanged(uint32_t bitrate_bps,
111 uint8_t fraction_loss,
112 int64_t rtt);
Stefan Holmer58c664c2016-02-08 14:31:30 +0100113 Clock* const clock_;
perkjec81bcd2016-05-11 06:01:13 -0700114 Observer* const observer_;
115 const std::unique_ptr<PacketRouter> packet_router_;
kwiberg84be5112016-04-27 01:19:58 -0700116 const std::unique_ptr<PacedSender> pacer_;
117 const std::unique_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
118 const std::unique_ptr<BitrateController> bitrate_controller_;
Stefan Holmer789ba922016-02-17 15:52:17 +0100119 RemoteEstimatorProxy remote_estimator_proxy_;
120 TransportFeedbackAdapter transport_feedback_adapter_;
stefan4fbd1452015-09-28 03:57:14 -0700121 int min_bitrate_bps_;
perkjec81bcd2016-05-11 06:01:13 -0700122 rtc::CriticalSection critsect_;
perkjfea93092016-05-14 00:58:48 -0700123 uint32_t last_reported_bitrate_bps_ GUARDED_BY(critsect_);
124 uint8_t last_reported_fraction_loss_ GUARDED_BY(critsect_);
125 int64_t last_reported_rtt_ GUARDED_BY(critsect_);
126 NetworkState network_state_ GUARDED_BY(critsect_);
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100127
128 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000129};
130
131} // namespace webrtc
132
Stefan Holmer80e12072016-02-23 13:30:42 +0100133#endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_