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