delay_based_bwe.h (5116B)
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 <stdint.h> 15 16 #include <memory> 17 #include <optional> 18 #include <vector> 19 20 #include "api/field_trials_view.h" 21 #include "api/network_state_predictor.h" 22 #include "api/transport/bandwidth_usage.h" 23 #include "api/transport/network_types.h" 24 #include "api/units/data_rate.h" 25 #include "api/units/time_delta.h" 26 #include "api/units/timestamp.h" 27 #include "modules/congestion_controller/goog_cc/delay_increase_detector_interface.h" 28 #include "modules/congestion_controller/goog_cc/inter_arrival_delta.h" 29 #include "modules/congestion_controller/goog_cc/link_capacity_estimator.h" 30 #include "modules/congestion_controller/goog_cc/probe_bitrate_estimator.h" 31 #include "modules/remote_bitrate_estimator/aimd_rate_control.h" 32 #include "modules/remote_bitrate_estimator/inter_arrival.h" 33 #include "rtc_base/experiments/struct_parameters_parser.h" 34 #include "rtc_base/race_checker.h" 35 36 namespace webrtc { 37 class RtcEventLog; 38 39 struct BweSeparateAudioPacketsSettings { 40 static constexpr char kKey[] = "WebRTC-Bwe-SeparateAudioPackets"; 41 42 BweSeparateAudioPacketsSettings() = default; 43 explicit BweSeparateAudioPacketsSettings( 44 const FieldTrialsView* key_value_config); 45 46 bool enabled = false; 47 int packet_threshold = 10; 48 TimeDelta time_threshold = TimeDelta::Seconds(1); 49 50 std::unique_ptr<StructParametersParser> Parser(); 51 }; 52 53 class DelayBasedBwe { 54 public: 55 struct Result { 56 Result(); 57 ~Result() = default; 58 bool updated; 59 bool probe; 60 DataRate target_bitrate = DataRate::Zero(); 61 bool recovered_from_overuse; 62 BandwidthUsage delay_detector_state; 63 }; 64 65 explicit DelayBasedBwe(const FieldTrialsView* key_value_config, 66 RtcEventLog* event_log, 67 NetworkStatePredictor* network_state_predictor); 68 69 DelayBasedBwe() = delete; 70 DelayBasedBwe(const DelayBasedBwe&) = delete; 71 DelayBasedBwe& operator=(const DelayBasedBwe&) = delete; 72 73 virtual ~DelayBasedBwe(); 74 75 Result IncomingPacketFeedbackVector( 76 const TransportPacketsFeedback& msg, 77 std::optional<DataRate> acked_bitrate, 78 std::optional<DataRate> probe_bitrate, 79 std::optional<NetworkStateEstimate> network_estimate, 80 bool in_alr); 81 void OnRttUpdate(TimeDelta avg_rtt); 82 bool LatestEstimate(std::vector<uint32_t>* ssrcs, DataRate* bitrate) const; 83 void SetStartBitrate(DataRate start_bitrate); 84 void SetMinBitrate(DataRate min_bitrate); 85 TimeDelta GetExpectedBwePeriod() const; 86 DataRate TriggerOveruse(Timestamp at_time, 87 std::optional<DataRate> link_capacity); 88 DataRate last_estimate() const { return prev_bitrate_; } 89 BandwidthUsage last_state() const { return prev_state_; } 90 91 private: 92 friend class GoogCcStatePrinter; 93 void IncomingPacketFeedback(const PacketResult& packet_feedback, 94 Timestamp at_time); 95 Result MaybeUpdateEstimate(std::optional<DataRate> acked_bitrate, 96 std::optional<DataRate> probe_bitrate, 97 std::optional<NetworkStateEstimate> state_estimate, 98 bool recovered_from_overuse, 99 bool in_alr, 100 Timestamp at_time); 101 // Updates the current remote rate estimate and returns true if a valid 102 // estimate exists. 103 bool UpdateEstimate(Timestamp at_time, 104 std::optional<DataRate> acked_bitrate, 105 DataRate* target_rate); 106 107 RaceChecker network_race_; 108 RtcEventLog* const event_log_; 109 const FieldTrialsView* const key_value_config_; 110 111 // Alternatively, run two separate overuse detectors for audio and video, 112 // and fall back to the audio one if we haven't seen a video packet in a 113 // while. 114 BweSeparateAudioPacketsSettings separate_audio_; 115 int64_t audio_packets_since_last_video_; 116 Timestamp last_video_packet_recv_time_; 117 118 NetworkStatePredictor* network_state_predictor_; 119 std::unique_ptr<InterArrival> video_inter_arrival_; 120 std::unique_ptr<InterArrivalDelta> video_inter_arrival_delta_; 121 std::unique_ptr<DelayIncreaseDetectorInterface> video_delay_detector_; 122 std::unique_ptr<InterArrival> audio_inter_arrival_; 123 std::unique_ptr<InterArrivalDelta> audio_inter_arrival_delta_; 124 std::unique_ptr<DelayIncreaseDetectorInterface> audio_delay_detector_; 125 DelayIncreaseDetectorInterface* active_delay_detector_; 126 127 Timestamp last_seen_packet_; 128 bool uma_recorded_; 129 AimdRateControl rate_control_; 130 DataRate prev_bitrate_; 131 BandwidthUsage prev_state_; 132 }; 133 134 } // namespace webrtc 135 136 #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_DELAY_BASED_BWE_H_