1 /* 2 * Copyright (c) 2015 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_RTP_TRANSPORT_FEEDBACK_ADAPTER_H_ 12 #define MODULES_CONGESTION_CONTROLLER_RTP_TRANSPORT_FEEDBACK_ADAPTER_H_ 13 14 #include <deque> 15 #include <map> 16 #include <utility> 17 #include <vector> 18 19 #include "api/sequence_checker.h" 20 #include "api/transport/network_types.h" 21 #include "api/units/timestamp.h" 22 #include "modules/include/module_common_types_public.h" 23 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" 24 #include "rtc_base/network/sent_packet.h" 25 #include "rtc_base/network_route.h" 26 #include "rtc_base/thread_annotations.h" 27 28 namespace webrtc { 29 30 struct PacketFeedback { 31 PacketFeedback() = default; 32 // Time corresponding to when this object was created. 33 Timestamp creation_time = Timestamp::MinusInfinity(); 34 SentPacket sent; 35 // Time corresponding to when the packet was received. Timestamped with the 36 // receiver's clock. For unreceived packet, Timestamp::PlusInfinity() is 37 // used. 38 Timestamp receive_time = Timestamp::PlusInfinity(); 39 40 // The network route that this packet is associated with. 41 rtc::NetworkRoute network_route; 42 }; 43 44 class InFlightBytesTracker { 45 public: 46 void AddInFlightPacketBytes(const PacketFeedback& packet); 47 void RemoveInFlightPacketBytes(const PacketFeedback& packet); 48 DataSize GetOutstandingData(const rtc::NetworkRoute& network_route) const; 49 50 private: 51 struct NetworkRouteComparator { 52 bool operator()(const rtc::NetworkRoute& a, 53 const rtc::NetworkRoute& b) const; 54 }; 55 std::map<rtc::NetworkRoute, DataSize, NetworkRouteComparator> in_flight_data_; 56 }; 57 58 class TransportFeedbackAdapter { 59 public: 60 TransportFeedbackAdapter(); 61 62 void AddPacket(const RtpPacketSendInfo& packet_info, 63 size_t overhead_bytes, 64 Timestamp creation_time); 65 absl::optional<SentPacket> ProcessSentPacket( 66 const rtc::SentPacket& sent_packet); 67 68 absl::optional<TransportPacketsFeedback> ProcessTransportFeedback( 69 const rtcp::TransportFeedback& feedback, 70 Timestamp feedback_receive_time); 71 72 void SetNetworkRoute(const rtc::NetworkRoute& network_route); 73 74 DataSize GetOutstandingData() const; 75 76 private: 77 enum class SendTimeHistoryStatus { kNotAdded, kOk, kDuplicate }; 78 79 std::vector<PacketResult> ProcessTransportFeedbackInner( 80 const rtcp::TransportFeedback& feedback, 81 Timestamp feedback_receive_time); 82 83 DataSize pending_untracked_size_ = DataSize::Zero(); 84 Timestamp last_send_time_ = Timestamp::MinusInfinity(); 85 Timestamp last_untracked_send_time_ = Timestamp::MinusInfinity(); 86 SequenceNumberUnwrapper seq_num_unwrapper_; 87 std::map<int64_t, PacketFeedback> history_; 88 89 // Sequence numbers are never negative, using -1 as it always < a real 90 // sequence number. 91 int64_t last_ack_seq_num_ = -1; 92 InFlightBytesTracker in_flight_; 93 94 Timestamp current_offset_ = Timestamp::MinusInfinity(); 95 Timestamp last_timestamp_ = Timestamp::MinusInfinity(); 96 97 rtc::NetworkRoute network_route_; 98 }; 99 100 } // namespace webrtc 101 102 #endif // MODULES_CONGESTION_CONTROLLER_RTP_TRANSPORT_FEEDBACK_ADAPTER_H_ 103