Line data Source code
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 WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_
12 : #define WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_
13 :
14 : #include <memory>
15 : #include <utility>
16 : #include <vector>
17 :
18 : #include "webrtc/base/checks.h"
19 : #include "webrtc/base/constructormagic.h"
20 : #include "webrtc/base/rate_statistics.h"
21 : #include "webrtc/base/thread_checker.h"
22 : #include "webrtc/modules/congestion_controller/median_slope_estimator.h"
23 : #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h"
24 : #include "webrtc/modules/congestion_controller/probing_interval_estimator.h"
25 : #include "webrtc/modules/congestion_controller/trendline_estimator.h"
26 : #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h"
27 : #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
28 : #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h"
29 : #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h"
30 : #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h"
31 :
32 : namespace webrtc {
33 :
34 : class DelayBasedBwe {
35 : public:
36 : static const int64_t kStreamTimeOutMs = 2000;
37 :
38 : struct Result {
39 0 : Result() : updated(false), probe(false), target_bitrate_bps(0) {}
40 : Result(bool probe, uint32_t target_bitrate_bps)
41 : : updated(true), probe(probe), target_bitrate_bps(target_bitrate_bps) {}
42 : bool updated;
43 : bool probe;
44 : uint32_t target_bitrate_bps;
45 : };
46 :
47 : explicit DelayBasedBwe(Clock* clock);
48 0 : virtual ~DelayBasedBwe() {}
49 :
50 : Result IncomingPacketFeedbackVector(
51 : const std::vector<PacketInfo>& packet_feedback_vector);
52 : void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms);
53 : bool LatestEstimate(std::vector<uint32_t>* ssrcs,
54 : uint32_t* bitrate_bps) const;
55 : void SetMinBitrate(int min_bitrate_bps);
56 : int64_t GetProbingIntervalMs() const;
57 :
58 : private:
59 : // Computes a bayesian estimate of the throughput given acks containing
60 : // the arrival time and payload size. Samples which are far from the current
61 : // estimate or are based on few packets are given a smaller weight, as they
62 : // are considered to be more likely to have been caused by, e.g., delay spikes
63 : // unrelated to congestion.
64 0 : class BitrateEstimator {
65 : public:
66 : BitrateEstimator();
67 : void Update(int64_t now_ms, int bytes);
68 : rtc::Optional<uint32_t> bitrate_bps() const;
69 :
70 : private:
71 : float UpdateWindow(int64_t now_ms, int bytes, int rate_window_ms);
72 : int sum_;
73 : int64_t current_win_ms_;
74 : int64_t prev_time_ms_;
75 : float bitrate_estimate_;
76 : float bitrate_estimate_var_;
77 : RateStatistics old_estimator_;
78 : const bool in_experiment_;
79 : };
80 :
81 : Result IncomingPacketInfo(const PacketInfo& info);
82 : // Updates the current remote rate estimate and returns true if a valid
83 : // estimate exists.
84 : bool UpdateEstimate(int64_t packet_arrival_time_ms,
85 : int64_t now_ms,
86 : rtc::Optional<uint32_t> acked_bitrate_bps,
87 : uint32_t* target_bitrate_bps);
88 : const bool in_trendline_experiment_;
89 : const bool in_median_slope_experiment_;
90 :
91 : rtc::ThreadChecker network_thread_;
92 : Clock* const clock_;
93 : std::unique_ptr<InterArrival> inter_arrival_;
94 : std::unique_ptr<OveruseEstimator> kalman_estimator_;
95 : std::unique_ptr<TrendlineEstimator> trendline_estimator_;
96 : std::unique_ptr<MedianSlopeEstimator> median_slope_estimator_;
97 : OveruseDetector detector_;
98 : BitrateEstimator receiver_incoming_bitrate_;
99 : int64_t last_update_ms_;
100 : int64_t last_seen_packet_ms_;
101 : bool uma_recorded_;
102 : AimdRateControl rate_control_;
103 : ProbeBitrateEstimator probe_bitrate_estimator_;
104 : size_t trendline_window_size_;
105 : double trendline_smoothing_coeff_;
106 : double trendline_threshold_gain_;
107 : ProbingIntervalEstimator probing_interval_estimator_;
108 : size_t median_slope_window_size_;
109 : double median_slope_threshold_gain_;
110 :
111 : RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe);
112 : };
113 :
114 : } // namespace webrtc
115 :
116 : #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_
|