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_GOOG_CC_GOOG_CC_NETWORK_CONTROL_H_ 12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_GOOG_CC_NETWORK_CONTROL_H_ 13 14 #include <stdint.h> 15 16 #include <deque> 17 #include <memory> 18 #include <vector> 19 20 #include "absl/types/optional.h" 21 #include "api/network_state_predictor.h" 22 #include "api/rtc_event_log/rtc_event_log.h" 23 #include "api/transport/field_trial_based_config.h" 24 #include "api/transport/network_control.h" 25 #include "api/transport/network_types.h" 26 #include "api/transport/webrtc_key_value_config.h" 27 #include "api/units/data_rate.h" 28 #include "api/units/data_size.h" 29 #include "api/units/timestamp.h" 30 #include "modules/congestion_controller/goog_cc/acknowledged_bitrate_estimator_interface.h" 31 #include "modules/congestion_controller/goog_cc/alr_detector.h" 32 #include "modules/congestion_controller/goog_cc/congestion_window_pushback_controller.h" 33 #include "modules/congestion_controller/goog_cc/delay_based_bwe.h" 34 #include "modules/congestion_controller/goog_cc/probe_controller.h" 35 #include "modules/congestion_controller/goog_cc/send_side_bandwidth_estimation.h" 36 #include "rtc_base/constructor_magic.h" 37 #include "rtc_base/experiments/field_trial_parser.h" 38 #include "rtc_base/experiments/rate_control_settings.h" 39 40 namespace webrtc { 41 struct GoogCcConfig { 42 std::unique_ptr<NetworkStateEstimator> network_state_estimator = nullptr; 43 std::unique_ptr<NetworkStatePredictor> network_state_predictor = nullptr; 44 bool feedback_only = false; 45 }; 46 47 class GoogCcNetworkController : public NetworkControllerInterface { 48 public: 49 GoogCcNetworkController(NetworkControllerConfig config, 50 GoogCcConfig goog_cc_config); 51 ~GoogCcNetworkController() override; 52 53 // NetworkControllerInterface 54 NetworkControlUpdate OnNetworkAvailability(NetworkAvailability msg) override; 55 NetworkControlUpdate OnNetworkRouteChange(NetworkRouteChange msg) override; 56 NetworkControlUpdate OnProcessInterval(ProcessInterval msg) override; 57 NetworkControlUpdate OnRemoteBitrateReport(RemoteBitrateReport msg) override; 58 NetworkControlUpdate OnRoundTripTimeUpdate(RoundTripTimeUpdate msg) override; 59 NetworkControlUpdate OnSentPacket(SentPacket msg) override; 60 NetworkControlUpdate OnReceivedPacket(ReceivedPacket msg) override; 61 NetworkControlUpdate OnStreamsConfig(StreamsConfig msg) override; 62 NetworkControlUpdate OnTargetRateConstraints( 63 TargetRateConstraints msg) override; 64 NetworkControlUpdate OnTransportLossReport(TransportLossReport msg) override; 65 NetworkControlUpdate OnTransportPacketsFeedback( 66 TransportPacketsFeedback msg) override; 67 NetworkControlUpdate OnNetworkStateEstimate( 68 NetworkStateEstimate msg) override; 69 70 NetworkControlUpdate GetNetworkState(Timestamp at_time) const; 71 72 private: 73 friend class GoogCcStatePrinter; 74 std::vector<ProbeClusterConfig> ResetConstraints( 75 TargetRateConstraints new_constraints); 76 void ClampConstraints(); 77 void MaybeTriggerOnNetworkChanged(NetworkControlUpdate* update, 78 Timestamp at_time); 79 void UpdateCongestionWindowSize(); 80 PacerConfig GetPacingRates(Timestamp at_time) const; 81 const FieldTrialBasedConfig trial_based_config_; 82 83 const WebRtcKeyValueConfig* const key_value_config_; 84 RtcEventLog* const event_log_; 85 const bool packet_feedback_only_; 86 FieldTrialFlag safe_reset_on_route_change_; 87 FieldTrialFlag safe_reset_acknowledged_rate_; 88 const bool use_min_allocatable_as_lower_bound_; 89 const bool ignore_probes_lower_than_network_estimate_; 90 const bool limit_probes_lower_than_throughput_estimate_; 91 const RateControlSettings rate_control_settings_; 92 const bool loss_based_stable_rate_; 93 94 const std::unique_ptr<ProbeController> probe_controller_; 95 const std::unique_ptr<CongestionWindowPushbackController> 96 congestion_window_pushback_controller_; 97 98 std::unique_ptr<SendSideBandwidthEstimation> bandwidth_estimation_; 99 std::unique_ptr<AlrDetector> alr_detector_; 100 std::unique_ptr<ProbeBitrateEstimator> probe_bitrate_estimator_; 101 std::unique_ptr<NetworkStateEstimator> network_estimator_; 102 std::unique_ptr<NetworkStatePredictor> network_state_predictor_; 103 std::unique_ptr<DelayBasedBwe> delay_based_bwe_; 104 std::unique_ptr<AcknowledgedBitrateEstimatorInterface> 105 acknowledged_bitrate_estimator_; 106 107 absl::optional<NetworkControllerConfig> initial_config_; 108 109 DataRate min_target_rate_ = DataRate::Zero(); 110 DataRate min_data_rate_ = DataRate::Zero(); 111 DataRate max_data_rate_ = DataRate::PlusInfinity(); 112 absl::optional<DataRate> starting_rate_; 113 114 bool first_packet_sent_ = false; 115 116 absl::optional<NetworkStateEstimate> estimate_; 117 118 Timestamp next_loss_update_ = Timestamp::MinusInfinity(); 119 int lost_packets_since_last_loss_update_ = 0; 120 int expected_packets_since_last_loss_update_ = 0; 121 122 std::deque<int64_t> feedback_max_rtts_; 123 124 DataRate last_loss_based_target_rate_; 125 DataRate last_pushback_target_rate_; 126 DataRate last_stable_target_rate_; 127 128 absl::optional<uint8_t> last_estimated_fraction_loss_ = 0; 129 TimeDelta last_estimated_round_trip_time_ = TimeDelta::PlusInfinity(); 130 Timestamp last_packet_received_time_ = Timestamp::MinusInfinity(); 131 132 double pacing_factor_; 133 DataRate min_total_allocated_bitrate_; 134 DataRate max_padding_rate_; 135 DataRate max_total_allocated_bitrate_; 136 137 bool previously_in_alr_ = false; 138 139 absl::optional<DataSize> current_data_window_; 140 141 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(GoogCcNetworkController); 142 }; 143 144 } // namespace webrtc 145 146 #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_GOOG_CC_NETWORK_CONTROL_H_ 147