mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 1 | /* |
| 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 Holmer | 80e1207 | 2016-02-23 13:30:42 +0100 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ |
| 12 | #define WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 13 | |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
kwiberg | 4485ffb | 2016-04-26 08:14:39 -0700 | [diff] [blame] | 16 | #include "webrtc/base/constructormagic.h" |
pbos | 1ba8d39 | 2016-05-01 20:18:34 -0700 | [diff] [blame] | 17 | #include "webrtc/common_types.h" |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 18 | #include "webrtc/modules/include/module.h" |
| 19 | #include "webrtc/modules/include/module_common_types.h" |
| 20 | #include "webrtc/modules/pacing/packet_router.h" |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 21 | #include "webrtc/modules/pacing/paced_sender.h" |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 22 | #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
| 23 | #include "webrtc/modules/remote_bitrate_estimator/transport_feedback_adapter.h" |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 24 | |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 25 | namespace rtc { |
| 26 | struct SentPacket; |
| 27 | } |
| 28 | |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 29 | namespace webrtc { |
| 30 | |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 31 | class BitrateController; |
| 32 | class BitrateObserver; |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 33 | class Clock; |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 34 | class ProcessThread; |
andresp@webrtc.org | 29b2219 | 2013-05-14 12:10:58 +0000 | [diff] [blame] | 35 | class RemoteBitrateEstimator; |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 36 | class RemoteBitrateObserver; |
mflodman | 0e7e259 | 2015-11-12 21:02:42 -0800 | [diff] [blame] | 37 | class TransportFeedbackObserver; |
stefan@webrtc.org | a50e6f0 | 2015-03-09 10:06:40 +0000 | [diff] [blame] | 38 | |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 39 | class CongestionController : public CallStatsObserver, public Module { |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 40 | public: |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 41 | // 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 Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 57 | CongestionController(Clock* clock, |
perkj | 825eb58 | 2016-05-04 01:08:05 -0700 | [diff] [blame] | 58 | BitrateObserver* bitrate_observer, |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 59 | RemoteBitrateObserver* remote_bitrate_observer); |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 60 | 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 Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 68 | virtual ~CongestionController(); |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 69 | |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 70 | virtual void SetBweBitrates(int min_bitrate_bps, |
| 71 | int start_bitrate_bps, |
| 72 | int max_bitrate_bps); |
honghaiz | 059e183 | 2016-06-24 11:03:55 -0700 | [diff] [blame^] | 73 | // Resets both the BWE state and the bitrate estimator. Note the first |
| 74 | // argument is the bitrate_bps. |
| 75 | virtual void ResetBweAndBitrates(int bitrate_bps, |
| 76 | int min_bitrate_bps, |
| 77 | int max_bitrate_bps); |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 78 | virtual void SignalNetworkState(NetworkState state); |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 79 | virtual BitrateController* GetBitrateController() const; |
| 80 | virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator( |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 81 | bool send_side_bwe); |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 82 | virtual int64_t GetPacerQueuingDelayMs() const; |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 83 | virtual PacedSender* pacer() { return pacer_.get(); } |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 84 | virtual PacketRouter* packet_router() { return packet_router_.get(); } |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 85 | virtual TransportFeedbackObserver* GetTransportFeedbackObserver(); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 +0000 | [diff] [blame] | 86 | |
perkj | 71ee44c | 2016-06-15 00:47:53 -0700 | [diff] [blame] | 87 | // SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec |
| 88 | // settings. |
| 89 | // |min_send_bitrate_bps| is the total minimum send bitrate required by all |
| 90 | // sending streams. This is the minimum bitrate the PacedSender will use. |
| 91 | // Note that CongestionController::OnNetworkChanged can still be called with |
| 92 | // a lower bitrate estimate. |
| 93 | // |max_padding_bitrate_bps| is the max bitrate the send streams request for |
| 94 | // padding. This can be higher than the current network estimate and tells |
| 95 | // the PacedSender how much it should max pad unless there is real packets to |
| 96 | // send. |
| 97 | void SetAllocatedSendBitrateLimits(int min_send_bitrate_bps, |
| 98 | int max_padding_bitrate_bps); |
stefan@webrtc.org | 792f1a1 | 2015-03-04 12:24:26 +0000 | [diff] [blame] | 99 | |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 100 | virtual void OnSentPacket(const rtc::SentPacket& sent_packet); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 101 | |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 102 | // Implements CallStatsObserver. |
| 103 | void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; |
| 104 | |
| 105 | // Implements Module. |
| 106 | int64_t TimeUntilNextProcess() override; |
pbos | a26ac92 | 2016-02-25 04:50:01 -0800 | [diff] [blame] | 107 | void Process() override; |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 108 | |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 109 | private: |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 110 | void Init(); |
| 111 | void MaybeTriggerOnNetworkChanged(); |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 112 | |
perkj | fea9309 | 2016-05-14 00:58:48 -0700 | [diff] [blame] | 113 | bool IsSendQueueFull() const; |
| 114 | bool IsNetworkDown() const; |
| 115 | bool HasNetworkParametersToReportChanged(uint32_t bitrate_bps, |
| 116 | uint8_t fraction_loss, |
| 117 | int64_t rtt); |
Stefan Holmer | 58c664c | 2016-02-08 14:31:30 +0100 | [diff] [blame] | 118 | Clock* const clock_; |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 119 | Observer* const observer_; |
| 120 | const std::unique_ptr<PacketRouter> packet_router_; |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 121 | const std::unique_ptr<PacedSender> pacer_; |
| 122 | const std::unique_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_; |
| 123 | const std::unique_ptr<BitrateController> bitrate_controller_; |
Stefan Holmer | 789ba92 | 2016-02-17 15:52:17 +0100 | [diff] [blame] | 124 | RemoteEstimatorProxy remote_estimator_proxy_; |
| 125 | TransportFeedbackAdapter transport_feedback_adapter_; |
stefan | 4fbd145 | 2015-09-28 03:57:14 -0700 | [diff] [blame] | 126 | int min_bitrate_bps_; |
perkj | ec81bcd | 2016-05-11 06:01:13 -0700 | [diff] [blame] | 127 | rtc::CriticalSection critsect_; |
perkj | fea9309 | 2016-05-14 00:58:48 -0700 | [diff] [blame] | 128 | uint32_t last_reported_bitrate_bps_ GUARDED_BY(critsect_); |
| 129 | uint8_t last_reported_fraction_loss_ GUARDED_BY(critsect_); |
| 130 | int64_t last_reported_rtt_ GUARDED_BY(critsect_); |
| 131 | NetworkState network_state_ GUARDED_BY(critsect_); |
Stefan Holmer | 3842c5c | 2016-01-12 13:55:00 +0100 | [diff] [blame] | 132 | |
| 133 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController); |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | } // namespace webrtc |
| 137 | |
Stefan Holmer | 80e1207 | 2016-02-23 13:30:42 +0100 | [diff] [blame] | 138 | #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ |