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 | |
| 14 | #include <list> |
| 15 | #include <map> |
| 16 | #include <memory> |
| 17 | #include <vector> |
| 18 | |
| 19 | #include "webrtc/base/checks.h" |
| 20 | #include "webrtc/base/constructormagic.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 21 | #include "webrtc/base/rate_statistics.h" |
| 22 | #include "webrtc/base/thread_checker.h" |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 23 | #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 24 | #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" |
| 25 | #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
| 26 | #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h" |
| 27 | #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" |
| 28 | #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
| 31 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 32 | class DelayBasedBwe { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 33 | public: |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 34 | static const int64_t kStreamTimeOutMs = 2000; |
| 35 | |
| 36 | struct Result { |
| 37 | Result() : updated(false), probe(false), target_bitrate_bps(0) {} |
| 38 | Result(bool probe, uint32_t target_bitrate_bps) |
| 39 | : updated(true), probe(probe), target_bitrate_bps(target_bitrate_bps) {} |
| 40 | bool updated; |
| 41 | bool probe; |
| 42 | uint32_t target_bitrate_bps; |
| 43 | }; |
| 44 | |
| 45 | explicit DelayBasedBwe(Clock* clock); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 46 | virtual ~DelayBasedBwe() {} |
| 47 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 48 | Result IncomingPacketFeedbackVector( |
| 49 | const std::vector<PacketInfo>& packet_feedback_vector); |
| 50 | void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms); |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 51 | bool LatestEstimate(std::vector<uint32_t>* ssrcs, |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 52 | uint32_t* bitrate_bps) const; |
| 53 | void SetMinBitrate(int min_bitrate_bps); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 54 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 55 | private: |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 56 | Result IncomingPacketInfo(const PacketInfo& info); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 57 | // Updates the current remote rate estimate and returns true if a valid |
| 58 | // estimate exists. |
| 59 | bool UpdateEstimate(int64_t packet_arrival_time_ms, |
| 60 | int64_t now_ms, |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 61 | uint32_t* target_bitrate_bps); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 62 | |
| 63 | rtc::ThreadChecker network_thread_; |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 64 | Clock* const clock_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 65 | std::unique_ptr<InterArrival> inter_arrival_; |
| 66 | std::unique_ptr<OveruseEstimator> estimator_; |
| 67 | OveruseDetector detector_; |
| 68 | RateStatistics incoming_bitrate_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 69 | int64_t last_update_ms_; |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 70 | int64_t last_seen_packet_ms_; |
stefan | 64636dd | 2016-08-03 00:29:03 -0700 | [diff] [blame] | 71 | bool uma_recorded_; |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 72 | AimdRateControl remote_rate_; |
| 73 | ProbeBitrateEstimator probe_bitrate_estimator_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 74 | |
| 75 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); |
| 76 | }; |
| 77 | |
| 78 | } // namespace webrtc |
| 79 | |
| 80 | #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |