blob: ed37b9a4ce67dfcf55d250579c93c98561b571a8 [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 Holmer280de9e2016-09-30 10:06:51 +020018#include "webrtc/modules/congestion_controller/transport_feedback_adapter.h"
Stefan Holmer789ba922016-02-17 15:52:17 +010019#include "webrtc/modules/include/module.h"
20#include "webrtc/modules/include/module_common_types.h"
21#include "webrtc/modules/pacing/packet_router.h"
perkjec81bcd2016-05-11 06:01:13 -070022#include "webrtc/modules/pacing/paced_sender.h"
Stefan Holmer789ba922016-02-17 15:52:17 +010023#include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.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;
Stefan Holmer58c664c2016-02-08 14:31:30 +010032class Clock;
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070033class ProbeController;
sprangcd349d92016-07-13 09:11:28 -070034class RateLimiter;
andresp@webrtc.org29b22192013-05-14 12:10:58 +000035class RemoteBitrateEstimator;
Stefan Holmer58c664c2016-02-08 14:31:30 +010036class RemoteBitrateObserver;
ivoc14d5dbe2016-07-04 07:06:55 -070037class RtcEventLog;
mflodman0e7e2592015-11-12 21:02:42 -080038class TransportFeedbackObserver;
stefan@webrtc.orga50e6f02015-03-09 10:06:40 +000039
Stefan Holmer789ba922016-02-17 15:52:17 +010040class CongestionController : public CallStatsObserver, public Module {
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000041 public:
perkjec81bcd2016-05-11 06:01:13 -070042 // Observer class for bitrate changes announced due to change in bandwidth
43 // estimate or due to that the send pacer is full. Fraction loss and rtt is
44 // also part of this callback to allow the observer to optimize its settings
45 // for different types of network environments. The bitrate does not include
46 // packet headers and is measured in bits per second.
47 class Observer {
48 public:
49 virtual void OnNetworkChanged(uint32_t bitrate_bps,
50 uint8_t fraction_loss, // 0 - 255.
ossu6287e822016-11-28 08:05:16 -080051 int64_t rtt_ms) = 0;
perkjec81bcd2016-05-11 06:01:13 -070052
53 protected:
54 virtual ~Observer() {}
55 };
perkjec81bcd2016-05-11 06:01:13 -070056 CongestionController(Clock* clock,
57 Observer* observer,
58 RemoteBitrateObserver* remote_bitrate_observer,
nisse0245da02016-11-30 03:35:20 -080059 RtcEventLog* event_log,
60 PacketRouter* packet_router);
61 // TODO(nisse): Deprecated. Will create and own a PacketRouter.
62 CongestionController(Clock* clock,
63 Observer* observer,
64 RemoteBitrateObserver* remote_bitrate_observer,
ivoc14d5dbe2016-07-04 07:06:55 -070065 RtcEventLog* event_log);
66 CongestionController(Clock* clock,
67 Observer* observer,
68 RemoteBitrateObserver* remote_bitrate_observer,
69 RtcEventLog* event_log,
nisse0245da02016-11-30 03:35:20 -080070 PacketRouter* packet_router,
perkjec81bcd2016-05-11 06:01:13 -070071 std::unique_ptr<PacedSender> pacer);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010072 virtual ~CongestionController();
Stefan Holmer789ba922016-02-17 15:52:17 +010073
Stefan Holmer3842c5c2016-01-12 13:55:00 +010074 virtual void SetBweBitrates(int min_bitrate_bps,
75 int start_bitrate_bps,
76 int max_bitrate_bps);
honghaiz059e1832016-06-24 11:03:55 -070077 // Resets both the BWE state and the bitrate estimator. Note the first
78 // argument is the bitrate_bps.
79 virtual void ResetBweAndBitrates(int bitrate_bps,
80 int min_bitrate_bps,
81 int max_bitrate_bps);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010082 virtual void SignalNetworkState(NetworkState state);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010083 virtual BitrateController* GetBitrateController() const;
84 virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator(
Stefan Holmer789ba922016-02-17 15:52:17 +010085 bool send_side_bwe);
Stefan Holmer3842c5c2016-01-12 13:55:00 +010086 virtual int64_t GetPacerQueuingDelayMs() const;
Stefan Holmer789ba922016-02-17 15:52:17 +010087 virtual PacedSender* pacer() { return pacer_.get(); }
nisse0245da02016-11-30 03:35:20 -080088 // TODO(nisse): Deprecated, but still used by downstream projects.
89 virtual PacketRouter* packet_router() { return packet_router_; }
Stefan Holmer3842c5c2016-01-12 13:55:00 +010090 virtual TransportFeedbackObserver* GetTransportFeedbackObserver();
sprangcd349d92016-07-13 09:11:28 -070091 RateLimiter* GetRetransmissionRateLimiter();
sergeyu80ed35e2016-11-28 13:11:13 -080092 void EnablePeriodicAlrProbing(bool enable);
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +000093
perkj71ee44c2016-06-15 00:47:53 -070094 // SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec
95 // settings.
96 // |min_send_bitrate_bps| is the total minimum send bitrate required by all
97 // sending streams. This is the minimum bitrate the PacedSender will use.
98 // Note that CongestionController::OnNetworkChanged can still be called with
99 // a lower bitrate estimate.
100 // |max_padding_bitrate_bps| is the max bitrate the send streams request for
101 // padding. This can be higher than the current network estimate and tells
102 // the PacedSender how much it should max pad unless there is real packets to
103 // send.
104 void SetAllocatedSendBitrateLimits(int min_send_bitrate_bps,
105 int max_padding_bitrate_bps);
stefan@webrtc.org792f1a12015-03-04 12:24:26 +0000106
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100107 virtual void OnSentPacket(const rtc::SentPacket& sent_packet);
stefanc1aeaf02015-10-15 07:26:07 -0700108
Stefan Holmer789ba922016-02-17 15:52:17 +0100109 // Implements CallStatsObserver.
110 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
111
112 // Implements Module.
113 int64_t TimeUntilNextProcess() override;
pbosa26ac922016-02-25 04:50:01 -0800114 void Process() override;
Stefan Holmer789ba922016-02-17 15:52:17 +0100115
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000116 private:
perkjec81bcd2016-05-11 06:01:13 -0700117 void MaybeTriggerOnNetworkChanged();
perkjec81bcd2016-05-11 06:01:13 -0700118
perkjfea93092016-05-14 00:58:48 -0700119 bool IsSendQueueFull() const;
120 bool IsNetworkDown() const;
121 bool HasNetworkParametersToReportChanged(uint32_t bitrate_bps,
122 uint8_t fraction_loss,
123 int64_t rtt);
Stefan Holmer58c664c2016-02-08 14:31:30 +0100124 Clock* const clock_;
perkjec81bcd2016-05-11 06:01:13 -0700125 Observer* const observer_;
nisse0245da02016-11-30 03:35:20 -0800126 // Used by the deprecated constructor, where caller doesn't provide
127 // the packet_router.
128 std::unique_ptr<PacketRouter> owned_packet_router_;
129 PacketRouter* const packet_router_;
kwiberg84be5112016-04-27 01:19:58 -0700130 const std::unique_ptr<PacedSender> pacer_;
131 const std::unique_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
132 const std::unique_ptr<BitrateController> bitrate_controller_;
Irfan Sheriffb2540bb2016-09-12 12:28:54 -0700133 const std::unique_ptr<ProbeController> probe_controller_;
sprangcd349d92016-07-13 09:11:28 -0700134 const std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
Stefan Holmer789ba922016-02-17 15:52:17 +0100135 RemoteEstimatorProxy remote_estimator_proxy_;
136 TransportFeedbackAdapter transport_feedback_adapter_;
stefan4fbd1452015-09-28 03:57:14 -0700137 int min_bitrate_bps_;
philipeleb680ea2016-08-17 11:11:59 +0200138 int max_bitrate_bps_;
perkjec81bcd2016-05-11 06:01:13 -0700139 rtc::CriticalSection critsect_;
perkjfea93092016-05-14 00:58:48 -0700140 uint32_t last_reported_bitrate_bps_ GUARDED_BY(critsect_);
141 uint8_t last_reported_fraction_loss_ GUARDED_BY(critsect_);
142 int64_t last_reported_rtt_ GUARDED_BY(critsect_);
143 NetworkState network_state_ GUARDED_BY(critsect_);
Stefan Holmer3842c5c2016-01-12 13:55:00 +0100144
145 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController);
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +0000146};
147
148} // namespace webrtc
149
Stefan Holmer80e12072016-02-23 13:30:42 +0100150#endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_