blob: 49c1e0c8852d825f9b8bf8581c70d4a147805224 [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>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Johannes Kron72d69152020-02-10 14:05:55 +010016#include <map>
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -070017#include <string>
skvladdc1c62c2016-03-16 19:07:43 -070018#include <vector>
19
Markus Handelldfeb0df2020-03-16 22:20:47 +010020#include "absl/strings/string_view.h"
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020021#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "api/media_types.h"
Markus Handell0357b3e2020-03-16 13:40:51 +010023#include "api/rtp_transceiver_direction.h"
Mirko Bonadeiac194142018-10-22 17:08:37 +020024#include "rtc_base/system/rtc_export.h"
sakal1fd95952016-06-22 00:46:15 -070025
skvladdc1c62c2016-03-16 19:07:43 -070026namespace webrtc {
27
deadbeefe702b302017-02-04 12:09:01 -080028// These structures are intended to mirror those defined by:
29// http://draft.ortc.org/#rtcrtpdictionaries*
30// Contains everything specified as of 2017 Jan 24.
31//
32// They are used when retrieving or modifying the parameters of an
33// RtpSender/RtpReceiver, or retrieving capabilities.
34//
35// Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
36// types, we typically use "int", in keeping with our style guidelines. The
37// parameter's actual valid range will be enforced when the parameters are set,
38// rather than when the parameters struct is built. An exception is made for
39// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
40// be used for any numeric comparisons/operations.
41//
42// Additionally, where ORTC uses strings, we may use enums for things that have
43// a fixed number of supported values. However, for things that can be extended
44// (such as codecs, by providing an external encoder factory), a string
45// identifier is used.
46
47enum class FecMechanism {
48 RED,
49 RED_AND_ULPFEC,
50 FLEXFEC,
51};
52
53// Used in RtcpFeedback struct.
54enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 12:09:01 -080055 CCM,
Elad Alonfadb1812019-05-24 13:40:02 +020056 LNTF, // "goog-lntf"
deadbeefe702b302017-02-04 12:09:01 -080057 NACK,
58 REMB, // "goog-remb"
59 TRANSPORT_CC,
60};
61
deadbeefe814a0d2017-02-25 18:15:09 -080062// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 12:09:01 -080063enum class RtcpFeedbackMessageType {
64 // Equivalent to {type: "nack", parameter: undefined} in ORTC.
65 GENERIC_NACK,
66 PLI, // Usable with NACK.
67 FIR, // Usable with CCM.
68};
69
70enum class DtxStatus {
71 DISABLED,
72 ENABLED,
73};
74
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070075// Based on the spec in
76// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
77// These options are enforced on a best-effort basis. For instance, all of
78// these options may suffer some frame drops in order to avoid queuing.
79// TODO(sprang): Look into possibility of more strictly enforcing the
80// maintain-framerate option.
81// TODO(deadbeef): Default to "balanced", as the spec indicates?
deadbeefe702b302017-02-04 12:09:01 -080082enum class DegradationPreference {
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070083 // Don't take any actions based on over-utilization signals. Not part of the
84 // web API.
85 DISABLED,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070086 // On over-use, request lower resolution, possibly causing down-scaling.
Åsa Persson90bc1e12019-05-31 13:29:35 +020087 MAINTAIN_FRAMERATE,
88 // On over-use, request lower frame rate, possibly causing frame drops.
deadbeefe702b302017-02-04 12:09:01 -080089 MAINTAIN_RESOLUTION,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070090 // Try to strike a "pleasing" balance between frame rate or resolution.
deadbeefe702b302017-02-04 12:09:01 -080091 BALANCED,
92};
93
Mirko Bonadei66e76792019-04-02 11:33:59 +020094RTC_EXPORT extern const double kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -080095
Taylor Brandstettere3a294c2020-03-23 23:16:58 +000096// GENERATED_JAVA_ENUM_PACKAGE: org.webrtc
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -080097enum class Priority {
98 kVeryLow,
99 kLow,
100 kMedium,
101 kHigh,
Taylor Brandstetter567f03f2020-02-18 13:41:54 -0800102};
103
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200104struct RTC_EXPORT RtcpFeedback {
deadbeefe814a0d2017-02-25 18:15:09 -0800105 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 12:09:01 -0800106
107 // Equivalent to ORTC "parameter" field with slight differences:
108 // 1. It's an enum instead of a string.
109 // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
110 // rather than an unset "parameter" value.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200111 absl::optional<RtcpFeedbackMessageType> message_type;
deadbeefe702b302017-02-04 12:09:01 -0800112
deadbeefe814a0d2017-02-25 18:15:09 -0800113 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200114 RtcpFeedback();
115 explicit RtcpFeedback(RtcpFeedbackType type);
116 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200117 RtcpFeedback(const RtcpFeedback&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200118 ~RtcpFeedback();
deadbeefe814a0d2017-02-25 18:15:09 -0800119
deadbeefe702b302017-02-04 12:09:01 -0800120 bool operator==(const RtcpFeedback& o) const {
121 return type == o.type && message_type == o.message_type;
122 }
123 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
124};
125
126// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
127// RtpParameters. This represents the static capabilities of an endpoint's
128// implementation of a codec.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200129struct RTC_EXPORT RtpCodecCapability {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200130 RtpCodecCapability();
131 ~RtpCodecCapability();
132
deadbeefe702b302017-02-04 12:09:01 -0800133 // Build MIME "type/subtype" string from |name| and |kind|.
134 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
135
136 // Used to identify the codec. Equivalent to MIME subtype.
137 std::string name;
138
139 // The media type of this codec. Equivalent to MIME top-level type.
140 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
141
142 // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200143 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800144
145 // Default payload type for this codec. Mainly needed for codecs that use
146 // that have statically assigned payload types.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200147 absl::optional<int> preferred_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800148
149 // Maximum packetization time supported by an RtpReceiver for this codec.
150 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200151 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800152
Åsa Persson90bc1e12019-05-31 13:29:35 +0200153 // Preferred packetization time for an RtpReceiver or RtpSender of this codec.
deadbeefe702b302017-02-04 12:09:01 -0800154 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200155 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800156
157 // The number of audio channels supported. Unused for video codecs.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200158 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800159
160 // Feedback mechanisms supported for this codec.
161 std::vector<RtcpFeedback> rtcp_feedback;
162
163 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800164 //
deadbeefe702b302017-02-04 12:09:01 -0800165 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800166 //
167 // Contrary to ORTC, these parameters are named using all lowercase strings.
Åsa Persson90bc1e12019-05-31 13:29:35 +0200168 // This helps make the mapping to SDP simpler, if an application is using SDP.
169 // Boolean values are represented by the string "1".
Johannes Kron72d69152020-02-10 14:05:55 +0100170 std::map<std::string, std::string> parameters;
deadbeefe702b302017-02-04 12:09:01 -0800171
172 // Codec-specific parameters that may optionally be signaled to the remote
173 // party.
174 // TODO(deadbeef): Not implemented.
Johannes Kron72d69152020-02-10 14:05:55 +0100175 std::map<std::string, std::string> options;
deadbeefe702b302017-02-04 12:09:01 -0800176
177 // Maximum number of temporal layer extensions supported by this codec.
178 // For example, a value of 1 indicates that 2 total layers are supported.
179 // TODO(deadbeef): Not implemented.
180 int max_temporal_layer_extensions = 0;
181
182 // Maximum number of spatial layer extensions supported by this codec.
183 // For example, a value of 1 indicates that 2 total layers are supported.
184 // TODO(deadbeef): Not implemented.
185 int max_spatial_layer_extensions = 0;
186
Åsa Persson90bc1e12019-05-31 13:29:35 +0200187 // Whether the implementation can send/receive SVC layers with distinct SSRCs.
188 // Always false for audio codecs. True for video codecs that support scalable
189 // video coding with MRST.
deadbeefe702b302017-02-04 12:09:01 -0800190 // TODO(deadbeef): Not implemented.
191 bool svc_multi_stream_support = false;
192
193 bool operator==(const RtpCodecCapability& o) const {
194 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
195 preferred_payload_type == o.preferred_payload_type &&
196 max_ptime == o.max_ptime && ptime == o.ptime &&
197 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
198 parameters == o.parameters && options == o.options &&
199 max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
200 max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
201 svc_multi_stream_support == o.svc_multi_stream_support;
202 }
203 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
204};
205
Markus Handell0357b3e2020-03-16 13:40:51 +0100206// Used in RtpCapabilities and RtpTransceiverInterface's header extensions query
207// and setup methods; represents the capabilities/preferences of an
deadbeefe702b302017-02-04 12:09:01 -0800208// implementation for a header extension.
209//
210// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
211// added here for consistency and to avoid confusion with
212// RtpHeaderExtensionParameters.
213//
214// Note that ORTC includes a "kind" field, but we omit this because it's
215// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
216// you know you're getting audio capabilities.
Markus Handell0357b3e2020-03-16 13:40:51 +0100217struct RTC_EXPORT RtpHeaderExtensionCapability {
Johannes Kron07ba2b92018-09-26 13:33:35 +0200218 // URI of this extension, as defined in RFC8285.
deadbeefe702b302017-02-04 12:09:01 -0800219 std::string uri;
220
221 // Preferred value of ID that goes in the packet.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200222 absl::optional<int> preferred_id;
deadbeefe702b302017-02-04 12:09:01 -0800223
224 // If true, it's preferred that the value in the header is encrypted.
225 // TODO(deadbeef): Not implemented.
226 bool preferred_encrypt = false;
227
Markus Handell0357b3e2020-03-16 13:40:51 +0100228 // The direction of the extension. The kStopped value is only used with
229 // RtpTransceiverInterface::header_extensions_offered() and
230 // SetOfferedRtpHeaderExtensions().
231 RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
232
deadbeefe814a0d2017-02-25 18:15:09 -0800233 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200234 RtpHeaderExtensionCapability();
Danil Chapovalov2b4ec9e2020-03-25 17:23:37 +0100235 explicit RtpHeaderExtensionCapability(absl::string_view uri);
236 RtpHeaderExtensionCapability(absl::string_view uri, int preferred_id);
237 RtpHeaderExtensionCapability(absl::string_view uri,
Markus Handell0357b3e2020-03-16 13:40:51 +0100238 int preferred_id,
239 RtpTransceiverDirection direction);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200240 ~RtpHeaderExtensionCapability();
deadbeefe814a0d2017-02-25 18:15:09 -0800241
deadbeefe702b302017-02-04 12:09:01 -0800242 bool operator==(const RtpHeaderExtensionCapability& o) const {
243 return uri == o.uri && preferred_id == o.preferred_id &&
Markus Handell0357b3e2020-03-16 13:40:51 +0100244 preferred_encrypt == o.preferred_encrypt && direction == o.direction;
deadbeefe702b302017-02-04 12:09:01 -0800245 }
246 bool operator!=(const RtpHeaderExtensionCapability& o) const {
247 return !(*this == o);
248 }
249};
250
Johannes Kron07ba2b92018-09-26 13:33:35 +0200251// RTP header extension, see RFC8285.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200252struct RTC_EXPORT RtpExtension {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200253 RtpExtension();
Danil Chapovalov2b4ec9e2020-03-25 17:23:37 +0100254 RtpExtension(absl::string_view uri, int id);
255 RtpExtension(absl::string_view uri, int id, bool encrypt);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200256 ~RtpExtension();
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100257
Stefan Holmer1acbd682017-09-01 15:29:28 +0200258 std::string ToString() const;
259 bool operator==(const RtpExtension& rhs) const {
260 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
261 }
Markus Handelldfeb0df2020-03-16 22:20:47 +0100262 static bool IsSupportedForAudio(absl::string_view uri);
263 static bool IsSupportedForVideo(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200264 // Return "true" if the given RTP header extension URI may be encrypted.
Markus Handelldfeb0df2020-03-16 22:20:47 +0100265 static bool IsEncryptionSupported(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200266
267 // Returns the named header extension if found among all extensions,
268 // nullptr otherwise.
269 static const RtpExtension* FindHeaderExtensionByUri(
270 const std::vector<RtpExtension>& extensions,
Markus Handelldfeb0df2020-03-16 22:20:47 +0100271 absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200272
273 // Return a list of RTP header extensions with the non-encrypted extensions
274 // removed if both the encrypted and non-encrypted extension is present for
275 // the same URI.
276 static std::vector<RtpExtension> FilterDuplicateNonEncrypted(
277 const std::vector<RtpExtension>& extensions);
278
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100279 // Encryption of Header Extensions, see RFC 6904 for details:
280 // https://tools.ietf.org/html/rfc6904
281 static constexpr char kEncryptHeaderExtensionsUri[] =
282 "urn:ietf:params:rtp-hdrext:encrypt";
283
Stefan Holmer1acbd682017-09-01 15:29:28 +0200284 // Header extension for audio levels, as defined in:
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100285 // https://tools.ietf.org/html/rfc6464
286 static constexpr char kAudioLevelUri[] =
287 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200288
289 // Header extension for RTP timestamp offset, see RFC 5450 for details:
290 // http://tools.ietf.org/html/rfc5450
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100291 static constexpr char kTimestampOffsetUri[] =
292 "urn:ietf:params:rtp-hdrext:toffset";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200293
294 // Header extension for absolute send time, see url for details:
295 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100296 static constexpr char kAbsSendTimeUri[] =
297 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200298
Chen Xingcd8a6e22019-07-01 10:56:51 +0200299 // Header extension for absolute capture time, see url for details:
300 // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100301 static constexpr char kAbsoluteCaptureTimeUri[] =
302 "http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time";
Chen Xingcd8a6e22019-07-01 10:56:51 +0200303
Stefan Holmer1acbd682017-09-01 15:29:28 +0200304 // Header extension for coordination of video orientation, see url for
305 // details:
306 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100307 static constexpr char kVideoRotationUri[] = "urn:3gpp:video-orientation";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200308
309 // Header extension for video content type. E.g. default or screenshare.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100310 static constexpr char kVideoContentTypeUri[] =
311 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200312
313 // Header extension for video timing.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100314 static constexpr char kVideoTimingUri[] =
315 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200316
Johnny Leee0c8b232018-09-11 16:50:49 -0400317 // Header extension for video frame marking.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100318 static constexpr char kFrameMarkingUri[] =
319 "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07";
Johnny Leee0c8b232018-09-11 16:50:49 -0400320
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200321 // Experimental codec agnostic frame descriptor.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100322 static constexpr char kGenericFrameDescriptorUri00[] =
323 "http://www.webrtc.org/experiments/rtp-hdrext/"
324 "generic-frame-descriptor-00";
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100325 static constexpr char kDependencyDescriptorUri[] =
326 "https://aomediacodec.github.io/av1-rtp-spec/"
327 "#dependency-descriptor-rtp-header-extension";
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200328
Stefan Holmer1acbd682017-09-01 15:29:28 +0200329 // Header extension for transport sequence number, see url for details:
330 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100331 static constexpr char kTransportSequenceNumberUri[] =
332 "http://www.ietf.org/id/"
333 "draft-holmer-rmcat-transport-wide-cc-extensions-01";
334 static constexpr char kTransportSequenceNumberV2Uri[] =
335 "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200336
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100337 // This extension allows applications to adaptively limit the playout delay
338 // on frames as per the current needs. For example, a gaming application
339 // has very different needs on end-to-end delay compared to a video-conference
340 // application.
341 static constexpr char kPlayoutDelayUri[] =
342 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
343
344 // Header extension for color space information.
345 static constexpr char kColorSpaceUri[] =
346 "http://www.webrtc.org/experiments/rtp-hdrext/color-space";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200347
Steve Antonbb50ce52018-03-26 10:24:32 -0700348 // Header extension for identifying media section within a transport.
349 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100350 static constexpr char kMidUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
Johannes Krond0b69a82018-12-03 14:18:53 +0100351
Amit Hilbuch77938e62018-12-21 09:23:38 -0800352 // Header extension for RIDs and Repaired RIDs
353 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
354 // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100355 static constexpr char kRidUri[] =
356 "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
357 static constexpr char kRepairedRidUri[] =
358 "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
Amit Hilbuch77938e62018-12-21 09:23:38 -0800359
Johannes Kron07ba2b92018-09-26 13:33:35 +0200360 // Inclusive min and max IDs for two-byte header extensions and one-byte
361 // header extensions, per RFC8285 Section 4.2-4.3.
362 static constexpr int kMinId = 1;
363 static constexpr int kMaxId = 255;
Johannes Kron78cdde32018-10-05 10:00:46 +0200364 static constexpr int kMaxValueSize = 255;
Johannes Kron07ba2b92018-09-26 13:33:35 +0200365 static constexpr int kOneByteHeaderExtensionMaxId = 14;
Johannes Kron78cdde32018-10-05 10:00:46 +0200366 static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200367
368 std::string uri;
369 int id = 0;
370 bool encrypt = false;
371};
372
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200373struct RTC_EXPORT RtpFecParameters {
deadbeefe702b302017-02-04 12:09:01 -0800374 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800375 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200376 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800377
378 FecMechanism mechanism = FecMechanism::RED;
379
deadbeefe814a0d2017-02-25 18:15:09 -0800380 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200381 RtpFecParameters();
382 explicit RtpFecParameters(FecMechanism mechanism);
383 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200384 RtpFecParameters(const RtpFecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200385 ~RtpFecParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800386
deadbeefe702b302017-02-04 12:09:01 -0800387 bool operator==(const RtpFecParameters& o) const {
388 return ssrc == o.ssrc && mechanism == o.mechanism;
389 }
390 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
391};
392
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200393struct RTC_EXPORT RtpRtxParameters {
deadbeefe702b302017-02-04 12:09:01 -0800394 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800395 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200396 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800397
deadbeefe814a0d2017-02-25 18:15:09 -0800398 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200399 RtpRtxParameters();
400 explicit RtpRtxParameters(uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200401 RtpRtxParameters(const RtpRtxParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200402 ~RtpRtxParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800403
deadbeefe702b302017-02-04 12:09:01 -0800404 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
405 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
406};
407
Mirko Bonadei66e76792019-04-02 11:33:59 +0200408struct RTC_EXPORT RtpEncodingParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200409 RtpEncodingParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200410 RtpEncodingParameters(const RtpEncodingParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200411 ~RtpEncodingParameters();
412
deadbeefe702b302017-02-04 12:09:01 -0800413 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800414 //
415 // Note that the chosen value is NOT returned by GetParameters, because it
416 // may change due to an SSRC conflict, in which case the conflict is handled
417 // internally without any event. Another way of looking at this is that an
418 // unset SSRC acts as a "wildcard" SSRC.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200419 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800420
Seth Hampson24722b32017-12-22 09:36:42 -0800421 // The relative bitrate priority of this encoding. Currently this is
Seth Hampsona881ac02018-02-12 14:14:39 -0800422 // implemented for the entire rtp sender by using the value of the first
423 // encoding parameter.
Taylor Brandstettere3a294c2020-03-23 23:16:58 +0000424 // See: https://w3c.github.io/webrtc-priority/#enumdef-rtcprioritytype
425 // "very-low" = 0.5
426 // "low" = 1.0
427 // "medium" = 2.0
428 // "high" = 4.0
Seth Hampsona881ac02018-02-12 14:14:39 -0800429 // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
430 // Currently there is logic for how bitrate is distributed per simulcast layer
431 // in the VideoBitrateAllocator. This must be updated to incorporate relative
432 // bitrate priority.
Seth Hampson24722b32017-12-22 09:36:42 -0800433 double bitrate_priority = kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -0800434
Tim Haloun648d28a2018-10-18 16:52:22 -0700435 // The relative DiffServ Code Point priority for this encoding, allowing
436 // packets to be marked relatively higher or lower without affecting
Taylor Brandstettere3a294c2020-03-23 23:16:58 +0000437 // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ .
Tim Haloun648d28a2018-10-18 16:52:22 -0700438 // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -0800439 // TODO(http://crbug.com/webrtc/11379): TCP connections should use a single
440 // DSCP value even if shared by multiple senders; this is not implemented.
441 Priority network_priority = Priority::kLow;
Tim Haloun648d28a2018-10-18 16:52:22 -0700442
deadbeefe702b302017-02-04 12:09:01 -0800443 // If set, this represents the Transport Independent Application Specific
444 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
Seth Hampsona881ac02018-02-12 14:14:39 -0800445 // bitrate. Currently this is implemented for the entire rtp sender by using
446 // the value of the first encoding parameter.
447 //
deadbeefe702b302017-02-04 12:09:01 -0800448 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-25 18:15:09 -0800449 //
450 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
451 // bandwidth for the entire bandwidth estimator (audio and video). This is
452 // just always how "b=AS" was handled, but it's not correct and should be
453 // fixed.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200454 absl::optional<int> max_bitrate_bps;
deadbeefe702b302017-02-04 12:09:01 -0800455
Åsa Persson55659812018-06-18 17:51:32 +0200456 // Specifies the minimum bitrate in bps for video.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200457 absl::optional<int> min_bitrate_bps;
Åsa Persson613591a2018-05-29 09:21:31 +0200458
Åsa Persson8c1bf952018-09-13 10:42:19 +0200459 // Specifies the maximum framerate in fps for video.
Florent Castelli907dc802019-12-06 15:03:19 +0100460 absl::optional<double> max_framerate;
deadbeefe702b302017-02-04 12:09:01 -0800461
Åsa Persson23eba222018-10-02 14:47:06 +0200462 // Specifies the number of temporal layers for video (if the feature is
463 // supported by the codec implementation).
464 // TODO(asapersson): Different number of temporal layers are not supported
465 // per simulcast layer.
Ilya Nikolaevskiy9f6a0d52019-02-05 10:29:41 +0100466 // Screencast support is experimental.
Åsa Persson23eba222018-10-02 14:47:06 +0200467 absl::optional<int> num_temporal_layers;
468
deadbeefe702b302017-02-04 12:09:01 -0800469 // For video, scale the resolution down by this factor.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200470 absl::optional<double> scale_resolution_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800471
Seth Hampsona881ac02018-02-12 14:14:39 -0800472 // For an RtpSender, set to true to cause this encoding to be encoded and
473 // sent, and false for it not to be encoded and sent. This allows control
474 // across multiple encodings of a sender for turning simulcast layers on and
475 // off.
476 // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
477 // reset, but this isn't necessarily required.
deadbeefdbe2b872016-03-22 15:42:00 -0700478 bool active = true;
deadbeefe702b302017-02-04 12:09:01 -0800479
480 // Value to use for RID RTP header extension.
481 // Called "encodingId" in ORTC.
deadbeefe702b302017-02-04 12:09:01 -0800482 std::string rid;
483
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700484 bool operator==(const RtpEncodingParameters& o) const {
Florent Castellia8c2f512019-11-28 15:48:24 +0100485 return ssrc == o.ssrc && bitrate_priority == o.bitrate_priority &&
486 network_priority == o.network_priority &&
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 &&
Florent Castellia8c2f512019-11-28 15:48:24 +0100492 active == o.active && rid == o.rid;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700493 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700494 bool operator!=(const RtpEncodingParameters& o) const {
495 return !(*this == o);
496 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700497};
498
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200499struct RTC_EXPORT RtpCodecParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200500 RtpCodecParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200501 RtpCodecParameters(const RtpCodecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200502 ~RtpCodecParameters();
503
deadbeefe702b302017-02-04 12:09:01 -0800504 // Build MIME "type/subtype" string from |name| and |kind|.
505 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
506
507 // Used to identify the codec. Equivalent to MIME subtype.
508 std::string name;
509
510 // The media type of this codec. Equivalent to MIME top-level type.
511 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
512
513 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-25 18:15:09 -0800514 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 12:09:01 -0800515 // the same transport.
516 int payload_type = 0;
517
518 // If unset, the implementation default is used.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200519 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800520
521 // The number of audio channels used. Unset for video codecs. If unset for
522 // audio, the implementation default is used.
deadbeefe814a0d2017-02-25 18:15:09 -0800523 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
524 // Only defaults to 1, even though some codecs (such as opus) should really
525 // default to 2.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200526 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800527
528 // The maximum packetization time to be used by an RtpSender.
529 // If |ptime| is also set, this will be ignored.
530 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200531 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800532
533 // The packetization time to be used by an RtpSender.
534 // If unset, will use any time up to max_ptime.
535 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200536 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800537
538 // Feedback mechanisms to be used for this codec.
deadbeefe814a0d2017-02-25 18:15:09 -0800539 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800540 std::vector<RtcpFeedback> rtcp_feedback;
541
542 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800543 //
deadbeefe702b302017-02-04 12:09:01 -0800544 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800545 //
546 // Contrary to ORTC, these parameters are named using all lowercase strings.
Åsa Persson90bc1e12019-05-31 13:29:35 +0200547 // This helps make the mapping to SDP simpler, if an application is using SDP.
548 // Boolean values are represented by the string "1".
Johannes Kron72d69152020-02-10 14:05:55 +0100549 std::map<std::string, std::string> parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700550
551 bool operator==(const RtpCodecParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800552 return name == o.name && kind == o.kind && payload_type == o.payload_type &&
553 clock_rate == o.clock_rate && num_channels == o.num_channels &&
554 max_ptime == o.max_ptime && ptime == o.ptime &&
555 rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700556 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700557 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700558};
559
Åsa Persson90bc1e12019-05-31 13:29:35 +0200560// RtpCapabilities is used to represent the static capabilities of an endpoint.
561// An application can use these capabilities to construct an RtpParameters.
Mirko Bonadei66e76792019-04-02 11:33:59 +0200562struct RTC_EXPORT 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
Mirko Bonadeiac194142018-10-22 17:08:37 +0200619struct RTC_EXPORT 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
Danil Chapovalovb19eb392019-12-23 17:55:05 +0100636 std::vector<RtpExtension> header_extensions;
deadbeefe702b302017-02-04 12:09:01 -0800637
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.
Florent Castellib05ca4b2020-03-05 13:39:55 +0100648 absl::optional<DegradationPreference> degradation_preference;
deadbeefe702b302017-02-04 12:09:01 -0800649
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700650 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800651 return mid == o.mid && codecs == o.codecs &&
652 header_extensions == o.header_extensions &&
Florent Castellidacec712018-05-24 16:24:21 +0200653 encodings == o.encodings && rtcp == o.rtcp &&
deadbeefe702b302017-02-04 12:09:01 -0800654 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700655 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700656 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700657};
658
659} // namespace webrtc
660
Steve Anton10542f22019-01-11 09:11:00 -0800661#endif // API_RTP_PARAMETERS_H_