blob: fe80fa72a9ce923bcc16bd3e52a957bbffeb44ae [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>
14#include "modules/congestion_controller/network_control/include/network_units.h"
15
16namespace webrtc {
17namespace bbr {
18class DataTransferTracker {
19 public:
20 struct Result {
21 TimeDelta ack_timespan;
22 TimeDelta send_timespan;
23 DataSize acked_data;
24 };
25 DataTransferTracker();
26 ~DataTransferTracker();
27 void AddSample(DataSize size_delta, Timestamp send_time, Timestamp ack_time);
28 void ClearOldSamples(Timestamp excluding_end);
29
30 // Get the average data rate in the window that starts with the last ack which
31 // comes before covered_start and ends at the first ack that comes after or at
32 // including_end.
33 Result GetRatesByAckTime(Timestamp covered_start, Timestamp including_end);
34
35 private:
36 struct Sample {
37 Timestamp ack_time;
38 Timestamp send_time;
39 DataSize size_delta;
40 DataSize size_sum;
41 };
42 std::deque<Sample> samples_;
43 DataSize size_sum_ = DataSize::Zero();
44};
45} // namespace bbr
46} // namespace webrtc
47#endif // MODULES_CONGESTION_CONTROLLER_BBR_DATA_TRANSFER_TRACKER_H_