blob: 377fb789540a299573b1c11f24379d4e7f03d220 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef API_RTPPARAMETERS_H_
12#define API_RTPPARAMETERS_H_
skvladdc1c62c2016-03-16 19:07:43 -070013
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
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020018#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/mediatypes.h"
sakal1fd95952016-06-22 00:46:15 -070020
skvladdc1c62c2016-03-16 19:07:43 -070021namespace webrtc {
22
deadbeefe702b302017-02-04 12:09:01 -080023// 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
42enum class FecMechanism {
43 RED,
44 RED_AND_ULPFEC,
45 FLEXFEC,
46};
47
48// Used in RtcpFeedback struct.
49enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 12:09:01 -080050 CCM,
51 NACK,
52 REMB, // "goog-remb"
53 TRANSPORT_CC,
54};
55
deadbeefe814a0d2017-02-25 18:15:09 -080056// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 12:09:01 -080057enum class RtcpFeedbackMessageType {
58 // Equivalent to {type: "nack", parameter: undefined} in ORTC.
59 GENERIC_NACK,
60 PLI, // Usable with NACK.
61 FIR, // Usable with CCM.
62};
63
64enum class DtxStatus {
65 DISABLED,
66 ENABLED,
67};
68
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070069// Based on the spec in
70// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
71// These options are enforced on a best-effort basis. For instance, all of
72// these options may suffer some frame drops in order to avoid queuing.
73// TODO(sprang): Look into possibility of more strictly enforcing the
74// maintain-framerate option.
75// TODO(deadbeef): Default to "balanced", as the spec indicates?
deadbeefe702b302017-02-04 12:09:01 -080076enum class DegradationPreference {
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070077 // Don't take any actions based on over-utilization signals. Not part of the
78 // web API.
79 DISABLED,
80 // On over-use, request lower frame rate, possibly causing frame drops.
deadbeefe702b302017-02-04 12:09:01 -080081 MAINTAIN_FRAMERATE,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070082 // On over-use, request lower resolution, possibly causing down-scaling.
deadbeefe702b302017-02-04 12:09:01 -080083 MAINTAIN_RESOLUTION,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070084 // Try to strike a "pleasing" balance between frame rate or resolution.
deadbeefe702b302017-02-04 12:09:01 -080085 BALANCED,
86};
87
Seth Hampsonf32795e2017-12-19 11:37:41 -080088extern const double kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -080089
90struct RtcpFeedback {
deadbeefe814a0d2017-02-25 18:15:09 -080091 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 12:09:01 -080092
93 // Equivalent to ORTC "parameter" field with slight differences:
94 // 1. It's an enum instead of a string.
95 // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
96 // rather than an unset "parameter" value.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020097 absl::optional<RtcpFeedbackMessageType> message_type;
deadbeefe702b302017-02-04 12:09:01 -080098
deadbeefe814a0d2017-02-25 18:15:09 -080099 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200100 RtcpFeedback();
101 explicit RtcpFeedback(RtcpFeedbackType type);
102 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200103 RtcpFeedback(const RtcpFeedback&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200104 ~RtcpFeedback();
deadbeefe814a0d2017-02-25 18:15:09 -0800105
deadbeefe702b302017-02-04 12:09:01 -0800106 bool operator==(const RtcpFeedback& o) const {
107 return type == o.type && message_type == o.message_type;
108 }
109 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
110};
111
112// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
113// RtpParameters. This represents the static capabilities of an endpoint's
114// implementation of a codec.
115struct RtpCodecCapability {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200116 RtpCodecCapability();
117 ~RtpCodecCapability();
118
deadbeefe702b302017-02-04 12:09:01 -0800119 // Build MIME "type/subtype" string from |name| and |kind|.
120 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
121
122 // Used to identify the codec. Equivalent to MIME subtype.
123 std::string name;
124
125 // The media type of this codec. Equivalent to MIME top-level type.
126 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
127
128 // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200129 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800130
131 // Default payload type for this codec. Mainly needed for codecs that use
132 // that have statically assigned payload types.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200133 absl::optional<int> preferred_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800134
135 // Maximum packetization time supported by an RtpReceiver for this codec.
136 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200137 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800138
139 // Preferred packetization time for an RtpReceiver or RtpSender of this
140 // codec.
141 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200142 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800143
144 // The number of audio channels supported. Unused for video codecs.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200145 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800146
147 // Feedback mechanisms supported for this codec.
148 std::vector<RtcpFeedback> rtcp_feedback;
149
150 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800151 //
deadbeefe702b302017-02-04 12:09:01 -0800152 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800153 //
154 // Contrary to ORTC, these parameters are named using all lowercase strings.
155 // This helps make the mapping to SDP simpler, if an application is using
156 // SDP. Boolean values are represented by the string "1".
deadbeefe702b302017-02-04 12:09:01 -0800157 std::unordered_map<std::string, std::string> parameters;
158
159 // Codec-specific parameters that may optionally be signaled to the remote
160 // party.
161 // TODO(deadbeef): Not implemented.
162 std::unordered_map<std::string, std::string> options;
163
164 // Maximum number of temporal layer extensions supported by this codec.
165 // For example, a value of 1 indicates that 2 total layers are supported.
166 // TODO(deadbeef): Not implemented.
167 int max_temporal_layer_extensions = 0;
168
169 // Maximum number of spatial layer extensions supported by this codec.
170 // For example, a value of 1 indicates that 2 total layers are supported.
171 // TODO(deadbeef): Not implemented.
172 int max_spatial_layer_extensions = 0;
173
174 // Whether the implementation can send/receive SVC layers with distinct
175 // SSRCs. Always false for audio codecs. True for video codecs that support
176 // scalable video coding with MRST.
177 // TODO(deadbeef): Not implemented.
178 bool svc_multi_stream_support = false;
179
180 bool operator==(const RtpCodecCapability& o) const {
181 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
182 preferred_payload_type == o.preferred_payload_type &&
183 max_ptime == o.max_ptime && ptime == o.ptime &&
184 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
185 parameters == o.parameters && options == o.options &&
186 max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
187 max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
188 svc_multi_stream_support == o.svc_multi_stream_support;
189 }
190 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
191};
192
193// Used in RtpCapabilities; represents the capabilities/preferences of an
194// implementation for a header extension.
195//
196// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
197// added here for consistency and to avoid confusion with
198// RtpHeaderExtensionParameters.
199//
200// Note that ORTC includes a "kind" field, but we omit this because it's
201// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
202// you know you're getting audio capabilities.
203struct RtpHeaderExtensionCapability {
Johannes Kron07ba2b92018-09-26 13:33:35 +0200204 // URI of this extension, as defined in RFC8285.
deadbeefe702b302017-02-04 12:09:01 -0800205 std::string uri;
206
207 // Preferred value of ID that goes in the packet.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200208 absl::optional<int> preferred_id;
deadbeefe702b302017-02-04 12:09:01 -0800209
210 // If true, it's preferred that the value in the header is encrypted.
211 // TODO(deadbeef): Not implemented.
212 bool preferred_encrypt = false;
213
deadbeefe814a0d2017-02-25 18:15:09 -0800214 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200215 RtpHeaderExtensionCapability();
216 explicit RtpHeaderExtensionCapability(const std::string& uri);
217 RtpHeaderExtensionCapability(const std::string& uri, int preferred_id);
218 ~RtpHeaderExtensionCapability();
deadbeefe814a0d2017-02-25 18:15:09 -0800219
deadbeefe702b302017-02-04 12:09:01 -0800220 bool operator==(const RtpHeaderExtensionCapability& o) const {
221 return uri == o.uri && preferred_id == o.preferred_id &&
222 preferred_encrypt == o.preferred_encrypt;
223 }
224 bool operator!=(const RtpHeaderExtensionCapability& o) const {
225 return !(*this == o);
226 }
227};
228
Johannes Kron07ba2b92018-09-26 13:33:35 +0200229// RTP header extension, see RFC8285.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200230struct RtpExtension {
231 RtpExtension();
232 RtpExtension(const std::string& uri, int id);
233 RtpExtension(const std::string& uri, int id, bool encrypt);
234 ~RtpExtension();
235 std::string ToString() const;
236 bool operator==(const RtpExtension& rhs) const {
237 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
238 }
239 static bool IsSupportedForAudio(const std::string& uri);
240 static bool IsSupportedForVideo(const std::string& uri);
241 // Return "true" if the given RTP header extension URI may be encrypted.
242 static bool IsEncryptionSupported(const std::string& uri);
243
244 // Returns the named header extension if found among all extensions,
245 // nullptr otherwise.
246 static const RtpExtension* FindHeaderExtensionByUri(
247 const std::vector<RtpExtension>& extensions,
248 const std::string& uri);
249
250 // Return a list of RTP header extensions with the non-encrypted extensions
251 // removed if both the encrypted and non-encrypted extension is present for
252 // the same URI.
253 static std::vector<RtpExtension> FilterDuplicateNonEncrypted(
254 const std::vector<RtpExtension>& extensions);
255
256 // Header extension for audio levels, as defined in:
257 // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
258 static const char kAudioLevelUri[];
259 static const int kAudioLevelDefaultId;
260
261 // Header extension for RTP timestamp offset, see RFC 5450 for details:
262 // http://tools.ietf.org/html/rfc5450
263 static const char kTimestampOffsetUri[];
264 static const int kTimestampOffsetDefaultId;
265
266 // Header extension for absolute send time, see url for details:
267 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
268 static const char kAbsSendTimeUri[];
269 static const int kAbsSendTimeDefaultId;
270
271 // Header extension for coordination of video orientation, see url for
272 // details:
273 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
274 static const char kVideoRotationUri[];
275 static const int kVideoRotationDefaultId;
276
277 // Header extension for video content type. E.g. default or screenshare.
278 static const char kVideoContentTypeUri[];
279 static const int kVideoContentTypeDefaultId;
280
281 // Header extension for video timing.
282 static const char kVideoTimingUri[];
283 static const int kVideoTimingDefaultId;
284
Johnny Leee0c8b232018-09-11 16:50:49 -0400285 // Header extension for video frame marking.
286 static const char kFrameMarkingUri[];
287 static const int kFrameMarkingDefaultId;
288
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200289 // Experimental codec agnostic frame descriptor.
290 static const char kGenericFrameDescriptorUri[];
291 static const int kGenericFrameDescriptorDefaultId;
292
Stefan Holmer1acbd682017-09-01 15:29:28 +0200293 // Header extension for transport sequence number, see url for details:
294 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
295 static const char kTransportSequenceNumberUri[];
296 static const int kTransportSequenceNumberDefaultId;
297
298 static const char kPlayoutDelayUri[];
299 static const int kPlayoutDelayDefaultId;
300
Steve Antonbb50ce52018-03-26 10:24:32 -0700301 // Header extension for identifying media section within a transport.
302 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
303 static const char kMidUri[];
304 static const int kMidDefaultId;
305
Stefan Holmer1acbd682017-09-01 15:29:28 +0200306 // Encryption of Header Extensions, see RFC 6904 for details:
307 // https://tools.ietf.org/html/rfc6904
308 static const char kEncryptHeaderExtensionsUri[];
309
Johannes Kron07ba2b92018-09-26 13:33:35 +0200310 // Inclusive min and max IDs for two-byte header extensions and one-byte
311 // header extensions, per RFC8285 Section 4.2-4.3.
312 static constexpr int kMinId = 1;
313 static constexpr int kMaxId = 255;
Johannes Kron78cdde32018-10-05 10:00:46 +0200314 static constexpr int kMaxValueSize = 255;
Johannes Kron07ba2b92018-09-26 13:33:35 +0200315 static constexpr int kOneByteHeaderExtensionMaxId = 14;
Johannes Kron78cdde32018-10-05 10:00:46 +0200316 static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200317
318 std::string uri;
319 int id = 0;
320 bool encrypt = false;
321};
322
deadbeefe814a0d2017-02-25 18:15:09 -0800323// TODO(deadbeef): This is missing the "encrypt" flag, which is unimplemented.
324typedef RtpExtension RtpHeaderExtensionParameters;
deadbeefe702b302017-02-04 12:09:01 -0800325
326struct RtpFecParameters {
327 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800328 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200329 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800330
331 FecMechanism mechanism = FecMechanism::RED;
332
deadbeefe814a0d2017-02-25 18:15:09 -0800333 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200334 RtpFecParameters();
335 explicit RtpFecParameters(FecMechanism mechanism);
336 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200337 RtpFecParameters(const RtpFecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200338 ~RtpFecParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800339
deadbeefe702b302017-02-04 12:09:01 -0800340 bool operator==(const RtpFecParameters& o) const {
341 return ssrc == o.ssrc && mechanism == o.mechanism;
342 }
343 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
344};
345
346struct RtpRtxParameters {
347 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800348 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200349 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800350
deadbeefe814a0d2017-02-25 18:15:09 -0800351 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200352 RtpRtxParameters();
353 explicit RtpRtxParameters(uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200354 RtpRtxParameters(const RtpRtxParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200355 ~RtpRtxParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800356
deadbeefe702b302017-02-04 12:09:01 -0800357 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
358 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
359};
360
361struct RtpEncodingParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200362 RtpEncodingParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200363 RtpEncodingParameters(const RtpEncodingParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200364 ~RtpEncodingParameters();
365
deadbeefe702b302017-02-04 12:09:01 -0800366 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800367 //
368 // Note that the chosen value is NOT returned by GetParameters, because it
369 // may change due to an SSRC conflict, in which case the conflict is handled
370 // internally without any event. Another way of looking at this is that an
371 // unset SSRC acts as a "wildcard" SSRC.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200372 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800373
374 // Can be used to reference a codec in the |codecs| member of the
375 // RtpParameters that contains this RtpEncodingParameters. If unset, the
deadbeefe814a0d2017-02-25 18:15:09 -0800376 // implementation will choose the first possible codec (if a sender), or
377 // prepare to receive any codec (for a receiver).
378 // TODO(deadbeef): Not implemented. Implementation of RtpSender will always
379 // choose the first codec from the list.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200380 absl::optional<int> codec_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800381
382 // Specifies the FEC mechanism, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800383 // TODO(deadbeef): Not implemented. Current implementation will use whatever
384 // FEC codecs are available, including red+ulpfec.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200385 absl::optional<RtpFecParameters> fec;
deadbeefe702b302017-02-04 12:09:01 -0800386
387 // Specifies the RTX parameters, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800388 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200389 absl::optional<RtpRtxParameters> rtx;
deadbeefe702b302017-02-04 12:09:01 -0800390
391 // Only used for audio. If set, determines whether or not discontinuous
392 // transmission will be used, if an available codec supports it. If not
393 // set, the implementation default setting will be used.
deadbeefe814a0d2017-02-25 18:15:09 -0800394 // TODO(deadbeef): Not implemented. Current implementation will use a CN
395 // codec as long as it's present.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200396 absl::optional<DtxStatus> dtx;
deadbeefe702b302017-02-04 12:09:01 -0800397
Seth Hampson24722b32017-12-22 09:36:42 -0800398 // The relative bitrate priority of this encoding. Currently this is
Seth Hampsona881ac02018-02-12 14:14:39 -0800399 // implemented for the entire rtp sender by using the value of the first
400 // encoding parameter.
401 // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
402 // Currently there is logic for how bitrate is distributed per simulcast layer
403 // in the VideoBitrateAllocator. This must be updated to incorporate relative
404 // bitrate priority.
Seth Hampson24722b32017-12-22 09:36:42 -0800405 double bitrate_priority = kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -0800406
Tim Haloun648d28a2018-10-18 16:52:22 -0700407 // The relative DiffServ Code Point priority for this encoding, allowing
408 // packets to be marked relatively higher or lower without affecting
409 // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ . NB
410 // we follow chromium's translation of the allowed string enum values for
411 // this field to 1.0, 0.5, et cetera, similar to bitrate_priority above.
412 // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
413 double network_priority = kDefaultBitratePriority;
414
Seth Hampsonf209cb52018-02-06 14:28:16 -0800415 // Indicates the preferred duration of media represented by a packet in
416 // milliseconds for this encoding. If set, this will take precedence over the
417 // ptime set in the RtpCodecParameters. This could happen if SDP negotiation
418 // creates a ptime for a specific codec, which is later changed in the
419 // RtpEncodingParameters by the application.
420 // TODO(bugs.webrtc.org/8819): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200421 absl::optional<int> ptime;
Seth Hampsonf209cb52018-02-06 14:28:16 -0800422
deadbeefe702b302017-02-04 12:09:01 -0800423 // If set, this represents the Transport Independent Application Specific
424 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
Seth Hampsona881ac02018-02-12 14:14:39 -0800425 // bitrate. Currently this is implemented for the entire rtp sender by using
426 // the value of the first encoding parameter.
427 //
deadbeefe702b302017-02-04 12:09:01 -0800428 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-25 18:15:09 -0800429 //
430 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
431 // bandwidth for the entire bandwidth estimator (audio and video). This is
432 // just always how "b=AS" was handled, but it's not correct and should be
433 // fixed.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200434 absl::optional<int> max_bitrate_bps;
deadbeefe702b302017-02-04 12:09:01 -0800435
Ã…sa Persson55659812018-06-18 17:51:32 +0200436 // Specifies the minimum bitrate in bps for video.
437 // TODO(asapersson): Not implemented for ORTC API.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200438 absl::optional<int> min_bitrate_bps;
Ã…sa Persson613591a2018-05-29 09:21:31 +0200439
Ã…sa Persson8c1bf952018-09-13 10:42:19 +0200440 // Specifies the maximum framerate in fps for video.
Ã…sa Persson23eba222018-10-02 14:47:06 +0200441 // TODO(asapersson): Different framerates are not supported per simulcast
442 // layer. If set, the maximum |max_framerate| is currently used.
Ã…sa Persson8c1bf952018-09-13 10:42:19 +0200443 // Not supported for screencast.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200444 absl::optional<int> max_framerate;
deadbeefe702b302017-02-04 12:09:01 -0800445
Ã…sa Persson23eba222018-10-02 14:47:06 +0200446 // Specifies the number of temporal layers for video (if the feature is
447 // supported by the codec implementation).
448 // TODO(asapersson): Different number of temporal layers are not supported
449 // per simulcast layer.
450 // Not supported for screencast.
451 absl::optional<int> num_temporal_layers;
452
deadbeefe702b302017-02-04 12:09:01 -0800453 // For video, scale the resolution down by this factor.
454 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200455 absl::optional<double> scale_resolution_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800456
457 // Scale the framerate down by this factor.
458 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200459 absl::optional<double> scale_framerate_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800460
Seth Hampsona881ac02018-02-12 14:14:39 -0800461 // For an RtpSender, set to true to cause this encoding to be encoded and
462 // sent, and false for it not to be encoded and sent. This allows control
463 // across multiple encodings of a sender for turning simulcast layers on and
464 // off.
465 // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
466 // reset, but this isn't necessarily required.
deadbeefdbe2b872016-03-22 15:42:00 -0700467 bool active = true;
deadbeefe702b302017-02-04 12:09:01 -0800468
469 // Value to use for RID RTP header extension.
470 // Called "encodingId" in ORTC.
471 // TODO(deadbeef): Not implemented.
472 std::string rid;
473
474 // RIDs of encodings on which this layer depends.
475 // Called "dependencyEncodingIds" in ORTC spec.
476 // TODO(deadbeef): Not implemented.
477 std::vector<std::string> dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700478
479 bool operator==(const RtpEncodingParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800480 return ssrc == o.ssrc && codec_payload_type == o.codec_payload_type &&
481 fec == o.fec && rtx == o.rtx && dtx == o.dtx &&
Tim Haloun648d28a2018-10-18 16:52:22 -0700482 bitrate_priority == o.bitrate_priority &&
483 network_priority == o.network_priority && ptime == o.ptime &&
Seth Hampson24722b32017-12-22 09:36:42 -0800484 max_bitrate_bps == o.max_bitrate_bps &&
Ã…sa Persson8c1bf952018-09-13 10:42:19 +0200485 min_bitrate_bps == o.min_bitrate_bps &&
deadbeefe702b302017-02-04 12:09:01 -0800486 max_framerate == o.max_framerate &&
Ã…sa Persson23eba222018-10-02 14:47:06 +0200487 num_temporal_layers == o.num_temporal_layers &&
deadbeefe702b302017-02-04 12:09:01 -0800488 scale_resolution_down_by == o.scale_resolution_down_by &&
489 scale_framerate_down_by == o.scale_framerate_down_by &&
490 active == o.active && rid == o.rid &&
491 dependency_rids == o.dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700492 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700493 bool operator!=(const RtpEncodingParameters& o) const {
494 return !(*this == o);
495 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700496};
497
498struct RtpCodecParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200499 RtpCodecParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200500 RtpCodecParameters(const RtpCodecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200501 ~RtpCodecParameters();
502
deadbeefe702b302017-02-04 12:09:01 -0800503 // Build MIME "type/subtype" string from |name| and |kind|.
504 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
505
506 // Used to identify the codec. Equivalent to MIME subtype.
507 std::string name;
508
509 // The media type of this codec. Equivalent to MIME top-level type.
510 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
511
512 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-25 18:15:09 -0800513 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 12:09:01 -0800514 // the same transport.
515 int payload_type = 0;
516
517 // If unset, the implementation default is used.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200518 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800519
520 // The number of audio channels used. Unset for video codecs. If unset for
521 // audio, the implementation default is used.
deadbeefe814a0d2017-02-25 18:15:09 -0800522 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
523 // Only defaults to 1, even though some codecs (such as opus) should really
524 // default to 2.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200525 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800526
527 // The maximum packetization time to be used by an RtpSender.
528 // If |ptime| is also set, this will be ignored.
529 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200530 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800531
532 // The packetization time to be used by an RtpSender.
533 // If unset, will use any time up to max_ptime.
534 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200535 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800536
537 // Feedback mechanisms to be used for this codec.
deadbeefe814a0d2017-02-25 18:15:09 -0800538 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800539 std::vector<RtcpFeedback> rtcp_feedback;
540
541 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800542 //
deadbeefe702b302017-02-04 12:09:01 -0800543 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800544 //
545 // Contrary to ORTC, these parameters are named using all lowercase strings.
546 // This helps make the mapping to SDP simpler, if an application is using
547 // SDP. Boolean values are represented by the string "1".
deadbeefe702b302017-02-04 12:09:01 -0800548 std::unordered_map<std::string, std::string> parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700549
550 bool operator==(const RtpCodecParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800551 return name == o.name && kind == o.kind && payload_type == o.payload_type &&
552 clock_rate == o.clock_rate && num_channels == o.num_channels &&
553 max_ptime == o.max_ptime && ptime == o.ptime &&
554 rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700555 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700556 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700557};
558
deadbeefe702b302017-02-04 12:09:01 -0800559// RtpCapabilities is used to represent the static capabilities of an
560// endpoint. An application can use these capabilities to construct an
561// RtpParameters.
562struct RtpCapabilities {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200563 RtpCapabilities();
564 ~RtpCapabilities();
565
deadbeefe702b302017-02-04 12:09:01 -0800566 // Supported codecs.
567 std::vector<RtpCodecCapability> codecs;
568
569 // Supported RTP header extensions.
570 std::vector<RtpHeaderExtensionCapability> header_extensions;
571
deadbeefe814a0d2017-02-25 18:15:09 -0800572 // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
573 // ulpfec and flexfec codecs used by these mechanisms will still appear in
574 // |codecs|.
deadbeefe702b302017-02-04 12:09:01 -0800575 std::vector<FecMechanism> fec;
576
577 bool operator==(const RtpCapabilities& o) const {
578 return codecs == o.codecs && header_extensions == o.header_extensions &&
579 fec == o.fec;
580 }
581 bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
582};
583
Florent Castellidacec712018-05-24 16:24:21 +0200584struct RtcpParameters final {
585 RtcpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200586 RtcpParameters(const RtcpParameters&);
Florent Castellidacec712018-05-24 16:24:21 +0200587 ~RtcpParameters();
588
589 // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
590 // will be chosen by the implementation.
591 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200592 absl::optional<uint32_t> ssrc;
Florent Castellidacec712018-05-24 16:24:21 +0200593
594 // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
595 //
596 // If empty in the construction of the RtpTransport, one will be generated by
597 // the implementation, and returned in GetRtcpParameters. Multiple
598 // RtpTransports created by the same OrtcFactory will use the same generated
599 // CNAME.
600 //
601 // If empty when passed into SetParameters, the CNAME simply won't be
602 // modified.
603 std::string cname;
604
605 // Send reduced-size RTCP?
606 bool reduced_size = false;
607
608 // Send RTCP multiplexed on the RTP transport?
609 // Not used with PeerConnection senders/receivers
610 bool mux = true;
611
612 bool operator==(const RtcpParameters& o) const {
613 return ssrc == o.ssrc && cname == o.cname &&
614 reduced_size == o.reduced_size && mux == o.mux;
615 }
616 bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
617};
618
skvladdc1c62c2016-03-16 19:07:43 -0700619struct RtpParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200620 RtpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200621 RtpParameters(const RtpParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200622 ~RtpParameters();
623
deadbeefe702b302017-02-04 12:09:01 -0800624 // Used when calling getParameters/setParameters with a PeerConnection
625 // RtpSender, to ensure that outdated parameters are not unintentionally
626 // applied successfully.
deadbeefe702b302017-02-04 12:09:01 -0800627 std::string transaction_id;
628
629 // Value to use for MID RTP header extension.
630 // Called "muxId" in ORTC.
631 // TODO(deadbeef): Not implemented.
632 std::string mid;
633
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700634 std::vector<RtpCodecParameters> codecs;
635
deadbeefe702b302017-02-04 12:09:01 -0800636 std::vector<RtpHeaderExtensionParameters> header_extensions;
637
638 std::vector<RtpEncodingParameters> encodings;
639
Florent Castellidacec712018-05-24 16:24:21 +0200640 // Only available with a Peerconnection RtpSender.
641 // In ORTC, our API includes an additional "RtpTransport"
642 // abstraction on which RTCP parameters are set.
643 RtcpParameters rtcp;
644
Florent Castelli87b3c512018-07-18 16:00:28 +0200645 // When bandwidth is constrained and the RtpSender needs to choose between
646 // degrading resolution or degrading framerate, degradationPreference
647 // indicates which is preferred. Only for video tracks.
deadbeefe702b302017-02-04 12:09:01 -0800648 DegradationPreference degradation_preference =
649 DegradationPreference::BALANCED;
650
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700651 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800652 return mid == o.mid && codecs == o.codecs &&
653 header_extensions == o.header_extensions &&
Florent Castellidacec712018-05-24 16:24:21 +0200654 encodings == o.encodings && rtcp == o.rtcp &&
deadbeefe702b302017-02-04 12:09:01 -0800655 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700656 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700657 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700658};
659
660} // namespace webrtc
661
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200662#endif // API_RTPPARAMETERS_H_