rtt_tracker.cc (1417B)
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 11 #include "modules/congestion_controller/pcc/rtt_tracker.h" 12 13 #include <algorithm> 14 #include <vector> 15 16 #include "api/transport/network_types.h" 17 #include "api/units/time_delta.h" 18 #include "api/units/timestamp.h" 19 20 namespace webrtc { 21 namespace pcc { 22 23 RttTracker::RttTracker(TimeDelta initial_rtt, double alpha) 24 : rtt_estimate_(initial_rtt), alpha_(alpha) {} 25 26 void RttTracker::OnPacketsFeedback( 27 const std::vector<PacketResult>& packet_feedbacks, 28 Timestamp feedback_received_time) { 29 TimeDelta packet_rtt = TimeDelta::MinusInfinity(); 30 for (const PacketResult& packet_result : packet_feedbacks) { 31 if (!packet_result.IsReceived()) 32 continue; 33 packet_rtt = std::max<TimeDelta>( 34 packet_rtt, 35 feedback_received_time - packet_result.sent_packet.send_time); 36 } 37 if (packet_rtt.IsFinite()) 38 rtt_estimate_ = (1 - alpha_) * rtt_estimate_ + alpha_ * packet_rtt; 39 } 40 41 TimeDelta RttTracker::GetRtt() const { 42 return rtt_estimate_; 43 } 44 45 } // namespace pcc 46 } // namespace webrtc