blob: 6e7a6f8d63a654e078f41127b6919263f182df07 [file] [log] [blame]
philipel863a8262016-06-17 09:21:34 -07001/*
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
philipel863a8262016-06-17 09:21:34 -070014#include <memory>
Stefan Holmer492ee282016-10-27 17:19:20 +020015#include <utility>
philipel863a8262016-06-17 09:21:34 -070016#include <vector>
17
18#include "webrtc/base/checks.h"
19#include "webrtc/base/constructormagic.h"
philipel863a8262016-06-17 09:21:34 -070020#include "webrtc/base/rate_statistics.h"
21#include "webrtc/base/thread_checker.h"
terelius5a388362016-12-09 05:50:01 -080022#include "webrtc/modules/congestion_controller/median_slope_estimator.h"
philipel7522a282016-08-16 10:59:36 +020023#include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h"
minyue78b4d562016-11-30 04:47:39 -080024#include "webrtc/modules/congestion_controller/probing_interval_estimator.h"
tereliusafaef8b2016-11-17 03:48:18 -080025#include "webrtc/modules/congestion_controller/trendline_estimator.h"
philipel863a8262016-06-17 09:21:34 -070026#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"
philipel863a8262016-06-17 09:21:34 -070031
32namespace webrtc {
33
Stefan Holmer280de9e2016-09-30 10:06:51 +020034class DelayBasedBwe {
philipel863a8262016-06-17 09:21:34 -070035 public:
Stefan Holmer280de9e2016-09-30 10:06:51 +020036 static const int64_t kStreamTimeOutMs = 2000;
37
38 struct Result {
39 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);
philipel863a8262016-06-17 09:21:34 -070048 virtual ~DelayBasedBwe() {}
49
Stefan Holmer280de9e2016-09-30 10:06:51 +020050 Result IncomingPacketFeedbackVector(
51 const std::vector<PacketInfo>& packet_feedback_vector);
52 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms);
philipel7522a282016-08-16 10:59:36 +020053 bool LatestEstimate(std::vector<uint32_t>* ssrcs,
Stefan Holmer280de9e2016-09-30 10:06:51 +020054 uint32_t* bitrate_bps) const;
55 void SetMinBitrate(int min_bitrate_bps);
minyue78b4d562016-11-30 04:47:39 -080056 int64_t GetProbingIntervalMs() const;
philipel863a8262016-06-17 09:21:34 -070057
philipel863a8262016-06-17 09:21:34 -070058 private:
Stefan Holmer492ee282016-10-27 17:19:20 +020059 // 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 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
Stefan Holmer280de9e2016-09-30 10:06:51 +020081 Result IncomingPacketInfo(const PacketInfo& info);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070082 // 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,
Stefan Holmer492ee282016-10-27 17:19:20 +020086 rtc::Optional<uint32_t> acked_bitrate_bps,
Stefan Holmer280de9e2016-09-30 10:06:51 +020087 uint32_t* target_bitrate_bps);
terelius5a388362016-12-09 05:50:01 -080088 const bool in_trendline_experiment_;
89 const bool in_median_slope_experiment_;
philipel863a8262016-06-17 09:21:34 -070090
91 rtc::ThreadChecker network_thread_;
stefan5e12d362016-07-11 01:44:02 -070092 Clock* const clock_;
philipel863a8262016-06-17 09:21:34 -070093 std::unique_ptr<InterArrival> inter_arrival_;
tereliusafaef8b2016-11-17 03:48:18 -080094 std::unique_ptr<OveruseEstimator> kalman_estimator_;
95 std::unique_ptr<TrendlineEstimator> trendline_estimator_;
terelius5a388362016-12-09 05:50:01 -080096 std::unique_ptr<MedianSlopeEstimator> median_slope_estimator_;
philipel863a8262016-06-17 09:21:34 -070097 OveruseDetector detector_;
Stefan Holmer492ee282016-10-27 17:19:20 +020098 BitrateEstimator receiver_incoming_bitrate_;
philipel863a8262016-06-17 09:21:34 -070099 int64_t last_update_ms_;
philipel7522a282016-08-16 10:59:36 +0200100 int64_t last_seen_packet_ms_;
stefan64636dd2016-08-03 00:29:03 -0700101 bool uma_recorded_;
terelius6ed592d2016-10-18 05:55:30 -0700102 AimdRateControl rate_control_;
Stefan Holmer280de9e2016-09-30 10:06:51 +0200103 ProbeBitrateEstimator probe_bitrate_estimator_;
tereliusafaef8b2016-11-17 03:48:18 -0800104 size_t trendline_window_size_;
105 double trendline_smoothing_coeff_;
106 double trendline_threshold_gain_;
minyue78b4d562016-11-30 04:47:39 -0800107 ProbingIntervalEstimator probing_interval_estimator_;
terelius5a388362016-12-09 05:50:01 -0800108 size_t median_slope_window_size_;
109 double median_slope_threshold_gain_;
philipel863a8262016-06-17 09:21:34 -0700110
111 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe);
112};
113
114} // namespace webrtc
115
116#endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_