tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 | |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 11 | #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_BITRATE_ESTIMATOR_H_ |
| 12 | #define WEBRTC_MODULES_CONGESTION_CONTROLLER_BITRATE_ESTIMATOR_H_ |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 13 | |
| 14 | #include <vector> |
| 15 | |
kwiberg | 84f6a3f | 2017-09-05 08:43:13 -0700 | [diff] [blame] | 16 | #include "webrtc/api/optional.h" |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 20 | // Computes a bayesian estimate of the throughput given acks containing |
| 21 | // the arrival time and payload size. Samples which are far from the current |
| 22 | // estimate or are based on few packets are given a smaller weight, as they |
| 23 | // are considered to be more likely to have been caused by, e.g., delay spikes |
| 24 | // unrelated to congestion. |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 25 | class BitrateEstimator { |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 26 | public: |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 27 | BitrateEstimator(); |
| 28 | virtual ~BitrateEstimator(); |
| 29 | virtual void Update(int64_t now_ms, int bytes); |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 30 | |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 31 | virtual rtc::Optional<uint32_t> bitrate_bps() const; |
| 32 | |
| 33 | virtual void ExpectFastRateChange(); |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 34 | |
| 35 | private: |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 36 | float UpdateWindow(int64_t now_ms, int bytes, int rate_window_ms); |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 37 | int sum_; |
| 38 | int64_t current_win_ms_; |
| 39 | int64_t prev_time_ms_; |
| 40 | float bitrate_estimate_; |
| 41 | float bitrate_estimate_var_; |
| 42 | }; |
| 43 | |
| 44 | } // namespace webrtc |
| 45 | |
tschumim | 9d11764 | 2017-07-17 01:41:41 -0700 | [diff] [blame] | 46 | #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_BITRATE_ESTIMATOR_H_ |