blob: 5764d9739c3d382c6010719c41e5fef8ae12b833 [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"
Harald Alvestrandfd5ae7f2020-05-16 08:37:49 +020023#include "api/priority.h"
Markus Handell0357b3e2020-03-16 13:40:51 +010024#include "api/rtp_transceiver_direction.h"
Mirko Bonadeiac194142018-10-22 17:08:37 +020025#include "rtc_base/system/rtc_export.h"
sakal1fd95952016-06-22 00:46:15 -070026
skvladdc1c62c2016-03-16 19:07:43 -070027namespace webrtc {
28
deadbeefe702b302017-02-04 12:09:01 -080029// These structures are intended to mirror those defined by:
30// http://draft.ortc.org/#rtcrtpdictionaries*
31// Contains everything specified as of 2017 Jan 24.
32//
33// They are used when retrieving or modifying the parameters of an
34// RtpSender/RtpReceiver, or retrieving capabilities.
35//
36// Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
37// types, we typically use "int", in keeping with our style guidelines. The
38// parameter's actual valid range will be enforced when the parameters are set,
39// rather than when the parameters struct is built. An exception is made for
40// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
41// be used for any numeric comparisons/operations.
42//
43// Additionally, where ORTC uses strings, we may use enums for things that have
44// a fixed number of supported values. However, for things that can be extended
45// (such as codecs, by providing an external encoder factory), a string
46// identifier is used.
47
48enum class FecMechanism {
49 RED,
50 RED_AND_ULPFEC,
51 FLEXFEC,
52};
53
54// Used in RtcpFeedback struct.
55enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 12:09:01 -080056 CCM,
Elad Alonfadb1812019-05-24 13:40:02 +020057 LNTF, // "goog-lntf"
deadbeefe702b302017-02-04 12:09:01 -080058 NACK,
59 REMB, // "goog-remb"
60 TRANSPORT_CC,
61};
62
deadbeefe814a0d2017-02-25 18:15:09 -080063// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 12:09:01 -080064enum class RtcpFeedbackMessageType {
65 // Equivalent to {type: "nack", parameter: undefined} in ORTC.
66 GENERIC_NACK,
67 PLI, // Usable with NACK.
68 FIR, // Usable with CCM.
69};
70
71enum class DtxStatus {
72 DISABLED,
73 ENABLED,
74};
75
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070076// Based on the spec in
77// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
78// These options are enforced on a best-effort basis. For instance, all of
79// these options may suffer some frame drops in order to avoid queuing.
80// TODO(sprang): Look into possibility of more strictly enforcing the
81// maintain-framerate option.
82// TODO(deadbeef): Default to "balanced", as the spec indicates?
deadbeefe702b302017-02-04 12:09:01 -080083enum class DegradationPreference {
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070084 // Don't take any actions based on over-utilization signals. Not part of the
85 // web API.
86 DISABLED,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070087 // On over-use, request lower resolution, possibly causing down-scaling.
Åsa Persson90bc1e12019-05-31 13:29:35 +020088 MAINTAIN_FRAMERATE,
89 // On over-use, request lower frame rate, possibly causing frame drops.
deadbeefe702b302017-02-04 12:09:01 -080090 MAINTAIN_RESOLUTION,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070091 // Try to strike a "pleasing" balance between frame rate or resolution.
deadbeefe702b302017-02-04 12:09:01 -080092 BALANCED,
93};
94
Henrik Boströmf0eef122020-05-28 16:22:42 +020095RTC_EXPORT const char* DegradationPreferenceToString(
96 DegradationPreference degradation_preference);
97
Mirko Bonadei66e76792019-04-02 11:33:59 +020098RTC_EXPORT extern const double kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -080099
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200100struct RTC_EXPORT RtcpFeedback {
deadbeefe814a0d2017-02-25 18:15:09 -0800101 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 12:09:01 -0800102
103 // Equivalent to ORTC "parameter" field with slight differences:
104 // 1. It's an enum instead of a string.
105 // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
106 // rather than an unset "parameter" value.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200107 absl::optional<RtcpFeedbackMessageType> message_type;
deadbeefe702b302017-02-04 12:09:01 -0800108
deadbeefe814a0d2017-02-25 18:15:09 -0800109 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200110 RtcpFeedback();
111 explicit RtcpFeedback(RtcpFeedbackType type);
112 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200113 RtcpFeedback(const RtcpFeedback&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200114 ~RtcpFeedback();
deadbeefe814a0d2017-02-25 18:15:09 -0800115
deadbeefe702b302017-02-04 12:09:01 -0800116 bool operator==(const RtcpFeedback& o) const {
117 return type == o.type && message_type == o.message_type;
118 }
119 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
120};
121
122// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
123// RtpParameters. This represents the static capabilities of an endpoint's
124// implementation of a codec.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200125struct RTC_EXPORT RtpCodecCapability {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200126 RtpCodecCapability();
127 ~RtpCodecCapability();
128
deadbeefe702b302017-02-04 12:09:01 -0800129 // Build MIME "type/subtype" string from |name| and |kind|.
130 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
131
132 // Used to identify the codec. Equivalent to MIME subtype.
133 std::string name;
134
135 // The media type of this codec. Equivalent to MIME top-level type.
136 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
137
138 // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200139 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800140
141 // Default payload type for this codec. Mainly needed for codecs that use
142 // that have statically assigned payload types.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200143 absl::optional<int> preferred_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800144
145 // Maximum packetization time supported by an RtpReceiver for this codec.
146 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200147 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800148
Åsa Persson90bc1e12019-05-31 13:29:35 +0200149 // Preferred packetization time for an RtpReceiver or RtpSender of this codec.
deadbeefe702b302017-02-04 12:09:01 -0800150 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200151 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800152
153 // The number of audio channels supported. Unused for video codecs.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200154 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800155
156 // Feedback mechanisms supported for this codec.
157 std::vector<RtcpFeedback> rtcp_feedback;
158
159 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800160 //
deadbeefe702b302017-02-04 12:09:01 -0800161 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800162 //
163 // Contrary to ORTC, these parameters are named using all lowercase strings.
Åsa Persson90bc1e12019-05-31 13:29:35 +0200164 // This helps make the mapping to SDP simpler, if an application is using SDP.
165 // Boolean values are represented by the string "1".
Johannes Kron72d69152020-02-10 14:05:55 +0100166 std::map<std::string, std::string> parameters;
deadbeefe702b302017-02-04 12:09:01 -0800167
168 // Codec-specific parameters that may optionally be signaled to the remote
169 // party.
170 // TODO(deadbeef): Not implemented.
Johannes Kron72d69152020-02-10 14:05:55 +0100171 std::map<std::string, std::string> options;
deadbeefe702b302017-02-04 12:09:01 -0800172
173 // Maximum number of temporal layer extensions supported by this codec.
174 // For example, a value of 1 indicates that 2 total layers are supported.
175 // TODO(deadbeef): Not implemented.
176 int max_temporal_layer_extensions = 0;
177
178 // Maximum number of spatial layer extensions supported by this codec.
179 // For example, a value of 1 indicates that 2 total layers are supported.
180 // TODO(deadbeef): Not implemented.
181 int max_spatial_layer_extensions = 0;
182
Åsa Persson90bc1e12019-05-31 13:29:35 +0200183 // Whether the implementation can send/receive SVC layers with distinct SSRCs.
184 // Always false for audio codecs. True for video codecs that support scalable
185 // video coding with MRST.
deadbeefe702b302017-02-04 12:09:01 -0800186 // TODO(deadbeef): Not implemented.
187 bool svc_multi_stream_support = false;
188
189 bool operator==(const RtpCodecCapability& o) const {
190 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
191 preferred_payload_type == o.preferred_payload_type &&
192 max_ptime == o.max_ptime && ptime == o.ptime &&
193 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
194 parameters == o.parameters && options == o.options &&
195 max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
196 max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
197 svc_multi_stream_support == o.svc_multi_stream_support;
198 }
199 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
200};
201
Markus Handell0357b3e2020-03-16 13:40:51 +0100202// Used in RtpCapabilities and RtpTransceiverInterface's header extensions query
203// and setup methods; represents the capabilities/preferences of an
deadbeefe702b302017-02-04 12:09:01 -0800204// implementation for a header extension.
205//
206// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
207// added here for consistency and to avoid confusion with
208// RtpHeaderExtensionParameters.
209//
210// Note that ORTC includes a "kind" field, but we omit this because it's
211// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
212// you know you're getting audio capabilities.
Markus Handell0357b3e2020-03-16 13:40:51 +0100213struct RTC_EXPORT RtpHeaderExtensionCapability {
Johannes Kron07ba2b92018-09-26 13:33:35 +0200214 // URI of this extension, as defined in RFC8285.
deadbeefe702b302017-02-04 12:09:01 -0800215 std::string uri;
216
217 // Preferred value of ID that goes in the packet.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200218 absl::optional<int> preferred_id;
deadbeefe702b302017-02-04 12:09:01 -0800219
220 // If true, it's preferred that the value in the header is encrypted.
221 // TODO(deadbeef): Not implemented.
222 bool preferred_encrypt = false;
223
Markus Handell0357b3e2020-03-16 13:40:51 +0100224 // The direction of the extension. The kStopped value is only used with
Markus Handell755c65d2020-06-24 01:06:10 +0200225 // RtpTransceiverInterface::HeaderExtensionsToOffer() and
Markus Handell0357b3e2020-03-16 13:40:51 +0100226 // SetOfferedRtpHeaderExtensions().
227 RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
228
deadbeefe814a0d2017-02-25 18:15:09 -0800229 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200230 RtpHeaderExtensionCapability();
Danil Chapovalov2b4ec9e2020-03-25 17:23:37 +0100231 explicit RtpHeaderExtensionCapability(absl::string_view uri);
232 RtpHeaderExtensionCapability(absl::string_view uri, int preferred_id);
233 RtpHeaderExtensionCapability(absl::string_view uri,
Markus Handell0357b3e2020-03-16 13:40:51 +0100234 int preferred_id,
235 RtpTransceiverDirection direction);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200236 ~RtpHeaderExtensionCapability();
deadbeefe814a0d2017-02-25 18:15:09 -0800237
deadbeefe702b302017-02-04 12:09:01 -0800238 bool operator==(const RtpHeaderExtensionCapability& o) const {
239 return uri == o.uri && preferred_id == o.preferred_id &&
Markus Handell0357b3e2020-03-16 13:40:51 +0100240 preferred_encrypt == o.preferred_encrypt && direction == o.direction;
deadbeefe702b302017-02-04 12:09:01 -0800241 }
242 bool operator!=(const RtpHeaderExtensionCapability& o) const {
243 return !(*this == o);
244 }
245};
246
Johannes Kron07ba2b92018-09-26 13:33:35 +0200247// RTP header extension, see RFC8285.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200248struct RTC_EXPORT RtpExtension {
Lennart Grahla7433032021-04-09 22:05:06 +0200249 enum Filter {
250 // Encrypted extensions will be ignored and only non-encrypted extensions
251 // will be considered.
252 kDiscardEncryptedExtension,
253 // Encrypted extensions will be preferred but will fall back to
254 // non-encrypted extensions if necessary.
255 kPreferEncryptedExtension,
256 // Encrypted extensions will be required, so any non-encrypted extensions
257 // will be discarded.
258 kRequireEncryptedExtension,
259 };
260
Stefan Holmer1acbd682017-09-01 15:29:28 +0200261 RtpExtension();
Danil Chapovalov2b4ec9e2020-03-25 17:23:37 +0100262 RtpExtension(absl::string_view uri, int id);
263 RtpExtension(absl::string_view uri, int id, bool encrypt);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200264 ~RtpExtension();
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100265
Stefan Holmer1acbd682017-09-01 15:29:28 +0200266 std::string ToString() const;
267 bool operator==(const RtpExtension& rhs) const {
268 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
269 }
Markus Handelldfeb0df2020-03-16 22:20:47 +0100270 static bool IsSupportedForAudio(absl::string_view uri);
271 static bool IsSupportedForVideo(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200272 // Return "true" if the given RTP header extension URI may be encrypted.
Markus Handelldfeb0df2020-03-16 22:20:47 +0100273 static bool IsEncryptionSupported(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200274
Lennart Grahla7433032021-04-09 22:05:06 +0200275 // Returns the header extension with the given URI or nullptr if not found.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200276 static const RtpExtension* FindHeaderExtensionByUri(
277 const std::vector<RtpExtension>& extensions,
Lennart Grahla7433032021-04-09 22:05:06 +0200278 absl::string_view uri,
279 Filter filter);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200280
Lennart Grahla7433032021-04-09 22:05:06 +0200281 // Returns the header extension with the given URI and encrypt parameter,
282 // if found, otherwise nullptr.
283 static const RtpExtension* FindHeaderExtensionByUriAndEncryption(
284 const std::vector<RtpExtension>& extensions,
285 absl::string_view uri,
286 bool encrypt);
287
288 // Returns a list of extensions where any extension URI is unique.
289 static const std::vector<RtpExtension> DeduplicateHeaderExtensions(
290 const std::vector<RtpExtension>& extensions,
291 Filter filter);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200292
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100293 // Encryption of Header Extensions, see RFC 6904 for details:
294 // https://tools.ietf.org/html/rfc6904
295 static constexpr char kEncryptHeaderExtensionsUri[] =
296 "urn:ietf:params:rtp-hdrext:encrypt";
297
Stefan Holmer1acbd682017-09-01 15:29:28 +0200298 // Header extension for audio levels, as defined in:
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100299 // https://tools.ietf.org/html/rfc6464
300 static constexpr char kAudioLevelUri[] =
301 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200302
303 // Header extension for RTP timestamp offset, see RFC 5450 for details:
304 // http://tools.ietf.org/html/rfc5450
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100305 static constexpr char kTimestampOffsetUri[] =
306 "urn:ietf:params:rtp-hdrext:toffset";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200307
308 // Header extension for absolute send time, see url for details:
309 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100310 static constexpr char kAbsSendTimeUri[] =
311 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200312
Chen Xingcd8a6e22019-07-01 10:56:51 +0200313 // Header extension for absolute capture time, see url for details:
314 // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100315 static constexpr char kAbsoluteCaptureTimeUri[] =
316 "http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time";
Chen Xingcd8a6e22019-07-01 10:56:51 +0200317
Stefan Holmer1acbd682017-09-01 15:29:28 +0200318 // Header extension for coordination of video orientation, see url for
319 // details:
320 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100321 static constexpr char kVideoRotationUri[] = "urn:3gpp:video-orientation";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200322
323 // Header extension for video content type. E.g. default or screenshare.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100324 static constexpr char kVideoContentTypeUri[] =
325 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200326
327 // Header extension for video timing.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100328 static constexpr char kVideoTimingUri[] =
329 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200330
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200331 // Experimental codec agnostic frame descriptor.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100332 static constexpr char kGenericFrameDescriptorUri00[] =
333 "http://www.webrtc.org/experiments/rtp-hdrext/"
334 "generic-frame-descriptor-00";
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100335 static constexpr char kDependencyDescriptorUri[] =
336 "https://aomediacodec.github.io/av1-rtp-spec/"
337 "#dependency-descriptor-rtp-header-extension";
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200338
Per Kjellander70c89452020-10-21 13:35:07 +0200339 // Experimental extension for signalling target bitrate per layer.
340 static constexpr char kVideoLayersAllocationUri[] =
341 "http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00";
342
Stefan Holmer1acbd682017-09-01 15:29:28 +0200343 // Header extension for transport sequence number, see url for details:
344 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100345 static constexpr char kTransportSequenceNumberUri[] =
346 "http://www.ietf.org/id/"
347 "draft-holmer-rmcat-transport-wide-cc-extensions-01";
348 static constexpr char kTransportSequenceNumberV2Uri[] =
349 "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200350
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100351 // This extension allows applications to adaptively limit the playout delay
352 // on frames as per the current needs. For example, a gaming application
353 // has very different needs on end-to-end delay compared to a video-conference
354 // application.
355 static constexpr char kPlayoutDelayUri[] =
356 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
357
358 // Header extension for color space information.
359 static constexpr char kColorSpaceUri[] =
360 "http://www.webrtc.org/experiments/rtp-hdrext/color-space";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200361
Steve Antonbb50ce52018-03-26 10:24:32 -0700362 // Header extension for identifying media section within a transport.
363 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100364 static constexpr char kMidUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
Johannes Krond0b69a82018-12-03 14:18:53 +0100365
Amit Hilbuch77938e62018-12-21 09:23:38 -0800366 // Header extension for RIDs and Repaired RIDs
367 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
368 // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100369 static constexpr char kRidUri[] =
370 "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
371 static constexpr char kRepairedRidUri[] =
372 "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
Amit Hilbuch77938e62018-12-21 09:23:38 -0800373
Jeremy Leconteb258c562021-03-18 13:50:42 +0100374 // Header extension to propagate webrtc::VideoFrame id field
375 static constexpr char kVideoFrameTrackingIdUri[] =
376 "http://www.webrtc.org/experiments/rtp-hdrext/video-frame-tracking-id";
377
Johannes Kron07ba2b92018-09-26 13:33:35 +0200378 // Inclusive min and max IDs for two-byte header extensions and one-byte
379 // header extensions, per RFC8285 Section 4.2-4.3.
380 static constexpr int kMinId = 1;
381 static constexpr int kMaxId = 255;
Johannes Kron78cdde32018-10-05 10:00:46 +0200382 static constexpr int kMaxValueSize = 255;
Johannes Kron07ba2b92018-09-26 13:33:35 +0200383 static constexpr int kOneByteHeaderExtensionMaxId = 14;
Johannes Kron78cdde32018-10-05 10:00:46 +0200384 static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200385
386 std::string uri;
387 int id = 0;
388 bool encrypt = false;
389};
390
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200391struct RTC_EXPORT RtpFecParameters {
deadbeefe702b302017-02-04 12:09:01 -0800392 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800393 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200394 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800395
396 FecMechanism mechanism = FecMechanism::RED;
397
deadbeefe814a0d2017-02-25 18:15:09 -0800398 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200399 RtpFecParameters();
400 explicit RtpFecParameters(FecMechanism mechanism);
401 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200402 RtpFecParameters(const RtpFecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200403 ~RtpFecParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800404
deadbeefe702b302017-02-04 12:09:01 -0800405 bool operator==(const RtpFecParameters& o) const {
406 return ssrc == o.ssrc && mechanism == o.mechanism;
407 }
408 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
409};
410
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200411struct RTC_EXPORT RtpRtxParameters {
deadbeefe702b302017-02-04 12:09:01 -0800412 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800413 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200414 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800415
deadbeefe814a0d2017-02-25 18:15:09 -0800416 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200417 RtpRtxParameters();
418 explicit RtpRtxParameters(uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200419 RtpRtxParameters(const RtpRtxParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200420 ~RtpRtxParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800421
deadbeefe702b302017-02-04 12:09:01 -0800422 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
423 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
424};
425
Mirko Bonadei66e76792019-04-02 11:33:59 +0200426struct RTC_EXPORT RtpEncodingParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200427 RtpEncodingParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200428 RtpEncodingParameters(const RtpEncodingParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200429 ~RtpEncodingParameters();
430
deadbeefe702b302017-02-04 12:09:01 -0800431 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800432 //
433 // Note that the chosen value is NOT returned by GetParameters, because it
434 // may change due to an SSRC conflict, in which case the conflict is handled
435 // internally without any event. Another way of looking at this is that an
436 // unset SSRC acts as a "wildcard" SSRC.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200437 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800438
Seth Hampson24722b32017-12-22 09:36:42 -0800439 // The relative bitrate priority of this encoding. Currently this is
Seth Hampsona881ac02018-02-12 14:14:39 -0800440 // implemented for the entire rtp sender by using the value of the first
441 // encoding parameter.
Taylor Brandstettere3a294c2020-03-23 23:16:58 +0000442 // See: https://w3c.github.io/webrtc-priority/#enumdef-rtcprioritytype
443 // "very-low" = 0.5
444 // "low" = 1.0
445 // "medium" = 2.0
446 // "high" = 4.0
Seth Hampsona881ac02018-02-12 14:14:39 -0800447 // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
448 // Currently there is logic for how bitrate is distributed per simulcast layer
449 // in the VideoBitrateAllocator. This must be updated to incorporate relative
450 // bitrate priority.
Seth Hampson24722b32017-12-22 09:36:42 -0800451 double bitrate_priority = kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -0800452
Tim Haloun648d28a2018-10-18 16:52:22 -0700453 // The relative DiffServ Code Point priority for this encoding, allowing
454 // packets to be marked relatively higher or lower without affecting
Taylor Brandstettere3a294c2020-03-23 23:16:58 +0000455 // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ .
Tim Haloun648d28a2018-10-18 16:52:22 -0700456 // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -0800457 // TODO(http://crbug.com/webrtc/11379): TCP connections should use a single
458 // DSCP value even if shared by multiple senders; this is not implemented.
459 Priority network_priority = Priority::kLow;
Tim Haloun648d28a2018-10-18 16:52:22 -0700460
deadbeefe702b302017-02-04 12:09:01 -0800461 // If set, this represents the Transport Independent Application Specific
462 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
Seth Hampsona881ac02018-02-12 14:14:39 -0800463 // bitrate. Currently this is implemented for the entire rtp sender by using
464 // the value of the first encoding parameter.
465 //
deadbeefe702b302017-02-04 12:09:01 -0800466 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-25 18:15:09 -0800467 //
468 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
469 // bandwidth for the entire bandwidth estimator (audio and video). This is
470 // just always how "b=AS" was handled, but it's not correct and should be
471 // fixed.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200472 absl::optional<int> max_bitrate_bps;
deadbeefe702b302017-02-04 12:09:01 -0800473
Åsa Persson55659812018-06-18 17:51:32 +0200474 // Specifies the minimum bitrate in bps for video.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200475 absl::optional<int> min_bitrate_bps;
Åsa Persson613591a2018-05-29 09:21:31 +0200476
Åsa Persson8c1bf952018-09-13 10:42:19 +0200477 // Specifies the maximum framerate in fps for video.
Florent Castelli907dc802019-12-06 15:03:19 +0100478 absl::optional<double> max_framerate;
deadbeefe702b302017-02-04 12:09:01 -0800479
Åsa Persson23eba222018-10-02 14:47:06 +0200480 // Specifies the number of temporal layers for video (if the feature is
481 // supported by the codec implementation).
482 // TODO(asapersson): Different number of temporal layers are not supported
483 // per simulcast layer.
Ilya Nikolaevskiy9f6a0d52019-02-05 10:29:41 +0100484 // Screencast support is experimental.
Åsa Persson23eba222018-10-02 14:47:06 +0200485 absl::optional<int> num_temporal_layers;
486
deadbeefe702b302017-02-04 12:09:01 -0800487 // For video, scale the resolution down by this factor.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200488 absl::optional<double> scale_resolution_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800489
philipel87e99092020-11-18 11:52:04 +0100490 // https://w3c.github.io/webrtc-svc/#rtcrtpencodingparameters
491 absl::optional<std::string> scalability_mode;
492
Seth Hampsona881ac02018-02-12 14:14:39 -0800493 // For an RtpSender, set to true to cause this encoding to be encoded and
494 // sent, and false for it not to be encoded and sent. This allows control
495 // across multiple encodings of a sender for turning simulcast layers on and
496 // off.
497 // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
498 // reset, but this isn't necessarily required.
deadbeefdbe2b872016-03-22 15:42:00 -0700499 bool active = true;
deadbeefe702b302017-02-04 12:09:01 -0800500
501 // Value to use for RID RTP header extension.
502 // Called "encodingId" in ORTC.
deadbeefe702b302017-02-04 12:09:01 -0800503 std::string rid;
504
Jakob Ivarsson39adce12020-06-25 14:09:58 +0200505 // Allow dynamic frame length changes for audio:
506 // https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime
507 bool adaptive_ptime = false;
508
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700509 bool operator==(const RtpEncodingParameters& o) const {
Florent Castellia8c2f512019-11-28 15:48:24 +0100510 return ssrc == o.ssrc && bitrate_priority == o.bitrate_priority &&
511 network_priority == o.network_priority &&
Seth Hampson24722b32017-12-22 09:36:42 -0800512 max_bitrate_bps == o.max_bitrate_bps &&
Åsa Persson8c1bf952018-09-13 10:42:19 +0200513 min_bitrate_bps == o.min_bitrate_bps &&
deadbeefe702b302017-02-04 12:09:01 -0800514 max_framerate == o.max_framerate &&
Åsa Persson23eba222018-10-02 14:47:06 +0200515 num_temporal_layers == o.num_temporal_layers &&
deadbeefe702b302017-02-04 12:09:01 -0800516 scale_resolution_down_by == o.scale_resolution_down_by &&
Jakob Ivarsson39adce12020-06-25 14:09:58 +0200517 active == o.active && rid == o.rid &&
518 adaptive_ptime == o.adaptive_ptime;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700519 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700520 bool operator!=(const RtpEncodingParameters& o) const {
521 return !(*this == o);
522 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700523};
524
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200525struct RTC_EXPORT RtpCodecParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200526 RtpCodecParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200527 RtpCodecParameters(const RtpCodecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200528 ~RtpCodecParameters();
529
deadbeefe702b302017-02-04 12:09:01 -0800530 // Build MIME "type/subtype" string from |name| and |kind|.
531 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
532
533 // Used to identify the codec. Equivalent to MIME subtype.
534 std::string name;
535
536 // The media type of this codec. Equivalent to MIME top-level type.
537 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
538
539 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-25 18:15:09 -0800540 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 12:09:01 -0800541 // the same transport.
542 int payload_type = 0;
543
544 // If unset, the implementation default is used.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200545 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800546
547 // The number of audio channels used. Unset for video codecs. If unset for
548 // audio, the implementation default is used.
deadbeefe814a0d2017-02-25 18:15:09 -0800549 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
550 // Only defaults to 1, even though some codecs (such as opus) should really
551 // default to 2.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200552 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800553
554 // The maximum packetization time to be used by an RtpSender.
555 // If |ptime| is also set, this will be ignored.
556 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200557 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800558
559 // The packetization time to be used by an RtpSender.
560 // If unset, will use any time up to max_ptime.
561 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200562 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800563
564 // Feedback mechanisms to be used for this codec.
deadbeefe814a0d2017-02-25 18:15:09 -0800565 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800566 std::vector<RtcpFeedback> rtcp_feedback;
567
568 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800569 //
deadbeefe702b302017-02-04 12:09:01 -0800570 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800571 //
572 // Contrary to ORTC, these parameters are named using all lowercase strings.
Åsa Persson90bc1e12019-05-31 13:29:35 +0200573 // This helps make the mapping to SDP simpler, if an application is using SDP.
574 // Boolean values are represented by the string "1".
Johannes Kron72d69152020-02-10 14:05:55 +0100575 std::map<std::string, std::string> parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700576
577 bool operator==(const RtpCodecParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800578 return name == o.name && kind == o.kind && payload_type == o.payload_type &&
579 clock_rate == o.clock_rate && num_channels == o.num_channels &&
580 max_ptime == o.max_ptime && ptime == o.ptime &&
581 rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700582 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700583 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700584};
585
Åsa Persson90bc1e12019-05-31 13:29:35 +0200586// RtpCapabilities is used to represent the static capabilities of an endpoint.
587// An application can use these capabilities to construct an RtpParameters.
Mirko Bonadei66e76792019-04-02 11:33:59 +0200588struct RTC_EXPORT RtpCapabilities {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200589 RtpCapabilities();
590 ~RtpCapabilities();
591
deadbeefe702b302017-02-04 12:09:01 -0800592 // Supported codecs.
593 std::vector<RtpCodecCapability> codecs;
594
595 // Supported RTP header extensions.
596 std::vector<RtpHeaderExtensionCapability> header_extensions;
597
deadbeefe814a0d2017-02-25 18:15:09 -0800598 // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
599 // ulpfec and flexfec codecs used by these mechanisms will still appear in
600 // |codecs|.
deadbeefe702b302017-02-04 12:09:01 -0800601 std::vector<FecMechanism> fec;
602
603 bool operator==(const RtpCapabilities& o) const {
604 return codecs == o.codecs && header_extensions == o.header_extensions &&
605 fec == o.fec;
606 }
607 bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
608};
609
Florent Castellidacec712018-05-24 16:24:21 +0200610struct RtcpParameters final {
611 RtcpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200612 RtcpParameters(const RtcpParameters&);
Florent Castellidacec712018-05-24 16:24:21 +0200613 ~RtcpParameters();
614
615 // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
616 // will be chosen by the implementation.
617 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200618 absl::optional<uint32_t> ssrc;
Florent Castellidacec712018-05-24 16:24:21 +0200619
620 // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
621 //
622 // If empty in the construction of the RtpTransport, one will be generated by
623 // the implementation, and returned in GetRtcpParameters. Multiple
624 // RtpTransports created by the same OrtcFactory will use the same generated
625 // CNAME.
626 //
627 // If empty when passed into SetParameters, the CNAME simply won't be
628 // modified.
629 std::string cname;
630
631 // Send reduced-size RTCP?
632 bool reduced_size = false;
633
634 // Send RTCP multiplexed on the RTP transport?
635 // Not used with PeerConnection senders/receivers
636 bool mux = true;
637
638 bool operator==(const RtcpParameters& o) const {
639 return ssrc == o.ssrc && cname == o.cname &&
640 reduced_size == o.reduced_size && mux == o.mux;
641 }
642 bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
643};
644
Mirko Bonadeiac194142018-10-22 17:08:37 +0200645struct RTC_EXPORT RtpParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200646 RtpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200647 RtpParameters(const RtpParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200648 ~RtpParameters();
649
deadbeefe702b302017-02-04 12:09:01 -0800650 // Used when calling getParameters/setParameters with a PeerConnection
651 // RtpSender, to ensure that outdated parameters are not unintentionally
652 // applied successfully.
deadbeefe702b302017-02-04 12:09:01 -0800653 std::string transaction_id;
654
655 // Value to use for MID RTP header extension.
656 // Called "muxId" in ORTC.
657 // TODO(deadbeef): Not implemented.
658 std::string mid;
659
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700660 std::vector<RtpCodecParameters> codecs;
661
Danil Chapovalovb19eb392019-12-23 17:55:05 +0100662 std::vector<RtpExtension> header_extensions;
deadbeefe702b302017-02-04 12:09:01 -0800663
664 std::vector<RtpEncodingParameters> encodings;
665
Florent Castellidacec712018-05-24 16:24:21 +0200666 // Only available with a Peerconnection RtpSender.
667 // In ORTC, our API includes an additional "RtpTransport"
668 // abstraction on which RTCP parameters are set.
669 RtcpParameters rtcp;
670
Florent Castelli87b3c512018-07-18 16:00:28 +0200671 // When bandwidth is constrained and the RtpSender needs to choose between
672 // degrading resolution or degrading framerate, degradationPreference
673 // indicates which is preferred. Only for video tracks.
Florent Castellib05ca4b2020-03-05 13:39:55 +0100674 absl::optional<DegradationPreference> degradation_preference;
deadbeefe702b302017-02-04 12:09:01 -0800675
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700676 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800677 return mid == o.mid && codecs == o.codecs &&
678 header_extensions == o.header_extensions &&
Florent Castellidacec712018-05-24 16:24:21 +0200679 encodings == o.encodings && rtcp == o.rtcp &&
deadbeefe702b302017-02-04 12:09:01 -0800680 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700681 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700682 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700683};
684
685} // namespace webrtc
686
Steve Anton10542f22019-01-11 09:11:00 -0800687#endif // API_RTP_PARAMETERS_H_