1 /* 2 * Copyright (c) 2020 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 11 #ifndef MODULES_CONGESTION_CONTROLLER_GOOG_CC_INTER_ARRIVAL_DELTA_H_ 12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_INTER_ARRIVAL_DELTA_H_ 13 14 #include "api/units/time_delta.h" 15 #include "api/units/timestamp.h" 16 17 namespace webrtc { 18 19 // Helper class to compute the inter-arrival time delta and the size delta 20 // between two send bursts. This code is branched from 21 // modules/remote_bitrate_estimator/inter_arrival. 22 class InterArrivalDelta { 23 public: 24 // After this many packet groups received out of order InterArrival will 25 // reset, assuming that clocks have made a jump. 26 static constexpr int kReorderedResetThreshold = 3; 27 static constexpr TimeDelta kArrivalTimeOffsetThreshold = 28 TimeDelta::Seconds(3); 29 30 // A send time group is defined as all packets with a send time which are at 31 // most send_time_group_length older than the first timestamp in that 32 // group. 33 explicit InterArrivalDelta(TimeDelta send_time_group_length); 34 35 InterArrivalDelta() = delete; 36 InterArrivalDelta(const InterArrivalDelta&) = delete; 37 InterArrivalDelta& operator=(const InterArrivalDelta&) = delete; 38 39 // This function returns true if a delta was computed, or false if the current 40 // group is still incomplete or if only one group has been completed. 41 // `send_time` is the send time. 42 // `arrival_time` is the time at which the packet arrived. 43 // `packet_size` is the size of the packet. 44 // `timestamp_delta` (output) is the computed send time delta. 45 // `arrival_time_delta` (output) is the computed arrival-time delta. 46 // `packet_size_delta` (output) is the computed size delta. 47 bool ComputeDeltas(Timestamp send_time, 48 Timestamp arrival_time, 49 Timestamp system_time, 50 size_t packet_size, 51 TimeDelta* send_time_delta, 52 TimeDelta* arrival_time_delta, 53 int* packet_size_delta); 54 55 private: 56 struct SendTimeGroup { SendTimeGroupSendTimeGroup57 SendTimeGroup() 58 : size(0), 59 first_send_time(Timestamp::MinusInfinity()), 60 send_time(Timestamp::MinusInfinity()), 61 first_arrival(Timestamp::MinusInfinity()), 62 complete_time(Timestamp::MinusInfinity()), 63 last_system_time(Timestamp::MinusInfinity()) {} 64 IsFirstPacketSendTimeGroup65 bool IsFirstPacket() const { return complete_time.IsInfinite(); } 66 67 size_t size; 68 Timestamp first_send_time; 69 Timestamp send_time; 70 Timestamp first_arrival; 71 Timestamp complete_time; 72 Timestamp last_system_time; 73 }; 74 75 // Returns true if the last packet was the end of the current batch and the 76 // packet with `send_time` is the first of a new batch. 77 bool NewTimestampGroup(Timestamp arrival_time, Timestamp send_time) const; 78 79 bool BelongsToBurst(Timestamp arrival_time, Timestamp send_time) const; 80 81 void Reset(); 82 83 const TimeDelta send_time_group_length_; 84 SendTimeGroup current_timestamp_group_; 85 SendTimeGroup prev_timestamp_group_; 86 int num_consecutive_reordered_packets_; 87 }; 88 } // namespace webrtc 89 90 #endif // MODULES_CONGESTION_CONTROLLER_GOOG_CC_INTER_ARRIVAL_DELTA_H_ 91