blob: a428804d54b91ebd43571a916728afdbf29d27f6 [file] [log] [blame]
skvladdc1c62c2016-03-16 19:07:43 -07001/*
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 Brandstetter0cd086b2016-04-20 16:23:10 -070014#include <string>
deadbeefe702b302017-02-04 12:09:01 -080015#include <unordered_map>
skvladdc1c62c2016-03-16 19:07:43 -070016#include <vector>
17
deadbeefe702b302017-02-04 12:09:01 -080018#include "webrtc/api/mediatypes.h"
sakal1fd95952016-06-22 00:46:15 -070019#include "webrtc/base/optional.h"
zhihuangd3501ad2017-03-03 14:39:06 -080020#include "webrtc/config.h"
sakal1fd95952016-06-22 00:46:15 -070021
skvladdc1c62c2016-03-16 19:07:43 -070022namespace webrtc {
23
deadbeefe702b302017-02-04 12:09:01 -080024// These structures are intended to mirror those defined by:
25// http://draft.ortc.org/#rtcrtpdictionaries*
26// Contains everything specified as of 2017 Jan 24.
27//
28// They are used when retrieving or modifying the parameters of an
29// RtpSender/RtpReceiver, or retrieving capabilities.
30//
31// Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
32// types, we typically use "int", in keeping with our style guidelines. The
33// parameter's actual valid range will be enforced when the parameters are set,
34// rather than when the parameters struct is built. An exception is made for
35// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
36// be used for any numeric comparisons/operations.
37//
38// Additionally, where ORTC uses strings, we may use enums for things that have
39// a fixed number of supported values. However, for things that can be extended
40// (such as codecs, by providing an external encoder factory), a string
41// identifier is used.
42
43enum class FecMechanism {
44 RED,
45 RED_AND_ULPFEC,
46 FLEXFEC,
47};
48
49// Used in RtcpFeedback struct.
50enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 12:09:01 -080051 CCM,
52 NACK,
53 REMB, // "goog-remb"
54 TRANSPORT_CC,
55};
56
deadbeefe814a0d2017-02-25 18:15:09 -080057// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 12:09:01 -080058enum 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
65enum class DtxStatus {
66 DISABLED,
67 ENABLED,
68};
69
70enum class DegradationPreference {
71 MAINTAIN_FRAMERATE,
72 MAINTAIN_RESOLUTION,
73 BALANCED,
74};
75
76enum class PriorityType { VERY_LOW, LOW, MEDIUM, HIGH };
77
78struct RtcpFeedback {
deadbeefe814a0d2017-02-25 18:15:09 -080079 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 12:09:01 -080080
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
deadbeefe814a0d2017-02-25 18:15:09 -080087 // Constructors for convenience.
88 RtcpFeedback() {}
89 explicit RtcpFeedback(RtcpFeedbackType type) : type(type) {}
90 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type)
91 : type(type), message_type(message_type) {}
92
deadbeefe702b302017-02-04 12:09:01 -080093 bool operator==(const RtcpFeedback& o) const {
94 return type == o.type && message_type == o.message_type;
95 }
96 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
97};
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.
102struct RtpCodecCapability {
103 // Build MIME "type/subtype" string from |name| and |kind|.
104 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
105
106 // Used to identify the codec. Equivalent to MIME subtype.
107 std::string name;
108
109 // The media type of this codec. Equivalent to MIME top-level type.
110 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
111
112 // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
113 rtc::Optional<int> clock_rate;
114
115 // Default payload type for this codec. Mainly needed for codecs that use
116 // that have statically assigned payload types.
117 rtc::Optional<int> preferred_payload_type;
118
119 // Maximum packetization time supported by an RtpReceiver for this codec.
120 // TODO(deadbeef): Not implemented.
121 rtc::Optional<int> max_ptime;
122
123 // Preferred packetization time for an RtpReceiver or RtpSender of this
124 // codec.
125 // TODO(deadbeef): Not implemented.
126 rtc::Optional<int> ptime;
127
128 // The number of audio channels supported. Unused for video codecs.
129 rtc::Optional<int> num_channels;
130
131 // Feedback mechanisms supported for this codec.
132 std::vector<RtcpFeedback> rtcp_feedback;
133
134 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800135 //
deadbeefe702b302017-02-04 12:09:01 -0800136 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800137 //
138 // Contrary to ORTC, these parameters are named using all lowercase strings.
139 // This helps make the mapping to SDP simpler, if an application is using
140 // SDP. Boolean values are represented by the string "1".
deadbeefe702b302017-02-04 12:09:01 -0800141 std::unordered_map<std::string, std::string> parameters;
142
143 // Codec-specific parameters that may optionally be signaled to the remote
144 // party.
145 // TODO(deadbeef): Not implemented.
146 std::unordered_map<std::string, std::string> options;
147
148 // Maximum number of temporal layer extensions supported by this codec.
149 // For example, a value of 1 indicates that 2 total layers are supported.
150 // TODO(deadbeef): Not implemented.
151 int max_temporal_layer_extensions = 0;
152
153 // Maximum number of spatial layer extensions supported by this codec.
154 // For example, a value of 1 indicates that 2 total layers are supported.
155 // TODO(deadbeef): Not implemented.
156 int max_spatial_layer_extensions = 0;
157
158 // Whether the implementation can send/receive SVC layers with distinct
159 // SSRCs. Always false for audio codecs. True for video codecs that support
160 // scalable video coding with MRST.
161 // TODO(deadbeef): Not implemented.
162 bool svc_multi_stream_support = false;
163
164 bool operator==(const RtpCodecCapability& o) const {
165 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
166 preferred_payload_type == o.preferred_payload_type &&
167 max_ptime == o.max_ptime && ptime == o.ptime &&
168 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
169 parameters == o.parameters && options == o.options &&
170 max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
171 max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
172 svc_multi_stream_support == o.svc_multi_stream_support;
173 }
174 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
175};
176
177// Used in RtpCapabilities; represents the capabilities/preferences of an
178// implementation for a header extension.
179//
180// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
181// added here for consistency and to avoid confusion with
182// RtpHeaderExtensionParameters.
183//
184// Note that ORTC includes a "kind" field, but we omit this because it's
185// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
186// you know you're getting audio capabilities.
187struct RtpHeaderExtensionCapability {
188 // URI of this extension, as defined in RFC5285.
189 std::string uri;
190
191 // Preferred value of ID that goes in the packet.
192 rtc::Optional<int> preferred_id;
193
194 // If true, it's preferred that the value in the header is encrypted.
195 // TODO(deadbeef): Not implemented.
196 bool preferred_encrypt = false;
197
deadbeefe814a0d2017-02-25 18:15:09 -0800198 // Constructors for convenience.
199 RtpHeaderExtensionCapability() = default;
200 explicit RtpHeaderExtensionCapability(const std::string& uri) : uri(uri) {}
201 RtpHeaderExtensionCapability(const std::string& uri, int preferred_id)
202 : uri(uri), preferred_id(preferred_id) {}
203
deadbeefe702b302017-02-04 12:09:01 -0800204 bool operator==(const RtpHeaderExtensionCapability& o) const {
205 return uri == o.uri && preferred_id == o.preferred_id &&
206 preferred_encrypt == o.preferred_encrypt;
207 }
208 bool operator!=(const RtpHeaderExtensionCapability& o) const {
209 return !(*this == o);
210 }
211};
212
deadbeefe814a0d2017-02-25 18:15:09 -0800213// See webrtc/config.h. Has "uri" and "id" fields.
214// TODO(deadbeef): This is missing the "encrypt" flag, which is unimplemented.
215typedef RtpExtension RtpHeaderExtensionParameters;
deadbeefe702b302017-02-04 12:09:01 -0800216
217struct RtpFecParameters {
218 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800219 // Works just like RtpEncodingParameters::ssrc.
sakal1fd95952016-06-22 00:46:15 -0700220 rtc::Optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800221
222 FecMechanism mechanism = FecMechanism::RED;
223
deadbeefe814a0d2017-02-25 18:15:09 -0800224 // Constructors for convenience.
225 RtpFecParameters() = default;
226 explicit RtpFecParameters(FecMechanism mechanism) : mechanism(mechanism) {}
227 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc)
228 : ssrc(ssrc), mechanism(mechanism) {}
229
deadbeefe702b302017-02-04 12:09:01 -0800230 bool operator==(const RtpFecParameters& o) const {
231 return ssrc == o.ssrc && mechanism == o.mechanism;
232 }
233 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
234};
235
236struct RtpRtxParameters {
237 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800238 // Works just like RtpEncodingParameters::ssrc.
deadbeefe702b302017-02-04 12:09:01 -0800239 rtc::Optional<uint32_t> ssrc;
240
deadbeefe814a0d2017-02-25 18:15:09 -0800241 // Constructors for convenience.
242 RtpRtxParameters() = default;
243 explicit RtpRtxParameters(uint32_t ssrc) : ssrc(ssrc) {}
244
deadbeefe702b302017-02-04 12:09:01 -0800245 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
246 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
247};
248
249struct RtpEncodingParameters {
250 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800251 //
252 // Note that the chosen value is NOT returned by GetParameters, because it
253 // may change due to an SSRC conflict, in which case the conflict is handled
254 // internally without any event. Another way of looking at this is that an
255 // unset SSRC acts as a "wildcard" SSRC.
deadbeefe702b302017-02-04 12:09:01 -0800256 rtc::Optional<uint32_t> ssrc;
257
258 // Can be used to reference a codec in the |codecs| member of the
259 // RtpParameters that contains this RtpEncodingParameters. If unset, the
deadbeefe814a0d2017-02-25 18:15:09 -0800260 // implementation will choose the first possible codec (if a sender), or
261 // prepare to receive any codec (for a receiver).
262 // TODO(deadbeef): Not implemented. Implementation of RtpSender will always
263 // choose the first codec from the list.
deadbeefe702b302017-02-04 12:09:01 -0800264 rtc::Optional<int> codec_payload_type;
265
266 // Specifies the FEC mechanism, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800267 // TODO(deadbeef): Not implemented. Current implementation will use whatever
268 // FEC codecs are available, including red+ulpfec.
deadbeefe702b302017-02-04 12:09:01 -0800269 rtc::Optional<RtpFecParameters> fec;
270
271 // Specifies the RTX parameters, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800272 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800273 rtc::Optional<RtpRtxParameters> rtx;
274
275 // Only used for audio. If set, determines whether or not discontinuous
276 // transmission will be used, if an available codec supports it. If not
277 // set, the implementation default setting will be used.
deadbeefe814a0d2017-02-25 18:15:09 -0800278 // TODO(deadbeef): Not implemented. Current implementation will use a CN
279 // codec as long as it's present.
deadbeefe702b302017-02-04 12:09:01 -0800280 rtc::Optional<DtxStatus> dtx;
281
282 // The relative priority of this encoding.
283 // TODO(deadbeef): Not implemented.
284 rtc::Optional<PriorityType> priority;
285
286 // If set, this represents the Transport Independent Application Specific
287 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
288 // bitrate.
deadbeefe814a0d2017-02-25 18:15:09 -0800289 //
deadbeefe702b302017-02-04 12:09:01 -0800290 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-25 18:15:09 -0800291 //
292 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
293 // bandwidth for the entire bandwidth estimator (audio and video). This is
294 // just always how "b=AS" was handled, but it's not correct and should be
295 // fixed.
deadbeefe702b302017-02-04 12:09:01 -0800296 rtc::Optional<int> max_bitrate_bps;
297
298 // TODO(deadbeef): Not implemented.
299 rtc::Optional<int> max_framerate;
300
301 // For video, scale the resolution down by this factor.
302 // TODO(deadbeef): Not implemented.
303 double scale_resolution_down_by = 1.0;
304
305 // Scale the framerate down by this factor.
306 // TODO(deadbeef): Not implemented.
307 double scale_framerate_down_by = 1.0;
308
309 // For an RtpSender, set to true to cause this encoding to be sent, and false
310 // for it not to be sent. For an RtpReceiver, set to true to cause the
311 // encoding to be decoded, and false for it to be ignored.
deadbeefe814a0d2017-02-25 18:15:09 -0800312 // TODO(deadbeef): Not implemented for PeerConnection RtpReceivers.
deadbeefdbe2b872016-03-22 15:42:00 -0700313 bool active = true;
deadbeefe702b302017-02-04 12:09:01 -0800314
315 // Value to use for RID RTP header extension.
316 // Called "encodingId" in ORTC.
317 // TODO(deadbeef): Not implemented.
318 std::string rid;
319
320 // RIDs of encodings on which this layer depends.
321 // Called "dependencyEncodingIds" in ORTC spec.
322 // TODO(deadbeef): Not implemented.
323 std::vector<std::string> dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700324
325 bool operator==(const RtpEncodingParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800326 return ssrc == o.ssrc && codec_payload_type == o.codec_payload_type &&
327 fec == o.fec && rtx == o.rtx && dtx == o.dtx &&
328 priority == o.priority && max_bitrate_bps == o.max_bitrate_bps &&
329 max_framerate == o.max_framerate &&
330 scale_resolution_down_by == o.scale_resolution_down_by &&
331 scale_framerate_down_by == o.scale_framerate_down_by &&
332 active == o.active && rid == o.rid &&
333 dependency_rids == o.dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700334 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700335 bool operator!=(const RtpEncodingParameters& o) const {
336 return !(*this == o);
337 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700338};
339
340struct RtpCodecParameters {
deadbeefe702b302017-02-04 12:09:01 -0800341 // Build MIME "type/subtype" string from |name| and |kind|.
342 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
343
344 // Used to identify the codec. Equivalent to MIME subtype.
345 std::string name;
346
347 // The media type of this codec. Equivalent to MIME top-level type.
348 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
349
350 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-25 18:15:09 -0800351 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 12:09:01 -0800352 // the same transport.
353 int payload_type = 0;
354
355 // If unset, the implementation default is used.
356 rtc::Optional<int> clock_rate;
357
358 // The number of audio channels used. Unset for video codecs. If unset for
359 // audio, the implementation default is used.
deadbeefe814a0d2017-02-25 18:15:09 -0800360 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
361 // Only defaults to 1, even though some codecs (such as opus) should really
362 // default to 2.
deadbeefe702b302017-02-04 12:09:01 -0800363 rtc::Optional<int> num_channels;
364
365 // The maximum packetization time to be used by an RtpSender.
366 // If |ptime| is also set, this will be ignored.
367 // TODO(deadbeef): Not implemented.
368 rtc::Optional<int> max_ptime;
369
370 // The packetization time to be used by an RtpSender.
371 // If unset, will use any time up to max_ptime.
372 // TODO(deadbeef): Not implemented.
373 rtc::Optional<int> ptime;
374
375 // Feedback mechanisms to be used for this codec.
deadbeefe814a0d2017-02-25 18:15:09 -0800376 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800377 std::vector<RtcpFeedback> rtcp_feedback;
378
379 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800380 //
deadbeefe702b302017-02-04 12:09:01 -0800381 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800382 //
383 // Contrary to ORTC, these parameters are named using all lowercase strings.
384 // This helps make the mapping to SDP simpler, if an application is using
385 // SDP. Boolean values are represented by the string "1".
386 //
387 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800388 std::unordered_map<std::string, std::string> parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700389
390 bool operator==(const RtpCodecParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800391 return name == o.name && kind == o.kind && payload_type == o.payload_type &&
392 clock_rate == o.clock_rate && num_channels == o.num_channels &&
393 max_ptime == o.max_ptime && ptime == o.ptime &&
394 rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700395 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700396 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700397};
398
deadbeefe702b302017-02-04 12:09:01 -0800399// RtpCapabilities is used to represent the static capabilities of an
400// endpoint. An application can use these capabilities to construct an
401// RtpParameters.
402struct RtpCapabilities {
403 // Supported codecs.
404 std::vector<RtpCodecCapability> codecs;
405
406 // Supported RTP header extensions.
407 std::vector<RtpHeaderExtensionCapability> header_extensions;
408
deadbeefe814a0d2017-02-25 18:15:09 -0800409 // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
410 // ulpfec and flexfec codecs used by these mechanisms will still appear in
411 // |codecs|.
deadbeefe702b302017-02-04 12:09:01 -0800412 std::vector<FecMechanism> fec;
413
414 bool operator==(const RtpCapabilities& o) const {
415 return codecs == o.codecs && header_extensions == o.header_extensions &&
416 fec == o.fec;
417 }
418 bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
419};
420
deadbeefe814a0d2017-02-25 18:15:09 -0800421// Note that unlike in ORTC, an RtcpParameters structure is not included in
422// RtpParameters, because our API includes an additional "RtpTransport"
deadbeefe702b302017-02-04 12:09:01 -0800423// abstraction on which RTCP parameters are set.
skvladdc1c62c2016-03-16 19:07:43 -0700424struct RtpParameters {
deadbeefe702b302017-02-04 12:09:01 -0800425 // Used when calling getParameters/setParameters with a PeerConnection
426 // RtpSender, to ensure that outdated parameters are not unintentionally
427 // applied successfully.
428 // TODO(deadbeef): Not implemented.
429 std::string transaction_id;
430
431 // Value to use for MID RTP header extension.
432 // Called "muxId" in ORTC.
433 // TODO(deadbeef): Not implemented.
434 std::string mid;
435
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700436 std::vector<RtpCodecParameters> codecs;
437
deadbeefe814a0d2017-02-25 18:15:09 -0800438 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800439 std::vector<RtpHeaderExtensionParameters> header_extensions;
440
441 std::vector<RtpEncodingParameters> encodings;
442
443 // TODO(deadbeef): Not implemented.
444 DegradationPreference degradation_preference =
445 DegradationPreference::BALANCED;
446
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700447 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800448 return mid == o.mid && codecs == o.codecs &&
449 header_extensions == o.header_extensions &&
450 encodings == o.encodings &&
451 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700452 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700453 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700454};
455
456} // namespace webrtc
457
458#endif // WEBRTC_API_RTPPARAMETERS_H_