blob: ab7e52f3ff542bf3d37f1b501a2c83c2e561a63e [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
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef API_RTP_PARAMETERS_H_
12#define API_RTP_PARAMETERS_H_
skvladdc1c62c2016-03-16 19:07:43 -070013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stdint.h>
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -070015#include <string>
deadbeefe702b302017-02-04 12:09:01 -080016#include <unordered_map>
skvladdc1c62c2016-03-16 19:07:43 -070017#include <vector>
18
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020019#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/media_types.h"
Mirko Bonadeiac194142018-10-22 17:08:37 +020021#include "rtc_base/system/rtc_export.h"
sakal1fd95952016-06-22 00:46:15 -070022
skvladdc1c62c2016-03-16 19:07:43 -070023namespace webrtc {
24
deadbeefe702b302017-02-04 12:09:01 -080025// These structures are intended to mirror those defined by:
26// http://draft.ortc.org/#rtcrtpdictionaries*
27// Contains everything specified as of 2017 Jan 24.
28//
29// They are used when retrieving or modifying the parameters of an
30// RtpSender/RtpReceiver, or retrieving capabilities.
31//
32// Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
33// types, we typically use "int", in keeping with our style guidelines. The
34// parameter's actual valid range will be enforced when the parameters are set,
35// rather than when the parameters struct is built. An exception is made for
36// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
37// be used for any numeric comparisons/operations.
38//
39// Additionally, where ORTC uses strings, we may use enums for things that have
40// a fixed number of supported values. However, for things that can be extended
41// (such as codecs, by providing an external encoder factory), a string
42// identifier is used.
43
44enum class FecMechanism {
45 RED,
46 RED_AND_ULPFEC,
47 FLEXFEC,
48};
49
50// Used in RtcpFeedback struct.
51enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 12:09:01 -080052 CCM,
Elad Alonfadb1812019-05-24 13:40:02 +020053 LNTF, // "goog-lntf"
deadbeefe702b302017-02-04 12:09:01 -080054 NACK,
55 REMB, // "goog-remb"
56 TRANSPORT_CC,
57};
58
deadbeefe814a0d2017-02-25 18:15:09 -080059// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 12:09:01 -080060enum class RtcpFeedbackMessageType {
61 // Equivalent to {type: "nack", parameter: undefined} in ORTC.
62 GENERIC_NACK,
63 PLI, // Usable with NACK.
64 FIR, // Usable with CCM.
65};
66
67enum class DtxStatus {
68 DISABLED,
69 ENABLED,
70};
71
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070072// Based on the spec in
73// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
74// These options are enforced on a best-effort basis. For instance, all of
75// these options may suffer some frame drops in order to avoid queuing.
76// TODO(sprang): Look into possibility of more strictly enforcing the
77// maintain-framerate option.
78// TODO(deadbeef): Default to "balanced", as the spec indicates?
deadbeefe702b302017-02-04 12:09:01 -080079enum class DegradationPreference {
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070080 // Don't take any actions based on over-utilization signals. Not part of the
81 // web API.
82 DISABLED,
83 // On over-use, request lower frame rate, possibly causing frame drops.
deadbeefe702b302017-02-04 12:09:01 -080084 MAINTAIN_FRAMERATE,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070085 // On over-use, request lower resolution, possibly causing down-scaling.
deadbeefe702b302017-02-04 12:09:01 -080086 MAINTAIN_RESOLUTION,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070087 // Try to strike a "pleasing" balance between frame rate or resolution.
deadbeefe702b302017-02-04 12:09:01 -080088 BALANCED,
89};
90
Mirko Bonadei66e76792019-04-02 11:33:59 +020091RTC_EXPORT extern const double kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -080092
93struct RtcpFeedback {
deadbeefe814a0d2017-02-25 18:15:09 -080094 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 12:09:01 -080095
96 // Equivalent to ORTC "parameter" field with slight differences:
97 // 1. It's an enum instead of a string.
98 // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
99 // rather than an unset "parameter" value.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200100 absl::optional<RtcpFeedbackMessageType> message_type;
deadbeefe702b302017-02-04 12:09:01 -0800101
deadbeefe814a0d2017-02-25 18:15:09 -0800102 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200103 RtcpFeedback();
104 explicit RtcpFeedback(RtcpFeedbackType type);
105 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200106 RtcpFeedback(const RtcpFeedback&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200107 ~RtcpFeedback();
deadbeefe814a0d2017-02-25 18:15:09 -0800108
deadbeefe702b302017-02-04 12:09:01 -0800109 bool operator==(const RtcpFeedback& o) const {
110 return type == o.type && message_type == o.message_type;
111 }
112 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
113};
114
115// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
116// RtpParameters. This represents the static capabilities of an endpoint's
117// implementation of a codec.
118struct RtpCodecCapability {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200119 RtpCodecCapability();
120 ~RtpCodecCapability();
121
deadbeefe702b302017-02-04 12:09:01 -0800122 // Build MIME "type/subtype" string from |name| and |kind|.
123 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
124
125 // Used to identify the codec. Equivalent to MIME subtype.
126 std::string name;
127
128 // The media type of this codec. Equivalent to MIME top-level type.
129 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
130
131 // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200132 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800133
134 // Default payload type for this codec. Mainly needed for codecs that use
135 // that have statically assigned payload types.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200136 absl::optional<int> preferred_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800137
138 // Maximum packetization time supported by an RtpReceiver for this codec.
139 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200140 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800141
142 // Preferred packetization time for an RtpReceiver or RtpSender of this
143 // codec.
144 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200145 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800146
147 // The number of audio channels supported. Unused for video codecs.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200148 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800149
150 // Feedback mechanisms supported for this codec.
151 std::vector<RtcpFeedback> rtcp_feedback;
152
153 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800154 //
deadbeefe702b302017-02-04 12:09:01 -0800155 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800156 //
157 // Contrary to ORTC, these parameters are named using all lowercase strings.
158 // This helps make the mapping to SDP simpler, if an application is using
159 // SDP. Boolean values are represented by the string "1".
deadbeefe702b302017-02-04 12:09:01 -0800160 std::unordered_map<std::string, std::string> parameters;
161
162 // Codec-specific parameters that may optionally be signaled to the remote
163 // party.
164 // TODO(deadbeef): Not implemented.
165 std::unordered_map<std::string, std::string> options;
166
167 // Maximum number of temporal layer extensions supported by this codec.
168 // For example, a value of 1 indicates that 2 total layers are supported.
169 // TODO(deadbeef): Not implemented.
170 int max_temporal_layer_extensions = 0;
171
172 // Maximum number of spatial layer extensions supported by this codec.
173 // For example, a value of 1 indicates that 2 total layers are supported.
174 // TODO(deadbeef): Not implemented.
175 int max_spatial_layer_extensions = 0;
176
177 // Whether the implementation can send/receive SVC layers with distinct
178 // SSRCs. Always false for audio codecs. True for video codecs that support
179 // scalable video coding with MRST.
180 // TODO(deadbeef): Not implemented.
181 bool svc_multi_stream_support = false;
182
183 bool operator==(const RtpCodecCapability& o) const {
184 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
185 preferred_payload_type == o.preferred_payload_type &&
186 max_ptime == o.max_ptime && ptime == o.ptime &&
187 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
188 parameters == o.parameters && options == o.options &&
189 max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
190 max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
191 svc_multi_stream_support == o.svc_multi_stream_support;
192 }
193 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
194};
195
196// Used in RtpCapabilities; represents the capabilities/preferences of an
197// implementation for a header extension.
198//
199// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
200// added here for consistency and to avoid confusion with
201// RtpHeaderExtensionParameters.
202//
203// Note that ORTC includes a "kind" field, but we omit this because it's
204// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
205// you know you're getting audio capabilities.
206struct RtpHeaderExtensionCapability {
Johannes Kron07ba2b92018-09-26 13:33:35 +0200207 // URI of this extension, as defined in RFC8285.
deadbeefe702b302017-02-04 12:09:01 -0800208 std::string uri;
209
210 // Preferred value of ID that goes in the packet.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200211 absl::optional<int> preferred_id;
deadbeefe702b302017-02-04 12:09:01 -0800212
213 // If true, it's preferred that the value in the header is encrypted.
214 // TODO(deadbeef): Not implemented.
215 bool preferred_encrypt = false;
216
deadbeefe814a0d2017-02-25 18:15:09 -0800217 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200218 RtpHeaderExtensionCapability();
219 explicit RtpHeaderExtensionCapability(const std::string& uri);
220 RtpHeaderExtensionCapability(const std::string& uri, int preferred_id);
221 ~RtpHeaderExtensionCapability();
deadbeefe814a0d2017-02-25 18:15:09 -0800222
deadbeefe702b302017-02-04 12:09:01 -0800223 bool operator==(const RtpHeaderExtensionCapability& o) const {
224 return uri == o.uri && preferred_id == o.preferred_id &&
225 preferred_encrypt == o.preferred_encrypt;
226 }
227 bool operator!=(const RtpHeaderExtensionCapability& o) const {
228 return !(*this == o);
229 }
230};
231
Johannes Kron07ba2b92018-09-26 13:33:35 +0200232// RTP header extension, see RFC8285.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200233struct RtpExtension {
234 RtpExtension();
235 RtpExtension(const std::string& uri, int id);
236 RtpExtension(const std::string& uri, int id, bool encrypt);
237 ~RtpExtension();
238 std::string ToString() const;
239 bool operator==(const RtpExtension& rhs) const {
240 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
241 }
242 static bool IsSupportedForAudio(const std::string& uri);
243 static bool IsSupportedForVideo(const std::string& uri);
244 // Return "true" if the given RTP header extension URI may be encrypted.
245 static bool IsEncryptionSupported(const std::string& uri);
246
247 // Returns the named header extension if found among all extensions,
248 // nullptr otherwise.
249 static const RtpExtension* FindHeaderExtensionByUri(
250 const std::vector<RtpExtension>& extensions,
251 const std::string& uri);
252
253 // Return a list of RTP header extensions with the non-encrypted extensions
254 // removed if both the encrypted and non-encrypted extension is present for
255 // the same URI.
256 static std::vector<RtpExtension> FilterDuplicateNonEncrypted(
257 const std::vector<RtpExtension>& extensions);
258
259 // Header extension for audio levels, as defined in:
260 // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
261 static const char kAudioLevelUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200262
263 // Header extension for RTP timestamp offset, see RFC 5450 for details:
264 // http://tools.ietf.org/html/rfc5450
265 static const char kTimestampOffsetUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200266
267 // Header extension for absolute send time, see url for details:
268 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
269 static const char kAbsSendTimeUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200270
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[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200275
276 // Header extension for video content type. E.g. default or screenshare.
277 static const char kVideoContentTypeUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200278
279 // Header extension for video timing.
280 static const char kVideoTimingUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200281
Johnny Leee0c8b232018-09-11 16:50:49 -0400282 // Header extension for video frame marking.
283 static const char kFrameMarkingUri[];
Johnny Leee0c8b232018-09-11 16:50:49 -0400284
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200285 // Experimental codec agnostic frame descriptor.
Elad Alonccb9b752019-02-19 13:01:31 +0100286 static const char kGenericFrameDescriptorUri00[];
287 static const char kGenericFrameDescriptorUri01[];
288 // TODO(bugs.webrtc.org/10243): Remove once dependencies have been updated.
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200289 static const char kGenericFrameDescriptorUri[];
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200290
Stefan Holmer1acbd682017-09-01 15:29:28 +0200291 // Header extension for transport sequence number, see url for details:
292 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
293 static const char kTransportSequenceNumberUri[];
Johannes Kron7ff164e2019-02-07 12:50:18 +0100294 static const char kTransportSequenceNumberV2Uri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200295
296 static const char kPlayoutDelayUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200297
Steve Antonbb50ce52018-03-26 10:24:32 -0700298 // Header extension for identifying media section within a transport.
299 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
300 static const char kMidUri[];
Steve Antonbb50ce52018-03-26 10:24:32 -0700301
Stefan Holmer1acbd682017-09-01 15:29:28 +0200302 // Encryption of Header Extensions, see RFC 6904 for details:
303 // https://tools.ietf.org/html/rfc6904
304 static const char kEncryptHeaderExtensionsUri[];
305
Johannes Krond0b69a82018-12-03 14:18:53 +0100306 // Header extension for color space information.
307 static const char kColorSpaceUri[];
Johannes Krond0b69a82018-12-03 14:18:53 +0100308
Amit Hilbuch77938e62018-12-21 09:23:38 -0800309 // Header extension for RIDs and Repaired RIDs
310 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
311 // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
312 static const char kRidUri[];
Amit Hilbuch77938e62018-12-21 09:23:38 -0800313 static const char kRepairedRidUri[];
Amit Hilbuch77938e62018-12-21 09:23:38 -0800314
Johannes Kron07ba2b92018-09-26 13:33:35 +0200315 // Inclusive min and max IDs for two-byte header extensions and one-byte
316 // header extensions, per RFC8285 Section 4.2-4.3.
317 static constexpr int kMinId = 1;
318 static constexpr int kMaxId = 255;
Johannes Kron78cdde32018-10-05 10:00:46 +0200319 static constexpr int kMaxValueSize = 255;
Johannes Kron07ba2b92018-09-26 13:33:35 +0200320 static constexpr int kOneByteHeaderExtensionMaxId = 14;
Johannes Kron78cdde32018-10-05 10:00:46 +0200321 static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200322
323 std::string uri;
324 int id = 0;
325 bool encrypt = false;
326};
327
deadbeefe814a0d2017-02-25 18:15:09 -0800328// TODO(deadbeef): This is missing the "encrypt" flag, which is unimplemented.
329typedef RtpExtension RtpHeaderExtensionParameters;
deadbeefe702b302017-02-04 12:09:01 -0800330
331struct RtpFecParameters {
332 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800333 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200334 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800335
336 FecMechanism mechanism = FecMechanism::RED;
337
deadbeefe814a0d2017-02-25 18:15:09 -0800338 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200339 RtpFecParameters();
340 explicit RtpFecParameters(FecMechanism mechanism);
341 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200342 RtpFecParameters(const RtpFecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200343 ~RtpFecParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800344
deadbeefe702b302017-02-04 12:09:01 -0800345 bool operator==(const RtpFecParameters& o) const {
346 return ssrc == o.ssrc && mechanism == o.mechanism;
347 }
348 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
349};
350
351struct RtpRtxParameters {
352 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800353 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200354 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800355
deadbeefe814a0d2017-02-25 18:15:09 -0800356 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200357 RtpRtxParameters();
358 explicit RtpRtxParameters(uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200359 RtpRtxParameters(const RtpRtxParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200360 ~RtpRtxParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800361
deadbeefe702b302017-02-04 12:09:01 -0800362 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
363 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
364};
365
Mirko Bonadei66e76792019-04-02 11:33:59 +0200366struct RTC_EXPORT RtpEncodingParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200367 RtpEncodingParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200368 RtpEncodingParameters(const RtpEncodingParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200369 ~RtpEncodingParameters();
370
deadbeefe702b302017-02-04 12:09:01 -0800371 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800372 //
373 // Note that the chosen value is NOT returned by GetParameters, because it
374 // may change due to an SSRC conflict, in which case the conflict is handled
375 // internally without any event. Another way of looking at this is that an
376 // unset SSRC acts as a "wildcard" SSRC.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200377 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800378
Henrik Grunelle1301a82018-12-13 12:13:22 +0000379 // Can be used to reference a codec in the |codecs| member of the
380 // RtpParameters that contains this RtpEncodingParameters. If unset, the
381 // implementation will choose the first possible codec (if a sender), or
382 // prepare to receive any codec (for a receiver).
383 // TODO(deadbeef): Not implemented. Implementation of RtpSender will always
384 // choose the first codec from the list.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200385 absl::optional<int> codec_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800386
387 // Specifies the FEC mechanism, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800388 // TODO(deadbeef): Not implemented. Current implementation will use whatever
389 // FEC codecs are available, including red+ulpfec.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200390 absl::optional<RtpFecParameters> fec;
deadbeefe702b302017-02-04 12:09:01 -0800391
392 // Specifies the RTX parameters, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800393 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200394 absl::optional<RtpRtxParameters> rtx;
deadbeefe702b302017-02-04 12:09:01 -0800395
396 // Only used for audio. If set, determines whether or not discontinuous
397 // transmission will be used, if an available codec supports it. If not
398 // set, the implementation default setting will be used.
deadbeefe814a0d2017-02-25 18:15:09 -0800399 // TODO(deadbeef): Not implemented. Current implementation will use a CN
400 // codec as long as it's present.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200401 absl::optional<DtxStatus> dtx;
deadbeefe702b302017-02-04 12:09:01 -0800402
Seth Hampson24722b32017-12-22 09:36:42 -0800403 // The relative bitrate priority of this encoding. Currently this is
Seth Hampsona881ac02018-02-12 14:14:39 -0800404 // implemented for the entire rtp sender by using the value of the first
405 // encoding parameter.
406 // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
407 // Currently there is logic for how bitrate is distributed per simulcast layer
408 // in the VideoBitrateAllocator. This must be updated to incorporate relative
409 // bitrate priority.
Seth Hampson24722b32017-12-22 09:36:42 -0800410 double bitrate_priority = kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -0800411
Tim Haloun648d28a2018-10-18 16:52:22 -0700412 // The relative DiffServ Code Point priority for this encoding, allowing
413 // packets to be marked relatively higher or lower without affecting
414 // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ . NB
415 // we follow chromium's translation of the allowed string enum values for
416 // this field to 1.0, 0.5, et cetera, similar to bitrate_priority above.
417 // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
418 double network_priority = kDefaultBitratePriority;
419
Seth Hampsonf209cb52018-02-06 14:28:16 -0800420 // Indicates the preferred duration of media represented by a packet in
421 // milliseconds for this encoding. If set, this will take precedence over the
422 // ptime set in the RtpCodecParameters. This could happen if SDP negotiation
423 // creates a ptime for a specific codec, which is later changed in the
424 // RtpEncodingParameters by the application.
425 // TODO(bugs.webrtc.org/8819): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200426 absl::optional<int> ptime;
Seth Hampsonf209cb52018-02-06 14:28:16 -0800427
deadbeefe702b302017-02-04 12:09:01 -0800428 // If set, this represents the Transport Independent Application Specific
429 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
Seth Hampsona881ac02018-02-12 14:14:39 -0800430 // bitrate. Currently this is implemented for the entire rtp sender by using
431 // the value of the first encoding parameter.
432 //
deadbeefe702b302017-02-04 12:09:01 -0800433 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-25 18:15:09 -0800434 //
435 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
436 // bandwidth for the entire bandwidth estimator (audio and video). This is
437 // just always how "b=AS" was handled, but it's not correct and should be
438 // fixed.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200439 absl::optional<int> max_bitrate_bps;
deadbeefe702b302017-02-04 12:09:01 -0800440
Ã…sa Persson55659812018-06-18 17:51:32 +0200441 // Specifies the minimum bitrate in bps for video.
442 // TODO(asapersson): Not implemented for ORTC API.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200443 absl::optional<int> min_bitrate_bps;
Ã…sa Persson613591a2018-05-29 09:21:31 +0200444
Ã…sa Persson8c1bf952018-09-13 10:42:19 +0200445 // Specifies the maximum framerate in fps for video.
Ã…sa Persson23eba222018-10-02 14:47:06 +0200446 // TODO(asapersson): Different framerates are not supported per simulcast
447 // layer. If set, the maximum |max_framerate| is currently used.
Ã…sa Persson8c1bf952018-09-13 10:42:19 +0200448 // Not supported for screencast.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200449 absl::optional<int> max_framerate;
deadbeefe702b302017-02-04 12:09:01 -0800450
Ã…sa Persson23eba222018-10-02 14:47:06 +0200451 // Specifies the number of temporal layers for video (if the feature is
452 // supported by the codec implementation).
453 // TODO(asapersson): Different number of temporal layers are not supported
454 // per simulcast layer.
Ilya Nikolaevskiy9f6a0d52019-02-05 10:29:41 +0100455 // Screencast support is experimental.
Ã…sa Persson23eba222018-10-02 14:47:06 +0200456 absl::optional<int> num_temporal_layers;
457
deadbeefe702b302017-02-04 12:09:01 -0800458 // For video, scale the resolution down by this factor.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200459 absl::optional<double> scale_resolution_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800460
461 // Scale the framerate down by this factor.
462 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200463 absl::optional<double> scale_framerate_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800464
Seth Hampsona881ac02018-02-12 14:14:39 -0800465 // For an RtpSender, set to true to cause this encoding to be encoded and
466 // sent, and false for it not to be encoded and sent. This allows control
467 // across multiple encodings of a sender for turning simulcast layers on and
468 // off.
469 // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
470 // reset, but this isn't necessarily required.
deadbeefdbe2b872016-03-22 15:42:00 -0700471 bool active = true;
deadbeefe702b302017-02-04 12:09:01 -0800472
473 // Value to use for RID RTP header extension.
474 // Called "encodingId" in ORTC.
deadbeefe702b302017-02-04 12:09:01 -0800475 std::string rid;
476
477 // RIDs of encodings on which this layer depends.
478 // Called "dependencyEncodingIds" in ORTC spec.
479 // TODO(deadbeef): Not implemented.
480 std::vector<std::string> dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700481
482 bool operator==(const RtpEncodingParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800483 return ssrc == o.ssrc && codec_payload_type == o.codec_payload_type &&
484 fec == o.fec && rtx == o.rtx && dtx == o.dtx &&
Tim Haloun648d28a2018-10-18 16:52:22 -0700485 bitrate_priority == o.bitrate_priority &&
486 network_priority == o.network_priority && ptime == o.ptime &&
Seth Hampson24722b32017-12-22 09:36:42 -0800487 max_bitrate_bps == o.max_bitrate_bps &&
Ã…sa Persson8c1bf952018-09-13 10:42:19 +0200488 min_bitrate_bps == o.min_bitrate_bps &&
deadbeefe702b302017-02-04 12:09:01 -0800489 max_framerate == o.max_framerate &&
Ã…sa Persson23eba222018-10-02 14:47:06 +0200490 num_temporal_layers == o.num_temporal_layers &&
deadbeefe702b302017-02-04 12:09:01 -0800491 scale_resolution_down_by == o.scale_resolution_down_by &&
492 scale_framerate_down_by == o.scale_framerate_down_by &&
493 active == o.active && rid == o.rid &&
494 dependency_rids == o.dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700495 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700496 bool operator!=(const RtpEncodingParameters& o) const {
497 return !(*this == o);
498 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700499};
500
501struct RtpCodecParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200502 RtpCodecParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200503 RtpCodecParameters(const RtpCodecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200504 ~RtpCodecParameters();
505
deadbeefe702b302017-02-04 12:09:01 -0800506 // Build MIME "type/subtype" string from |name| and |kind|.
507 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
508
509 // Used to identify the codec. Equivalent to MIME subtype.
510 std::string name;
511
512 // The media type of this codec. Equivalent to MIME top-level type.
513 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
514
515 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-25 18:15:09 -0800516 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 12:09:01 -0800517 // the same transport.
518 int payload_type = 0;
519
520 // If unset, the implementation default is used.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200521 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800522
523 // The number of audio channels used. Unset for video codecs. If unset for
524 // audio, the implementation default is used.
deadbeefe814a0d2017-02-25 18:15:09 -0800525 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
526 // Only defaults to 1, even though some codecs (such as opus) should really
527 // default to 2.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200528 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800529
530 // The maximum packetization time to be used by an RtpSender.
531 // If |ptime| is also set, this will be ignored.
532 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200533 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800534
535 // The packetization time to be used by an RtpSender.
536 // If unset, will use any time up to max_ptime.
537 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200538 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800539
540 // Feedback mechanisms to be used for this codec.
deadbeefe814a0d2017-02-25 18:15:09 -0800541 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800542 std::vector<RtcpFeedback> rtcp_feedback;
543
544 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800545 //
deadbeefe702b302017-02-04 12:09:01 -0800546 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800547 //
548 // Contrary to ORTC, these parameters are named using all lowercase strings.
549 // This helps make the mapping to SDP simpler, if an application is using
550 // SDP. Boolean values are represented by the string "1".
deadbeefe702b302017-02-04 12:09:01 -0800551 std::unordered_map<std::string, std::string> parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700552
553 bool operator==(const RtpCodecParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800554 return name == o.name && kind == o.kind && payload_type == o.payload_type &&
555 clock_rate == o.clock_rate && num_channels == o.num_channels &&
556 max_ptime == o.max_ptime && ptime == o.ptime &&
557 rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700558 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700559 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700560};
561
deadbeefe702b302017-02-04 12:09:01 -0800562// RtpCapabilities is used to represent the static capabilities of an
563// endpoint. An application can use these capabilities to construct an
564// RtpParameters.
Mirko Bonadei66e76792019-04-02 11:33:59 +0200565struct RTC_EXPORT RtpCapabilities {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200566 RtpCapabilities();
567 ~RtpCapabilities();
568
deadbeefe702b302017-02-04 12:09:01 -0800569 // Supported codecs.
570 std::vector<RtpCodecCapability> codecs;
571
572 // Supported RTP header extensions.
573 std::vector<RtpHeaderExtensionCapability> header_extensions;
574
deadbeefe814a0d2017-02-25 18:15:09 -0800575 // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
576 // ulpfec and flexfec codecs used by these mechanisms will still appear in
577 // |codecs|.
deadbeefe702b302017-02-04 12:09:01 -0800578 std::vector<FecMechanism> fec;
579
580 bool operator==(const RtpCapabilities& o) const {
581 return codecs == o.codecs && header_extensions == o.header_extensions &&
582 fec == o.fec;
583 }
584 bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
585};
586
Florent Castellidacec712018-05-24 16:24:21 +0200587struct RtcpParameters final {
588 RtcpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200589 RtcpParameters(const RtcpParameters&);
Florent Castellidacec712018-05-24 16:24:21 +0200590 ~RtcpParameters();
591
592 // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
593 // will be chosen by the implementation.
594 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200595 absl::optional<uint32_t> ssrc;
Florent Castellidacec712018-05-24 16:24:21 +0200596
597 // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
598 //
599 // If empty in the construction of the RtpTransport, one will be generated by
600 // the implementation, and returned in GetRtcpParameters. Multiple
601 // RtpTransports created by the same OrtcFactory will use the same generated
602 // CNAME.
603 //
604 // If empty when passed into SetParameters, the CNAME simply won't be
605 // modified.
606 std::string cname;
607
608 // Send reduced-size RTCP?
609 bool reduced_size = false;
610
611 // Send RTCP multiplexed on the RTP transport?
612 // Not used with PeerConnection senders/receivers
613 bool mux = true;
614
615 bool operator==(const RtcpParameters& o) const {
616 return ssrc == o.ssrc && cname == o.cname &&
617 reduced_size == o.reduced_size && mux == o.mux;
618 }
619 bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
620};
621
Mirko Bonadeiac194142018-10-22 17:08:37 +0200622struct RTC_EXPORT RtpParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200623 RtpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200624 RtpParameters(const RtpParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200625 ~RtpParameters();
626
deadbeefe702b302017-02-04 12:09:01 -0800627 // Used when calling getParameters/setParameters with a PeerConnection
628 // RtpSender, to ensure that outdated parameters are not unintentionally
629 // applied successfully.
deadbeefe702b302017-02-04 12:09:01 -0800630 std::string transaction_id;
631
632 // Value to use for MID RTP header extension.
633 // Called "muxId" in ORTC.
634 // TODO(deadbeef): Not implemented.
635 std::string mid;
636
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700637 std::vector<RtpCodecParameters> codecs;
638
deadbeefe702b302017-02-04 12:09:01 -0800639 std::vector<RtpHeaderExtensionParameters> header_extensions;
640
641 std::vector<RtpEncodingParameters> encodings;
642
Florent Castellidacec712018-05-24 16:24:21 +0200643 // Only available with a Peerconnection RtpSender.
644 // In ORTC, our API includes an additional "RtpTransport"
645 // abstraction on which RTCP parameters are set.
646 RtcpParameters rtcp;
647
Florent Castelli87b3c512018-07-18 16:00:28 +0200648 // When bandwidth is constrained and the RtpSender needs to choose between
649 // degrading resolution or degrading framerate, degradationPreference
650 // indicates which is preferred. Only for video tracks.
deadbeefe702b302017-02-04 12:09:01 -0800651 DegradationPreference degradation_preference =
652 DegradationPreference::BALANCED;
653
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700654 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800655 return mid == o.mid && codecs == o.codecs &&
656 header_extensions == o.header_extensions &&
Florent Castellidacec712018-05-24 16:24:21 +0200657 encodings == o.encodings && rtcp == o.rtcp &&
deadbeefe702b302017-02-04 12:09:01 -0800658 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700659 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700660 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700661};
662
663} // namespace webrtc
664
Steve Anton10542f22019-01-11 09:11:00 -0800665#endif // API_RTP_PARAMETERS_H_