| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ | 11 #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ |
| 12 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ | 12 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ |
| 13 | 13 |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <utility> |
| 15 #include <vector> | 16 #include <vector> |
| 16 | 17 |
| 17 #include "webrtc/base/constructormagic.h" | 18 #include "webrtc/base/constructormagic.h" |
| 18 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
| 19 #include "webrtc/base/networkroute.h" | 20 #include "webrtc/base/networkroute.h" |
| 20 #include "webrtc/base/thread_checker.h" | 21 #include "webrtc/base/thread_checker.h" |
| 21 #include "webrtc/common_types.h" | 22 #include "webrtc/common_types.h" |
| 22 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" | 23 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
| 24 #include "webrtc/modules/congestion_controller/include/receive_side_congestion_c
ontroller.h" |
| 25 #include "webrtc/modules/congestion_controller/include/send_side_congestion_cont
roller.h" |
| 23 #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h" | 26 #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h" |
| 24 #include "webrtc/modules/include/module.h" | 27 #include "webrtc/modules/include/module.h" |
| 25 #include "webrtc/modules/include/module_common_types.h" | 28 #include "webrtc/modules/include/module_common_types.h" |
| 26 #include "webrtc/modules/pacing/paced_sender.h" | 29 #include "webrtc/modules/pacing/paced_sender.h" |
| 27 #include "webrtc/modules/pacing/packet_router.h" | 30 #include "webrtc/modules/pacing/packet_router.h" |
| 28 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" | |
| 29 | 31 |
| 30 namespace rtc { | 32 namespace rtc { |
| 31 struct SentPacket; | 33 struct SentPacket; |
| 32 } | 34 } |
| 33 | 35 |
| 34 namespace webrtc { | 36 namespace webrtc { |
| 35 | 37 |
| 36 class BitrateController; | 38 class BitrateController; |
| 37 class Clock; | 39 class Clock; |
| 38 class ProbeController; | 40 class ProbeController; |
| 39 class RateLimiter; | 41 class RateLimiter; |
| 40 class RemoteBitrateEstimator; | 42 class RemoteBitrateEstimator; |
| 41 class RemoteBitrateObserver; | 43 class RemoteBitrateObserver; |
| 42 class RtcEventLog; | 44 class RtcEventLog; |
| 43 | 45 |
| 44 class CongestionController : public CallStatsObserver, | 46 class CongestionController : public CallStatsObserver, |
| 45 public Module, | 47 public Module, |
| 46 public TransportFeedbackObserver { | 48 public TransportFeedbackObserver { |
| 47 public: | 49 public: |
| 48 // Observer class for bitrate changes announced due to change in bandwidth | 50 using Observer = SendSideCongestionController::Observer; |
| 49 // estimate or due to that the send pacer is full. Fraction loss and rtt is | |
| 50 // also part of this callback to allow the observer to optimize its settings | |
| 51 // for different types of network environments. The bitrate does not include | |
| 52 // packet headers and is measured in bits per second. | |
| 53 class Observer { | |
| 54 public: | |
| 55 virtual void OnNetworkChanged(uint32_t bitrate_bps, | |
| 56 uint8_t fraction_loss, // 0 - 255. | |
| 57 int64_t rtt_ms, | |
| 58 int64_t probing_interval_ms) = 0; | |
| 59 | 51 |
| 60 protected: | |
| 61 virtual ~Observer() {} | |
| 62 }; | |
| 63 CongestionController(const Clock* clock, | 52 CongestionController(const Clock* clock, |
| 64 Observer* observer, | 53 Observer* observer, |
| 65 RemoteBitrateObserver* remote_bitrate_observer, | 54 RemoteBitrateObserver* remote_bitrate_observer, |
| 66 RtcEventLog* event_log, | 55 RtcEventLog* event_log, |
| 67 PacketRouter* packet_router); | 56 PacketRouter* packet_router) |
| 57 : send_side_cc_(clock, observer, event_log, packet_router), |
| 58 receive_side_cc_(clock, remote_bitrate_observer, packet_router) {} |
| 68 CongestionController(const Clock* clock, | 59 CongestionController(const Clock* clock, |
| 69 Observer* observer, | 60 Observer* observer, |
| 70 RemoteBitrateObserver* remote_bitrate_observer, | 61 RemoteBitrateObserver* remote_bitrate_observer, |
| 71 RtcEventLog* event_log, | 62 RtcEventLog* event_log, |
| 72 PacketRouter* packet_router, | 63 PacketRouter* packet_router, |
| 73 std::unique_ptr<PacedSender> pacer); | 64 std::unique_ptr<PacedSender> pacer) |
| 74 virtual ~CongestionController(); | 65 : send_side_cc_(clock, observer, event_log, std::move(pacer)), |
| 66 receive_side_cc_(clock, remote_bitrate_observer, packet_router) {} |
| 67 |
| 68 virtual ~CongestionController() {} |
| 75 | 69 |
| 76 virtual void OnReceivedPacket(int64_t arrival_time_ms, | 70 virtual void OnReceivedPacket(int64_t arrival_time_ms, |
| 77 size_t payload_size, | 71 size_t payload_size, |
| 78 const RTPHeader& header); | 72 const RTPHeader& header); |
| 79 | 73 |
| 80 virtual void SetBweBitrates(int min_bitrate_bps, | 74 virtual void SetBweBitrates(int min_bitrate_bps, |
| 81 int start_bitrate_bps, | 75 int start_bitrate_bps, |
| 82 int max_bitrate_bps); | 76 int max_bitrate_bps); |
| 83 // Resets both the BWE state and the bitrate estimator. Note the first | 77 // Resets both the BWE state and the bitrate estimator. Note the first |
| 84 // argument is the bitrate_bps. | 78 // argument is the bitrate_bps. |
| 85 virtual void OnNetworkRouteChanged(const rtc::NetworkRoute& network_route, | 79 virtual void OnNetworkRouteChanged(const rtc::NetworkRoute& network_route, |
| 86 int bitrate_bps, | 80 int bitrate_bps, |
| 87 int min_bitrate_bps, | 81 int min_bitrate_bps, |
| 88 int max_bitrate_bps); | 82 int max_bitrate_bps); |
| 89 virtual void SignalNetworkState(NetworkState state); | 83 virtual void SignalNetworkState(NetworkState state); |
| 90 virtual void SetTransportOverhead(size_t transport_overhead_bytes_per_packet); | 84 virtual void SetTransportOverhead(size_t transport_overhead_bytes_per_packet); |
| 91 | 85 |
| 92 virtual BitrateController* GetBitrateController() const; | 86 virtual BitrateController* GetBitrateController() const; |
| 93 virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator( | 87 virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator( |
| 94 bool send_side_bwe); | 88 bool send_side_bwe); |
| 95 virtual int64_t GetPacerQueuingDelayMs() const; | 89 virtual int64_t GetPacerQueuingDelayMs() const; |
| 96 // TODO(nisse): Delete this accessor function. The pacer should be | 90 // TODO(nisse): Delete this accessor function. The pacer should be |
| 97 // internal to the congestion controller. | 91 // internal to the congestion controller. |
| 98 virtual PacedSender* pacer() { return pacer_.get(); } | 92 virtual PacedSender* pacer() { return send_side_cc_.pacer(); } |
| 99 virtual TransportFeedbackObserver* GetTransportFeedbackObserver() { | 93 virtual TransportFeedbackObserver* GetTransportFeedbackObserver() { |
| 100 return this; | 94 return this; |
| 101 } | 95 } |
| 102 RateLimiter* GetRetransmissionRateLimiter(); | 96 RateLimiter* GetRetransmissionRateLimiter(); |
| 103 void EnablePeriodicAlrProbing(bool enable); | 97 void EnablePeriodicAlrProbing(bool enable); |
| 104 | 98 |
| 105 // SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec | 99 // SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec |
| 106 // settings. | 100 // settings. |
| 107 // |min_send_bitrate_bps| is the total minimum send bitrate required by all | 101 // |min_send_bitrate_bps| is the total minimum send bitrate required by all |
| 108 // sending streams. This is the minimum bitrate the PacedSender will use. | 102 // sending streams. This is the minimum bitrate the PacedSender will use. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 125 void Process() override; | 119 void Process() override; |
| 126 | 120 |
| 127 // Implements TransportFeedbackObserver. | 121 // Implements TransportFeedbackObserver. |
| 128 void AddPacket(uint16_t sequence_number, | 122 void AddPacket(uint16_t sequence_number, |
| 129 size_t length, | 123 size_t length, |
| 130 const PacedPacketInfo& pacing_info) override; | 124 const PacedPacketInfo& pacing_info) override; |
| 131 void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override; | 125 void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override; |
| 132 std::vector<PacketFeedback> GetTransportFeedbackVector() const override; | 126 std::vector<PacketFeedback> GetTransportFeedbackVector() const override; |
| 133 | 127 |
| 134 private: | 128 private: |
| 135 class WrappingBitrateEstimator : public RemoteBitrateEstimator { | 129 SendSideCongestionController send_side_cc_; |
| 136 public: | 130 ReceiveSideCongestionController receive_side_cc_; |
| 137 WrappingBitrateEstimator(RemoteBitrateObserver* observer, | |
| 138 const Clock* clock); | |
| 139 | |
| 140 virtual ~WrappingBitrateEstimator() {} | |
| 141 | |
| 142 void IncomingPacket(int64_t arrival_time_ms, | |
| 143 size_t payload_size, | |
| 144 const RTPHeader& header) override; | |
| 145 | |
| 146 void Process() override; | |
| 147 | |
| 148 int64_t TimeUntilNextProcess() override; | |
| 149 | |
| 150 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; | |
| 151 | |
| 152 void RemoveStream(unsigned int ssrc) override; | |
| 153 | |
| 154 bool LatestEstimate(std::vector<unsigned int>* ssrcs, | |
| 155 unsigned int* bitrate_bps) const override; | |
| 156 | |
| 157 void SetMinBitrate(int min_bitrate_bps) override; | |
| 158 | |
| 159 private: | |
| 160 void PickEstimatorFromHeader(const RTPHeader& header) | |
| 161 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
| 162 void PickEstimator() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
| 163 RemoteBitrateObserver* observer_; | |
| 164 const Clock* const clock_; | |
| 165 rtc::CriticalSection crit_sect_; | |
| 166 std::unique_ptr<RemoteBitrateEstimator> rbe_; | |
| 167 bool using_absolute_send_time_; | |
| 168 uint32_t packets_since_absolute_send_time_; | |
| 169 int min_bitrate_bps_; | |
| 170 | |
| 171 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); | |
| 172 }; | |
| 173 | |
| 174 void MaybeTriggerOnNetworkChanged(); | |
| 175 | |
| 176 bool IsSendQueueFull() const; | |
| 177 bool IsNetworkDown() const; | |
| 178 bool HasNetworkParametersToReportChanged(uint32_t bitrate_bps, | |
| 179 uint8_t fraction_loss, | |
| 180 int64_t rtt); | |
| 181 const Clock* const clock_; | |
| 182 Observer* const observer_; | |
| 183 RtcEventLog* const event_log_; | |
| 184 PacketRouter* const packet_router_; | |
| 185 const std::unique_ptr<PacedSender> pacer_; | |
| 186 const std::unique_ptr<BitrateController> bitrate_controller_; | |
| 187 const std::unique_ptr<ProbeController> probe_controller_; | |
| 188 const std::unique_ptr<RateLimiter> retransmission_rate_limiter_; | |
| 189 WrappingBitrateEstimator remote_bitrate_estimator_; | |
| 190 RemoteEstimatorProxy remote_estimator_proxy_; | |
| 191 TransportFeedbackAdapter transport_feedback_adapter_; | |
| 192 rtc::CriticalSection network_state_lock_; | |
| 193 uint32_t last_reported_bitrate_bps_ GUARDED_BY(network_state_lock_); | |
| 194 uint8_t last_reported_fraction_loss_ GUARDED_BY(network_state_lock_); | |
| 195 int64_t last_reported_rtt_ GUARDED_BY(network_state_lock_); | |
| 196 NetworkState network_state_ GUARDED_BY(network_state_lock_); | |
| 197 rtc::CriticalSection bwe_lock_; | |
| 198 int min_bitrate_bps_ GUARDED_BY(bwe_lock_); | |
| 199 std::unique_ptr<DelayBasedBwe> delay_based_bwe_ GUARDED_BY(bwe_lock_); | |
| 200 | |
| 201 rtc::ThreadChecker worker_thread_checker_; | |
| 202 | 131 |
| 203 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController); | 132 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController); |
| 204 }; | 133 }; |
| 205 | 134 |
| 206 } // namespace webrtc | 135 } // namespace webrtc |
| 207 | 136 |
| 208 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ | 137 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ |
| OLD | NEW |