blob: c0820e1142b5697fecc80d9bace4778da62199f3 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_
12#define MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_
philipel863a8262016-06-17 09:21:34 -070013
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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "modules/congestion_controller/median_slope_estimator.h"
19#include "modules/congestion_controller/probe_bitrate_estimator.h"
20#include "modules/congestion_controller/trendline_estimator.h"
21#include "modules/remote_bitrate_estimator/aimd_rate_control.h"
22#include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
23#include "modules/remote_bitrate_estimator/inter_arrival.h"
24#include "modules/remote_bitrate_estimator/overuse_detector.h"
25#include "modules/remote_bitrate_estimator/overuse_estimator.h"
26#include "rtc_base/checks.h"
27#include "rtc_base/constructormagic.h"
28#include "rtc_base/race_checker.h"
philipel863a8262016-06-17 09:21:34 -070029
30namespace webrtc {
31
terelius0baf55d2017-02-17 03:38:28 -080032class RtcEventLog;
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 {
terelius3376c842017-07-31 04:23:25 -070039 Result();
40 Result(bool probe, uint32_t target_bitrate_bps);
41 ~Result();
Stefan Holmer280de9e2016-09-30 10:06:51 +020042 bool updated;
43 bool probe;
44 uint32_t target_bitrate_bps;
terelius3376c842017-07-31 04:23:25 -070045 bool recovered_from_overuse;
Stefan Holmer280de9e2016-09-30 10:06:51 +020046 };
47
elad.alon61ce37e2017-03-09 07:09:31 -080048 DelayBasedBwe(RtcEventLog* event_log, const Clock* clock);
nisse76e62b02017-05-31 02:24:52 -070049 virtual ~DelayBasedBwe();
philipel863a8262016-06-17 09:21:34 -070050
Stefan Holmer280de9e2016-09-30 10:06:51 +020051 Result IncomingPacketFeedbackVector(
tschumim3fae6282017-06-11 23:57:17 -070052 const std::vector<PacketFeedback>& packet_feedback_vector,
53 rtc::Optional<uint32_t> acked_bitrate_bps);
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);
terelius67370452017-04-19 09:15:04 -070059 int64_t GetExpectedBwePeriodMs() const;
philipel863a8262016-06-17 09:21:34 -070060
philipel863a8262016-06-17 09:21:34 -070061 private:
michaelt8490f8a2017-04-20 10:10:10 -070062 void IncomingPacketFeedback(const PacketFeedback& packet_feedback);
stefane3a55672017-02-13 09:08:22 -080063 Result OnLongFeedbackDelay(int64_t arrival_time_ms);
tschumim3fae6282017-06-11 23:57:17 -070064 Result MaybeUpdateEstimate(bool overusing,
terelius3376c842017-07-31 04:23:25 -070065 rtc::Optional<uint32_t> acked_bitrate_bps,
66 bool request_probe);
Irfan Sheriffb2540bb2016-09-12 12:28:54 -070067 // Updates the current remote rate estimate and returns true if a valid
68 // estimate exists.
michaelt8490f8a2017-04-20 10:10:10 -070069 bool UpdateEstimate(int64_t now_ms,
Stefan Holmer492ee282016-10-27 17:19:20 +020070 rtc::Optional<uint32_t> acked_bitrate_bps,
michaelt8490f8a2017-04-20 10:10:10 -070071 bool overusing,
Stefan Holmer280de9e2016-09-30 10:06:51 +020072 uint32_t* target_bitrate_bps);
philipel863a8262016-06-17 09:21:34 -070073
erikvargabf5a2fc2017-06-16 05:02:05 -070074 rtc::RaceChecker network_race_;
terelius0baf55d2017-02-17 03:38:28 -080075 RtcEventLog* const event_log_;
elad.alon61ce37e2017-03-09 07:09:31 -080076 const Clock* const clock_;
philipel863a8262016-06-17 09:21:34 -070077 std::unique_ptr<InterArrival> inter_arrival_;
tereliusafaef8b2016-11-17 03:48:18 -080078 std::unique_ptr<TrendlineEstimator> trendline_estimator_;
philipel863a8262016-06-17 09:21:34 -070079 OveruseDetector detector_;
philipel7522a282016-08-16 10:59:36 +020080 int64_t last_seen_packet_ms_;
stefan64636dd2016-08-03 00:29:03 -070081 bool uma_recorded_;
terelius6ed592d2016-10-18 05:55:30 -070082 AimdRateControl rate_control_;
Stefan Holmer280de9e2016-09-30 10:06:51 +020083 ProbeBitrateEstimator probe_bitrate_estimator_;
tereliusafaef8b2016-11-17 03:48:18 -080084 size_t trendline_window_size_;
85 double trendline_smoothing_coeff_;
86 double trendline_threshold_gain_;
stefane3a55672017-02-13 09:08:22 -080087 int consecutive_delayed_feedbacks_;
terelius0baf55d2017-02-17 03:38:28 -080088 uint32_t last_logged_bitrate_;
89 BandwidthUsage last_logged_state_;
tereliusbf2c0492017-05-02 01:04:26 -070090 bool in_sparse_update_experiment_;
philipel863a8262016-06-17 09:21:34 -070091
92 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe);
93};
94
95} // namespace webrtc
96
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020097#endif // MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_