tor-browser

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

rtp_parameters.h (28443B)


      1 /*
      2 *  Copyright 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 API_RTP_PARAMETERS_H_
     12 #define API_RTP_PARAMETERS_H_
     13 
     14 #include <stdint.h>
     15 
     16 #include <map>
     17 #include <optional>
     18 #include <string>
     19 #include <vector>
     20 
     21 #include "absl/container/inlined_vector.h"
     22 #include "absl/strings/str_format.h"
     23 #include "absl/strings/string_view.h"
     24 #include "api/media_types.h"
     25 #include "api/priority.h"
     26 #include "api/rtp_transceiver_direction.h"
     27 #include "api/video/resolution.h"
     28 #include "api/video_codecs/scalability_mode.h"
     29 #include "rtc_base/system/rtc_export.h"
     30 
     31 namespace webrtc {
     32 
     33 using CodecParameterMap = std::map<std::string, std::string>;
     34 
     35 // These structures are intended to mirror those defined by:
     36 // http://draft.ortc.org/#rtcrtpdictionaries*
     37 // Contains everything specified as of 2017 Jan 24.
     38 //
     39 // They are used when retrieving or modifying the parameters of an
     40 // RtpSender/RtpReceiver, or retrieving capabilities.
     41 //
     42 // Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
     43 // types, we typically use "int", in keeping with our style guidelines. The
     44 // parameter's actual valid range will be enforced when the parameters are set,
     45 // rather than when the parameters struct is built. An exception is made for
     46 // SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
     47 // be used for any numeric comparisons/operations.
     48 //
     49 // Additionally, where ORTC uses strings, we may use enums for things that have
     50 // a fixed number of supported values. However, for things that can be extended
     51 // (such as codecs, by providing an external encoder factory), a string
     52 // identifier is used.
     53 
     54 enum class FecMechanism {
     55  RED,
     56  RED_AND_ULPFEC,
     57  FLEXFEC,
     58 };
     59 
     60 // Used in RtcpFeedback struct.
     61 enum class RtcpFeedbackType {
     62  CCM,
     63  LNTF,  // "goog-lntf"
     64  NACK,
     65  REMB,  // "goog-remb"
     66  TRANSPORT_CC,
     67  CCFB,  // RFC8888
     68 };
     69 
     70 template <typename Sink>
     71 void AbslStringify(Sink& sink, RtcpFeedbackType type) {
     72  switch (type) {
     73    case RtcpFeedbackType::CCM:
     74      sink.Append("CCM");
     75      break;
     76    case RtcpFeedbackType::LNTF:
     77      sink.Append("LNTF");
     78      break;
     79    case RtcpFeedbackType::NACK:
     80      sink.Append("NACK");
     81      break;
     82    case RtcpFeedbackType::REMB:
     83      sink.Append("REMB");
     84      break;
     85    case RtcpFeedbackType::TRANSPORT_CC:
     86      sink.Append("TRANSPORT_CC");
     87      break;
     88    case RtcpFeedbackType::CCFB:
     89      sink.Append("CCFB");
     90      break;
     91  }
     92 }
     93 
     94 template <typename Sink>
     95 void AbslStringify(Sink& sink, std::optional<RtcpFeedbackType> type) {
     96  if (!type.has_value()) {
     97    sink.Append("nullopt");
     98    return;
     99  }
    100  AbslStringify(sink, *type);
    101 }
    102 
    103 // Used in RtcpFeedback struct when type is NACK or CCM.
    104 enum class RtcpFeedbackMessageType {
    105  // Equivalent to {type: "nack", parameter: undefined} in ORTC.
    106  GENERIC_NACK,
    107  PLI,  // Usable with NACK.
    108  FIR,  // Usable with CCM.
    109 };
    110 
    111 enum class DtxStatus {
    112  DISABLED,
    113  ENABLED,
    114 };
    115 
    116 // Based on the spec in
    117 // https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
    118 // These options are enforced on a best-effort basis. For instance, all of
    119 // these options may suffer some frame drops in order to avoid queuing.
    120 // TODO(sprang): Look into possibility of more strictly enforcing the
    121 // maintain-framerate option.
    122 // TODO(deadbeef): Default to "balanced", as the spec indicates?
    123 enum class DegradationPreference {
    124  // Don't take any actions based on over-utilization signals. Not part of the
    125  // web API.
    126  DISABLED,
    127  // On over-use, request lower resolution, possibly causing down-scaling.
    128  MAINTAIN_FRAMERATE,
    129  // On over-use, request lower frame rate, possibly causing frame drops.
    130  MAINTAIN_RESOLUTION,
    131  // Try to strike a "pleasing" balance between frame rate or resolution.
    132  BALANCED,
    133 };
    134 
    135 RTC_EXPORT const char* DegradationPreferenceToString(
    136    DegradationPreference degradation_preference);
    137 
    138 RTC_EXPORT extern const double kDefaultBitratePriority;
    139 
    140 struct RTC_EXPORT RtcpFeedback {
    141  RtcpFeedbackType type = RtcpFeedbackType::CCM;
    142 
    143  // Equivalent to ORTC "parameter" field with slight differences:
    144  // 1. It's an enum instead of a string.
    145  // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
    146  //    rather than an unset "parameter" value.
    147  std::optional<RtcpFeedbackMessageType> message_type;
    148 
    149  // Constructors for convenience.
    150  RtcpFeedback();
    151  explicit RtcpFeedback(RtcpFeedbackType type);
    152  RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
    153  RtcpFeedback(const RtcpFeedback&);
    154  ~RtcpFeedback();
    155 
    156  bool operator==(const RtcpFeedback& o) const {
    157    return type == o.type && message_type == o.message_type;
    158  }
    159  bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
    160 };
    161 
    162 struct RTC_EXPORT RtpCodec {
    163  RtpCodec();
    164  RtpCodec(const RtpCodec&);
    165  virtual ~RtpCodec();
    166 
    167  // Build MIME "type/subtype" string from `name` and `kind`.
    168  std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
    169 
    170  // Used to identify the codec. Equivalent to MIME subtype.
    171  std::string name;
    172 
    173  // The media type of this codec. Equivalent to MIME top-level type.
    174  MediaType kind = MediaType::AUDIO;
    175 
    176  // If unset, the implementation default is used.
    177  std::optional<int> clock_rate;
    178 
    179  // The number of audio channels used. Unset for video codecs. If unset for
    180  // audio, the implementation default is used.
    181  // TODO(deadbeef): The "implementation default" part isn't fully implemented.
    182  // Only defaults to 1, even though some codecs (such as opus) should really
    183  // default to 2.
    184  std::optional<int> num_channels;
    185 
    186  // Feedback mechanisms to be used for this codec.
    187  // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
    188  std::vector<RtcpFeedback> rtcp_feedback;
    189 
    190  // Codec-specific parameters that must be signaled to the remote party.
    191  //
    192  // Corresponds to "a=fmtp" parameters in SDP.
    193  //
    194  // Contrary to ORTC, these parameters are named using all lowercase strings.
    195  // This helps make the mapping to SDP simpler, if an application is using SDP.
    196  // Boolean values are represented by the string "1".
    197  std::map<std::string, std::string> parameters;
    198 
    199  bool operator==(const RtpCodec& o) const {
    200    return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
    201           num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
    202           parameters == o.parameters;
    203  }
    204  bool operator!=(const RtpCodec& o) const { return !(*this == o); }
    205  bool IsResiliencyCodec() const;
    206  bool IsMediaCodec() const;
    207 };
    208 
    209 // RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
    210 // RtpParameters. This represents the static capabilities of an endpoint's
    211 // implementation of a codec.
    212 struct RTC_EXPORT RtpCodecCapability : public RtpCodec {
    213  RtpCodecCapability();
    214  virtual ~RtpCodecCapability();
    215 
    216  // Default payload type for this codec. Mainly needed for codecs that have
    217  // statically assigned payload types.
    218  std::optional<int> preferred_payload_type;
    219 
    220  // List of scalability modes supported by the video codec.
    221  absl::InlinedVector<ScalabilityMode, kScalabilityModeCount> scalability_modes;
    222 
    223  bool operator==(const RtpCodecCapability& o) const {
    224    return RtpCodec::operator==(o) &&
    225           preferred_payload_type == o.preferred_payload_type &&
    226           scalability_modes == o.scalability_modes;
    227  }
    228  bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
    229 
    230  template <typename Sink>
    231  friend void AbslStringify(Sink& sink, const RtpCodecCapability& cap) {
    232    if (cap.kind == MediaType::AUDIO) {
    233      absl::Format(&sink, "[audio/%s/%d/%d]", cap.name,
    234                   cap.clock_rate.value_or(0), cap.num_channels.value_or(1));
    235    } else {
    236      absl::Format(&sink, "[video/%s]", cap.name);
    237    }
    238  }
    239 };
    240 
    241 // Used in RtpCapabilities and RtpTransceiverInterface's header extensions query
    242 // and setup methods; represents the capabilities/preferences of an
    243 // implementation for a header extension.
    244 //
    245 // Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
    246 // added here for consistency and to avoid confusion with
    247 // RtpHeaderExtensionParameters.
    248 //
    249 // Note that ORTC includes a "kind" field, but we omit this because it's
    250 // redundant; if you call
    251 // "RtpReceiver::GetCapabilities(MediaType::AUDIO)", you know you're
    252 // getting audio capabilities.
    253 struct RTC_EXPORT RtpHeaderExtensionCapability {
    254  // URI of this extension, as defined in RFC8285.
    255  std::string uri;
    256 
    257  // Preferred value of ID that goes in the packet.
    258  std::optional<int> preferred_id;
    259 
    260  // If true, it's preferred that the value in the header is encrypted.
    261  bool preferred_encrypt = false;
    262 
    263  // The direction of the extension. The kStopped value is only used with
    264  // RtpTransceiverInterface::SetHeaderExtensionsToNegotiate() and
    265  // SetHeaderExtensionsToNegotiate().
    266  RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
    267 
    268  // Constructors for convenience.
    269  RtpHeaderExtensionCapability();
    270  explicit RtpHeaderExtensionCapability(absl::string_view uri);
    271  RtpHeaderExtensionCapability(absl::string_view uri, int preferred_id);
    272  RtpHeaderExtensionCapability(absl::string_view uri,
    273                               int preferred_id,
    274                               RtpTransceiverDirection direction);
    275  RtpHeaderExtensionCapability(absl::string_view uri,
    276                               int preferred_id,
    277                               bool preferred_encrypt,
    278                               RtpTransceiverDirection direction);
    279  ~RtpHeaderExtensionCapability();
    280 
    281  bool operator==(const RtpHeaderExtensionCapability& o) const {
    282    return uri == o.uri && preferred_id == o.preferred_id &&
    283           preferred_encrypt == o.preferred_encrypt && direction == o.direction;
    284  }
    285  bool operator!=(const RtpHeaderExtensionCapability& o) const {
    286    return !(*this == o);
    287  }
    288  template <typename Sink>
    289  friend void AbslStringify(Sink& sink,
    290                            const RtpHeaderExtensionCapability& cap) {
    291    absl::Format(&sink, "%s", cap.uri);
    292    if (cap.direction != RtpTransceiverDirection::kSendRecv) {
    293      absl::Format(&sink, "/%v", cap.direction);
    294    }
    295    if (cap.preferred_encrypt) {
    296      sink.Append(" (encrypt)");
    297    }
    298  }
    299 };
    300 
    301 // RTP header extension, see RFC8285.
    302 struct RTC_EXPORT RtpExtension {
    303  enum Filter {
    304    // Encrypted extensions will be ignored and only non-encrypted extensions
    305    // will be considered.
    306    kDiscardEncryptedExtension,
    307    // Encrypted extensions will be preferred but will fall back to
    308    // non-encrypted extensions if necessary.
    309    kPreferEncryptedExtension,
    310    // Encrypted extensions will be required, so any non-encrypted extensions
    311    // will be discarded.
    312    kRequireEncryptedExtension,
    313  };
    314 
    315  RtpExtension();
    316  RtpExtension(absl::string_view uri, int id);
    317  RtpExtension(absl::string_view uri, int id, bool encrypt);
    318  ~RtpExtension();
    319 
    320  std::string ToString() const;
    321  bool operator==(const RtpExtension& rhs) const {
    322    return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
    323  }
    324  static bool IsSupportedForAudio(absl::string_view uri);
    325  static bool IsSupportedForVideo(absl::string_view uri);
    326  // Return "true" if the given RTP header extension URI may be encrypted.
    327  static bool IsEncryptionSupported(absl::string_view uri);
    328 
    329  // Returns the header extension with the given URI or nullptr if not found.
    330  static const RtpExtension* FindHeaderExtensionByUri(
    331      const std::vector<RtpExtension>& extensions,
    332      absl::string_view uri,
    333      Filter filter);
    334 
    335  // Returns the header extension with the given URI and encrypt parameter,
    336  // if found, otherwise nullptr.
    337  static const RtpExtension* FindHeaderExtensionByUriAndEncryption(
    338      const std::vector<RtpExtension>& extensions,
    339      absl::string_view uri,
    340      bool encrypt);
    341 
    342  // Returns a list of extensions where any extension URI is unique.
    343  // The returned list will be sorted by uri first, then encrypt and id last.
    344  // Having the list sorted allows the caller fo compare filtered lists for
    345  // equality to detect when changes have been made.
    346  static const std::vector<RtpExtension> DeduplicateHeaderExtensions(
    347      const std::vector<RtpExtension>& extensions,
    348      Filter filter);
    349 
    350  // Encryption of Header Extensions, see RFC 6904 for details:
    351  // https://tools.ietf.org/html/rfc6904
    352  static constexpr char kEncryptHeaderExtensionsUri[] =
    353      "urn:ietf:params:rtp-hdrext:encrypt";
    354 
    355  // Header extension for audio levels, as defined in:
    356  // https://tools.ietf.org/html/rfc6464
    357  static constexpr char kAudioLevelUri[] =
    358      "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
    359 
    360  // Header extension for RTP timestamp offset, see RFC 5450 for details:
    361  // http://tools.ietf.org/html/rfc5450
    362  static constexpr char kTimestampOffsetUri[] =
    363      "urn:ietf:params:rtp-hdrext:toffset";
    364 
    365  // Header extension for absolute send time, see url for details:
    366  // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
    367  static constexpr char kAbsSendTimeUri[] =
    368      "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
    369 
    370  // Header extension for absolute capture time, see url for details:
    371  // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
    372  static constexpr char kAbsoluteCaptureTimeUri[] =
    373      "http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time";
    374 
    375  // Header extension for coordination of video orientation, see url for
    376  // details:
    377  // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
    378  static constexpr char kVideoRotationUri[] = "urn:3gpp:video-orientation";
    379 
    380  // Header extension for video content type. E.g. default or screenshare.
    381  static constexpr char kVideoContentTypeUri[] =
    382      "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
    383 
    384  // Header extension for video timing.
    385  static constexpr char kVideoTimingUri[] =
    386      "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
    387 
    388  // Experimental codec agnostic frame descriptor.
    389  static constexpr char kGenericFrameDescriptorUri00[] =
    390      "http://www.webrtc.org/experiments/rtp-hdrext/"
    391      "generic-frame-descriptor-00";
    392  static constexpr char kDependencyDescriptorUri[] =
    393      "https://aomediacodec.github.io/av1-rtp-spec/"
    394      "#dependency-descriptor-rtp-header-extension";
    395 
    396  // Experimental extension for signalling target bitrate per layer.
    397  static constexpr char kVideoLayersAllocationUri[] =
    398      "http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00";
    399 
    400  // Header extension for transport sequence number, see url for details:
    401  // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
    402  static constexpr char kTransportSequenceNumberUri[] =
    403      "http://www.ietf.org/id/"
    404      "draft-holmer-rmcat-transport-wide-cc-extensions-01";
    405  static constexpr char kTransportSequenceNumberV2Uri[] =
    406      "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02";
    407 
    408  // This extension allows applications to adaptively limit the playout delay
    409  // on frames as per the current needs. For example, a gaming application
    410  // has very different needs on end-to-end delay compared to a video-conference
    411  // application.
    412  static constexpr char kPlayoutDelayUri[] =
    413      "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
    414 
    415  // Header extension for color space information.
    416  static constexpr char kColorSpaceUri[] =
    417      "http://www.webrtc.org/experiments/rtp-hdrext/color-space";
    418 
    419  // Header extension for identifying media section within a transport.
    420  // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
    421  static constexpr char kMidUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
    422 
    423  // Header extension for RIDs and Repaired RIDs
    424  // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
    425  // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
    426  static constexpr char kRidUri[] =
    427      "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
    428  static constexpr char kRepairedRidUri[] =
    429      "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
    430 
    431  // Header extension to propagate VideoFrame id field
    432  static constexpr char kVideoFrameTrackingIdUri[] =
    433      "http://www.webrtc.org/experiments/rtp-hdrext/video-frame-tracking-id";
    434 
    435  // Header extension for Mixer-to-Client audio levels per CSRC as defined in
    436  // https://tools.ietf.org/html/rfc6465
    437  static constexpr char kCsrcAudioLevelsUri[] =
    438      "urn:ietf:params:rtp-hdrext:csrc-audio-level";
    439 
    440  // Header extension for automatic corruption detection.
    441  static constexpr char kCorruptionDetectionUri[] =
    442      "http://www.webrtc.org/experiments/rtp-hdrext/corruption-detection";
    443 
    444  // Inclusive min and max IDs for two-byte header extensions and one-byte
    445  // header extensions, per RFC8285 Section 4.2-4.3.
    446  static constexpr int kMinId = 1;
    447  static constexpr int kMaxId = 255;
    448  static constexpr int kMaxValueSize = 255;
    449  static constexpr int kOneByteHeaderExtensionMaxId = 14;
    450  static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
    451 
    452  std::string uri;
    453  int id = 0;
    454  bool encrypt = false;
    455 
    456  template <typename Sink>
    457  friend void AbslStringify(Sink& sink, const RtpExtension& extension) {
    458    if (extension.encrypt) {
    459      absl::Format(&sink, "[%d %s (encrypted)]", extension.id, extension.uri);
    460    } else {
    461      absl::Format(&sink, "[%d %s]", extension.id, extension.uri);
    462    }
    463  }
    464 };
    465 
    466 struct RTC_EXPORT RtpFecParameters {
    467  // If unset, a value is chosen by the implementation.
    468  // Works just like RtpEncodingParameters::ssrc.
    469  std::optional<uint32_t> ssrc;
    470 
    471  FecMechanism mechanism = FecMechanism::RED;
    472 
    473  // Constructors for convenience.
    474  RtpFecParameters();
    475  explicit RtpFecParameters(FecMechanism mechanism);
    476  RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
    477  RtpFecParameters(const RtpFecParameters&);
    478  ~RtpFecParameters();
    479 
    480  bool operator==(const RtpFecParameters& o) const {
    481    return ssrc == o.ssrc && mechanism == o.mechanism;
    482  }
    483  bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
    484 };
    485 
    486 struct RTC_EXPORT RtpRtxParameters {
    487  // If unset, a value is chosen by the implementation.
    488  // Works just like RtpEncodingParameters::ssrc.
    489  std::optional<uint32_t> ssrc;
    490 
    491  // Constructors for convenience.
    492  RtpRtxParameters();
    493  explicit RtpRtxParameters(uint32_t ssrc);
    494  RtpRtxParameters(const RtpRtxParameters&);
    495  ~RtpRtxParameters();
    496 
    497  bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
    498  bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
    499 };
    500 
    501 struct RTC_EXPORT RtpEncodingParameters {
    502  RtpEncodingParameters();
    503  RtpEncodingParameters(const RtpEncodingParameters&);
    504  ~RtpEncodingParameters();
    505 
    506  // If unset, a value is chosen by the implementation.
    507  //
    508  // Note that the chosen value is NOT returned by GetParameters, because it
    509  // may change due to an SSRC conflict, in which case the conflict is handled
    510  // internally without any event. Another way of looking at this is that an
    511  // unset SSRC acts as a "wildcard" SSRC.
    512  std::optional<uint32_t> ssrc;
    513 
    514  // The list of CSRCs to be included in the RTP header. Defaults to an empty
    515  // list. At most 15 CSRCs can be specified, and they must be the same for all
    516  // encodings in an RtpParameters struct.
    517  //
    518  // If this field is set, the list is replaced with the specified values.
    519  // Otherwise, it is left unchanged. Specify an empty vector to clear the list.
    520  std::optional<std::vector<uint32_t>> csrcs;
    521 
    522  // The relative bitrate priority of this encoding. Currently this is
    523  // implemented for the entire rtp sender by using the value of the first
    524  // encoding parameter.
    525  // See: https://w3c.github.io/webrtc-priority/#enumdef-rtcprioritytype
    526  // "very-low" = 0.5
    527  // "low" = 1.0
    528  // "medium" = 2.0
    529  // "high" = 4.0
    530  // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
    531  // Currently there is logic for how bitrate is distributed per simulcast layer
    532  // in the VideoBitrateAllocator. This must be updated to incorporate relative
    533  // bitrate priority.
    534  double bitrate_priority = kDefaultBitratePriority;
    535 
    536  // The relative DiffServ Code Point priority for this encoding, allowing
    537  // packets to be marked relatively higher or lower without affecting
    538  // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ .
    539  // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
    540  // TODO(http://crbug.com/webrtc/11379): TCP connections should use a single
    541  // DSCP value even if shared by multiple senders; this is not implemented.
    542  Priority network_priority = Priority::kLow;
    543 
    544  // If set, this represents the Transport Independent Application Specific
    545  // maximum bandwidth defined in RFC3890. If unset, there is no maximum
    546  // bitrate. Currently this is implemented for the entire rtp sender by using
    547  // the value of the first encoding parameter.
    548  //
    549  // Just called "maxBitrate" in ORTC spec.
    550  //
    551  // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
    552  // bandwidth for the entire bandwidth estimator (audio and video). This is
    553  // just always how "b=AS" was handled, but it's not correct and should be
    554  // fixed.
    555  std::optional<int> max_bitrate_bps;
    556 
    557  // Specifies the minimum bitrate in bps for video.
    558  std::optional<int> min_bitrate_bps;
    559 
    560  // Specifies the maximum framerate in fps for video.
    561  std::optional<double> max_framerate;
    562 
    563  // Specifies the number of temporal layers for video (if the feature is
    564  // supported by the codec implementation).
    565  // Screencast support is experimental.
    566  std::optional<int> num_temporal_layers;
    567 
    568  // For video, scale the resolution down by this factor.
    569  std::optional<double> scale_resolution_down_by;
    570 
    571  // https://w3c.github.io/webrtc-svc/#rtcrtpencodingparameters
    572  std::optional<std::string> scalability_mode;
    573 
    574  // This is an alternative API to `scale_resolution_down_by` but expressed in
    575  // absolute terms (max width and max height) as opposed to relative terms (a
    576  // scaling factor that is relative to the input frame size).
    577  //
    578  // If both `scale_resolution_down_by` and `scale_resolution_down_to` are
    579  // specified, the "scale by" value is ignored.
    580  //
    581  // See spec:
    582  // https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-scaleresolutiondownto
    583  std::optional<Resolution> scale_resolution_down_to;
    584 
    585  // For an RtpSender, set to true to cause this encoding to be encoded and
    586  // sent, and false for it not to be encoded and sent. This allows control
    587  // across multiple encodings of a sender for turning simulcast layers on and
    588  // off.
    589  // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
    590  // reset, but this isn't necessarily required.
    591  bool active = true;
    592 
    593  // Value to use for RID RTP header extension.
    594  // Called "encodingId" in ORTC.
    595  std::string rid;
    596  bool request_key_frame = false;
    597 
    598  // Allow dynamic frame length changes for audio:
    599  // https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime
    600  bool adaptive_ptime = false;
    601 
    602  // Allow changing the used codec for this encoding.
    603  std::optional<RtpCodec> codec;
    604 
    605  bool operator==(const RtpEncodingParameters& o) const {
    606    return ssrc == o.ssrc && csrcs == o.csrcs &&
    607           bitrate_priority == o.bitrate_priority &&
    608           network_priority == o.network_priority &&
    609           max_bitrate_bps == o.max_bitrate_bps &&
    610           min_bitrate_bps == o.min_bitrate_bps &&
    611           max_framerate == o.max_framerate &&
    612           num_temporal_layers == o.num_temporal_layers &&
    613           scale_resolution_down_by == o.scale_resolution_down_by &&
    614           active == o.active && rid == o.rid &&
    615           adaptive_ptime == o.adaptive_ptime &&
    616           scale_resolution_down_to == o.scale_resolution_down_to &&
    617           codec == o.codec;
    618  }
    619  bool operator!=(const RtpEncodingParameters& o) const {
    620    return !(*this == o);
    621  }
    622 };
    623 
    624 struct RTC_EXPORT RtpCodecParameters : public RtpCodec {
    625  RtpCodecParameters();
    626  RtpCodecParameters(const RtpCodecParameters&);
    627  virtual ~RtpCodecParameters();
    628 
    629  // Payload type used to identify this codec in RTP packets.
    630  // This must always be present, and must be unique across all codecs using
    631  // the same transport.
    632  int payload_type = 0;
    633 
    634  bool operator==(const RtpCodecParameters& o) const {
    635    return RtpCodec::operator==(o) && payload_type == o.payload_type;
    636  }
    637  bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
    638  template <typename Sink>
    639  friend void AbslStringify(Sink& sink, const RtpCodecParameters& p) {
    640    absl::Format(&sink, "[%d: %s]", p.payload_type, p.mime_type());
    641  }
    642 };
    643 
    644 // RtpCapabilities is used to represent the static capabilities of an endpoint.
    645 // An application can use these capabilities to construct an RtpParameters.
    646 struct RTC_EXPORT RtpCapabilities {
    647  RtpCapabilities();
    648  ~RtpCapabilities();
    649 
    650  // Supported codecs.
    651  std::vector<RtpCodecCapability> codecs;
    652 
    653  // Supported RTP header extensions.
    654  std::vector<RtpHeaderExtensionCapability> header_extensions;
    655 
    656  // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
    657  // ulpfec and flexfec codecs used by these mechanisms will still appear in
    658  // `codecs`.
    659  std::vector<FecMechanism> fec;
    660 
    661  bool operator==(const RtpCapabilities& o) const {
    662    return codecs == o.codecs && header_extensions == o.header_extensions &&
    663           fec == o.fec;
    664  }
    665  bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
    666 };
    667 
    668 struct RtcpParameters final {
    669  RtcpParameters();
    670  RtcpParameters(const RtcpParameters&);
    671  ~RtcpParameters();
    672 
    673  // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
    674  // will be chosen by the implementation.
    675  // TODO(deadbeef): Not implemented.
    676  std::optional<uint32_t> ssrc;
    677 
    678  // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
    679  //
    680  // If empty in the construction of the RtpTransport, one will be generated by
    681  // the implementation, and returned in GetRtcpParameters. Multiple
    682  // RtpTransports created by the same OrtcFactory will use the same generated
    683  // CNAME.
    684  //
    685  // If empty when passed into SetParameters, the CNAME simply won't be
    686  // modified.
    687  std::string cname;
    688 
    689  // Send reduced-size RTCP?
    690  bool reduced_size = false;
    691 
    692  // Send RTCP multiplexed on the RTP transport?
    693  // Not used with PeerConnection senders/receivers
    694  bool mux = true;
    695 
    696  bool operator==(const RtcpParameters& o) const {
    697    return ssrc == o.ssrc && cname == o.cname &&
    698           reduced_size == o.reduced_size && mux == o.mux;
    699  }
    700  bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
    701 };
    702 
    703 struct RTC_EXPORT RtpParameters {
    704  RtpParameters();
    705  RtpParameters(const RtpParameters&);
    706  ~RtpParameters();
    707 
    708  // Used when calling getParameters/setParameters with a PeerConnection
    709  // RtpSender, to ensure that outdated parameters are not unintentionally
    710  // applied successfully.
    711  std::string transaction_id;
    712 
    713  // Value to use for MID RTP header extension.
    714  // Called "muxId" in ORTC.
    715  // TODO(deadbeef): Not implemented.
    716  std::string mid;
    717 
    718  std::vector<RtpCodecParameters> codecs;
    719 
    720  std::vector<RtpExtension> header_extensions;
    721 
    722  std::vector<RtpEncodingParameters> encodings;
    723 
    724  // Only available with a Peerconnection RtpSender.
    725  // In ORTC, our API includes an additional "RtpTransport"
    726  // abstraction on which RTCP parameters are set.
    727  RtcpParameters rtcp;
    728 
    729  // When bandwidth is constrained and the RtpSender needs to choose between
    730  // degrading resolution or degrading framerate, degradationPreference
    731  // indicates which is preferred. Only for video tracks.
    732  std::optional<DegradationPreference> degradation_preference;
    733 
    734  bool operator==(const RtpParameters& o) const {
    735    return mid == o.mid && codecs == o.codecs &&
    736           header_extensions == o.header_extensions &&
    737           encodings == o.encodings && rtcp == o.rtcp &&
    738           degradation_preference == o.degradation_preference;
    739  }
    740  bool operator!=(const RtpParameters& o) const { return !(*this == o); }
    741 };
    742 
    743 }  // namespace webrtc
    744 
    745 #endif  // API_RTP_PARAMETERS_H_