blob: c5a599f334c65d9c14c8ae0169dfe0558a9f9e79 [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"
philipel7522a282016-08-16 10:59:36 +020022#include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h"
minyue78b4d562016-11-30 04:47:39 -080023#include "webrtc/modules/congestion_controller/probing_interval_estimator.h"
tereliusafaef8b2016-11-17 03:48:18 -080024#include "webrtc/modules/congestion_controller/trendline_estimator.h"
philipel863a8262016-06-17 09:21:34 -070025#include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h"
26#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
27#include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h"
28#include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h"
29#include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h"
philipel863a8262016-06-17 09:21:34 -070030
31namespace webrtc {
32
Stefan Holmer280de9e2016-09-30 10:06:51 +020033class DelayBasedBwe {
philipel863a8262016-06-17 09:21:34 -070034 public:
Stefan Holmer280de9e2016-09-30 10:06:51 +020035 static const int64_t kStreamTimeOutMs = 2000;
36
37 struct Result {
38 Result() : updated(false), probe(false), target_bitrate_bps(0) {}
39 Result(bool probe, uint32_t target_bitrate_bps)
40 : updated(true), probe(probe), target_bitrate_bps(target_bitrate_bps) {}
41 bool updated;
42 bool probe;
43 uint32_t target_bitrate_bps;
44 };
45
46 explicit DelayBasedBwe(Clock* clock);
philipel863a8262016-06-17 09:21:34 -070047 virtual ~DelayBasedBwe() {}
48
Stefan Holmer280de9e2016-09-30 10:06:51 +020049 Result IncomingPacketFeedbackVector(
50 const std::vector<PacketInfo>& packet_feedback_vector);
51 void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms);
philipel7522a282016-08-16 10:59:36 +020052 bool LatestEstimate(std::vector<uint32_t>* ssrcs,
Stefan Holmer280de9e2016-09-30 10:06:51 +020053 uint32_t* bitrate_bps) const;
54 void SetMinBitrate(int min_bitrate_bps);
minyue78b4d562016-11-30 04:47:39 -080055 int64_t GetProbingIntervalMs() const;
philipel863a8262016-06-17 09:21:34 -070056
philipel863a8262016-06-17 09:21:34 -070057 private:
Stefan Holmer492ee282016-10-27 17:19:20 +020058 // Computes a bayesian estimate of the throughput given acks containing
59 // the arrival time and payload size. Samples which are far from the current
60 // estimate or are based on few packets are given a smaller weight, as they
61 // are considered to be more likely to have been caused by, e.g., delay spikes
62 // unrelated to congestion.
63 class BitrateEstimator {
64 public:
65 BitrateEstimator();
66 void Update(int64_t now_ms, int bytes);
67 rtc::Optional<uint32_t> bitrate_bps() const;
68
69 private:
70 float UpdateWindow(int64_t now_ms, int bytes, int rate_window_ms);
71 int sum_;
72 int64_t current_win_ms_;
73 int64_t prev_time_ms_;
74 float bitrate_estimate_;
75 float bitrate_estimate_var_;
76 RateStatistics old_estimator_;
77 const bool in_experiment_;
78 };
79
Stefan Holmer280de9e2016-09-30 10:06:51 +020080 Result IncomingPacketInfo(const PacketInfo& info);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070081 // Updates the current remote rate estimate and returns true if a valid
82 // estimate exists.
83 bool UpdateEstimate(int64_t packet_arrival_time_ms,
84 int64_t now_ms,
Stefan Holmer492ee282016-10-27 17:19:20 +020085 rtc::Optional<uint32_t> acked_bitrate_bps,
Stefan Holmer280de9e2016-09-30 10:06:51 +020086 uint32_t* target_bitrate_bps);
philipel863a8262016-06-17 09:21:34 -070087
88 rtc::ThreadChecker network_thread_;
stefan5e12d362016-07-11 01:44:02 -070089 Clock* const clock_;
philipel863a8262016-06-17 09:21:34 -070090 std::unique_ptr<InterArrival> inter_arrival_;
tereliusafaef8b2016-11-17 03:48:18 -080091 std::unique_ptr<OveruseEstimator> kalman_estimator_;
92 std::unique_ptr<TrendlineEstimator> trendline_estimator_;
philipel863a8262016-06-17 09:21:34 -070093 OveruseDetector detector_;
Stefan Holmer492ee282016-10-27 17:19:20 +020094 BitrateEstimator receiver_incoming_bitrate_;
philipel863a8262016-06-17 09:21:34 -070095 int64_t last_update_ms_;
philipel7522a282016-08-16 10:59:36 +020096 int64_t last_seen_packet_ms_;
stefan64636dd2016-08-03 00:29:03 -070097 bool uma_recorded_;
terelius6ed592d2016-10-18 05:55:30 -070098 AimdRateControl rate_control_;
Stefan Holmer280de9e2016-09-30 10:06:51 +020099 ProbeBitrateEstimator probe_bitrate_estimator_;
tereliusafaef8b2016-11-17 03:48:18 -0800100 size_t trendline_window_size_;
101 double trendline_smoothing_coeff_;
102 double trendline_threshold_gain_;
103 const bool in_trendline_experiment_;
minyue78b4d562016-11-30 04:47:39 -0800104 ProbingIntervalEstimator probing_interval_estimator_;
philipel863a8262016-06-17 09:21:34 -0700105
106 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe);
107};
108
109} // namespace webrtc
110
111#endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_