tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

transport_feedback_adapter.h (5014B)


      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 <cstddef>
     15 #include <cstdint>
     16 #include <map>
     17 #include <optional>
     18 #include <tuple>
     19 #include <vector>
     20 
     21 #include "api/transport/network_types.h"
     22 #include "api/units/data_size.h"
     23 #include "api/units/time_delta.h"
     24 #include "api/units/timestamp.h"
     25 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
     26 #include "modules/rtp_rtcp/source/rtcp_packet/congestion_control_feedback.h"
     27 #include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
     28 #include "rtc_base/network/sent_packet.h"
     29 #include "rtc_base/network_route.h"
     30 #include "rtc_base/numerics/sequence_number_unwrapper.h"
     31 
     32 namespace webrtc {
     33 
     34 struct PacketFeedback {
     35  PacketFeedback() = default;
     36  // Time corresponding to when this object was created.
     37  Timestamp creation_time = Timestamp::MinusInfinity();
     38  SentPacket sent;
     39 
     40  // The network route that this packet is associated with.
     41  NetworkRoute network_route;
     42 
     43  uint32_t ssrc = 0;
     44  uint16_t rtp_sequence_number = 0;
     45  bool is_retransmission = false;
     46 };
     47 
     48 class InFlightBytesTracker {
     49 public:
     50  void AddInFlightPacketBytes(const PacketFeedback& packet);
     51  void RemoveInFlightPacketBytes(const PacketFeedback& packet);
     52  DataSize GetOutstandingData(const NetworkRoute& network_route) const;
     53 
     54 private:
     55  struct NetworkRouteComparator {
     56    bool operator()(const NetworkRoute& a, const NetworkRoute& b) const;
     57  };
     58  std::map<NetworkRoute, DataSize, NetworkRouteComparator> in_flight_data_;
     59 };
     60 
     61 // TransportFeedbackAdapter converts RTCP feedback packets to RTCP agnostic per
     62 // packet send/receive information.
     63 // It supports rtcp::CongestionControlFeedback according to RFC 8888 and
     64 // rtcp::TransportFeedback according to
     65 // https://datatracker.ietf.org/doc/html/draft-holmer-rmcat-transport-wide-cc-extensions-01
     66 class TransportFeedbackAdapter {
     67 public:
     68  TransportFeedbackAdapter();
     69 
     70  void AddPacket(const RtpPacketToSend& packet,
     71                 const PacedPacketInfo& pacing_info,
     72                 size_t overhead_bytes,
     73                 Timestamp creation_time);
     74 
     75  std::optional<SentPacket> ProcessSentPacket(
     76      const SentPacketInfo& sent_packet);
     77 
     78  std::optional<TransportPacketsFeedback> ProcessTransportFeedback(
     79      const rtcp::TransportFeedback& feedback,
     80      Timestamp feedback_receive_time);
     81 
     82  std::optional<TransportPacketsFeedback> ProcessCongestionControlFeedback(
     83      const rtcp::CongestionControlFeedback& feedback,
     84      Timestamp feedback_receive_time);
     85 
     86  void SetNetworkRoute(const NetworkRoute& network_route);
     87 
     88  DataSize GetOutstandingData() const;
     89 
     90 private:
     91  enum class SendTimeHistoryStatus { kNotAdded, kOk, kDuplicate };
     92 
     93  struct SsrcAndRtpSequencenumber {
     94    uint32_t ssrc;
     95    uint16_t rtp_sequence_number;
     96 
     97    bool operator<(const SsrcAndRtpSequencenumber& other) const {
     98      return std::tie(ssrc, rtp_sequence_number) <
     99             std::tie(other.ssrc, other.rtp_sequence_number);
    100    }
    101  };
    102 
    103  std::optional<PacketFeedback> RetrievePacketFeedback(
    104      int64_t transport_seq_num,
    105      bool received);
    106  std::optional<PacketFeedback> RetrievePacketFeedback(
    107      const SsrcAndRtpSequencenumber& key,
    108      bool received);
    109  std::optional<TransportPacketsFeedback> ToTransportFeedback(
    110      std::vector<PacketResult> packet_results,
    111      Timestamp feedback_receive_time,
    112      bool supports_ecn);
    113 
    114  DataSize pending_untracked_size_ = DataSize::Zero();
    115  Timestamp last_send_time_ = Timestamp::MinusInfinity();
    116  Timestamp last_untracked_send_time_ = Timestamp::MinusInfinity();
    117  RtpSequenceNumberUnwrapper seq_num_unwrapper_;
    118 
    119  // Sequence numbers are never negative, using -1 as it always < a real
    120  // sequence number.
    121  int64_t last_ack_seq_num_ = -1;
    122  InFlightBytesTracker in_flight_;
    123  NetworkRoute network_route_;
    124 
    125  TimeDelta smoothed_rtt_ = TimeDelta::PlusInfinity();
    126 
    127  Timestamp current_offset_ = Timestamp::MinusInfinity();
    128 
    129  // `last_transport_feedback_base_time` is only used for transport feedback to
    130  // track base time.
    131  Timestamp last_transport_feedback_base_time_ = Timestamp::MinusInfinity();
    132  // Used by RFC 8888 congestion control feedback to track base time.
    133  std::optional<uint32_t> last_feedback_compact_ntp_time_;
    134 
    135  // Map SSRC and RTP sequence number to transport sequence number.
    136  std::map<SsrcAndRtpSequencenumber, int64_t /*transport_sequence_number*/>
    137      rtp_to_transport_sequence_number_;
    138  std::map<int64_t, PacketFeedback> history_;
    139 };
    140 
    141 }  // namespace webrtc
    142 
    143 #endif  // MODULES_CONGESTION_CONTROLLER_RTP_TRANSPORT_FEEDBACK_ADAPTER_H_