tor-browser

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

rtcp_transceiver_config.h (6593B)


      1 /*
      2 *  Copyright (c) 2017 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_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_CONFIG_H_
     12 #define MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_CONFIG_H_
     13 
     14 #include <cstddef>
     15 #include <cstdint>
     16 #include <functional>
     17 #include <string>
     18 
     19 #include "api/array_view.h"
     20 #include "api/rtp_headers.h"
     21 #include "api/task_queue/task_queue_base.h"
     22 #include "api/units/time_delta.h"
     23 #include "api/units/timestamp.h"
     24 #include "api/video/video_bitrate_allocation.h"
     25 #include "modules/rtp_rtcp/include/report_block_data.h"
     26 #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
     27 #include "system_wrappers/include/clock.h"
     28 #include "system_wrappers/include/ntp_time.h"
     29 
     30 namespace webrtc {
     31 class ReceiveStatisticsProvider;
     32 
     33 // Interface to watch incoming rtcp packets by media (rtp) receiver.
     34 // All message handlers have default empty implementation. This way users only
     35 // need to implement the ones they are interested in.
     36 class MediaReceiverRtcpObserver {
     37 public:
     38  virtual ~MediaReceiverRtcpObserver() = default;
     39 
     40  virtual void OnSenderReport(uint32_t /* sender_ssrc */,
     41                              NtpTime /* ntp_time */,
     42                              uint32_t /* rtp_time */) {}
     43  virtual void OnBye(uint32_t /* sender_ssrc */) {}
     44  virtual void OnBitrateAllocation(
     45      uint32_t /* sender_ssrc */,
     46      const VideoBitrateAllocation& /* allocation */) {}
     47 };
     48 
     49 // Handles RTCP related messages for a single RTP stream (i.e. single SSRC)
     50 class RtpStreamRtcpHandler {
     51 public:
     52  virtual ~RtpStreamRtcpHandler() = default;
     53 
     54  // Statistic about sent RTP packets to propagate to RTCP sender report.
     55  class RtpStats {
     56   public:
     57    RtpStats() = default;
     58    RtpStats(const RtpStats&) = default;
     59    RtpStats& operator=(const RtpStats&) = default;
     60    ~RtpStats() = default;
     61 
     62    size_t num_sent_packets() const { return num_sent_packets_; }
     63    size_t num_sent_bytes() const { return num_sent_bytes_; }
     64    Timestamp last_capture_time() const { return last_capture_time_; }
     65    uint32_t last_rtp_timestamp() const { return last_rtp_timestamp_; }
     66    int last_clock_rate() const { return last_clock_rate_; }
     67 
     68    void set_num_sent_packets(size_t v) { num_sent_packets_ = v; }
     69    void set_num_sent_bytes(size_t v) { num_sent_bytes_ = v; }
     70    void set_last_capture_time(Timestamp v) { last_capture_time_ = v; }
     71    void set_last_rtp_timestamp(uint32_t v) { last_rtp_timestamp_ = v; }
     72    void set_last_clock_rate(int v) { last_clock_rate_ = v; }
     73 
     74   private:
     75    size_t num_sent_packets_ = 0;
     76    size_t num_sent_bytes_ = 0;
     77    Timestamp last_capture_time_ = Timestamp::Zero();
     78    uint32_t last_rtp_timestamp_ = 0;
     79    int last_clock_rate_ = 90'000;
     80  };
     81  virtual RtpStats SentStats() = 0;
     82 
     83  virtual void OnNack(uint32_t /* sender_ssrc */,
     84                      ArrayView<const uint16_t> /* sequence_numbers */) {}
     85  virtual void OnFir(uint32_t /* sender_ssrc */) {}
     86  virtual void OnPli(uint32_t /* sender_ssrc */) {}
     87 
     88  // Called on an RTCP packet with sender or receiver reports with a report
     89  // block for the handled RTP stream.
     90  virtual void OnReport(const ReportBlockData& /* report_block */) {}
     91 };
     92 
     93 struct RtcpTransceiverConfig {
     94  RtcpTransceiverConfig();
     95  RtcpTransceiverConfig(const RtcpTransceiverConfig&);
     96  RtcpTransceiverConfig& operator=(const RtcpTransceiverConfig&);
     97  ~RtcpTransceiverConfig();
     98 
     99  // Logs the error and returns false if configuration miss key objects or
    100  // is inconsistant. May log warnings.
    101  bool Validate() const;
    102 
    103  // Used to prepend all log messages. Can be empty.
    104  std::string debug_id;
    105 
    106  // Ssrc to use as default sender ssrc, e.g. for transport-wide feedbacks.
    107  uint32_t feedback_ssrc = 1;
    108 
    109  // Canonical End-Point Identifier of the local particiapnt.
    110  // Defined in rfc3550 section 6 note 2 and section 6.5.1.
    111  std::string cname;
    112 
    113  // Maximum packet size outgoing transport accepts.
    114  size_t max_packet_size = 1200;
    115 
    116  // The clock to use when querying for the NTP time. Should be set.
    117  Clock* clock = nullptr;
    118 
    119  // Transport to send RTCP packets to.
    120  std::function<void(ArrayView<const uint8_t>)> rtcp_transport;
    121 
    122  // Queue for scheduling delayed tasks, e.g. sending periodic compound packets.
    123  TaskQueueBase* task_queue = nullptr;
    124 
    125  // Rtcp report block generator for outgoing receiver reports.
    126  ReceiveStatisticsProvider* receive_statistics = nullptr;
    127 
    128  // Should outlive RtcpTransceiver.
    129  // Callbacks will be invoked on the `task_queue`.
    130  NetworkLinkRtcpObserver* network_link_observer = nullptr;
    131 
    132  // Configures if sending should
    133  //  enforce compound packets: https://tools.ietf.org/html/rfc4585#section-3.1
    134  //  or allow reduced size packets: https://tools.ietf.org/html/rfc5506
    135  // Receiving accepts both compound and reduced-size packets.
    136  RtcpMode rtcp_mode = RtcpMode::kCompound;
    137 
    138  //
    139  // Tuning parameters.
    140  //
    141  // Initial flag if `rtcp_transport` can be used to send packets.
    142  // If set to false, RtcpTransciever won't call `rtcp_transport` until
    143  // `RtcpTransceover(Impl)::SetReadyToSend(true)` is called.
    144  bool initial_ready_to_send = true;
    145 
    146  // Delay before 1st periodic compound packet.
    147  TimeDelta initial_report_delay = TimeDelta::Millis(500);
    148 
    149  // Period between periodic compound packets.
    150  TimeDelta report_period = TimeDelta::Seconds(1);
    151 
    152  //
    153  // Flags for features and experiments.
    154  //
    155  bool schedule_periodic_compound_packets = true;
    156  // Estimate RTT as non-sender as described in
    157  // https://tools.ietf.org/html/rfc3611#section-4.4 and #section-4.5
    158  bool non_sender_rtt_measurement = false;
    159 
    160  // Reply to incoming RRTR messages so that remote endpoint may estimate RTT as
    161  // non-sender as described in https://tools.ietf.org/html/rfc3611#section-4.4
    162  // and #section-4.5
    163  bool reply_to_non_sender_rtt_measurement = true;
    164 
    165  // Reply to incoming RRTR messages multiple times, one per sender SSRC, to
    166  // support clients that calculate and process RTT per sender SSRC.
    167  bool reply_to_non_sender_rtt_mesaurments_on_all_ssrcs = true;
    168 
    169  // Allows a REMB message to be sent immediately when SetRemb is called without
    170  // having to wait for the next compount message to be sent.
    171  bool send_remb_on_change = false;
    172 };
    173 
    174 }  // namespace webrtc
    175 
    176 #endif  // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_CONFIG_H_