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