tor-browser

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

rtp_config.h (6078B)


      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 CALL_RTP_CONFIG_H_
     12 #define CALL_RTP_CONFIG_H_
     13 
     14 #include <stddef.h>
     15 #include <stdint.h>
     16 
     17 #include <optional>
     18 #include <string>
     19 #include <vector>
     20 
     21 #include "api/rtp_headers.h"
     22 #include "api/rtp_parameters.h"
     23 
     24 namespace webrtc {
     25 // Currently only VP8/VP9 specific.
     26 struct RtpPayloadState {
     27  int16_t picture_id = -1;
     28  uint8_t tl0_pic_idx = 0;
     29  int64_t shared_frame_id = 0;
     30  int64_t frame_id = 0;
     31 };
     32 
     33 // Settings for LNTF (LossNotification). Still highly experimental.
     34 struct LntfConfig {
     35  std::string ToString() const;
     36 
     37  bool enabled{false};
     38 };
     39 
     40 // Settings for NACK, see RFC 4585 for details.
     41 struct NackConfig {
     42  NackConfig() : rtp_history_ms(0) {}
     43  std::string ToString() const;
     44  // Send side: the time RTP packets are stored for retransmissions.
     45  // Receive side: the time the receiver is prepared to wait for
     46  // retransmissions.
     47  // Set to '0' to disable.
     48  int rtp_history_ms;
     49 };
     50 
     51 // Settings for ULPFEC forward error correction.
     52 // Set the payload types to '-1' to disable.
     53 struct UlpfecConfig {
     54  UlpfecConfig()
     55      : ulpfec_payload_type(-1),
     56        red_payload_type(-1),
     57        red_rtx_payload_type(-1) {}
     58  std::string ToString() const;
     59  bool operator==(const UlpfecConfig& other) const;
     60 
     61  // Payload type used for ULPFEC packets.
     62  int ulpfec_payload_type;
     63 
     64  // Payload type used for RED packets.
     65  int red_payload_type;
     66 
     67  // RTX payload type for RED payload.
     68  int red_rtx_payload_type;
     69 };
     70 
     71 struct RtpStreamConfig {
     72  std::string ToString() const;
     73 
     74  uint32_t ssrc = 0;
     75  std::string rid;
     76  std::string payload_name;
     77  int payload_type = -1;
     78  bool raw_payload = false;
     79  struct Rtx {
     80    std::string ToString() const;
     81    // SSRC to use for the RTX stream.
     82    uint32_t ssrc = 0;
     83 
     84    // Payload type to use for the RTX stream.
     85    int payload_type = -1;
     86  };
     87  std::optional<Rtx> rtx;
     88 };
     89 
     90 static const size_t kDefaultMaxPacketSize = 1500 - 40;  // TCP over IPv4.
     91 struct RtpConfig {
     92  RtpConfig();
     93  RtpConfig(const RtpConfig&);
     94  ~RtpConfig();
     95  std::string ToString() const;
     96 
     97  std::vector<uint32_t> ssrcs;
     98 
     99  // The Rtp Stream Ids (aka RIDs) to send in the RID RTP header extension
    100  // if the extension is included in the list of extensions.
    101  // If rids are specified, they should correspond to the `ssrcs` vector.
    102  // This means that:
    103  // 1. rids.size() == 0 || rids.size() == ssrcs.size().
    104  // 2. If rids is not empty, then `rids[i]` should use `ssrcs[i]`.
    105  std::vector<std::string> rids;
    106 
    107  // The value to send in the MID RTP header extension if the extension is
    108  // included in the list of extensions.
    109  std::string mid;
    110 
    111  // See RtcpMode for description.
    112  RtcpMode rtcp_mode = RtcpMode::kCompound;
    113 
    114  // Max RTP packet size delivered to send transport from VideoEngine.
    115  size_t max_packet_size = kDefaultMaxPacketSize;
    116 
    117  // Corresponds to the SDP attribute extmap-allow-mixed.
    118  bool extmap_allow_mixed = false;
    119 
    120  // RTP header extensions to use for this send stream.
    121  std::vector<RtpExtension> extensions;
    122 
    123  // TODO(nisse): For now, these are fixed, but we'd like to support
    124  // changing codec without recreating the VideoSendStream. Then these
    125  // fields must be removed, and association between payload type and codec
    126  // must move above the per-stream level. Ownership could be with
    127  // RtpTransportControllerSend, with a reference from RtpVideoSender, where
    128  // the latter would be responsible for mapping the codec type of encoded
    129  // images to the right payload type.
    130  std::string payload_name;
    131  int payload_type = -1;
    132  // Payload should be packetized using raw packetizer (payload header will
    133  // not be added, additional meta data is expected to be present in generic
    134  // frame descriptor RTP header extension).
    135  bool raw_payload = false;
    136 
    137  // Configurations for each RTP stream
    138  std::vector<RtpStreamConfig> stream_configs;
    139 
    140  // See LntfConfig for description.
    141  LntfConfig lntf;
    142 
    143  // See NackConfig for description.
    144  NackConfig nack;
    145 
    146  // See UlpfecConfig for description.
    147  UlpfecConfig ulpfec;
    148 
    149  struct Flexfec {
    150    Flexfec();
    151    Flexfec(const Flexfec&);
    152    ~Flexfec();
    153    // Payload type of FlexFEC. Set to -1 to disable sending FlexFEC.
    154    int payload_type = -1;
    155 
    156    // SSRC of FlexFEC stream.
    157    uint32_t ssrc = 0;
    158 
    159    // Vector containing a single element, corresponding to the SSRC of the
    160    // media stream being protected by this FlexFEC stream.
    161    // The vector MUST have size 1.
    162    //
    163    // TODO(brandtr): Update comment above when we support
    164    // multistream protection.
    165    std::vector<uint32_t> protected_media_ssrcs;
    166  } flexfec;
    167 
    168  // Settings for RTP retransmission payload format, see RFC 4588 for
    169  // details.
    170  struct Rtx {
    171    Rtx();
    172    Rtx(const Rtx&);
    173    ~Rtx();
    174    std::string ToString() const;
    175    // SSRCs to use for the RTX streams.
    176    std::vector<uint32_t> ssrcs;
    177 
    178    // Payload type to use for the RTX stream.
    179    int payload_type = -1;
    180  } rtx;
    181 
    182  // RTCP CNAME, see RFC 3550.
    183  std::string c_name;
    184 
    185  // Enables send packet batching from the egress RTP sender.
    186  bool enable_send_packet_batching = false;
    187 
    188  bool IsMediaSsrc(uint32_t ssrc) const;
    189  bool IsRtxSsrc(uint32_t ssrc) const;
    190  bool IsFlexfecSsrc(uint32_t ssrc) const;
    191  std::optional<uint32_t> GetRtxSsrcAssociatedWithMediaSsrc(
    192      uint32_t media_ssrc) const;
    193  uint32_t GetMediaSsrcAssociatedWithRtxSsrc(uint32_t rtx_ssrc) const;
    194  uint32_t GetMediaSsrcAssociatedWithFlexfecSsrc(uint32_t flexfec_ssrc) const;
    195  std::optional<std::string> GetRidForSsrc(uint32_t ssrc) const;
    196 
    197  // Returns send config for RTP stream by provided simulcast `index`.
    198  RtpStreamConfig GetStreamConfig(size_t index) const;
    199 };
    200 }  // namespace webrtc
    201 #endif  // CALL_RTP_CONFIG_H_