You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

668 lines
26 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. #ifndef API_RTP_PARAMETERS_H_
  11. #define API_RTP_PARAMETERS_H_
  12. #include <stdint.h>
  13. #include <string>
  14. #include <unordered_map>
  15. #include <vector>
  16. #include "absl/types/optional.h"
  17. #include "api/media_types.h"
  18. #include "rtc_base/system/rtc_export.h"
  19. namespace webrtc {
  20. // These structures are intended to mirror those defined by:
  21. // http://draft.ortc.org/#rtcrtpdictionaries*
  22. // Contains everything specified as of 2017 Jan 24.
  23. //
  24. // They are used when retrieving or modifying the parameters of an
  25. // RtpSender/RtpReceiver, or retrieving capabilities.
  26. //
  27. // Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
  28. // types, we typically use "int", in keeping with our style guidelines. The
  29. // parameter's actual valid range will be enforced when the parameters are set,
  30. // rather than when the parameters struct is built. An exception is made for
  31. // SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
  32. // be used for any numeric comparisons/operations.
  33. //
  34. // Additionally, where ORTC uses strings, we may use enums for things that have
  35. // a fixed number of supported values. However, for things that can be extended
  36. // (such as codecs, by providing an external encoder factory), a string
  37. // identifier is used.
  38. enum class FecMechanism {
  39. RED,
  40. RED_AND_ULPFEC,
  41. FLEXFEC,
  42. };
  43. // Used in RtcpFeedback struct.
  44. enum class RtcpFeedbackType {
  45. CCM,
  46. LNTF, // "goog-lntf"
  47. NACK,
  48. REMB, // "goog-remb"
  49. TRANSPORT_CC,
  50. };
  51. // Used in RtcpFeedback struct when type is NACK or CCM.
  52. enum class RtcpFeedbackMessageType {
  53. // Equivalent to {type: "nack", parameter: undefined} in ORTC.
  54. GENERIC_NACK,
  55. PLI, // Usable with NACK.
  56. FIR, // Usable with CCM.
  57. };
  58. enum class DtxStatus {
  59. DISABLED,
  60. ENABLED,
  61. };
  62. // Based on the spec in
  63. // https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
  64. // These options are enforced on a best-effort basis. For instance, all of
  65. // these options may suffer some frame drops in order to avoid queuing.
  66. // TODO(sprang): Look into possibility of more strictly enforcing the
  67. // maintain-framerate option.
  68. // TODO(deadbeef): Default to "balanced", as the spec indicates?
  69. enum class DegradationPreference {
  70. // Don't take any actions based on over-utilization signals. Not part of the
  71. // web API.
  72. DISABLED,
  73. // On over-use, request lower resolution, possibly causing down-scaling.
  74. MAINTAIN_FRAMERATE,
  75. // On over-use, request lower frame rate, possibly causing frame drops.
  76. MAINTAIN_RESOLUTION,
  77. // Try to strike a "pleasing" balance between frame rate or resolution.
  78. BALANCED,
  79. };
  80. RTC_EXPORT extern const double kDefaultBitratePriority;
  81. struct RTC_EXPORT RtcpFeedback {
  82. RtcpFeedbackType type = RtcpFeedbackType::CCM;
  83. // Equivalent to ORTC "parameter" field with slight differences:
  84. // 1. It's an enum instead of a string.
  85. // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
  86. // rather than an unset "parameter" value.
  87. absl::optional<RtcpFeedbackMessageType> message_type;
  88. // Constructors for convenience.
  89. RtcpFeedback();
  90. explicit RtcpFeedback(RtcpFeedbackType type);
  91. RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
  92. RtcpFeedback(const RtcpFeedback&);
  93. ~RtcpFeedback();
  94. bool operator==(const RtcpFeedback& o) const {
  95. return type == o.type && message_type == o.message_type;
  96. }
  97. bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
  98. };
  99. // RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
  100. // RtpParameters. This represents the static capabilities of an endpoint's
  101. // implementation of a codec.
  102. struct RTC_EXPORT RtpCodecCapability {
  103. RtpCodecCapability();
  104. ~RtpCodecCapability();
  105. // Build MIME "type/subtype" string from |name| and |kind|.
  106. std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
  107. // Used to identify the codec. Equivalent to MIME subtype.
  108. std::string name;
  109. // The media type of this codec. Equivalent to MIME top-level type.
  110. cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
  111. // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
  112. absl::optional<int> clock_rate;
  113. // Default payload type for this codec. Mainly needed for codecs that use
  114. // that have statically assigned payload types.
  115. absl::optional<int> preferred_payload_type;
  116. // Maximum packetization time supported by an RtpReceiver for this codec.
  117. // TODO(deadbeef): Not implemented.
  118. absl::optional<int> max_ptime;
  119. // Preferred packetization time for an RtpReceiver or RtpSender of this codec.
  120. // TODO(deadbeef): Not implemented.
  121. absl::optional<int> ptime;
  122. // The number of audio channels supported. Unused for video codecs.
  123. absl::optional<int> num_channels;
  124. // Feedback mechanisms supported for this codec.
  125. std::vector<RtcpFeedback> rtcp_feedback;
  126. // Codec-specific parameters that must be signaled to the remote party.
  127. //
  128. // Corresponds to "a=fmtp" parameters in SDP.
  129. //
  130. // Contrary to ORTC, these parameters are named using all lowercase strings.
  131. // This helps make the mapping to SDP simpler, if an application is using SDP.
  132. // Boolean values are represented by the string "1".
  133. std::unordered_map<std::string, std::string> parameters;
  134. // Codec-specific parameters that may optionally be signaled to the remote
  135. // party.
  136. // TODO(deadbeef): Not implemented.
  137. std::unordered_map<std::string, std::string> options;
  138. // Maximum number of temporal layer extensions supported by this codec.
  139. // For example, a value of 1 indicates that 2 total layers are supported.
  140. // TODO(deadbeef): Not implemented.
  141. int max_temporal_layer_extensions = 0;
  142. // Maximum number of spatial layer extensions supported by this codec.
  143. // For example, a value of 1 indicates that 2 total layers are supported.
  144. // TODO(deadbeef): Not implemented.
  145. int max_spatial_layer_extensions = 0;
  146. // Whether the implementation can send/receive SVC layers with distinct SSRCs.
  147. // Always false for audio codecs. True for video codecs that support scalable
  148. // video coding with MRST.
  149. // TODO(deadbeef): Not implemented.
  150. bool svc_multi_stream_support = false;
  151. bool operator==(const RtpCodecCapability& o) const {
  152. return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
  153. preferred_payload_type == o.preferred_payload_type &&
  154. max_ptime == o.max_ptime && ptime == o.ptime &&
  155. num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
  156. parameters == o.parameters && options == o.options &&
  157. max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
  158. max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
  159. svc_multi_stream_support == o.svc_multi_stream_support;
  160. }
  161. bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
  162. };
  163. // Used in RtpCapabilities; represents the capabilities/preferences of an
  164. // implementation for a header extension.
  165. //
  166. // Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
  167. // added here for consistency and to avoid confusion with
  168. // RtpHeaderExtensionParameters.
  169. //
  170. // Note that ORTC includes a "kind" field, but we omit this because it's
  171. // redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
  172. // you know you're getting audio capabilities.
  173. struct RtpHeaderExtensionCapability {
  174. // URI of this extension, as defined in RFC8285.
  175. std::string uri;
  176. // Preferred value of ID that goes in the packet.
  177. absl::optional<int> preferred_id;
  178. // If true, it's preferred that the value in the header is encrypted.
  179. // TODO(deadbeef): Not implemented.
  180. bool preferred_encrypt = false;
  181. // Constructors for convenience.
  182. RtpHeaderExtensionCapability();
  183. explicit RtpHeaderExtensionCapability(const std::string& uri);
  184. RtpHeaderExtensionCapability(const std::string& uri, int preferred_id);
  185. ~RtpHeaderExtensionCapability();
  186. bool operator==(const RtpHeaderExtensionCapability& o) const {
  187. return uri == o.uri && preferred_id == o.preferred_id &&
  188. preferred_encrypt == o.preferred_encrypt;
  189. }
  190. bool operator!=(const RtpHeaderExtensionCapability& o) const {
  191. return !(*this == o);
  192. }
  193. };
  194. // RTP header extension, see RFC8285.
  195. struct RTC_EXPORT RtpExtension {
  196. RtpExtension();
  197. RtpExtension(const std::string& uri, int id);
  198. RtpExtension(const std::string& uri, int id, bool encrypt);
  199. ~RtpExtension();
  200. std::string ToString() const;
  201. bool operator==(const RtpExtension& rhs) const {
  202. return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
  203. }
  204. static bool IsSupportedForAudio(const std::string& uri);
  205. static bool IsSupportedForVideo(const std::string& uri);
  206. // Return "true" if the given RTP header extension URI may be encrypted.
  207. static bool IsEncryptionSupported(const std::string& uri);
  208. // Returns the named header extension if found among all extensions,
  209. // nullptr otherwise.
  210. static const RtpExtension* FindHeaderExtensionByUri(
  211. const std::vector<RtpExtension>& extensions,
  212. const std::string& uri);
  213. // Return a list of RTP header extensions with the non-encrypted extensions
  214. // removed if both the encrypted and non-encrypted extension is present for
  215. // the same URI.
  216. static std::vector<RtpExtension> FilterDuplicateNonEncrypted(
  217. const std::vector<RtpExtension>& extensions);
  218. // Header extension for audio levels, as defined in:
  219. // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
  220. static const char kAudioLevelUri[];
  221. // Header extension for RTP timestamp offset, see RFC 5450 for details:
  222. // http://tools.ietf.org/html/rfc5450
  223. static const char kTimestampOffsetUri[];
  224. // Header extension for absolute send time, see url for details:
  225. // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
  226. static const char kAbsSendTimeUri[];
  227. // Header extension for absolute capture time, see url for details:
  228. // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
  229. static const char kAbsoluteCaptureTimeUri[];
  230. // Header extension for coordination of video orientation, see url for
  231. // details:
  232. // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
  233. static const char kVideoRotationUri[];
  234. // Header extension for video content type. E.g. default or screenshare.
  235. static const char kVideoContentTypeUri[];
  236. // Header extension for video timing.
  237. static const char kVideoTimingUri[];
  238. // Header extension for video frame marking.
  239. static const char kFrameMarkingUri[];
  240. // Experimental codec agnostic frame descriptor.
  241. static const char kGenericFrameDescriptorUri00[];
  242. static const char kGenericFrameDescriptorUri01[];
  243. // TODO(bugs.webrtc.org/10243): Remove once dependencies have been updated.
  244. static const char kGenericFrameDescriptorUri[];
  245. // Header extension for transport sequence number, see url for details:
  246. // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
  247. static const char kTransportSequenceNumberUri[];
  248. static const char kTransportSequenceNumberV2Uri[];
  249. static const char kPlayoutDelayUri[];
  250. // Header extension for identifying media section within a transport.
  251. // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
  252. static const char kMidUri[];
  253. // Encryption of Header Extensions, see RFC 6904 for details:
  254. // https://tools.ietf.org/html/rfc6904
  255. static const char kEncryptHeaderExtensionsUri[];
  256. // Header extension for color space information.
  257. static const char kColorSpaceUri[];
  258. // Header extension for RIDs and Repaired RIDs
  259. // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
  260. // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
  261. static const char kRidUri[];
  262. static const char kRepairedRidUri[];
  263. // Inclusive min and max IDs for two-byte header extensions and one-byte
  264. // header extensions, per RFC8285 Section 4.2-4.3.
  265. static constexpr int kMinId = 1;
  266. static constexpr int kMaxId = 255;
  267. static constexpr int kMaxValueSize = 255;
  268. static constexpr int kOneByteHeaderExtensionMaxId = 14;
  269. static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
  270. std::string uri;
  271. int id = 0;
  272. bool encrypt = false;
  273. };
  274. // TODO(deadbeef): This is missing the "encrypt" flag, which is unimplemented.
  275. typedef RtpExtension RtpHeaderExtensionParameters;
  276. struct RTC_EXPORT RtpFecParameters {
  277. // If unset, a value is chosen by the implementation.
  278. // Works just like RtpEncodingParameters::ssrc.
  279. absl::optional<uint32_t> ssrc;
  280. FecMechanism mechanism = FecMechanism::RED;
  281. // Constructors for convenience.
  282. RtpFecParameters();
  283. explicit RtpFecParameters(FecMechanism mechanism);
  284. RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
  285. RtpFecParameters(const RtpFecParameters&);
  286. ~RtpFecParameters();
  287. bool operator==(const RtpFecParameters& o) const {
  288. return ssrc == o.ssrc && mechanism == o.mechanism;
  289. }
  290. bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
  291. };
  292. struct RTC_EXPORT RtpRtxParameters {
  293. // If unset, a value is chosen by the implementation.
  294. // Works just like RtpEncodingParameters::ssrc.
  295. absl::optional<uint32_t> ssrc;
  296. // Constructors for convenience.
  297. RtpRtxParameters();
  298. explicit RtpRtxParameters(uint32_t ssrc);
  299. RtpRtxParameters(const RtpRtxParameters&);
  300. ~RtpRtxParameters();
  301. bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
  302. bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
  303. };
  304. struct RTC_EXPORT RtpEncodingParameters {
  305. RtpEncodingParameters();
  306. RtpEncodingParameters(const RtpEncodingParameters&);
  307. ~RtpEncodingParameters();
  308. // If unset, a value is chosen by the implementation.
  309. //
  310. // Note that the chosen value is NOT returned by GetParameters, because it
  311. // may change due to an SSRC conflict, in which case the conflict is handled
  312. // internally without any event. Another way of looking at this is that an
  313. // unset SSRC acts as a "wildcard" SSRC.
  314. absl::optional<uint32_t> ssrc;
  315. // Can be used to reference a codec in the |codecs| member of the
  316. // RtpParameters that contains this RtpEncodingParameters. If unset, the
  317. // implementation will choose the first possible codec (if a sender), or
  318. // prepare to receive any codec (for a receiver).
  319. // TODO(deadbeef): Not implemented. Implementation of RtpSender will always
  320. // choose the first codec from the list.
  321. absl::optional<int> codec_payload_type;
  322. // Specifies the FEC mechanism, if set.
  323. // TODO(deadbeef): Not implemented. Current implementation will use whatever
  324. // FEC codecs are available, including red+ulpfec.
  325. absl::optional<RtpFecParameters> fec;
  326. // Specifies the RTX parameters, if set.
  327. // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
  328. absl::optional<RtpRtxParameters> rtx;
  329. // Only used for audio. If set, determines whether or not discontinuous
  330. // transmission will be used, if an available codec supports it. If not
  331. // set, the implementation default setting will be used.
  332. // TODO(deadbeef): Not implemented. Current implementation will use a CN
  333. // codec as long as it's present.
  334. absl::optional<DtxStatus> dtx;
  335. // The relative bitrate priority of this encoding. Currently this is
  336. // implemented for the entire rtp sender by using the value of the first
  337. // encoding parameter.
  338. // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
  339. // Currently there is logic for how bitrate is distributed per simulcast layer
  340. // in the VideoBitrateAllocator. This must be updated to incorporate relative
  341. // bitrate priority.
  342. double bitrate_priority = kDefaultBitratePriority;
  343. // The relative DiffServ Code Point priority for this encoding, allowing
  344. // packets to be marked relatively higher or lower without affecting
  345. // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ . NB
  346. // we follow chromium's translation of the allowed string enum values for
  347. // this field to 1.0, 0.5, et cetera, similar to bitrate_priority above.
  348. // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
  349. double network_priority = kDefaultBitratePriority;
  350. // Indicates the preferred duration of media represented by a packet in
  351. // milliseconds for this encoding. If set, this will take precedence over the
  352. // ptime set in the RtpCodecParameters. This could happen if SDP negotiation
  353. // creates a ptime for a specific codec, which is later changed in the
  354. // RtpEncodingParameters by the application.
  355. // TODO(bugs.webrtc.org/8819): Not implemented.
  356. absl::optional<int> ptime;
  357. // If set, this represents the Transport Independent Application Specific
  358. // maximum bandwidth defined in RFC3890. If unset, there is no maximum
  359. // bitrate. Currently this is implemented for the entire rtp sender by using
  360. // the value of the first encoding parameter.
  361. //
  362. // Just called "maxBitrate" in ORTC spec.
  363. //
  364. // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
  365. // bandwidth for the entire bandwidth estimator (audio and video). This is
  366. // just always how "b=AS" was handled, but it's not correct and should be
  367. // fixed.
  368. absl::optional<int> max_bitrate_bps;
  369. // Specifies the minimum bitrate in bps for video.
  370. // TODO(asapersson): Not implemented for ORTC API.
  371. absl::optional<int> min_bitrate_bps;
  372. // Specifies the maximum framerate in fps for video.
  373. // TODO(asapersson): Different framerates are not supported per simulcast
  374. // layer. If set, the maximum |max_framerate| is currently used.
  375. // Not supported for screencast.
  376. absl::optional<int> max_framerate;
  377. // Specifies the number of temporal layers for video (if the feature is
  378. // supported by the codec implementation).
  379. // TODO(asapersson): Different number of temporal layers are not supported
  380. // per simulcast layer.
  381. // Screencast support is experimental.
  382. absl::optional<int> num_temporal_layers;
  383. // For video, scale the resolution down by this factor.
  384. absl::optional<double> scale_resolution_down_by;
  385. // Scale the framerate down by this factor.
  386. // TODO(deadbeef): Not implemented.
  387. absl::optional<double> scale_framerate_down_by;
  388. // For an RtpSender, set to true to cause this encoding to be encoded and
  389. // sent, and false for it not to be encoded and sent. This allows control
  390. // across multiple encodings of a sender for turning simulcast layers on and
  391. // off.
  392. // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
  393. // reset, but this isn't necessarily required.
  394. bool active = true;
  395. // Value to use for RID RTP header extension.
  396. // Called "encodingId" in ORTC.
  397. std::string rid;
  398. // RIDs of encodings on which this layer depends.
  399. // Called "dependencyEncodingIds" in ORTC spec.
  400. // TODO(deadbeef): Not implemented.
  401. std::vector<std::string> dependency_rids;
  402. bool operator==(const RtpEncodingParameters& o) const {
  403. return ssrc == o.ssrc && codec_payload_type == o.codec_payload_type &&
  404. fec == o.fec && rtx == o.rtx && dtx == o.dtx &&
  405. bitrate_priority == o.bitrate_priority &&
  406. network_priority == o.network_priority && ptime == o.ptime &&
  407. max_bitrate_bps == o.max_bitrate_bps &&
  408. min_bitrate_bps == o.min_bitrate_bps &&
  409. max_framerate == o.max_framerate &&
  410. num_temporal_layers == o.num_temporal_layers &&
  411. scale_resolution_down_by == o.scale_resolution_down_by &&
  412. scale_framerate_down_by == o.scale_framerate_down_by &&
  413. active == o.active && rid == o.rid &&
  414. dependency_rids == o.dependency_rids;
  415. }
  416. bool operator!=(const RtpEncodingParameters& o) const {
  417. return !(*this == o);
  418. }
  419. };
  420. struct RTC_EXPORT RtpCodecParameters {
  421. RtpCodecParameters();
  422. RtpCodecParameters(const RtpCodecParameters&);
  423. ~RtpCodecParameters();
  424. // Build MIME "type/subtype" string from |name| and |kind|.
  425. std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
  426. // Used to identify the codec. Equivalent to MIME subtype.
  427. std::string name;
  428. // The media type of this codec. Equivalent to MIME top-level type.
  429. cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
  430. // Payload type used to identify this codec in RTP packets.
  431. // This must always be present, and must be unique across all codecs using
  432. // the same transport.
  433. int payload_type = 0;
  434. // If unset, the implementation default is used.
  435. absl::optional<int> clock_rate;
  436. // The number of audio channels used. Unset for video codecs. If unset for
  437. // audio, the implementation default is used.
  438. // TODO(deadbeef): The "implementation default" part isn't fully implemented.
  439. // Only defaults to 1, even though some codecs (such as opus) should really
  440. // default to 2.
  441. absl::optional<int> num_channels;
  442. // The maximum packetization time to be used by an RtpSender.
  443. // If |ptime| is also set, this will be ignored.
  444. // TODO(deadbeef): Not implemented.
  445. absl::optional<int> max_ptime;
  446. // The packetization time to be used by an RtpSender.
  447. // If unset, will use any time up to max_ptime.
  448. // TODO(deadbeef): Not implemented.
  449. absl::optional<int> ptime;
  450. // Feedback mechanisms to be used for this codec.
  451. // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
  452. std::vector<RtcpFeedback> rtcp_feedback;
  453. // Codec-specific parameters that must be signaled to the remote party.
  454. //
  455. // Corresponds to "a=fmtp" parameters in SDP.
  456. //
  457. // Contrary to ORTC, these parameters are named using all lowercase strings.
  458. // This helps make the mapping to SDP simpler, if an application is using SDP.
  459. // Boolean values are represented by the string "1".
  460. std::unordered_map<std::string, std::string> parameters;
  461. bool operator==(const RtpCodecParameters& o) const {
  462. return name == o.name && kind == o.kind && payload_type == o.payload_type &&
  463. clock_rate == o.clock_rate && num_channels == o.num_channels &&
  464. max_ptime == o.max_ptime && ptime == o.ptime &&
  465. rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
  466. }
  467. bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
  468. };
  469. // RtpCapabilities is used to represent the static capabilities of an endpoint.
  470. // An application can use these capabilities to construct an RtpParameters.
  471. struct RTC_EXPORT RtpCapabilities {
  472. RtpCapabilities();
  473. ~RtpCapabilities();
  474. // Supported codecs.
  475. std::vector<RtpCodecCapability> codecs;
  476. // Supported RTP header extensions.
  477. std::vector<RtpHeaderExtensionCapability> header_extensions;
  478. // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
  479. // ulpfec and flexfec codecs used by these mechanisms will still appear in
  480. // |codecs|.
  481. std::vector<FecMechanism> fec;
  482. bool operator==(const RtpCapabilities& o) const {
  483. return codecs == o.codecs && header_extensions == o.header_extensions &&
  484. fec == o.fec;
  485. }
  486. bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
  487. };
  488. struct RtcpParameters final {
  489. RtcpParameters();
  490. RtcpParameters(const RtcpParameters&);
  491. ~RtcpParameters();
  492. // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
  493. // will be chosen by the implementation.
  494. // TODO(deadbeef): Not implemented.
  495. absl::optional<uint32_t> ssrc;
  496. // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
  497. //
  498. // If empty in the construction of the RtpTransport, one will be generated by
  499. // the implementation, and returned in GetRtcpParameters. Multiple
  500. // RtpTransports created by the same OrtcFactory will use the same generated
  501. // CNAME.
  502. //
  503. // If empty when passed into SetParameters, the CNAME simply won't be
  504. // modified.
  505. std::string cname;
  506. // Send reduced-size RTCP?
  507. bool reduced_size = false;
  508. // Send RTCP multiplexed on the RTP transport?
  509. // Not used with PeerConnection senders/receivers
  510. bool mux = true;
  511. bool operator==(const RtcpParameters& o) const {
  512. return ssrc == o.ssrc && cname == o.cname &&
  513. reduced_size == o.reduced_size && mux == o.mux;
  514. }
  515. bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
  516. };
  517. struct RTC_EXPORT RtpParameters {
  518. RtpParameters();
  519. RtpParameters(const RtpParameters&);
  520. ~RtpParameters();
  521. // Used when calling getParameters/setParameters with a PeerConnection
  522. // RtpSender, to ensure that outdated parameters are not unintentionally
  523. // applied successfully.
  524. std::string transaction_id;
  525. // Value to use for MID RTP header extension.
  526. // Called "muxId" in ORTC.
  527. // TODO(deadbeef): Not implemented.
  528. std::string mid;
  529. std::vector<RtpCodecParameters> codecs;
  530. std::vector<RtpHeaderExtensionParameters> header_extensions;
  531. std::vector<RtpEncodingParameters> encodings;
  532. // Only available with a Peerconnection RtpSender.
  533. // In ORTC, our API includes an additional "RtpTransport"
  534. // abstraction on which RTCP parameters are set.
  535. RtcpParameters rtcp;
  536. // When bandwidth is constrained and the RtpSender needs to choose between
  537. // degrading resolution or degrading framerate, degradationPreference
  538. // indicates which is preferred. Only for video tracks.
  539. DegradationPreference degradation_preference =
  540. DegradationPreference::BALANCED;
  541. bool operator==(const RtpParameters& o) const {
  542. return mid == o.mid && codecs == o.codecs &&
  543. header_extensions == o.header_extensions &&
  544. encodings == o.encodings && rtcp == o.rtcp &&
  545. degradation_preference == o.degradation_preference;
  546. }
  547. bool operator!=(const RtpParameters& o) const { return !(*this == o); }
  548. };
  549. } // namespace webrtc
  550. #endif // API_RTP_PARAMETERS_H_