Chromium Code Reviews| 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 <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/base/constructormagic.h" | 17 #include "webrtc/base/constructormagic.h" |
| 18 #include "webrtc/base/criticalsection.h" | 18 #include "webrtc/base/criticalsection.h" |
| 19 #include "webrtc/common_types.h" | 19 #include "webrtc/common_types.h" |
| 20 #include "webrtc/modules/congestion_controller/delay_based_bwe.h" | |
| 20 #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h" | 21 #include "webrtc/modules/congestion_controller/transport_feedback_adapter.h" |
| 21 #include "webrtc/modules/include/module.h" | 22 #include "webrtc/modules/include/module.h" |
| 22 #include "webrtc/modules/include/module_common_types.h" | 23 #include "webrtc/modules/include/module_common_types.h" |
| 23 #include "webrtc/modules/pacing/packet_router.h" | 24 #include "webrtc/modules/pacing/packet_router.h" |
| 24 #include "webrtc/modules/pacing/paced_sender.h" | 25 #include "webrtc/modules/pacing/paced_sender.h" |
| 25 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" | 26 #include "webrtc/modules/remote_bitrate_estimator/remote_estimator_proxy.h" |
| 26 | 27 |
| 27 namespace rtc { | 28 namespace rtc { |
| 28 struct SentPacket; | 29 struct SentPacket; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace webrtc { | 32 namespace webrtc { |
| 32 | 33 |
| 33 class BitrateController; | 34 class BitrateController; |
| 34 class Clock; | 35 class Clock; |
| 35 class ProbeController; | 36 class ProbeController; |
| 36 class RateLimiter; | 37 class RateLimiter; |
| 37 class RemoteBitrateEstimator; | 38 class RemoteBitrateEstimator; |
| 38 class RemoteBitrateObserver; | 39 class RemoteBitrateObserver; |
| 39 class RtcEventLog; | 40 class RtcEventLog; |
| 40 class TransportFeedbackObserver; | |
| 41 | 41 |
| 42 class CongestionController : public CallStatsObserver, public Module { | 42 class CongestionController : public CallStatsObserver, |
| 43 public Module, | |
| 44 public TransportFeedbackObserver { | |
| 43 public: | 45 public: |
| 44 // Observer class for bitrate changes announced due to change in bandwidth | 46 // Observer class for bitrate changes announced due to change in bandwidth |
| 45 // estimate or due to that the send pacer is full. Fraction loss and rtt is | 47 // estimate or due to that the send pacer is full. Fraction loss and rtt is |
| 46 // also part of this callback to allow the observer to optimize its settings | 48 // also part of this callback to allow the observer to optimize its settings |
| 47 // for different types of network environments. The bitrate does not include | 49 // for different types of network environments. The bitrate does not include |
| 48 // packet headers and is measured in bits per second. | 50 // packet headers and is measured in bits per second. |
| 49 class Observer { | 51 class Observer { |
| 50 public: | 52 public: |
| 51 virtual void OnNetworkChanged(uint32_t bitrate_bps, | 53 virtual void OnNetworkChanged(uint32_t bitrate_bps, |
| 52 uint8_t fraction_loss, // 0 - 255. | 54 uint8_t fraction_loss, // 0 - 255. |
| 53 int64_t rtt_ms, | 55 int64_t rtt_ms, |
| 54 int64_t probing_interval_ms) = 0; | 56 int64_t probing_interval_ms) = 0; |
| 55 | 57 |
| 56 protected: | 58 protected: |
| 57 virtual ~Observer() {} | 59 virtual ~Observer() {} |
| 58 }; | 60 }; |
| 59 CongestionController(Clock* clock, | 61 CongestionController(Clock* clock, |
| 60 Observer* observer, | 62 Observer* observer, |
| 61 RemoteBitrateObserver* remote_bitrate_observer, | 63 RemoteBitrateObserver* remote_bitrate_observer, |
| 62 RtcEventLog* event_log, | 64 RtcEventLog* event_log, |
| 63 PacketRouter* packet_router); | 65 PacketRouter* packet_router); |
| 64 CongestionController(Clock* clock, | 66 CongestionController(Clock* clock, |
| 65 Observer* observer, | 67 Observer* observer, |
| 66 RemoteBitrateObserver* remote_bitrate_observer, | 68 RemoteBitrateObserver* remote_bitrate_observer, |
| 67 RtcEventLog* event_log, | 69 RtcEventLog* event_log, |
| 68 PacketRouter* packet_router, | 70 PacketRouter* packet_router, |
| 69 std::unique_ptr<PacedSender> pacer); | 71 std::unique_ptr<PacedSender> pacer, |
| 72 std::unique_ptr<BitrateController> bitrate_controller); | |
| 70 virtual ~CongestionController(); | 73 virtual ~CongestionController(); |
| 71 | 74 |
| 72 virtual void OnReceivedPacket(int64_t arrival_time_ms, | 75 virtual void OnReceivedPacket(int64_t arrival_time_ms, |
| 73 size_t payload_size, | 76 size_t payload_size, |
| 74 const RTPHeader& header); | 77 const RTPHeader& header); |
| 75 | 78 |
| 76 virtual void SetBweBitrates(int min_bitrate_bps, | 79 virtual void SetBweBitrates(int min_bitrate_bps, |
| 77 int start_bitrate_bps, | 80 int start_bitrate_bps, |
| 78 int max_bitrate_bps); | 81 int max_bitrate_bps); |
| 79 // Resets both the BWE state and the bitrate estimator. Note the first | 82 // Resets both the BWE state and the bitrate estimator. Note the first |
| 80 // argument is the bitrate_bps. | 83 // argument is the bitrate_bps. |
| 81 virtual void ResetBweAndBitrates(int bitrate_bps, | 84 virtual void ResetBweAndBitrates(int bitrate_bps, |
| 82 int min_bitrate_bps, | 85 int min_bitrate_bps, |
| 83 int max_bitrate_bps); | 86 int max_bitrate_bps); |
| 84 virtual void SignalNetworkState(NetworkState state); | 87 virtual void SignalNetworkState(NetworkState state); |
| 85 virtual void SetTransportOverhead(size_t transport_overhead_bytes_per_packet); | 88 virtual void SetTransportOverhead(size_t transport_overhead_bytes_per_packet); |
| 86 | 89 |
| 87 virtual BitrateController* GetBitrateController() const; | 90 virtual BitrateController* GetBitrateController() const; |
| 88 virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator( | 91 virtual RemoteBitrateEstimator* GetRemoteBitrateEstimator( |
| 89 bool send_side_bwe); | 92 bool send_side_bwe); |
| 90 virtual int64_t GetPacerQueuingDelayMs() const; | 93 virtual int64_t GetPacerQueuingDelayMs() const; |
| 91 // TODO(nisse): Delete this accessor function. The pacer should be | 94 // TODO(nisse): Delete this accessor function. The pacer should be |
| 92 // internal to the congestion controller. | 95 // internal to the congestion controller. |
| 93 virtual PacedSender* pacer() { return pacer_.get(); } | 96 virtual PacedSender* pacer() { return pacer_.get(); } |
| 94 virtual TransportFeedbackObserver* GetTransportFeedbackObserver(); | |
| 95 RateLimiter* GetRetransmissionRateLimiter(); | 97 RateLimiter* GetRetransmissionRateLimiter(); |
| 96 void EnablePeriodicAlrProbing(bool enable); | 98 void EnablePeriodicAlrProbing(bool enable); |
| 97 | 99 |
| 98 // SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec | 100 // SetAllocatedSendBitrateLimits sets bitrates limits imposed by send codec |
| 99 // settings. | 101 // settings. |
| 100 // |min_send_bitrate_bps| is the total minimum send bitrate required by all | 102 // |min_send_bitrate_bps| is the total minimum send bitrate required by all |
| 101 // sending streams. This is the minimum bitrate the PacedSender will use. | 103 // sending streams. This is the minimum bitrate the PacedSender will use. |
| 102 // Note that CongestionController::OnNetworkChanged can still be called with | 104 // Note that CongestionController::OnNetworkChanged can still be called with |
| 103 // a lower bitrate estimate. | 105 // a lower bitrate estimate. |
| 104 // |max_padding_bitrate_bps| is the max bitrate the send streams request for | 106 // |max_padding_bitrate_bps| is the max bitrate the send streams request for |
| 105 // padding. This can be higher than the current network estimate and tells | 107 // padding. This can be higher than the current network estimate and tells |
| 106 // the PacedSender how much it should max pad unless there is real packets to | 108 // the PacedSender how much it should max pad unless there is real packets to |
| 107 // send. | 109 // send. |
| 108 void SetAllocatedSendBitrateLimits(int min_send_bitrate_bps, | 110 void SetAllocatedSendBitrateLimits(int min_send_bitrate_bps, |
| 109 int max_padding_bitrate_bps); | 111 int max_padding_bitrate_bps); |
| 110 | 112 |
| 111 virtual void OnSentPacket(const rtc::SentPacket& sent_packet); | 113 virtual void OnSentPacket(const rtc::SentPacket& sent_packet); |
| 112 | 114 |
| 113 // Implements CallStatsObserver. | 115 // Implements CallStatsObserver. |
| 114 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; | 116 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) override; |
| 115 | 117 |
| 116 // Implements Module. | 118 // Implements Module. |
| 117 int64_t TimeUntilNextProcess() override; | 119 int64_t TimeUntilNextProcess() override; |
| 118 void Process() override; | 120 void Process() override; |
| 119 | 121 |
| 122 // Implements TransportFeedbackObserver. | |
| 123 void AddPacket(uint16_t sequence_number, | |
| 124 size_t length, | |
| 125 const PacedPacketInfo& pacing_info) override; | |
| 126 void OnTransportFeedback(const rtcp::TransportFeedback& feedback) override; | |
| 127 std::vector<PacketFeedback> GetTransportFeedbackVector() const override; | |
| 128 | |
| 120 private: | 129 private: |
| 121 class WrappingBitrateEstimator : public RemoteBitrateEstimator { | 130 class WrappingBitrateEstimator : public RemoteBitrateEstimator { |
| 122 public: | 131 public: |
| 123 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock); | 132 WrappingBitrateEstimator(RemoteBitrateObserver* observer, Clock* clock); |
| 124 | 133 |
| 125 virtual ~WrappingBitrateEstimator() {} | 134 virtual ~WrappingBitrateEstimator() {} |
| 126 | 135 |
| 127 void IncomingPacket(int64_t arrival_time_ms, | 136 void IncomingPacket(int64_t arrival_time_ms, |
| 128 size_t payload_size, | 137 size_t payload_size, |
| 129 const RTPHeader& header) override; | 138 const RTPHeader& header) override; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 156 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); | 165 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(WrappingBitrateEstimator); |
| 157 }; | 166 }; |
| 158 | 167 |
| 159 void MaybeTriggerOnNetworkChanged(); | 168 void MaybeTriggerOnNetworkChanged(); |
| 160 | 169 |
| 161 bool IsSendQueueFull() const; | 170 bool IsSendQueueFull() const; |
| 162 bool IsNetworkDown() const; | 171 bool IsNetworkDown() const; |
| 163 bool HasNetworkParametersToReportChanged(uint32_t bitrate_bps, | 172 bool HasNetworkParametersToReportChanged(uint32_t bitrate_bps, |
| 164 uint8_t fraction_loss, | 173 uint8_t fraction_loss, |
| 165 int64_t rtt); | 174 int64_t rtt); |
| 166 Clock* const clock_; | 175 Clock* const clock_; |
|
minyue-webrtc
2017/03/02 19:53:58
if you can be nice, add "const"
elad.alon_webrtc.org
2017/03/08 18:25:09
This one is a bit less straight-forward than you t
elad.alon_webrtc.org
2017/03/08 19:03:55
Done separately in the following CL: https://coder
| |
| 167 Observer* const observer_; | 176 Observer* const observer_; |
|
minyue-webrtc
2017/03/02 19:53:58
here too
elad.alon_webrtc.org
2017/03/08 18:25:10
Done.
| |
| 177 RtcEventLog* const event_log_; | |
|
minyue-webrtc
2017/03/02 19:53:58
const RtcEventLog* const
elad.alon_webrtc.org
2017/03/08 18:25:09
Can't, because RtcEventLog::LogDelayBasedBweUpdate
| |
| 168 PacketRouter* const packet_router_; | 178 PacketRouter* const packet_router_; |
|
minyue-webrtc
2017/03/02 19:53:58
here too
elad.alon_webrtc.org
2017/03/08 18:25:10
Similar issue (due to PacketRouter::SendFeedback()
| |
| 169 const std::unique_ptr<PacedSender> pacer_; | 179 const std::unique_ptr<PacedSender> pacer_; |
| 170 const std::unique_ptr<BitrateController> bitrate_controller_; | 180 const std::unique_ptr<BitrateController> bitrate_controller_; |
| 171 const std::unique_ptr<ProbeController> probe_controller_; | 181 const std::unique_ptr<ProbeController> probe_controller_; |
| 172 const std::unique_ptr<RateLimiter> retransmission_rate_limiter_; | 182 const std::unique_ptr<RateLimiter> retransmission_rate_limiter_; |
| 173 WrappingBitrateEstimator remote_bitrate_estimator_; | 183 WrappingBitrateEstimator remote_bitrate_estimator_; |
| 174 RemoteEstimatorProxy remote_estimator_proxy_; | 184 RemoteEstimatorProxy remote_estimator_proxy_; |
| 175 TransportFeedbackAdapter transport_feedback_adapter_; | 185 TransportFeedbackAdapter transport_feedback_adapter_; |
| 176 int min_bitrate_bps_; | 186 int min_bitrate_bps_; |
| 177 int max_bitrate_bps_; | 187 int max_bitrate_bps_; |
| 178 rtc::CriticalSection critsect_; | 188 rtc::CriticalSection critsect_; |
|
minyue-webrtc
2017/03/02 19:53:58
should we rename this to differentiate from bwe_lo
elad.alon_webrtc.org
2017/03/08 18:25:09
Stefan, what do you suggest? Perhaps |network_lock
stefan-webrtc
2017/03/09 09:41:02
It protects access to members accessed both on inc
elad.alon_webrtc.org
2017/03/09 12:03:53
Done.
| |
| 179 uint32_t last_reported_bitrate_bps_ GUARDED_BY(critsect_); | 189 uint32_t last_reported_bitrate_bps_ GUARDED_BY(critsect_); |
| 180 uint8_t last_reported_fraction_loss_ GUARDED_BY(critsect_); | 190 uint8_t last_reported_fraction_loss_ GUARDED_BY(critsect_); |
| 181 int64_t last_reported_rtt_ GUARDED_BY(critsect_); | 191 int64_t last_reported_rtt_ GUARDED_BY(critsect_); |
| 182 NetworkState network_state_ GUARDED_BY(critsect_); | 192 NetworkState network_state_ GUARDED_BY(critsect_); |
| 193 rtc::CriticalSection bwe_lock_; | |
| 194 std::unique_ptr<DelayBasedBwe> delay_based_bwe_ GUARDED_BY(&bwe_lock_); | |
|
stefan-webrtc
2017/03/09 09:41:02
Why is &bwe_lock_ needed here but not &critsect_ a
elad.alon_webrtc.org
2017/03/09 12:03:53
It works with either. I happened to have the amper
| |
| 195 | |
| 196 // TODO(elad.alon): Subsequent CL re-introduces the thread-checking that | |
| 197 // was inside of TransportFeedbackAdapter before. | |
| 183 | 198 |
| 184 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController); | 199 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(CongestionController); |
| 185 }; | 200 }; |
| 186 | 201 |
| 187 } // namespace webrtc | 202 } // namespace webrtc |
| 188 | 203 |
| 189 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ | 204 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_INCLUDE_CONGESTION_CONTROLLER_H_ |
| OLD | NEW |