blob: c5f0f6182805bfa80c3e0dec2ee3d0b86b1c3a65 [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
terelius0baf55d2017-02-17 03:38:28 -080034class RtcEventLog;
35
Stefan Holmer280de9e2016-09-30 10:06:51 +020036class DelayBasedBwe {
philipel863a8262016-06-17 09:21:34 -070037 public:
Stefan Holmer280de9e2016-09-30 10:06:51 +020038 static const int64_t kStreamTimeOutMs = 2000;
39
40 struct Result {
41 Result() : updated(false), probe(false), target_bitrate_bps(0) {}
42 Result(bool probe, uint32_t target_bitrate_bps)
43 : updated(true), probe(probe), target_bitrate_bps(target_bitrate_bps) {}
44 bool updated;
45 bool probe;
46 uint32_t target_bitrate_bps;
47 };
48
terelius0baf55d2017-02-17 03:38:28 -080049 DelayBasedBwe(RtcEventLog* event_log, Clock* clock);
philipel863a8262016-06-17 09:21:34 -070050 virtual ~DelayBasedBwe() {}
51
Stefan Holmer280de9e2016-09-30 10:06:51 +020052 Result IncomingPacketFeedbackVector(
elad.alonf9490002017-03-06 05:32:21 -080053 const std::vector<PacketFeedback>& packet_feedback_vector);
Stefan Holmer280de9e2016-09-30 10:06:51 +020054 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms);
philipel7522a282016-08-16 10:59:36 +020055 bool LatestEstimate(std::vector<uint32_t>* ssrcs,
Stefan Holmer280de9e2016-09-30 10:06:51 +020056 uint32_t* bitrate_bps) const;
stefan5a2c5062017-01-27 06:43:18 -080057 void SetStartBitrate(int start_bitrate_bps);
Stefan Holmer280de9e2016-09-30 10:06:51 +020058 void SetMinBitrate(int min_bitrate_bps);
minyue78b4d562016-11-30 04:47:39 -080059 int64_t GetProbingIntervalMs() const;
philipel863a8262016-06-17 09:21:34 -070060
philipel863a8262016-06-17 09:21:34 -070061 private:
Stefan Holmer492ee282016-10-27 17:19:20 +020062 // Computes a bayesian estimate of the throughput given acks containing
63 // the arrival time and payload size. Samples which are far from the current
64 // estimate or are based on few packets are given a smaller weight, as they
65 // are considered to be more likely to have been caused by, e.g., delay spikes
66 // unrelated to congestion.
67 class BitrateEstimator {
68 public:
69 BitrateEstimator();
70 void Update(int64_t now_ms, int bytes);
71 rtc::Optional<uint32_t> bitrate_bps() const;
72
73 private:
74 float UpdateWindow(int64_t now_ms, int bytes, int rate_window_ms);
75 int sum_;
76 int64_t current_win_ms_;
77 int64_t prev_time_ms_;
78 float bitrate_estimate_;
79 float bitrate_estimate_var_;
80 RateStatistics old_estimator_;
81 const bool in_experiment_;
82 };
83
elad.alonf9490002017-03-06 05:32:21 -080084 Result IncomingPacketFeedback(const PacketFeedback& packet_feedback);
stefane3a55672017-02-13 09:08:22 -080085 Result OnLongFeedbackDelay(int64_t arrival_time_ms);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070086 // Updates the current remote rate estimate and returns true if a valid
87 // estimate exists.
88 bool UpdateEstimate(int64_t packet_arrival_time_ms,
89 int64_t now_ms,
Stefan Holmer492ee282016-10-27 17:19:20 +020090 rtc::Optional<uint32_t> acked_bitrate_bps,
Stefan Holmer280de9e2016-09-30 10:06:51 +020091 uint32_t* target_bitrate_bps);
terelius5a388362016-12-09 05:50:01 -080092 const bool in_trendline_experiment_;
93 const bool in_median_slope_experiment_;
philipel863a8262016-06-17 09:21:34 -070094
95 rtc::ThreadChecker network_thread_;
terelius0baf55d2017-02-17 03:38:28 -080096 RtcEventLog* const event_log_;
stefan5e12d362016-07-11 01:44:02 -070097 Clock* const clock_;
philipel863a8262016-06-17 09:21:34 -070098 std::unique_ptr<InterArrival> inter_arrival_;
tereliusafaef8b2016-11-17 03:48:18 -080099 std::unique_ptr<OveruseEstimator> kalman_estimator_;
100 std::unique_ptr<TrendlineEstimator> trendline_estimator_;
terelius5a388362016-12-09 05:50:01 -0800101 std::unique_ptr<MedianSlopeEstimator> median_slope_estimator_;
philipel863a8262016-06-17 09:21:34 -0700102 OveruseDetector detector_;
Stefan Holmer492ee282016-10-27 17:19:20 +0200103 BitrateEstimator receiver_incoming_bitrate_;
philipel863a8262016-06-17 09:21:34 -0700104 int64_t last_update_ms_;
philipel7522a282016-08-16 10:59:36 +0200105 int64_t last_seen_packet_ms_;
stefan64636dd2016-08-03 00:29:03 -0700106 bool uma_recorded_;
terelius6ed592d2016-10-18 05:55:30 -0700107 AimdRateControl rate_control_;
Stefan Holmer280de9e2016-09-30 10:06:51 +0200108 ProbeBitrateEstimator probe_bitrate_estimator_;
tereliusafaef8b2016-11-17 03:48:18 -0800109 size_t trendline_window_size_;
110 double trendline_smoothing_coeff_;
111 double trendline_threshold_gain_;
minyue78b4d562016-11-30 04:47:39 -0800112 ProbingIntervalEstimator probing_interval_estimator_;
terelius5a388362016-12-09 05:50:01 -0800113 size_t median_slope_window_size_;
114 double median_slope_threshold_gain_;
stefane3a55672017-02-13 09:08:22 -0800115 int consecutive_delayed_feedbacks_;
terelius0baf55d2017-02-17 03:38:28 -0800116 uint32_t last_logged_bitrate_;
117 BandwidthUsage last_logged_state_;
philipel863a8262016-06-17 09:21:34 -0700118
119 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe);
120};
121
122} // namespace webrtc
123
124#endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_