blob: e311577878eab23a45a3833fe61934da2e9a11cf [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
Byoungchan Leea1a7c632022-07-05 21:06:28 +090020#include "absl/container/inlined_vector.h"
Markus Handelldfeb0df2020-03-16 22:20:47 +010021#include "absl/strings/string_view.h"
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020022#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "api/media_types.h"
Harald Alvestrandfd5ae7f2020-05-16 08:37:49 +020024#include "api/priority.h"
Markus Handell0357b3e2020-03-16 13:40:51 +010025#include "api/rtp_transceiver_direction.h"
Byoungchan Leea1a7c632022-07-05 21:06:28 +090026#include "api/video_codecs/scalability_mode.h"
Mirko Bonadeiac194142018-10-22 17:08:37 +020027#include "rtc_base/system/rtc_export.h"
sakal1fd95952016-06-22 00:46:15 -070028
skvladdc1c62c2016-03-16 19:07:43 -070029namespace webrtc {
30
deadbeefe702b302017-02-04 12:09:01 -080031// These structures are intended to mirror those defined by:
32// http://draft.ortc.org/#rtcrtpdictionaries*
33// Contains everything specified as of 2017 Jan 24.
34//
35// They are used when retrieving or modifying the parameters of an
36// RtpSender/RtpReceiver, or retrieving capabilities.
37//
38// Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
39// types, we typically use "int", in keeping with our style guidelines. The
40// parameter's actual valid range will be enforced when the parameters are set,
41// rather than when the parameters struct is built. An exception is made for
42// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
43// be used for any numeric comparisons/operations.
44//
45// Additionally, where ORTC uses strings, we may use enums for things that have
46// a fixed number of supported values. However, for things that can be extended
47// (such as codecs, by providing an external encoder factory), a string
48// identifier is used.
49
50enum class FecMechanism {
51 RED,
52 RED_AND_ULPFEC,
53 FLEXFEC,
54};
55
56// Used in RtcpFeedback struct.
57enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 12:09:01 -080058 CCM,
Elad Alonfadb1812019-05-24 13:40:02 +020059 LNTF, // "goog-lntf"
deadbeefe702b302017-02-04 12:09:01 -080060 NACK,
61 REMB, // "goog-remb"
62 TRANSPORT_CC,
63};
64
deadbeefe814a0d2017-02-25 18:15:09 -080065// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 12:09:01 -080066enum class RtcpFeedbackMessageType {
67 // Equivalent to {type: "nack", parameter: undefined} in ORTC.
68 GENERIC_NACK,
69 PLI, // Usable with NACK.
70 FIR, // Usable with CCM.
71};
72
73enum class DtxStatus {
74 DISABLED,
75 ENABLED,
76};
77
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070078// Based on the spec in
79// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
80// These options are enforced on a best-effort basis. For instance, all of
81// these options may suffer some frame drops in order to avoid queuing.
82// TODO(sprang): Look into possibility of more strictly enforcing the
83// maintain-framerate option.
84// TODO(deadbeef): Default to "balanced", as the spec indicates?
deadbeefe702b302017-02-04 12:09:01 -080085enum class DegradationPreference {
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070086 // Don't take any actions based on over-utilization signals. Not part of the
87 // web API.
88 DISABLED,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070089 // On over-use, request lower resolution, possibly causing down-scaling.
Åsa Persson90bc1e12019-05-31 13:29:35 +020090 MAINTAIN_FRAMERATE,
91 // On over-use, request lower frame rate, possibly causing frame drops.
deadbeefe702b302017-02-04 12:09:01 -080092 MAINTAIN_RESOLUTION,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070093 // Try to strike a "pleasing" balance between frame rate or resolution.
deadbeefe702b302017-02-04 12:09:01 -080094 BALANCED,
95};
96
Henrik Boströmf0eef122020-05-28 16:22:42 +020097RTC_EXPORT const char* DegradationPreferenceToString(
98 DegradationPreference degradation_preference);
99
Mirko Bonadei66e76792019-04-02 11:33:59 +0200100RTC_EXPORT extern const double kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -0800101
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200102struct RTC_EXPORT RtcpFeedback {
deadbeefe814a0d2017-02-25 18:15:09 -0800103 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 12:09:01 -0800104
105 // Equivalent to ORTC "parameter" field with slight differences:
106 // 1. It's an enum instead of a string.
107 // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
108 // rather than an unset "parameter" value.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200109 absl::optional<RtcpFeedbackMessageType> message_type;
deadbeefe702b302017-02-04 12:09:01 -0800110
deadbeefe814a0d2017-02-25 18:15:09 -0800111 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200112 RtcpFeedback();
113 explicit RtcpFeedback(RtcpFeedbackType type);
114 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200115 RtcpFeedback(const RtcpFeedback&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200116 ~RtcpFeedback();
deadbeefe814a0d2017-02-25 18:15:09 -0800117
deadbeefe702b302017-02-04 12:09:01 -0800118 bool operator==(const RtcpFeedback& o) const {
119 return type == o.type && message_type == o.message_type;
120 }
121 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
122};
123
124// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
125// RtpParameters. This represents the static capabilities of an endpoint's
126// implementation of a codec.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200127struct RTC_EXPORT RtpCodecCapability {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200128 RtpCodecCapability();
129 ~RtpCodecCapability();
130
Artem Titov0e61fdd2021-07-25 21:50:14 +0200131 // Build MIME "type/subtype" string from `name` and `kind`.
deadbeefe702b302017-02-04 12:09:01 -0800132 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
133
134 // Used to identify the codec. Equivalent to MIME subtype.
135 std::string name;
136
137 // The media type of this codec. Equivalent to MIME top-level type.
138 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
139
140 // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200141 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800142
143 // Default payload type for this codec. Mainly needed for codecs that use
144 // that have statically assigned payload types.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200145 absl::optional<int> preferred_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800146
147 // Maximum packetization time supported by an RtpReceiver for this codec.
148 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200149 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800150
Åsa Persson90bc1e12019-05-31 13:29:35 +0200151 // Preferred packetization time for an RtpReceiver or RtpSender of this codec.
deadbeefe702b302017-02-04 12:09:01 -0800152 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200153 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800154
155 // The number of audio channels supported. Unused for video codecs.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200156 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800157
158 // Feedback mechanisms supported for this codec.
159 std::vector<RtcpFeedback> rtcp_feedback;
160
161 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800162 //
deadbeefe702b302017-02-04 12:09:01 -0800163 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800164 //
165 // Contrary to ORTC, these parameters are named using all lowercase strings.
Åsa Persson90bc1e12019-05-31 13:29:35 +0200166 // This helps make the mapping to SDP simpler, if an application is using SDP.
167 // Boolean values are represented by the string "1".
Johannes Kron72d69152020-02-10 14:05:55 +0100168 std::map<std::string, std::string> parameters;
deadbeefe702b302017-02-04 12:09:01 -0800169
170 // Codec-specific parameters that may optionally be signaled to the remote
171 // party.
172 // TODO(deadbeef): Not implemented.
Johannes Kron72d69152020-02-10 14:05:55 +0100173 std::map<std::string, std::string> options;
deadbeefe702b302017-02-04 12:09:01 -0800174
175 // Maximum number of temporal layer extensions supported by this codec.
176 // For example, a value of 1 indicates that 2 total layers are supported.
177 // TODO(deadbeef): Not implemented.
178 int max_temporal_layer_extensions = 0;
179
180 // Maximum number of spatial layer extensions supported by this codec.
181 // For example, a value of 1 indicates that 2 total layers are supported.
182 // TODO(deadbeef): Not implemented.
183 int max_spatial_layer_extensions = 0;
184
Åsa Persson90bc1e12019-05-31 13:29:35 +0200185 // Whether the implementation can send/receive SVC layers with distinct SSRCs.
186 // Always false for audio codecs. True for video codecs that support scalable
187 // video coding with MRST.
deadbeefe702b302017-02-04 12:09:01 -0800188 // TODO(deadbeef): Not implemented.
189 bool svc_multi_stream_support = false;
190
Byoungchan Leea1a7c632022-07-05 21:06:28 +0900191 // https://w3c.github.io/webrtc-svc/#dom-rtcrtpcodeccapability-scalabilitymodes
192 absl::InlinedVector<ScalabilityMode, kScalabilityModeCount> scalability_modes;
193
deadbeefe702b302017-02-04 12:09:01 -0800194 bool operator==(const RtpCodecCapability& o) const {
195 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
196 preferred_payload_type == o.preferred_payload_type &&
197 max_ptime == o.max_ptime && ptime == o.ptime &&
198 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
199 parameters == o.parameters && options == o.options &&
200 max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
201 max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
Byoungchan Leea1a7c632022-07-05 21:06:28 +0900202 svc_multi_stream_support == o.svc_multi_stream_support &&
203 scalability_modes == o.scalability_modes;
deadbeefe702b302017-02-04 12:09:01 -0800204 }
205 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
206};
207
Markus Handell0357b3e2020-03-16 13:40:51 +0100208// Used in RtpCapabilities and RtpTransceiverInterface's header extensions query
209// and setup methods; represents the capabilities/preferences of an
deadbeefe702b302017-02-04 12:09:01 -0800210// implementation for a header extension.
211//
212// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
213// added here for consistency and to avoid confusion with
214// RtpHeaderExtensionParameters.
215//
216// Note that ORTC includes a "kind" field, but we omit this because it's
217// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
218// you know you're getting audio capabilities.
Markus Handell0357b3e2020-03-16 13:40:51 +0100219struct RTC_EXPORT RtpHeaderExtensionCapability {
Johannes Kron07ba2b92018-09-26 13:33:35 +0200220 // URI of this extension, as defined in RFC8285.
deadbeefe702b302017-02-04 12:09:01 -0800221 std::string uri;
222
223 // Preferred value of ID that goes in the packet.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200224 absl::optional<int> preferred_id;
deadbeefe702b302017-02-04 12:09:01 -0800225
226 // If true, it's preferred that the value in the header is encrypted.
227 // TODO(deadbeef): Not implemented.
228 bool preferred_encrypt = false;
229
Markus Handell0357b3e2020-03-16 13:40:51 +0100230 // The direction of the extension. The kStopped value is only used with
Markus Handell755c65d2020-06-24 01:06:10 +0200231 // RtpTransceiverInterface::HeaderExtensionsToOffer() and
Markus Handell0357b3e2020-03-16 13:40:51 +0100232 // SetOfferedRtpHeaderExtensions().
233 RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
234
deadbeefe814a0d2017-02-25 18:15:09 -0800235 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200236 RtpHeaderExtensionCapability();
Danil Chapovalov2b4ec9e2020-03-25 17:23:37 +0100237 explicit RtpHeaderExtensionCapability(absl::string_view uri);
238 RtpHeaderExtensionCapability(absl::string_view uri, int preferred_id);
239 RtpHeaderExtensionCapability(absl::string_view uri,
Markus Handell0357b3e2020-03-16 13:40:51 +0100240 int preferred_id,
241 RtpTransceiverDirection direction);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200242 ~RtpHeaderExtensionCapability();
deadbeefe814a0d2017-02-25 18:15:09 -0800243
deadbeefe702b302017-02-04 12:09:01 -0800244 bool operator==(const RtpHeaderExtensionCapability& o) const {
245 return uri == o.uri && preferred_id == o.preferred_id &&
Markus Handell0357b3e2020-03-16 13:40:51 +0100246 preferred_encrypt == o.preferred_encrypt && direction == o.direction;
deadbeefe702b302017-02-04 12:09:01 -0800247 }
248 bool operator!=(const RtpHeaderExtensionCapability& o) const {
249 return !(*this == o);
250 }
251};
252
Johannes Kron07ba2b92018-09-26 13:33:35 +0200253// RTP header extension, see RFC8285.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200254struct RTC_EXPORT RtpExtension {
Lennart Grahl0d0ed762021-05-17 16:06:37 +0200255 enum Filter {
256 // Encrypted extensions will be ignored and only non-encrypted extensions
257 // will be considered.
258 kDiscardEncryptedExtension,
259 // Encrypted extensions will be preferred but will fall back to
260 // non-encrypted extensions if necessary.
261 kPreferEncryptedExtension,
262 // Encrypted extensions will be required, so any non-encrypted extensions
263 // will be discarded.
264 kRequireEncryptedExtension,
265 };
266
Stefan Holmer1acbd682017-09-01 15:29:28 +0200267 RtpExtension();
Danil Chapovalov2b4ec9e2020-03-25 17:23:37 +0100268 RtpExtension(absl::string_view uri, int id);
269 RtpExtension(absl::string_view uri, int id, bool encrypt);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200270 ~RtpExtension();
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100271
Stefan Holmer1acbd682017-09-01 15:29:28 +0200272 std::string ToString() const;
273 bool operator==(const RtpExtension& rhs) const {
274 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
275 }
Markus Handelldfeb0df2020-03-16 22:20:47 +0100276 static bool IsSupportedForAudio(absl::string_view uri);
277 static bool IsSupportedForVideo(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200278 // Return "true" if the given RTP header extension URI may be encrypted.
Markus Handelldfeb0df2020-03-16 22:20:47 +0100279 static bool IsEncryptionSupported(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200280
Lennart Grahl0d0ed762021-05-17 16:06:37 +0200281 // Returns the header extension with the given URI or nullptr if not found.
282 static const RtpExtension* FindHeaderExtensionByUri(
283 const std::vector<RtpExtension>& extensions,
284 absl::string_view uri,
285 Filter filter);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200286
Lennart Grahl0d0ed762021-05-17 16:06:37 +0200287 // Returns the header extension with the given URI and encrypt parameter,
288 // if found, otherwise nullptr.
289 static const RtpExtension* FindHeaderExtensionByUriAndEncryption(
290 const std::vector<RtpExtension>& extensions,
291 absl::string_view uri,
292 bool encrypt);
293
294 // Returns a list of extensions where any extension URI is unique.
Tomas Gunnarssonc69453d2022-01-06 12:36:04 +0000295 // The returned list will be sorted by uri first, then encrypt and id last.
296 // Having the list sorted allows the caller fo compare filtered lists for
297 // equality to detect when changes have been made.
Lennart Grahl0d0ed762021-05-17 16:06:37 +0200298 static const std::vector<RtpExtension> DeduplicateHeaderExtensions(
299 const std::vector<RtpExtension>& extensions,
300 Filter filter);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200301
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100302 // Encryption of Header Extensions, see RFC 6904 for details:
303 // https://tools.ietf.org/html/rfc6904
304 static constexpr char kEncryptHeaderExtensionsUri[] =
305 "urn:ietf:params:rtp-hdrext:encrypt";
306
Stefan Holmer1acbd682017-09-01 15:29:28 +0200307 // Header extension for audio levels, as defined in:
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100308 // https://tools.ietf.org/html/rfc6464
309 static constexpr char kAudioLevelUri[] =
310 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200311
312 // Header extension for RTP timestamp offset, see RFC 5450 for details:
313 // http://tools.ietf.org/html/rfc5450
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100314 static constexpr char kTimestampOffsetUri[] =
315 "urn:ietf:params:rtp-hdrext:toffset";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200316
317 // Header extension for absolute send time, see url for details:
318 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100319 static constexpr char kAbsSendTimeUri[] =
320 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200321
Chen Xingcd8a6e22019-07-01 10:56:51 +0200322 // Header extension for absolute capture time, see url for details:
323 // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100324 static constexpr char kAbsoluteCaptureTimeUri[] =
325 "http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time";
Chen Xingcd8a6e22019-07-01 10:56:51 +0200326
Stefan Holmer1acbd682017-09-01 15:29:28 +0200327 // Header extension for coordination of video orientation, see url for
328 // details:
329 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100330 static constexpr char kVideoRotationUri[] = "urn:3gpp:video-orientation";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200331
332 // Header extension for video content type. E.g. default or screenshare.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100333 static constexpr char kVideoContentTypeUri[] =
334 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200335
336 // Header extension for video timing.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100337 static constexpr char kVideoTimingUri[] =
338 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200339
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200340 // Experimental codec agnostic frame descriptor.
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100341 static constexpr char kGenericFrameDescriptorUri00[] =
342 "http://www.webrtc.org/experiments/rtp-hdrext/"
343 "generic-frame-descriptor-00";
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100344 static constexpr char kDependencyDescriptorUri[] =
345 "https://aomediacodec.github.io/av1-rtp-spec/"
346 "#dependency-descriptor-rtp-header-extension";
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200347
Per Kjellander70c89452020-10-21 13:35:07 +0200348 // Experimental extension for signalling target bitrate per layer.
349 static constexpr char kVideoLayersAllocationUri[] =
350 "http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00";
351
Stefan Holmer1acbd682017-09-01 15:29:28 +0200352 // Header extension for transport sequence number, see url for details:
353 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100354 static constexpr char kTransportSequenceNumberUri[] =
355 "http://www.ietf.org/id/"
356 "draft-holmer-rmcat-transport-wide-cc-extensions-01";
357 static constexpr char kTransportSequenceNumberV2Uri[] =
358 "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200359
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100360 // This extension allows applications to adaptively limit the playout delay
361 // on frames as per the current needs. For example, a gaming application
362 // has very different needs on end-to-end delay compared to a video-conference
363 // application.
364 static constexpr char kPlayoutDelayUri[] =
365 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
366
367 // Header extension for color space information.
368 static constexpr char kColorSpaceUri[] =
369 "http://www.webrtc.org/experiments/rtp-hdrext/color-space";
Stefan Holmer1acbd682017-09-01 15:29:28 +0200370
Steve Antonbb50ce52018-03-26 10:24:32 -0700371 // Header extension for identifying media section within a transport.
372 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100373 static constexpr char kMidUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
Johannes Krond0b69a82018-12-03 14:18:53 +0100374
Amit Hilbuch77938e62018-12-21 09:23:38 -0800375 // Header extension for RIDs and Repaired RIDs
376 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
377 // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
Danil Chapovalov418cfee2020-03-25 11:02:37 +0100378 static constexpr char kRidUri[] =
379 "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
380 static constexpr char kRepairedRidUri[] =
381 "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
Amit Hilbuch77938e62018-12-21 09:23:38 -0800382
Jeremy Leconteb258c562021-03-18 13:50:42 +0100383 // Header extension to propagate webrtc::VideoFrame id field
384 static constexpr char kVideoFrameTrackingIdUri[] =
385 "http://www.webrtc.org/experiments/rtp-hdrext/video-frame-tracking-id";
386
Doudou Kisabakaae0d1172021-05-24 13:04:45 +0200387 // Header extension for Mixer-to-Client audio levels per CSRC as defined in
388 // https://tools.ietf.org/html/rfc6465
389 static constexpr char kCsrcAudioLevelsUri[] =
390 "urn:ietf:params:rtp-hdrext:csrc-audio-level";
391
Johannes Kron07ba2b92018-09-26 13:33:35 +0200392 // Inclusive min and max IDs for two-byte header extensions and one-byte
393 // header extensions, per RFC8285 Section 4.2-4.3.
394 static constexpr int kMinId = 1;
395 static constexpr int kMaxId = 255;
Johannes Kron78cdde32018-10-05 10:00:46 +0200396 static constexpr int kMaxValueSize = 255;
Johannes Kron07ba2b92018-09-26 13:33:35 +0200397 static constexpr int kOneByteHeaderExtensionMaxId = 14;
Johannes Kron78cdde32018-10-05 10:00:46 +0200398 static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200399
400 std::string uri;
401 int id = 0;
402 bool encrypt = false;
403};
404
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200405struct RTC_EXPORT RtpFecParameters {
deadbeefe702b302017-02-04 12:09:01 -0800406 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800407 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200408 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800409
410 FecMechanism mechanism = FecMechanism::RED;
411
deadbeefe814a0d2017-02-25 18:15:09 -0800412 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200413 RtpFecParameters();
414 explicit RtpFecParameters(FecMechanism mechanism);
415 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200416 RtpFecParameters(const RtpFecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200417 ~RtpFecParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800418
deadbeefe702b302017-02-04 12:09:01 -0800419 bool operator==(const RtpFecParameters& o) const {
420 return ssrc == o.ssrc && mechanism == o.mechanism;
421 }
422 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
423};
424
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200425struct RTC_EXPORT RtpRtxParameters {
deadbeefe702b302017-02-04 12:09:01 -0800426 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800427 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200428 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800429
deadbeefe814a0d2017-02-25 18:15:09 -0800430 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200431 RtpRtxParameters();
432 explicit RtpRtxParameters(uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200433 RtpRtxParameters(const RtpRtxParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200434 ~RtpRtxParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800435
deadbeefe702b302017-02-04 12:09:01 -0800436 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
437 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
438};
439
Mirko Bonadei66e76792019-04-02 11:33:59 +0200440struct RTC_EXPORT RtpEncodingParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200441 RtpEncodingParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200442 RtpEncodingParameters(const RtpEncodingParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200443 ~RtpEncodingParameters();
444
deadbeefe702b302017-02-04 12:09:01 -0800445 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800446 //
447 // Note that the chosen value is NOT returned by GetParameters, because it
448 // may change due to an SSRC conflict, in which case the conflict is handled
449 // internally without any event. Another way of looking at this is that an
450 // unset SSRC acts as a "wildcard" SSRC.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200451 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800452
Seth Hampson24722b32017-12-22 09:36:42 -0800453 // The relative bitrate priority of this encoding. Currently this is
Seth Hampsona881ac02018-02-12 14:14:39 -0800454 // implemented for the entire rtp sender by using the value of the first
455 // encoding parameter.
Taylor Brandstettere3a294c2020-03-23 23:16:58 +0000456 // See: https://w3c.github.io/webrtc-priority/#enumdef-rtcprioritytype
457 // "very-low" = 0.5
458 // "low" = 1.0
459 // "medium" = 2.0
460 // "high" = 4.0
Seth Hampsona881ac02018-02-12 14:14:39 -0800461 // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
462 // Currently there is logic for how bitrate is distributed per simulcast layer
463 // in the VideoBitrateAllocator. This must be updated to incorporate relative
464 // bitrate priority.
Seth Hampson24722b32017-12-22 09:36:42 -0800465 double bitrate_priority = kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -0800466
Tim Haloun648d28a2018-10-18 16:52:22 -0700467 // The relative DiffServ Code Point priority for this encoding, allowing
468 // packets to be marked relatively higher or lower without affecting
Taylor Brandstettere3a294c2020-03-23 23:16:58 +0000469 // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ .
Tim Haloun648d28a2018-10-18 16:52:22 -0700470 // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -0800471 // TODO(http://crbug.com/webrtc/11379): TCP connections should use a single
472 // DSCP value even if shared by multiple senders; this is not implemented.
473 Priority network_priority = Priority::kLow;
Tim Haloun648d28a2018-10-18 16:52:22 -0700474
deadbeefe702b302017-02-04 12:09:01 -0800475 // If set, this represents the Transport Independent Application Specific
476 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
Seth Hampsona881ac02018-02-12 14:14:39 -0800477 // bitrate. Currently this is implemented for the entire rtp sender by using
478 // the value of the first encoding parameter.
479 //
deadbeefe702b302017-02-04 12:09:01 -0800480 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-25 18:15:09 -0800481 //
482 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
483 // bandwidth for the entire bandwidth estimator (audio and video). This is
484 // just always how "b=AS" was handled, but it's not correct and should be
485 // fixed.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200486 absl::optional<int> max_bitrate_bps;
deadbeefe702b302017-02-04 12:09:01 -0800487
Åsa Persson55659812018-06-18 17:51:32 +0200488 // Specifies the minimum bitrate in bps for video.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200489 absl::optional<int> min_bitrate_bps;
Åsa Persson613591a2018-05-29 09:21:31 +0200490
Åsa Persson8c1bf952018-09-13 10:42:19 +0200491 // Specifies the maximum framerate in fps for video.
Florent Castelli907dc802019-12-06 15:03:19 +0100492 absl::optional<double> max_framerate;
deadbeefe702b302017-02-04 12:09:01 -0800493
Åsa Persson23eba222018-10-02 14:47:06 +0200494 // Specifies the number of temporal layers for video (if the feature is
495 // supported by the codec implementation).
Ilya Nikolaevskiy9f6a0d52019-02-05 10:29:41 +0100496 // Screencast support is experimental.
Åsa Persson23eba222018-10-02 14:47:06 +0200497 absl::optional<int> num_temporal_layers;
498
deadbeefe702b302017-02-04 12:09:01 -0800499 // For video, scale the resolution down by this factor.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200500 absl::optional<double> scale_resolution_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800501
philipel87e99092020-11-18 11:52:04 +0100502 // https://w3c.github.io/webrtc-svc/#rtcrtpencodingparameters
503 absl::optional<std::string> scalability_mode;
504
Seth Hampsona881ac02018-02-12 14:14:39 -0800505 // For an RtpSender, set to true to cause this encoding to be encoded and
506 // sent, and false for it not to be encoded and sent. This allows control
507 // across multiple encodings of a sender for turning simulcast layers on and
508 // off.
509 // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
510 // reset, but this isn't necessarily required.
deadbeefdbe2b872016-03-22 15:42:00 -0700511 bool active = true;
deadbeefe702b302017-02-04 12:09:01 -0800512
513 // Value to use for RID RTP header extension.
514 // Called "encodingId" in ORTC.
deadbeefe702b302017-02-04 12:09:01 -0800515 std::string rid;
516
Jakob Ivarsson39adce12020-06-25 14:09:58 +0200517 // Allow dynamic frame length changes for audio:
518 // https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime
519 bool adaptive_ptime = false;
520
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700521 bool operator==(const RtpEncodingParameters& o) const {
Florent Castellia8c2f512019-11-28 15:48:24 +0100522 return ssrc == o.ssrc && bitrate_priority == o.bitrate_priority &&
523 network_priority == o.network_priority &&
Seth Hampson24722b32017-12-22 09:36:42 -0800524 max_bitrate_bps == o.max_bitrate_bps &&
Åsa Persson8c1bf952018-09-13 10:42:19 +0200525 min_bitrate_bps == o.min_bitrate_bps &&
deadbeefe702b302017-02-04 12:09:01 -0800526 max_framerate == o.max_framerate &&
Åsa Persson23eba222018-10-02 14:47:06 +0200527 num_temporal_layers == o.num_temporal_layers &&
deadbeefe702b302017-02-04 12:09:01 -0800528 scale_resolution_down_by == o.scale_resolution_down_by &&
Jakob Ivarsson39adce12020-06-25 14:09:58 +0200529 active == o.active && rid == o.rid &&
530 adaptive_ptime == o.adaptive_ptime;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700531 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700532 bool operator!=(const RtpEncodingParameters& o) const {
533 return !(*this == o);
534 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700535};
536
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200537struct RTC_EXPORT RtpCodecParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200538 RtpCodecParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200539 RtpCodecParameters(const RtpCodecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200540 ~RtpCodecParameters();
541
Artem Titov0e61fdd2021-07-25 21:50:14 +0200542 // Build MIME "type/subtype" string from `name` and `kind`.
deadbeefe702b302017-02-04 12:09:01 -0800543 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
544
545 // Used to identify the codec. Equivalent to MIME subtype.
546 std::string name;
547
548 // The media type of this codec. Equivalent to MIME top-level type.
549 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
550
551 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-25 18:15:09 -0800552 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 12:09:01 -0800553 // the same transport.
554 int payload_type = 0;
555
556 // If unset, the implementation default is used.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200557 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800558
559 // The number of audio channels used. Unset for video codecs. If unset for
560 // audio, the implementation default is used.
deadbeefe814a0d2017-02-25 18:15:09 -0800561 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
562 // Only defaults to 1, even though some codecs (such as opus) should really
563 // default to 2.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200564 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800565
566 // The maximum packetization time to be used by an RtpSender.
Artem Titov0e61fdd2021-07-25 21:50:14 +0200567 // If `ptime` is also set, this will be ignored.
deadbeefe702b302017-02-04 12:09:01 -0800568 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200569 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800570
571 // The packetization time to be used by an RtpSender.
572 // If unset, will use any time up to max_ptime.
573 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200574 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800575
576 // Feedback mechanisms to be used for this codec.
deadbeefe814a0d2017-02-25 18:15:09 -0800577 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800578 std::vector<RtcpFeedback> rtcp_feedback;
579
580 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800581 //
deadbeefe702b302017-02-04 12:09:01 -0800582 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800583 //
584 // Contrary to ORTC, these parameters are named using all lowercase strings.
Åsa Persson90bc1e12019-05-31 13:29:35 +0200585 // This helps make the mapping to SDP simpler, if an application is using SDP.
586 // Boolean values are represented by the string "1".
Johannes Kron72d69152020-02-10 14:05:55 +0100587 std::map<std::string, std::string> parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700588
589 bool operator==(const RtpCodecParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800590 return name == o.name && kind == o.kind && payload_type == o.payload_type &&
591 clock_rate == o.clock_rate && num_channels == o.num_channels &&
592 max_ptime == o.max_ptime && ptime == o.ptime &&
593 rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700594 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700595 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700596};
597
Åsa Persson90bc1e12019-05-31 13:29:35 +0200598// RtpCapabilities is used to represent the static capabilities of an endpoint.
599// An application can use these capabilities to construct an RtpParameters.
Mirko Bonadei66e76792019-04-02 11:33:59 +0200600struct RTC_EXPORT RtpCapabilities {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200601 RtpCapabilities();
602 ~RtpCapabilities();
603
deadbeefe702b302017-02-04 12:09:01 -0800604 // Supported codecs.
605 std::vector<RtpCodecCapability> codecs;
606
607 // Supported RTP header extensions.
608 std::vector<RtpHeaderExtensionCapability> header_extensions;
609
deadbeefe814a0d2017-02-25 18:15:09 -0800610 // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
611 // ulpfec and flexfec codecs used by these mechanisms will still appear in
Artem Titov0e61fdd2021-07-25 21:50:14 +0200612 // `codecs`.
deadbeefe702b302017-02-04 12:09:01 -0800613 std::vector<FecMechanism> fec;
614
615 bool operator==(const RtpCapabilities& o) const {
616 return codecs == o.codecs && header_extensions == o.header_extensions &&
617 fec == o.fec;
618 }
619 bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
620};
621
Florent Castellidacec712018-05-24 16:24:21 +0200622struct RtcpParameters final {
623 RtcpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200624 RtcpParameters(const RtcpParameters&);
Florent Castellidacec712018-05-24 16:24:21 +0200625 ~RtcpParameters();
626
627 // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
628 // will be chosen by the implementation.
629 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200630 absl::optional<uint32_t> ssrc;
Florent Castellidacec712018-05-24 16:24:21 +0200631
632 // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
633 //
634 // If empty in the construction of the RtpTransport, one will be generated by
635 // the implementation, and returned in GetRtcpParameters. Multiple
636 // RtpTransports created by the same OrtcFactory will use the same generated
637 // CNAME.
638 //
639 // If empty when passed into SetParameters, the CNAME simply won't be
640 // modified.
641 std::string cname;
642
643 // Send reduced-size RTCP?
644 bool reduced_size = false;
645
646 // Send RTCP multiplexed on the RTP transport?
647 // Not used with PeerConnection senders/receivers
648 bool mux = true;
649
650 bool operator==(const RtcpParameters& o) const {
651 return ssrc == o.ssrc && cname == o.cname &&
652 reduced_size == o.reduced_size && mux == o.mux;
653 }
654 bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
655};
656
Mirko Bonadeiac194142018-10-22 17:08:37 +0200657struct RTC_EXPORT RtpParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200658 RtpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200659 RtpParameters(const RtpParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200660 ~RtpParameters();
661
deadbeefe702b302017-02-04 12:09:01 -0800662 // Used when calling getParameters/setParameters with a PeerConnection
663 // RtpSender, to ensure that outdated parameters are not unintentionally
664 // applied successfully.
deadbeefe702b302017-02-04 12:09:01 -0800665 std::string transaction_id;
666
667 // Value to use for MID RTP header extension.
668 // Called "muxId" in ORTC.
669 // TODO(deadbeef): Not implemented.
670 std::string mid;
671
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700672 std::vector<RtpCodecParameters> codecs;
673
Danil Chapovalovb19eb392019-12-23 17:55:05 +0100674 std::vector<RtpExtension> header_extensions;
deadbeefe702b302017-02-04 12:09:01 -0800675
676 std::vector<RtpEncodingParameters> encodings;
677
Florent Castellidacec712018-05-24 16:24:21 +0200678 // Only available with a Peerconnection RtpSender.
679 // In ORTC, our API includes an additional "RtpTransport"
680 // abstraction on which RTCP parameters are set.
681 RtcpParameters rtcp;
682
Florent Castelli87b3c512018-07-18 16:00:28 +0200683 // When bandwidth is constrained and the RtpSender needs to choose between
684 // degrading resolution or degrading framerate, degradationPreference
685 // indicates which is preferred. Only for video tracks.
Florent Castellib05ca4b2020-03-05 13:39:55 +0100686 absl::optional<DegradationPreference> degradation_preference;
deadbeefe702b302017-02-04 12:09:01 -0800687
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700688 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800689 return mid == o.mid && codecs == o.codecs &&
690 header_extensions == o.header_extensions &&
Florent Castellidacec712018-05-24 16:24:21 +0200691 encodings == o.encodings && rtcp == o.rtcp &&
deadbeefe702b302017-02-04 12:09:01 -0800692 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700693 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700694 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700695};
696
697} // namespace webrtc
698
Steve Anton10542f22019-01-11 09:11:00 -0800699#endif // API_RTP_PARAMETERS_H_