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