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