Line data Source code
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 :
11 : #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
12 : #define WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
13 :
14 : #include <memory>
15 :
16 : #include "webrtc/base/constructormagic.h"
17 : #include "webrtc/base/deprecation.h"
18 : #include "webrtc/common_types.h"
19 : #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h"
20 : #include "webrtc/modules/include/module.h"
21 : #include "webrtc/modules/include/module_common_types.h"
22 : #include "webrtc/modules/pacing/packet_router.h"
23 : #include "webrtc/modules/pacing/paced_sender.h"
24 : #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h"
25 :
26 : namespace rtc {
27 : struct SentPacket;
28 : }
29 :
30 : namespace webrtc {
31 :
32 : class BitrateController;
33 : class Clock;
34 : class ProbeController;
35 : class RateLimiter;
36 : class RemoteBitrateEstimator;
37 : class RemoteBitrateObserver;
38 : class RtcEventLog;
39 : class TransportFeedbackObserver;
40 :
41 : class CongestionController : public CallStatsObserver, public Module {
42 : public:
43 : // Observer class for bitrate changes announced due to change in bandwidth
44 : // estimate or due to that the send pacer is full. Fraction loss and rtt is
45 : // also part of this callback to allow the observer to optimize its settings
46 : // for different types of network environments. The bitrate does not include
47 : // packet headers and is measured in bits per second.
48 0 : class Observer {
49 : public:
50 : virtual void OnNetworkChanged(uint32_t bitrate_bps,
51 : uint8_t fraction_loss, // 0 - 255.
52 : int64_t rtt_ms,
53 : int64_t probing_interval_ms) = 0;
54 :
55 : protected:
56 0 : virtual ~Observer() {}
57 : };
58 : CongestionController(Clock* clock,
59 : Observer* observer,
60 : RemoteBitrateObserver* remote_bitrate_observer,
61 : RtcEventLog* event_log,
62 : PacketRouter* packet_router);
63 : CongestionController(Clock* clock,
64 : Observer* observer,
65 : RemoteBitrateObserver* remote_bitrate_observer,
66 : RtcEventLog* event_log,
67 : PacketRouter* packet_router,
68 : std::unique_ptr<PacedSender> pacer);
69 : virtual ~CongestionController();
70 :
71 : virtual void OnReceivedPacket(int64_t arrival_time_ms,
72 : size_t payload_size,
73 : const RTPHeader& header);
74 :
75 : virtual void SetBweBitrates(int min_bitrate_bps,
76 : int start_bitrate_bps,
77 : int max_bitrate_bps);
78 : // Resets both the BWE state and the bitrate estimator. Note the first
79 : // argument is the bitrate_bps.
80 : virtual void ResetBweAndBitrates(int bitrate_bps,
81 : int min_bitrate_bps,
82 : int max_bitrate_bps);
83 : virtual void SignalNetworkState(NetworkState state);
84 : virtual void SetTransportOverhead(size_t transport_overhead_bytes_per_packet);
85 :
86 : virtual BitrateController* GetBitrateController() const;
87 : virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator(
88 : bool send_side_bwe);
89 : virtual int64_t GetPacerQueuingDelayMs() const;
90 : // TODO(nisse): Delete this accessor function. The pacer should be
91 : // internal to the congestion controller.
92 0 : virtual PacedSender* pacer() { return pacer_.get(); }
93 : virtual TransportFeedbackObserver* GetTransportFeedbackObserver();
94 : RateLimiter* GetRetransmissionRateLimiter();
95 : void EnablePeriodicAlrProbing(bool enable);
96 :
97 : // SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec
98 : // settings.
99 : // |min_send_bitrate_bps| is the total minimum send bitrate required by all
100 : // sending streams. This is the minimum bitrate the PacedSender will use.
101 : // Note that CongestionController::OnNetworkChanged can still be called with
102 : // a lower bitrate estimate.
103 : // |max_padding_bitrate_bps| is the max bitrate the send streams request for
104 : // padding. This can be higher than the current network estimate and tells
105 : // the PacedSender how much it should max pad unless there is real packets to
106 : // send.
107 : void SetAllocatedSendBitrateLimits(int min_send_bitrate_bps,
108 : int max_padding_bitrate_bps);
109 :
110 : virtual void OnSentPacket(const rtc::SentPacket& sent_packet);
111 :
112 : // Implements CallStatsObserver.
113 : void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override;
114 :
115 : // Implements Module.
116 : int64_t TimeUntilNextProcess() override;
117 : void Process() override;
118 :
119 : private:
120 : void MaybeTriggerOnNetworkChanged();
121 :
122 : bool IsSendQueueFull() const;
123 : bool IsNetworkDown() const;
124 : bool HasNetworkParametersToReportChanged(uint32_t bitrate_bps,
125 : uint8_t fraction_loss,
126 : int64_t rtt);
127 : Clock* const clock_;
128 : Observer* const observer_;
129 : PacketRouter* const packet_router_;
130 : const std::unique_ptr<PacedSender> pacer_;
131 : const std::unique_ptr<RemoteBitrateEstimator> remote_bitrate_estimator_;
132 : const std::unique_ptr<BitrateController> bitrate_controller_;
133 : const std::unique_ptr<ProbeController> probe_controller_;
134 : const std::unique_ptr<RateLimiter> retransmission_rate_limiter_;
135 : RemoteEstimatorProxy remote_estimator_proxy_;
136 : TransportFeedbackAdapter transport_feedback_adapter_;
137 : int min_bitrate_bps_;
138 : int max_bitrate_bps_;
139 : rtc::CriticalSection critsect_;
140 : 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_);
144 :
145 : RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController);
146 : };
147 :
148 : } // namespace webrtc
149 :
150 : #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_
|