blob: 1de8c8a1770c23aae897de7ad855916031ff303b [file] [log] [blame]
Sebastian Jansson883f4702018-03-22 15:34:10 +01001/*
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 Jansson324865a2018-04-16 12:17:06 +020014#include "modules/congestion_controller/network_control/units/data_size.h"
15#include "modules/congestion_controller/network_control/units/time_delta.h"
16#include "modules/congestion_controller/network_control/units/timestamp.h"
Sebastian Jansson883f4702018-03-22 15:34:10 +010017
18namespace webrtc {
19namespace bbr {
20class DataTransferTracker {
21 public:
22 struct Result {
Sebastian Jansson91c237e2018-05-04 14:55:33 +020023 TimeDelta ack_timespan = TimeDelta::Zero();
24 TimeDelta send_timespan = TimeDelta::Zero();
25 DataSize acked_data = DataSize::Zero();
Sebastian Jansson883f4702018-03-22 15:34:10 +010026 };
27 DataTransferTracker();
28 ~DataTransferTracker();
29 void AddSample(DataSize size_delta, Timestamp send_time, Timestamp ack_time);
30 void ClearOldSamples(Timestamp excluding_end);
31
32 // Get the average data rate in the window that starts with the last ack which
33 // comes before covered_start and ends at the first ack that comes after or at
34 // including_end.
35 Result GetRatesByAckTime(Timestamp covered_start, Timestamp including_end);
36
37 private:
38 struct Sample {
Sebastian Jansson91c237e2018-05-04 14:55:33 +020039 Timestamp ack_time = Timestamp::Infinity();
40 Timestamp send_time = Timestamp::Infinity();
41 DataSize size_delta = DataSize::Zero();
42 DataSize size_sum = DataSize::Zero();
Sebastian Jansson883f4702018-03-22 15:34:10 +010043 };
44 std::deque<Sample> samples_;
45 DataSize size_sum_ = DataSize::Zero();
46};
47} // namespace bbr
48} // namespace webrtc
49#endif // MODULES_CONGESTION_CONTROLLER_BBR_DATA_TRANSFER_TRACKER_H_