skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 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 WEBRTC_API_RTPPARAMETERS_H_ |
| 12 | #define WEBRTC_API_RTPPARAMETERS_H_ |
| 13 | |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 14 | #include <string> |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 15 | #include <unordered_map> |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 18 | #include "webrtc/api/mediatypes.h" |
sakal | 1fd9595 | 2016-06-22 00:46:15 -0700 | [diff] [blame] | 19 | #include "webrtc/base/optional.h" |
| 20 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 21 | namespace webrtc { |
| 22 | |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 23 | // These structures are intended to mirror those defined by: |
| 24 | // http://draft.ortc.org/#rtcrtpdictionaries* |
| 25 | // Contains everything specified as of 2017 Jan 24. |
| 26 | // |
| 27 | // They are used when retrieving or modifying the parameters of an |
| 28 | // RtpSender/RtpReceiver, or retrieving capabilities. |
| 29 | // |
| 30 | // Note on conventions: Where ORTC may use "octet", "short" and "unsigned" |
| 31 | // types, we typically use "int", in keeping with our style guidelines. The |
| 32 | // parameter's actual valid range will be enforced when the parameters are set, |
| 33 | // rather than when the parameters struct is built. An exception is made for |
| 34 | // SSRCs, since they use the full unsigned 32-bit range, and aren't expected to |
| 35 | // be used for any numeric comparisons/operations. |
| 36 | // |
| 37 | // Additionally, where ORTC uses strings, we may use enums for things that have |
| 38 | // a fixed number of supported values. However, for things that can be extended |
| 39 | // (such as codecs, by providing an external encoder factory), a string |
| 40 | // identifier is used. |
| 41 | |
| 42 | enum class FecMechanism { |
| 43 | RED, |
| 44 | RED_AND_ULPFEC, |
| 45 | FLEXFEC, |
| 46 | }; |
| 47 | |
| 48 | // Used in RtcpFeedback struct. |
| 49 | enum class RtcpFeedbackType { |
| 50 | ACK, |
| 51 | CCM, |
| 52 | NACK, |
| 53 | REMB, // "goog-remb" |
| 54 | TRANSPORT_CC, |
| 55 | }; |
| 56 | |
| 57 | // Used in RtcpFeedback struct when type is ACK, NACK or CCM. |
| 58 | enum class RtcpFeedbackMessageType { |
| 59 | // Equivalent to {type: "nack", parameter: undefined} in ORTC. |
| 60 | GENERIC_NACK, |
| 61 | PLI, // Usable with NACK. |
| 62 | FIR, // Usable with CCM. |
| 63 | }; |
| 64 | |
| 65 | enum class DtxStatus { |
| 66 | DISABLED, |
| 67 | ENABLED, |
| 68 | }; |
| 69 | |
| 70 | enum class DegradationPreference { |
| 71 | MAINTAIN_FRAMERATE, |
| 72 | MAINTAIN_RESOLUTION, |
| 73 | BALANCED, |
| 74 | }; |
| 75 | |
| 76 | enum class PriorityType { VERY_LOW, LOW, MEDIUM, HIGH }; |
| 77 | |
| 78 | struct RtcpFeedback { |
| 79 | RtcpFeedbackType type = RtcpFeedbackType::ACK; |
| 80 | |
| 81 | // Equivalent to ORTC "parameter" field with slight differences: |
| 82 | // 1. It's an enum instead of a string. |
| 83 | // 2. Generic NACK feedback is represented by a GENERIC_NACK message type, |
| 84 | // rather than an unset "parameter" value. |
| 85 | rtc::Optional<RtcpFeedbackMessageType> message_type; |
| 86 | |
| 87 | bool operator==(const RtcpFeedback& o) const { |
| 88 | return type == o.type && message_type == o.message_type; |
| 89 | } |
| 90 | bool operator!=(const RtcpFeedback& o) const { return !(*this == o); } |
| 91 | }; |
| 92 | |
| 93 | // RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to |
| 94 | // RtpParameters. This represents the static capabilities of an endpoint's |
| 95 | // implementation of a codec. |
| 96 | struct RtpCodecCapability { |
| 97 | // Build MIME "type/subtype" string from |name| and |kind|. |
| 98 | std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; } |
| 99 | |
| 100 | // Used to identify the codec. Equivalent to MIME subtype. |
| 101 | std::string name; |
| 102 | |
| 103 | // The media type of this codec. Equivalent to MIME top-level type. |
| 104 | cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO; |
| 105 | |
| 106 | // Clock rate in Hertz. If unset, the codec is applicable to any clock rate. |
| 107 | rtc::Optional<int> clock_rate; |
| 108 | |
| 109 | // Default payload type for this codec. Mainly needed for codecs that use |
| 110 | // that have statically assigned payload types. |
| 111 | rtc::Optional<int> preferred_payload_type; |
| 112 | |
| 113 | // Maximum packetization time supported by an RtpReceiver for this codec. |
| 114 | // TODO(deadbeef): Not implemented. |
| 115 | rtc::Optional<int> max_ptime; |
| 116 | |
| 117 | // Preferred packetization time for an RtpReceiver or RtpSender of this |
| 118 | // codec. |
| 119 | // TODO(deadbeef): Not implemented. |
| 120 | rtc::Optional<int> ptime; |
| 121 | |
| 122 | // The number of audio channels supported. Unused for video codecs. |
| 123 | rtc::Optional<int> num_channels; |
| 124 | |
| 125 | // Feedback mechanisms supported for this codec. |
| 126 | std::vector<RtcpFeedback> rtcp_feedback; |
| 127 | |
| 128 | // Codec-specific parameters that must be signaled to the remote party. |
| 129 | // Corresponds to "a=fmtp" parameters in SDP. |
| 130 | std::unordered_map<std::string, std::string> parameters; |
| 131 | |
| 132 | // Codec-specific parameters that may optionally be signaled to the remote |
| 133 | // party. |
| 134 | // TODO(deadbeef): Not implemented. |
| 135 | std::unordered_map<std::string, std::string> options; |
| 136 | |
| 137 | // Maximum number of temporal layer extensions supported by this codec. |
| 138 | // For example, a value of 1 indicates that 2 total layers are supported. |
| 139 | // TODO(deadbeef): Not implemented. |
| 140 | int max_temporal_layer_extensions = 0; |
| 141 | |
| 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 | |
| 147 | // Whether the implementation can send/receive SVC layers with distinct |
| 148 | // SSRCs. Always false for audio codecs. True for video codecs that support |
| 149 | // scalable video coding with MRST. |
| 150 | // TODO(deadbeef): Not implemented. |
| 151 | bool svc_multi_stream_support = false; |
| 152 | |
| 153 | bool operator==(const RtpCodecCapability& o) const { |
| 154 | return name == o.name && kind == o.kind && clock_rate == o.clock_rate && |
| 155 | preferred_payload_type == o.preferred_payload_type && |
| 156 | max_ptime == o.max_ptime && ptime == o.ptime && |
| 157 | num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback && |
| 158 | parameters == o.parameters && options == o.options && |
| 159 | max_temporal_layer_extensions == o.max_temporal_layer_extensions && |
| 160 | max_spatial_layer_extensions == o.max_spatial_layer_extensions && |
| 161 | svc_multi_stream_support == o.svc_multi_stream_support; |
| 162 | } |
| 163 | bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); } |
| 164 | }; |
| 165 | |
| 166 | // Used in RtpCapabilities; represents the capabilities/preferences of an |
| 167 | // implementation for a header extension. |
| 168 | // |
| 169 | // Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was |
| 170 | // added here for consistency and to avoid confusion with |
| 171 | // RtpHeaderExtensionParameters. |
| 172 | // |
| 173 | // Note that ORTC includes a "kind" field, but we omit this because it's |
| 174 | // redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)", |
| 175 | // you know you're getting audio capabilities. |
| 176 | struct RtpHeaderExtensionCapability { |
| 177 | // URI of this extension, as defined in RFC5285. |
| 178 | std::string uri; |
| 179 | |
| 180 | // Preferred value of ID that goes in the packet. |
| 181 | rtc::Optional<int> preferred_id; |
| 182 | |
| 183 | // If true, it's preferred that the value in the header is encrypted. |
| 184 | // TODO(deadbeef): Not implemented. |
| 185 | bool preferred_encrypt = false; |
| 186 | |
| 187 | bool operator==(const RtpHeaderExtensionCapability& o) const { |
| 188 | return uri == o.uri && preferred_id == o.preferred_id && |
| 189 | preferred_encrypt == o.preferred_encrypt; |
| 190 | } |
| 191 | bool operator!=(const RtpHeaderExtensionCapability& o) const { |
| 192 | return !(*this == o); |
| 193 | } |
| 194 | }; |
| 195 | |
| 196 | // Used in RtpParameters; represents a specific configuration of a header |
| 197 | // extension. |
| 198 | struct RtpHeaderExtensionParameters { |
| 199 | // URI of this extension, as defined in RFC5285. |
| 200 | std::string uri; |
| 201 | |
| 202 | // ID value that goes in the packet. |
| 203 | int id = 0; |
| 204 | |
| 205 | // If true, the value in the header is encrypted. |
| 206 | // TODO(deadbeef): Not implemented. |
| 207 | bool encrypt = false; |
| 208 | |
| 209 | bool operator==(const RtpHeaderExtensionParameters& o) const { |
| 210 | return uri == o.uri && id == o.id && encrypt == o.encrypt; |
| 211 | } |
| 212 | bool operator!=(const RtpHeaderExtensionParameters& o) const { |
| 213 | return !(*this == o); |
| 214 | } |
| 215 | }; |
| 216 | |
| 217 | struct RtpFecParameters { |
| 218 | // If unset, a value is chosen by the implementation. |
sakal | 1fd9595 | 2016-06-22 00:46:15 -0700 | [diff] [blame] | 219 | rtc::Optional<uint32_t> ssrc; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 220 | |
| 221 | FecMechanism mechanism = FecMechanism::RED; |
| 222 | |
| 223 | bool operator==(const RtpFecParameters& o) const { |
| 224 | return ssrc == o.ssrc && mechanism == o.mechanism; |
| 225 | } |
| 226 | bool operator!=(const RtpFecParameters& o) const { return !(*this == o); } |
| 227 | }; |
| 228 | |
| 229 | struct RtpRtxParameters { |
| 230 | // If unset, a value is chosen by the implementation. |
| 231 | rtc::Optional<uint32_t> ssrc; |
| 232 | |
| 233 | bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; } |
| 234 | bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); } |
| 235 | }; |
| 236 | |
| 237 | struct RtpEncodingParameters { |
| 238 | // If unset, a value is chosen by the implementation. |
| 239 | rtc::Optional<uint32_t> ssrc; |
| 240 | |
| 241 | // Can be used to reference a codec in the |codecs| member of the |
| 242 | // RtpParameters that contains this RtpEncodingParameters. If unset, the |
| 243 | // implementation will choose the first possible codec. |
| 244 | // TODO(deadbeef): Not implemented. |
| 245 | rtc::Optional<int> codec_payload_type; |
| 246 | |
| 247 | // Specifies the FEC mechanism, if set. |
| 248 | // TODO(deadbeef): Not implemented. |
| 249 | rtc::Optional<RtpFecParameters> fec; |
| 250 | |
| 251 | // Specifies the RTX parameters, if set. |
| 252 | // TODO(deadbeef): Not implemented. |
| 253 | rtc::Optional<RtpRtxParameters> rtx; |
| 254 | |
| 255 | // Only used for audio. If set, determines whether or not discontinuous |
| 256 | // transmission will be used, if an available codec supports it. If not |
| 257 | // set, the implementation default setting will be used. |
| 258 | rtc::Optional<DtxStatus> dtx; |
| 259 | |
| 260 | // The relative priority of this encoding. |
| 261 | // TODO(deadbeef): Not implemented. |
| 262 | rtc::Optional<PriorityType> priority; |
| 263 | |
| 264 | // If set, this represents the Transport Independent Application Specific |
| 265 | // maximum bandwidth defined in RFC3890. If unset, there is no maximum |
| 266 | // bitrate. |
| 267 | // Just called "maxBitrate" in ORTC spec. |
| 268 | rtc::Optional<int> max_bitrate_bps; |
| 269 | |
| 270 | // TODO(deadbeef): Not implemented. |
| 271 | rtc::Optional<int> max_framerate; |
| 272 | |
| 273 | // For video, scale the resolution down by this factor. |
| 274 | // TODO(deadbeef): Not implemented. |
| 275 | double scale_resolution_down_by = 1.0; |
| 276 | |
| 277 | // Scale the framerate down by this factor. |
| 278 | // TODO(deadbeef): Not implemented. |
| 279 | double scale_framerate_down_by = 1.0; |
| 280 | |
| 281 | // For an RtpSender, set to true to cause this encoding to be sent, and false |
| 282 | // for it not to be sent. For an RtpReceiver, set to true to cause the |
| 283 | // encoding to be decoded, and false for it to be ignored. |
| 284 | // TODO(deadbeef): RtpReceiver part is not implemented. |
deadbeef | dbe2b87 | 2016-03-22 15:42:00 -0700 | [diff] [blame] | 285 | bool active = true; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 286 | |
| 287 | // Value to use for RID RTP header extension. |
| 288 | // Called "encodingId" in ORTC. |
| 289 | // TODO(deadbeef): Not implemented. |
| 290 | std::string rid; |
| 291 | |
| 292 | // RIDs of encodings on which this layer depends. |
| 293 | // Called "dependencyEncodingIds" in ORTC spec. |
| 294 | // TODO(deadbeef): Not implemented. |
| 295 | std::vector<std::string> dependency_rids; |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 296 | |
| 297 | bool operator==(const RtpEncodingParameters& o) const { |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 298 | return ssrc == o.ssrc && codec_payload_type == o.codec_payload_type && |
| 299 | fec == o.fec && rtx == o.rtx && dtx == o.dtx && |
| 300 | priority == o.priority && max_bitrate_bps == o.max_bitrate_bps && |
| 301 | max_framerate == o.max_framerate && |
| 302 | scale_resolution_down_by == o.scale_resolution_down_by && |
| 303 | scale_framerate_down_by == o.scale_framerate_down_by && |
| 304 | active == o.active && rid == o.rid && |
| 305 | dependency_rids == o.dependency_rids; |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 306 | } |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 307 | bool operator!=(const RtpEncodingParameters& o) const { |
| 308 | return !(*this == o); |
| 309 | } |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 310 | }; |
| 311 | |
| 312 | struct RtpCodecParameters { |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 313 | // Build MIME "type/subtype" string from |name| and |kind|. |
| 314 | std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; } |
| 315 | |
| 316 | // Used to identify the codec. Equivalent to MIME subtype. |
| 317 | std::string name; |
| 318 | |
| 319 | // The media type of this codec. Equivalent to MIME top-level type. |
| 320 | cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO; |
| 321 | |
| 322 | // Payload type used to identify this codec in RTP packets. |
| 323 | // This MUST always be present, and must be unique across all codecs using |
| 324 | // the same transport. |
| 325 | int payload_type = 0; |
| 326 | |
| 327 | // If unset, the implementation default is used. |
| 328 | rtc::Optional<int> clock_rate; |
| 329 | |
| 330 | // The number of audio channels used. Unset for video codecs. If unset for |
| 331 | // audio, the implementation default is used. |
| 332 | // TODO(deadbeef): The "implementation default" part is unimplemented. |
| 333 | rtc::Optional<int> num_channels; |
| 334 | |
| 335 | // The maximum packetization time to be used by an RtpSender. |
| 336 | // If |ptime| is also set, this will be ignored. |
| 337 | // TODO(deadbeef): Not implemented. |
| 338 | rtc::Optional<int> max_ptime; |
| 339 | |
| 340 | // The packetization time to be used by an RtpSender. |
| 341 | // If unset, will use any time up to max_ptime. |
| 342 | // TODO(deadbeef): Not implemented. |
| 343 | rtc::Optional<int> ptime; |
| 344 | |
| 345 | // Feedback mechanisms to be used for this codec. |
| 346 | // TODO(deadbeef): Not implemented. |
| 347 | std::vector<RtcpFeedback> rtcp_feedback; |
| 348 | |
| 349 | // Codec-specific parameters that must be signaled to the remote party. |
| 350 | // Corresponds to "a=fmtp" parameters in SDP. |
| 351 | // TODO(deadbeef): Not implemented. |
| 352 | std::unordered_map<std::string, std::string> parameters; |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 353 | |
| 354 | bool operator==(const RtpCodecParameters& o) const { |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 355 | return name == o.name && kind == o.kind && payload_type == o.payload_type && |
| 356 | clock_rate == o.clock_rate && num_channels == o.num_channels && |
| 357 | max_ptime == o.max_ptime && ptime == o.ptime && |
| 358 | rtcp_feedback == o.rtcp_feedback && parameters == o.parameters; |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 359 | } |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 360 | bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 361 | }; |
| 362 | |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 363 | // RtpCapabilities is used to represent the static capabilities of an |
| 364 | // endpoint. An application can use these capabilities to construct an |
| 365 | // RtpParameters. |
| 366 | struct RtpCapabilities { |
| 367 | // Supported codecs. |
| 368 | std::vector<RtpCodecCapability> codecs; |
| 369 | |
| 370 | // Supported RTP header extensions. |
| 371 | std::vector<RtpHeaderExtensionCapability> header_extensions; |
| 372 | |
| 373 | // Supported Forward Error Correction (FEC) mechanisms. |
| 374 | std::vector<FecMechanism> fec; |
| 375 | |
| 376 | bool operator==(const RtpCapabilities& o) const { |
| 377 | return codecs == o.codecs && header_extensions == o.header_extensions && |
| 378 | fec == o.fec; |
| 379 | } |
| 380 | bool operator!=(const RtpCapabilities& o) const { return !(*this == o); } |
| 381 | }; |
| 382 | |
| 383 | // Note that unlike in ORTC, an RtcpParameters is not included in |
| 384 | // RtpParameters, because our API will include an additional "RtpTransport" |
| 385 | // abstraction on which RTCP parameters are set. |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 386 | struct RtpParameters { |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 387 | // Used when calling getParameters/setParameters with a PeerConnection |
| 388 | // RtpSender, to ensure that outdated parameters are not unintentionally |
| 389 | // applied successfully. |
| 390 | // TODO(deadbeef): Not implemented. |
| 391 | std::string transaction_id; |
| 392 | |
| 393 | // Value to use for MID RTP header extension. |
| 394 | // Called "muxId" in ORTC. |
| 395 | // TODO(deadbeef): Not implemented. |
| 396 | std::string mid; |
| 397 | |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 398 | std::vector<RtpCodecParameters> codecs; |
| 399 | |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 400 | // TODO(deadbeef): Not implemented. |
| 401 | std::vector<RtpHeaderExtensionParameters> header_extensions; |
| 402 | |
| 403 | std::vector<RtpEncodingParameters> encodings; |
| 404 | |
| 405 | // TODO(deadbeef): Not implemented. |
| 406 | DegradationPreference degradation_preference = |
| 407 | DegradationPreference::BALANCED; |
| 408 | |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 409 | bool operator==(const RtpParameters& o) const { |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 410 | return mid == o.mid && codecs == o.codecs && |
| 411 | header_extensions == o.header_extensions && |
| 412 | encodings == o.encodings && |
| 413 | degradation_preference == o.degradation_preference; |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 414 | } |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 415 | bool operator!=(const RtpParameters& o) const { return !(*this == o); } |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 416 | }; |
| 417 | |
| 418 | } // namespace webrtc |
| 419 | |
| 420 | #endif // WEBRTC_API_RTPPARAMETERS_H_ |