1 /* 2 * Copyright (c) 2018 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 MODULES_CONGESTION_CONTROLLER_PCC_PCC_NETWORK_CONTROLLER_H_ 12 #define MODULES_CONGESTION_CONTROLLER_PCC_PCC_NETWORK_CONTROLLER_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <deque> 18 #include <vector> 19 20 #include "api/transport/network_control.h" 21 #include "api/transport/network_types.h" 22 #include "api/units/data_rate.h" 23 #include "api/units/time_delta.h" 24 #include "api/units/timestamp.h" 25 #include "modules/congestion_controller/pcc/bitrate_controller.h" 26 #include "modules/congestion_controller/pcc/monitor_interval.h" 27 #include "modules/congestion_controller/pcc/rtt_tracker.h" 28 #include "rtc_base/random.h" 29 30 namespace webrtc { 31 namespace pcc { 32 33 // PCC (Performance-oriented Congestion Control) Vivace is a congestion 34 // control algorithm based on online (convex) optimization in machine learning. 35 // It divides time into consecutive Monitor Intervals (MI) to test sending 36 // rates r(1 + eps), r(1 - eps) for the current sending rate r. 37 // At the end of each MI it computes utility function to transform the 38 // performance statistics into a numerical value. Then it updates current 39 // sending rate using gradient ascent to maximize utility function. 40 class PccNetworkController : public NetworkControllerInterface { 41 public: 42 enum class Mode { 43 kStartup, 44 // Slow start phase of PCC doubles sending rate each monitor interval. 45 kSlowStart, 46 // After getting the first decrease in utility function PCC exits slow start 47 // and enters the online learning phase. 48 kOnlineLearning, 49 // If we got that sending with the lower rate resulted in higher packet 50 // loss, then the measurements are unreliable and we need to double check 51 // them. 52 kDoubleCheck 53 }; 54 55 enum class MonitorIntervalLengthStrategy { 56 // Monitor interval length adaptive when it is proportional to packets RTT. 57 kAdaptive, 58 // Monitor interval length is fixed when it is equal to the time of sending 59 // predefined amount of packets (kMinPacketsNumberPerInterval). 60 kFixed 61 }; 62 63 explicit PccNetworkController(NetworkControllerConfig config); 64 ~PccNetworkController() override; 65 66 // NetworkControllerInterface 67 NetworkControlUpdate OnNetworkAvailability(NetworkAvailability msg) override; 68 NetworkControlUpdate OnNetworkRouteChange(NetworkRouteChange msg) override; 69 NetworkControlUpdate OnProcessInterval(ProcessInterval msg) override; 70 NetworkControlUpdate OnSentPacket(SentPacket msg) override; 71 NetworkControlUpdate OnTargetRateConstraints( 72 TargetRateConstraints msg) override; 73 NetworkControlUpdate OnTransportPacketsFeedback( 74 TransportPacketsFeedback msg) override; 75 76 // Part of remote bitrate estimation api, not implemented for PCC 77 NetworkControlUpdate OnStreamsConfig(StreamsConfig msg) override; 78 NetworkControlUpdate OnRemoteBitrateReport(RemoteBitrateReport msg) override; 79 NetworkControlUpdate OnRoundTripTimeUpdate(RoundTripTimeUpdate msg) override; 80 NetworkControlUpdate OnTransportLossReport(TransportLossReport msg) override; 81 NetworkControlUpdate OnReceivedPacket(ReceivedPacket msg) override; 82 NetworkControlUpdate OnNetworkStateEstimate( 83 NetworkStateEstimate msg) override; 84 85 private: 86 void UpdateSendingRateAndMode(); 87 NetworkControlUpdate CreateRateUpdate(Timestamp at_time) const; 88 TimeDelta ComputeMonitorIntervalsDuration() const; 89 bool NeedDoubleCheckMeasurments() const; 90 bool IsTimeoutExpired(Timestamp current_time) const; 91 bool IsFeedbackCollectionDone() const; 92 93 Timestamp start_time_; 94 Timestamp last_sent_packet_time_; 95 TimeDelta smoothed_packets_sending_interval_; 96 Mode mode_; 97 98 // Default value used for initializing bandwidth. 99 DataRate default_bandwidth_; 100 // Current estimate r. 101 DataRate bandwidth_estimate_; 102 103 RttTracker rtt_tracker_; 104 TimeDelta monitor_interval_timeout_; 105 const MonitorIntervalLengthStrategy monitor_interval_length_strategy_; 106 const double monitor_interval_duration_ratio_; 107 const double sampling_step_; // Epsilon. 108 const double monitor_interval_timeout_ratio_; 109 const int64_t min_packets_number_per_interval_; 110 111 PccBitrateController bitrate_controller_; 112 113 std::vector<PccMonitorInterval> monitor_intervals_; 114 std::vector<DataRate> monitor_intervals_bitrates_; 115 TimeDelta monitor_intervals_duration_; 116 size_t complete_feedback_monitor_interval_number_; 117 118 webrtc::Random random_generator_; 119 std::deque<PacketResult> last_received_packets_; 120 }; 121 122 } // namespace pcc 123 } // namespace webrtc 124 125 #endif // MODULES_CONGESTION_CONTROLLER_PCC_PCC_NETWORK_CONTROLLER_H_ 126