1 /* 2 * Copyright (c) 2016 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_DELAY_BASED_BWE_H_ 12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_DELAY_BASED_BWE_H_ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 17 #include <memory> 18 #include <vector> 19 20 #include "absl/types/optional.h" 21 #include "api/network_state_predictor.h" 22 #include "api/transport/network_types.h" 23 #include "api/transport/webrtc_key_value_config.h" 24 #include "modules/congestion_controller/goog_cc/delay_increase_detector_interface.h" 25 #include "modules/congestion_controller/goog_cc/probe_bitrate_estimator.h" 26 #include "modules/remote_bitrate_estimator/aimd_rate_control.h" 27 #include "modules/remote_bitrate_estimator/include/bwe_defines.h" 28 #include "modules/remote_bitrate_estimator/inter_arrival.h" 29 #include "rtc_base/constructor_magic.h" 30 #include "rtc_base/experiments/struct_parameters_parser.h" 31 #include "rtc_base/race_checker.h" 32 33 namespace webrtc { 34 class RtcEventLog; 35 36 struct BweIgnoreSmallPacketsSettings { 37 static constexpr char kKey[] = "WebRTC-BweIgnoreSmallPacketsFix"; 38 39 BweIgnoreSmallPacketsSettings() = default; 40 explicit BweIgnoreSmallPacketsSettings( 41 const WebRtcKeyValueConfig* key_value_config); 42 43 double smoothing_factor = 0.1; 44 double fraction_large = 1.0; 45 DataSize large_threshold = DataSize::Zero(); 46 DataSize small_threshold = DataSize::Zero(); 47 48 std::unique_ptr<StructParametersParser> Parser(); 49 }; 50 51 struct BweSeparateAudioPacketsSettings { 52 static constexpr char kKey[] = "WebRTC-Bwe-SeparateAudioPackets"; 53 54 BweSeparateAudioPacketsSettings() = default; 55 explicit BweSeparateAudioPacketsSettings( 56 const WebRtcKeyValueConfig* key_value_config); 57 58 bool enabled = false; 59 int packet_threshold = 10; 60 TimeDelta time_threshold = TimeDelta::Seconds(1); 61 62 std::unique_ptr<StructParametersParser> Parser(); 63 }; 64 65 class DelayBasedBwe { 66 public: 67 struct Result { 68 Result(); 69 Result(bool probe, DataRate target_bitrate); 70 ~Result() = default; 71 bool updated; 72 bool probe; 73 DataRate target_bitrate = DataRate::Zero(); 74 bool recovered_from_overuse; 75 bool backoff_in_alr; 76 }; 77 78 explicit DelayBasedBwe(const WebRtcKeyValueConfig* key_value_config, 79 RtcEventLog* event_log, 80 NetworkStatePredictor* network_state_predictor); 81 virtual ~DelayBasedBwe(); 82 83 Result IncomingPacketFeedbackVector( 84 const TransportPacketsFeedback& msg, 85 absl::optional<DataRate> acked_bitrate, 86 absl::optional<DataRate> probe_bitrate, 87 absl::optional<NetworkStateEstimate> network_estimate, 88 bool in_alr); 89 void OnRttUpdate(TimeDelta avg_rtt); 90 bool LatestEstimate(std::vector<uint32_t>* ssrcs, DataRate* bitrate) const; 91 void SetStartBitrate(DataRate start_bitrate); 92 void SetMinBitrate(DataRate min_bitrate); 93 TimeDelta GetExpectedBwePeriod() const; 94 void SetAlrLimitedBackoffExperiment(bool enabled); 95 DataRate TriggerOveruse(Timestamp at_time, 96 absl::optional<DataRate> link_capacity); last_estimate()97 DataRate last_estimate() const { return prev_bitrate_; } 98 99 private: 100 friend class GoogCcStatePrinter; 101 void IncomingPacketFeedback(const PacketResult& packet_feedback, 102 Timestamp at_time); 103 Result MaybeUpdateEstimate( 104 absl::optional<DataRate> acked_bitrate, 105 absl::optional<DataRate> probe_bitrate, 106 absl::optional<NetworkStateEstimate> state_estimate, 107 bool recovered_from_overuse, 108 bool in_alr, 109 Timestamp at_time); 110 // Updates the current remote rate estimate and returns true if a valid 111 // estimate exists. 112 bool UpdateEstimate(Timestamp now, 113 absl::optional<DataRate> acked_bitrate, 114 DataRate* target_bitrate); 115 116 rtc::RaceChecker network_race_; 117 RtcEventLog* const event_log_; 118 const WebRtcKeyValueConfig* const key_value_config_; 119 120 // Filtering out small packets. Intention is to base the detection only 121 // on video packets even if we have TWCC sequence numbers for audio. 122 BweIgnoreSmallPacketsSettings ignore_small_; 123 double fraction_large_packets_; 124 125 // Alternatively, run two separate overuse detectors for audio and video, 126 // and fall back to the audio one if we haven't seen a video packet in a 127 // while. 128 BweSeparateAudioPacketsSettings separate_audio_; 129 int64_t audio_packets_since_last_video_; 130 Timestamp last_video_packet_recv_time_; 131 132 NetworkStatePredictor* network_state_predictor_; 133 std::unique_ptr<InterArrival> video_inter_arrival_; 134 std::unique_ptr<DelayIncreaseDetectorInterface> video_delay_detector_; 135 std::unique_ptr<InterArrival> audio_inter_arrival_; 136 std::unique_ptr<DelayIncreaseDetectorInterface> audio_delay_detector_; 137 DelayIncreaseDetectorInterface* active_delay_detector_; 138 139 Timestamp last_seen_packet_; 140 bool uma_recorded_; 141 AimdRateControl rate_control_; 142 DataRate prev_bitrate_; 143 bool has_once_detected_overuse_; 144 BandwidthUsage prev_state_; 145 bool alr_limited_backoff_enabled_; 146 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); 147 }; 148 149 } // namespace webrtc 150 151 #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_DELAY_BASED_BWE_H_ 152