philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 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 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 14 | #include <memory> |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 15 | #include <utility> |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
| 18 | #include "webrtc/base/checks.h" |
| 19 | #include "webrtc/base/constructormagic.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 20 | #include "webrtc/base/rate_statistics.h" |
| 21 | #include "webrtc/base/thread_checker.h" |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 22 | #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 23 | #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" |
| 24 | #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
| 25 | #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h" |
| 26 | #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" |
| 27 | #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 28 | |
| 29 | namespace webrtc { |
| 30 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 31 | class DelayBasedBwe { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 32 | public: |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 33 | static const int64_t kStreamTimeOutMs = 2000; |
| 34 | |
| 35 | struct Result { |
| 36 | Result() : updated(false), probe(false), target_bitrate_bps(0) {} |
| 37 | Result(bool probe, uint32_t target_bitrate_bps) |
| 38 | : updated(true), probe(probe), target_bitrate_bps(target_bitrate_bps) {} |
| 39 | bool updated; |
| 40 | bool probe; |
| 41 | uint32_t target_bitrate_bps; |
| 42 | }; |
| 43 | |
| 44 | explicit DelayBasedBwe(Clock* clock); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 45 | virtual ~DelayBasedBwe() {} |
| 46 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 47 | Result IncomingPacketFeedbackVector( |
| 48 | const std::vector<PacketInfo>& packet_feedback_vector); |
| 49 | void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms); |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 50 | bool LatestEstimate(std::vector<uint32_t>* ssrcs, |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 51 | uint32_t* bitrate_bps) const; |
| 52 | void SetMinBitrate(int min_bitrate_bps); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 53 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 54 | private: |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 55 | // Computes a bayesian estimate of the throughput given acks containing |
| 56 | // the arrival time and payload size. Samples which are far from the current |
| 57 | // estimate or are based on few packets are given a smaller weight, as they |
| 58 | // are considered to be more likely to have been caused by, e.g., delay spikes |
| 59 | // unrelated to congestion. |
| 60 | class BitrateEstimator { |
| 61 | public: |
| 62 | BitrateEstimator(); |
| 63 | void Update(int64_t now_ms, int bytes); |
| 64 | rtc::Optional<uint32_t> bitrate_bps() const; |
| 65 | |
| 66 | private: |
| 67 | float UpdateWindow(int64_t now_ms, int bytes, int rate_window_ms); |
| 68 | int sum_; |
| 69 | int64_t current_win_ms_; |
| 70 | int64_t prev_time_ms_; |
| 71 | float bitrate_estimate_; |
| 72 | float bitrate_estimate_var_; |
| 73 | RateStatistics old_estimator_; |
| 74 | const bool in_experiment_; |
| 75 | }; |
| 76 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 77 | Result IncomingPacketInfo(const PacketInfo& info); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 78 | // Updates the current remote rate estimate and returns true if a valid |
| 79 | // estimate exists. |
| 80 | bool UpdateEstimate(int64_t packet_arrival_time_ms, |
| 81 | int64_t now_ms, |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 82 | rtc::Optional<uint32_t> acked_bitrate_bps, |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 83 | uint32_t* target_bitrate_bps); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 84 | |
| 85 | rtc::ThreadChecker network_thread_; |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 86 | Clock* const clock_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 87 | std::unique_ptr<InterArrival> inter_arrival_; |
| 88 | std::unique_ptr<OveruseEstimator> estimator_; |
| 89 | OveruseDetector detector_; |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 90 | BitrateEstimator receiver_incoming_bitrate_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 91 | int64_t last_update_ms_; |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 92 | int64_t last_seen_packet_ms_; |
stefan | 64636dd | 2016-08-03 00:29:03 -0700 | [diff] [blame] | 93 | bool uma_recorded_; |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 94 | AimdRateControl rate_control_; |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 95 | ProbeBitrateEstimator probe_bitrate_estimator_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 96 | |
| 97 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); |
| 98 | }; |
| 99 | |
| 100 | } // namespace webrtc |
| 101 | |
| 102 | #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |