Sebastian Jansson | 883f470 | 2018-03-22 15:34:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 | #ifndef MODULES_CONGESTION_CONTROLLER_BBR_DATA_TRANSFER_TRACKER_H_ |
| 11 | #define MODULES_CONGESTION_CONTROLLER_BBR_DATA_TRANSFER_TRACKER_H_ |
| 12 | |
| 13 | #include <deque> |
Sebastian Jansson | 6fae6ec | 2018-05-08 10:43:18 +0200 | [diff] [blame] | 14 | |
| 15 | #include "api/units/data_size.h" |
| 16 | #include "api/units/time_delta.h" |
| 17 | #include "api/units/timestamp.h" |
Sebastian Jansson | 883f470 | 2018-03-22 15:34:10 +0100 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | namespace bbr { |
| 21 | class DataTransferTracker { |
| 22 | public: |
| 23 | struct Result { |
Sebastian Jansson | 91c237e | 2018-05-04 14:55:33 +0200 | [diff] [blame] | 24 | TimeDelta ack_timespan = TimeDelta::Zero(); |
| 25 | TimeDelta send_timespan = TimeDelta::Zero(); |
| 26 | DataSize acked_data = DataSize::Zero(); |
Sebastian Jansson | 883f470 | 2018-03-22 15:34:10 +0100 | [diff] [blame] | 27 | }; |
| 28 | DataTransferTracker(); |
| 29 | ~DataTransferTracker(); |
| 30 | void AddSample(DataSize size_delta, Timestamp send_time, Timestamp ack_time); |
| 31 | void ClearOldSamples(Timestamp excluding_end); |
| 32 | |
| 33 | // Get the average data rate in the window that starts with the last ack which |
| 34 | // comes before covered_start and ends at the first ack that comes after or at |
| 35 | // including_end. |
| 36 | Result GetRatesByAckTime(Timestamp covered_start, Timestamp including_end); |
| 37 | |
| 38 | private: |
| 39 | struct Sample { |
Sebastian Jansson | 9de4ef4 | 2018-09-04 17:32:36 +0200 | [diff] [blame] | 40 | Timestamp ack_time = Timestamp::PlusInfinity(); |
| 41 | Timestamp send_time = Timestamp::PlusInfinity(); |
Sebastian Jansson | 91c237e | 2018-05-04 14:55:33 +0200 | [diff] [blame] | 42 | DataSize size_delta = DataSize::Zero(); |
| 43 | DataSize size_sum = DataSize::Zero(); |
Sebastian Jansson | 883f470 | 2018-03-22 15:34:10 +0100 | [diff] [blame] | 44 | }; |
| 45 | std::deque<Sample> samples_; |
| 46 | DataSize size_sum_ = DataSize::Zero(); |
| 47 | }; |
| 48 | } // namespace bbr |
| 49 | } // namespace webrtc |
| 50 | #endif // MODULES_CONGESTION_CONTROLLER_BBR_DATA_TRANSFER_TRACKER_H_ |