blob: 29dd7a32357c02f3d21bb54e82fdfa72c5574213 [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 Jansson6fae6ec2018-05-08 10:43:18 +020014
15#include "api/units/data_size.h"
16#include "api/units/time_delta.h"
17#include "api/units/timestamp.h"
Sebastian Jansson883f4702018-03-22 15:34:10 +010018
19namespace webrtc {
20namespace bbr {
21class DataTransferTracker {
22 public:
23 struct Result {
Sebastian Jansson91c237e2018-05-04 14:55:33 +020024 TimeDelta ack_timespan = TimeDelta::Zero();
25 TimeDelta send_timespan = TimeDelta::Zero();
26 DataSize acked_data = DataSize::Zero();
Sebastian Jansson883f4702018-03-22 15:34:10 +010027 };
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 Jansson9de4ef42018-09-04 17:32:36 +020040 Timestamp ack_time = Timestamp::PlusInfinity();
41 Timestamp send_time = Timestamp::PlusInfinity();
Sebastian Jansson91c237e2018-05-04 14:55:33 +020042 DataSize size_delta = DataSize::Zero();
43 DataSize size_sum = DataSize::Zero();
Sebastian Jansson883f4702018-03-22 15:34:10 +010044 };
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_