blob: 025817cf37842679a6ddf0723925845c57a761f8 [file] [log] [blame]
skvladdc1c62c2016-03-17 02:07:431/*
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 17:11:0011#ifndef API_RTP_PARAMETERS_H_
12#define API_RTP_PARAMETERS_H_
skvladdc1c62c2016-03-17 02:07:4313
Yves Gerey988cc082018-10-23 10:03:0114#include <stdint.h>
Jonas Olssona4d87372019-07-05 17:08:3315
Johannes Kron72d69152020-02-10 13:05:5516#include <map>
Taylor Brandstetter0cd086b2016-04-20 23:23:1017#include <string>
skvladdc1c62c2016-03-17 02:07:4318#include <vector>
19
Byoungchan Leea1a7c632022-07-05 12:06:2820#include "absl/container/inlined_vector.h"
Markus Handelldfeb0df2020-03-16 21:20:4721#include "absl/strings/string_view.h"
Danil Chapovalov0bc58cf2018-06-21 11:32:5622#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 17:11:0023#include "api/media_types.h"
Harald Alvestrandfd5ae7f2020-05-16 06:37:4924#include "api/priority.h"
Markus Handell0357b3e2020-03-16 12:40:5125#include "api/rtp_transceiver_direction.h"
Jonas Oreland0deda152022-09-23 10:08:5726#include "api/video/resolution.h"
Byoungchan Leea1a7c632022-07-05 12:06:2827#include "api/video_codecs/scalability_mode.h"
Mirko Bonadeiac194142018-10-22 15:08:3728#include "rtc_base/system/rtc_export.h"
sakal1fd95952016-06-22 07:46:1529
skvladdc1c62c2016-03-17 02:07:4330namespace webrtc {
31
Philipp Hanckede172522023-12-14 08:45:3932using CodecParameterMap = std::map<std::string, std::string>;
33
deadbeefe702b302017-02-04 20:09:0134// These structures are intended to mirror those defined by:
35// http://draft.ortc.org/#rtcrtpdictionaries*
36// Contains everything specified as of 2017 Jan 24.
37//
38// They are used when retrieving or modifying the parameters of an
39// RtpSender/RtpReceiver, or retrieving capabilities.
40//
41// Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
42// types, we typically use "int", in keeping with our style guidelines. The
43// parameter's actual valid range will be enforced when the parameters are set,
44// rather than when the parameters struct is built. An exception is made for
45// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
46// be used for any numeric comparisons/operations.
47//
48// Additionally, where ORTC uses strings, we may use enums for things that have
49// a fixed number of supported values. However, for things that can be extended
50// (such as codecs, by providing an external encoder factory), a string
51// identifier is used.
52
53enum class FecMechanism {
54 RED,
55 RED_AND_ULPFEC,
56 FLEXFEC,
57};
58
59// Used in RtcpFeedback struct.
60enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 20:09:0161 CCM,
Elad Alonfadb1812019-05-24 11:40:0262 LNTF, // "goog-lntf"
deadbeefe702b302017-02-04 20:09:0163 NACK,
64 REMB, // "goog-remb"
65 TRANSPORT_CC,
66};
67
deadbeefe814a0d2017-02-26 02:15:0968// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 20:09:0169enum class RtcpFeedbackMessageType {
70 // Equivalent to {type: "nack", parameter: undefined} in ORTC.
71 GENERIC_NACK,
72 PLI, // Usable with NACK.
73 FIR, // Usable with CCM.
74};
75
76enum class DtxStatus {
77 DISABLED,
78 ENABLED,
79};
80
Taylor Brandstetter49fcc102018-05-16 21:20:4181// Based on the spec in
82// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
83// These options are enforced on a best-effort basis. For instance, all of
84// these options may suffer some frame drops in order to avoid queuing.
85// TODO(sprang): Look into possibility of more strictly enforcing the
86// maintain-framerate option.
87// TODO(deadbeef): Default to "balanced", as the spec indicates?
deadbeefe702b302017-02-04 20:09:0188enum class DegradationPreference {
Taylor Brandstetter49fcc102018-05-16 21:20:4189 // Don't take any actions based on over-utilization signals. Not part of the
90 // web API.
91 DISABLED,
Taylor Brandstetter49fcc102018-05-16 21:20:4192 // On over-use, request lower resolution, possibly causing down-scaling.
Åsa Persson90bc1e12019-05-31 11:29:3593 MAINTAIN_FRAMERATE,
94 // On over-use, request lower frame rate, possibly causing frame drops.
deadbeefe702b302017-02-04 20:09:0195 MAINTAIN_RESOLUTION,
Taylor Brandstetter49fcc102018-05-16 21:20:4196 // Try to strike a "pleasing" balance between frame rate or resolution.
deadbeefe702b302017-02-04 20:09:0197 BALANCED,
98};
99
Henrik Boströmf0eef122020-05-28 14:22:42100RTC_EXPORT const char* DegradationPreferenceToString(
101 DegradationPreference degradation_preference);
102
Mirko Bonadei66e76792019-04-02 09:33:59103RTC_EXPORT extern const double kDefaultBitratePriority;
deadbeefe702b302017-02-04 20:09:01104
Mirko Bonadei35214fc2019-09-23 12:54:28105struct RTC_EXPORT RtcpFeedback {
deadbeefe814a0d2017-02-26 02:15:09106 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 20:09:01107
108 // Equivalent to ORTC "parameter" field with slight differences:
109 // 1. It's an enum instead of a string.
110 // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
111 // rather than an unset "parameter" value.
Danil Chapovalov0bc58cf2018-06-21 11:32:56112 absl::optional<RtcpFeedbackMessageType> message_type;
deadbeefe702b302017-02-04 20:09:01113
deadbeefe814a0d2017-02-26 02:15:09114 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 13:29:28115 RtcpFeedback();
116 explicit RtcpFeedback(RtcpFeedbackType type);
117 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
Mirko Bonadei2ffed6d2018-07-20 09:09:32118 RtcpFeedback(const RtcpFeedback&);
Stefan Holmer1acbd682017-09-01 13:29:28119 ~RtcpFeedback();
deadbeefe814a0d2017-02-26 02:15:09120
deadbeefe702b302017-02-04 20:09:01121 bool operator==(const RtcpFeedback& o) const {
122 return type == o.type && message_type == o.message_type;
123 }
124 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
125};
126
Florent Castelli0a4a9842023-04-03 17:25:29127struct RTC_EXPORT RtpCodec {
128 RtpCodec();
129 RtpCodec(const RtpCodec&);
130 virtual ~RtpCodec();
Stefan Holmer1acbd682017-09-01 13:29:28131
Artem Titov0e61fdd2021-07-25 19:50:14132 // Build MIME "type/subtype" string from `name` and `kind`.
deadbeefe702b302017-02-04 20:09:01133 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
134
135 // Used to identify the codec. Equivalent to MIME subtype.
136 std::string name;
137
138 // The media type of this codec. Equivalent to MIME top-level type.
139 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
140
Florent Castelli0a4a9842023-04-03 17:25:29141 // If unset, the implementation default is used.
Danil Chapovalov0bc58cf2018-06-21 11:32:56142 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 20:09:01143
Florent Castelli0a4a9842023-04-03 17:25:29144 // The number of audio channels used. Unset for video codecs. If unset for
145 // audio, the implementation default is used.
146 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
147 // Only defaults to 1, even though some codecs (such as opus) should really
148 // default to 2.
Danil Chapovalov0bc58cf2018-06-21 11:32:56149 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 20:09:01150
Florent Castelli0a4a9842023-04-03 17:25:29151 // Feedback mechanisms to be used for this codec.
152 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 20:09:01153 std::vector<RtcpFeedback> rtcp_feedback;
154
155 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-26 02:15:09156 //
deadbeefe702b302017-02-04 20:09:01157 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-26 02:15:09158 //
159 // Contrary to ORTC, these parameters are named using all lowercase strings.
Åsa Persson90bc1e12019-05-31 11:29:35160 // This helps make the mapping to SDP simpler, if an application is using SDP.
161 // Boolean values are represented by the string "1".
Johannes Kron72d69152020-02-10 13:05:55162 std::map<std::string, std::string> parameters;
deadbeefe702b302017-02-04 20:09:01163
Florent Castelli0a4a9842023-04-03 17:25:29164 bool operator==(const RtpCodec& o) const {
165 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
166 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
167 parameters == o.parameters;
168 }
169 bool operator!=(const RtpCodec& o) const { return !(*this == o); }
Philipp Hanckeb9405c42023-12-07 17:00:47170 bool IsResiliencyCodec() const;
171 bool IsMediaCodec() const;
Florent Castelli0a4a9842023-04-03 17:25:29172};
deadbeefe702b302017-02-04 20:09:01173
Florent Castelli0a4a9842023-04-03 17:25:29174// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
175// RtpParameters. This represents the static capabilities of an endpoint's
176// implementation of a codec.
177struct RTC_EXPORT RtpCodecCapability : public RtpCodec {
178 RtpCodecCapability();
179 virtual ~RtpCodecCapability();
deadbeefe702b302017-02-04 20:09:01180
Florent Castelli0a4a9842023-04-03 17:25:29181 // Default payload type for this codec. Mainly needed for codecs that have
182 // statically assigned payload types.
183 absl::optional<int> preferred_payload_type;
deadbeefe702b302017-02-04 20:09:01184
Florent Castelli0a4a9842023-04-03 17:25:29185 // List of scalability modes supported by the video codec.
Byoungchan Leea1a7c632022-07-05 12:06:28186 absl::InlinedVector<ScalabilityMode, kScalabilityModeCount> scalability_modes;
187
deadbeefe702b302017-02-04 20:09:01188 bool operator==(const RtpCodecCapability& o) const {
Florent Castelli0a4a9842023-04-03 17:25:29189 return RtpCodec::operator==(o) &&
deadbeefe702b302017-02-04 20:09:01190 preferred_payload_type == o.preferred_payload_type &&
Byoungchan Leea1a7c632022-07-05 12:06:28191 scalability_modes == o.scalability_modes;
deadbeefe702b302017-02-04 20:09:01192 }
193 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
194};
195
Markus Handell0357b3e2020-03-16 12:40:51196// Used in RtpCapabilities and RtpTransceiverInterface's header extensions query
197// and setup methods; represents the capabilities/preferences of an
deadbeefe702b302017-02-04 20:09:01198// implementation for a header extension.
199//
200// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
201// added here for consistency and to avoid confusion with
202// RtpHeaderExtensionParameters.
203//
204// Note that ORTC includes a "kind" field, but we omit this because it's
205// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
206// you know you're getting audio capabilities.
Markus Handell0357b3e2020-03-16 12:40:51207struct RTC_EXPORT RtpHeaderExtensionCapability {
Johannes Kron07ba2b92018-09-26 11:33:35208 // URI of this extension, as defined in RFC8285.
deadbeefe702b302017-02-04 20:09:01209 std::string uri;
210
211 // Preferred value of ID that goes in the packet.
Danil Chapovalov0bc58cf2018-06-21 11:32:56212 absl::optional<int> preferred_id;
deadbeefe702b302017-02-04 20:09:01213
214 // If true, it's preferred that the value in the header is encrypted.
215 // TODO(deadbeef): Not implemented.
216 bool preferred_encrypt = false;
217
Markus Handell0357b3e2020-03-16 12:40:51218 // The direction of the extension. The kStopped value is only used with
Philipp Hancke9f6ae372023-03-06 17:08:31219 // RtpTransceiverInterface::SetHeaderExtensionsToNegotiate() and
220 // SetHeaderExtensionsToNegotiate().
Markus Handell0357b3e2020-03-16 12:40:51221 RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
222
deadbeefe814a0d2017-02-26 02:15:09223 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 13:29:28224 RtpHeaderExtensionCapability();
Danil Chapovalov2b4ec9e2020-03-25 16:23:37225 explicit RtpHeaderExtensionCapability(absl::string_view uri);
226 RtpHeaderExtensionCapability(absl::string_view uri, int preferred_id);
227 RtpHeaderExtensionCapability(absl::string_view uri,
Markus Handell0357b3e2020-03-16 12:40:51228 int preferred_id,
229 RtpTransceiverDirection direction);
Stefan Holmer1acbd682017-09-01 13:29:28230 ~RtpHeaderExtensionCapability();
deadbeefe814a0d2017-02-26 02:15:09231
deadbeefe702b302017-02-04 20:09:01232 bool operator==(const RtpHeaderExtensionCapability& o) const {
233 return uri == o.uri && preferred_id == o.preferred_id &&
Markus Handell0357b3e2020-03-16 12:40:51234 preferred_encrypt == o.preferred_encrypt && direction == o.direction;
deadbeefe702b302017-02-04 20:09:01235 }
236 bool operator!=(const RtpHeaderExtensionCapability& o) const {
237 return !(*this == o);
238 }
239};
240
Johannes Kron07ba2b92018-09-26 11:33:35241// RTP header extension, see RFC8285.
Mirko Bonadei35214fc2019-09-23 12:54:28242struct RTC_EXPORT RtpExtension {
Lennart Grahl0d0ed762021-05-17 14:06:37243 enum Filter {
244 // Encrypted extensions will be ignored and only non-encrypted extensions
245 // will be considered.
246 kDiscardEncryptedExtension,
247 // Encrypted extensions will be preferred but will fall back to
248 // non-encrypted extensions if necessary.
249 kPreferEncryptedExtension,
250 // Encrypted extensions will be required, so any non-encrypted extensions
251 // will be discarded.
252 kRequireEncryptedExtension,
253 };
254
Stefan Holmer1acbd682017-09-01 13:29:28255 RtpExtension();
Danil Chapovalov2b4ec9e2020-03-25 16:23:37256 RtpExtension(absl::string_view uri, int id);
257 RtpExtension(absl::string_view uri, int id, bool encrypt);
Stefan Holmer1acbd682017-09-01 13:29:28258 ~RtpExtension();
Danil Chapovalov418cfee2020-03-25 10:02:37259
Stefan Holmer1acbd682017-09-01 13:29:28260 std::string ToString() const;
261 bool operator==(const RtpExtension& rhs) const {
262 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
263 }
Markus Handelldfeb0df2020-03-16 21:20:47264 static bool IsSupportedForAudio(absl::string_view uri);
265 static bool IsSupportedForVideo(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 13:29:28266 // Return "true" if the given RTP header extension URI may be encrypted.
Markus Handelldfeb0df2020-03-16 21:20:47267 static bool IsEncryptionSupported(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 13:29:28268
Lennart Grahl0d0ed762021-05-17 14:06:37269 // Returns the header extension with the given URI or nullptr if not found.
270 static const RtpExtension* FindHeaderExtensionByUri(
271 const std::vector<RtpExtension>& extensions,
272 absl::string_view uri,
273 Filter filter);
Stefan Holmer1acbd682017-09-01 13:29:28274
Lennart Grahl0d0ed762021-05-17 14:06:37275 // Returns the header extension with the given URI and encrypt parameter,
276 // if found, otherwise nullptr.
277 static const RtpExtension* FindHeaderExtensionByUriAndEncryption(
278 const std::vector<RtpExtension>& extensions,
279 absl::string_view uri,
280 bool encrypt);
281
282 // Returns a list of extensions where any extension URI is unique.
Tomas Gunnarssonc69453d2022-01-06 12:36:04283 // The returned list will be sorted by uri first, then encrypt and id last.
284 // Having the list sorted allows the caller fo compare filtered lists for
285 // equality to detect when changes have been made.
Lennart Grahl0d0ed762021-05-17 14:06:37286 static const std::vector<RtpExtension> DeduplicateHeaderExtensions(
287 const std::vector<RtpExtension>& extensions,
288 Filter filter);
Stefan Holmer1acbd682017-09-01 13:29:28289
Danil Chapovalov418cfee2020-03-25 10:02:37290 // Encryption of Header Extensions, see RFC 6904 for details:
291 // https://tools.ietf.org/html/rfc6904
292 static constexpr char kEncryptHeaderExtensionsUri[] =
293 "urn:ietf:params:rtp-hdrext:encrypt";
294
Stefan Holmer1acbd682017-09-01 13:29:28295 // Header extension for audio levels, as defined in:
Danil Chapovalov418cfee2020-03-25 10:02:37296 // https://tools.ietf.org/html/rfc6464
297 static constexpr char kAudioLevelUri[] =
298 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
Stefan Holmer1acbd682017-09-01 13:29:28299
300 // Header extension for RTP timestamp offset, see RFC 5450 for details:
301 // http://tools.ietf.org/html/rfc5450
Danil Chapovalov418cfee2020-03-25 10:02:37302 static constexpr char kTimestampOffsetUri[] =
303 "urn:ietf:params:rtp-hdrext:toffset";
Stefan Holmer1acbd682017-09-01 13:29:28304
305 // Header extension for absolute send time, see url for details:
306 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
Danil Chapovalov418cfee2020-03-25 10:02:37307 static constexpr char kAbsSendTimeUri[] =
308 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
Stefan Holmer1acbd682017-09-01 13:29:28309
Chen Xingcd8a6e22019-07-01 08:56:51310 // Header extension for absolute capture time, see url for details:
311 // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
Danil Chapovalov418cfee2020-03-25 10:02:37312 static constexpr char kAbsoluteCaptureTimeUri[] =
313 "http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time";
Chen Xingcd8a6e22019-07-01 08:56:51314
Stefan Holmer1acbd682017-09-01 13:29:28315 // Header extension for coordination of video orientation, see url for
316 // details:
317 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
Danil Chapovalov418cfee2020-03-25 10:02:37318 static constexpr char kVideoRotationUri[] = "urn:3gpp:video-orientation";
Stefan Holmer1acbd682017-09-01 13:29:28319
320 // Header extension for video content type. E.g. default or screenshare.
Danil Chapovalov418cfee2020-03-25 10:02:37321 static constexpr char kVideoContentTypeUri[] =
322 "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
Stefan Holmer1acbd682017-09-01 13:29:28323
324 // Header extension for video timing.
Danil Chapovalov418cfee2020-03-25 10:02:37325 static constexpr char kVideoTimingUri[] =
326 "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
Stefan Holmer1acbd682017-09-01 13:29:28327
Danil Chapovalovf3119ef2018-09-25 10:20:37328 // Experimental codec agnostic frame descriptor.
Danil Chapovalov418cfee2020-03-25 10:02:37329 static constexpr char kGenericFrameDescriptorUri00[] =
330 "http://www.webrtc.org/experiments/rtp-hdrext/"
331 "generic-frame-descriptor-00";
Danil Chapovalov418cfee2020-03-25 10:02:37332 static constexpr char kDependencyDescriptorUri[] =
333 "https://aomediacodec.github.io/av1-rtp-spec/"
334 "#dependency-descriptor-rtp-header-extension";
Danil Chapovalovf3119ef2018-09-25 10:20:37335
Per Kjellander70c89452020-10-21 11:35:07336 // Experimental extension for signalling target bitrate per layer.
337 static constexpr char kVideoLayersAllocationUri[] =
338 "http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00";
339
Stefan Holmer1acbd682017-09-01 13:29:28340 // Header extension for transport sequence number, see url for details:
341 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
Danil Chapovalov418cfee2020-03-25 10:02:37342 static constexpr char kTransportSequenceNumberUri[] =
343 "http://www.ietf.org/id/"
344 "draft-holmer-rmcat-transport-wide-cc-extensions-01";
345 static constexpr char kTransportSequenceNumberV2Uri[] =
346 "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02";
Stefan Holmer1acbd682017-09-01 13:29:28347
Danil Chapovalov418cfee2020-03-25 10:02:37348 // This extension allows applications to adaptively limit the playout delay
349 // on frames as per the current needs. For example, a gaming application
350 // has very different needs on end-to-end delay compared to a video-conference
351 // application.
352 static constexpr char kPlayoutDelayUri[] =
353 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
354
355 // Header extension for color space information.
356 static constexpr char kColorSpaceUri[] =
357 "http://www.webrtc.org/experiments/rtp-hdrext/color-space";
Stefan Holmer1acbd682017-09-01 13:29:28358
Steve Antonbb50ce52018-03-26 17:24:32359 // Header extension for identifying media section within a transport.
360 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
Danil Chapovalov418cfee2020-03-25 10:02:37361 static constexpr char kMidUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
Johannes Krond0b69a82018-12-03 13:18:53362
Amit Hilbuch77938e62018-12-21 17:23:38363 // Header extension for RIDs and Repaired RIDs
364 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
365 // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
Danil Chapovalov418cfee2020-03-25 10:02:37366 static constexpr char kRidUri[] =
367 "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
368 static constexpr char kRepairedRidUri[] =
369 "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
Amit Hilbuch77938e62018-12-21 17:23:38370
Jeremy Leconteb258c562021-03-18 12:50:42371 // Header extension to propagate webrtc::VideoFrame id field
372 static constexpr char kVideoFrameTrackingIdUri[] =
373 "http://www.webrtc.org/experiments/rtp-hdrext/video-frame-tracking-id";
374
Doudou Kisabakaae0d1172021-05-24 11:04:45375 // Header extension for Mixer-to-Client audio levels per CSRC as defined in
376 // https://tools.ietf.org/html/rfc6465
377 static constexpr char kCsrcAudioLevelsUri[] =
378 "urn:ietf:params:rtp-hdrext:csrc-audio-level";
379
Johannes Kron07ba2b92018-09-26 11:33:35380 // Inclusive min and max IDs for two-byte header extensions and one-byte
381 // header extensions, per RFC8285 Section 4.2-4.3.
382 static constexpr int kMinId = 1;
383 static constexpr int kMaxId = 255;
Johannes Kron78cdde32018-10-05 08:00:46384 static constexpr int kMaxValueSize = 255;
Johannes Kron07ba2b92018-09-26 11:33:35385 static constexpr int kOneByteHeaderExtensionMaxId = 14;
Johannes Kron78cdde32018-10-05 08:00:46386 static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
Stefan Holmer1acbd682017-09-01 13:29:28387
388 std::string uri;
389 int id = 0;
390 bool encrypt = false;
391};
392
Mirko Bonadei35214fc2019-09-23 12:54:28393struct RTC_EXPORT RtpFecParameters {
deadbeefe702b302017-02-04 20:09:01394 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-26 02:15:09395 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 11:32:56396 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 20:09:01397
398 FecMechanism mechanism = FecMechanism::RED;
399
deadbeefe814a0d2017-02-26 02:15:09400 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 13:29:28401 RtpFecParameters();
402 explicit RtpFecParameters(FecMechanism mechanism);
403 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 09:09:32404 RtpFecParameters(const RtpFecParameters&);
Stefan Holmer1acbd682017-09-01 13:29:28405 ~RtpFecParameters();
deadbeefe814a0d2017-02-26 02:15:09406
deadbeefe702b302017-02-04 20:09:01407 bool operator==(const RtpFecParameters& o) const {
408 return ssrc == o.ssrc && mechanism == o.mechanism;
409 }
410 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
411};
412
Mirko Bonadei35214fc2019-09-23 12:54:28413struct RTC_EXPORT RtpRtxParameters {
deadbeefe702b302017-02-04 20:09:01414 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-26 02:15:09415 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 11:32:56416 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 20:09:01417
deadbeefe814a0d2017-02-26 02:15:09418 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 13:29:28419 RtpRtxParameters();
420 explicit RtpRtxParameters(uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 09:09:32421 RtpRtxParameters(const RtpRtxParameters&);
Stefan Holmer1acbd682017-09-01 13:29:28422 ~RtpRtxParameters();
deadbeefe814a0d2017-02-26 02:15:09423
deadbeefe702b302017-02-04 20:09:01424 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
425 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
426};
427
Mirko Bonadei66e76792019-04-02 09:33:59428struct RTC_EXPORT RtpEncodingParameters {
Stefan Holmer1acbd682017-09-01 13:29:28429 RtpEncodingParameters();
Mirko Bonadei2ffed6d2018-07-20 09:09:32430 RtpEncodingParameters(const RtpEncodingParameters&);
Stefan Holmer1acbd682017-09-01 13:29:28431 ~RtpEncodingParameters();
432
deadbeefe702b302017-02-04 20:09:01433 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-26 02:15:09434 //
435 // Note that the chosen value is NOT returned by GetParameters, because it
436 // may change due to an SSRC conflict, in which case the conflict is handled
437 // internally without any event. Another way of looking at this is that an
438 // unset SSRC acts as a "wildcard" SSRC.
Danil Chapovalov0bc58cf2018-06-21 11:32:56439 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 20:09:01440
Seth Hampson24722b32017-12-22 17:36:42441 // The relative bitrate priority of this encoding. Currently this is
Seth Hampsona881ac02018-02-12 22:14:39442 // implemented for the entire rtp sender by using the value of the first
443 // encoding parameter.
Taylor Brandstettere3a294c2020-03-23 23:16:58444 // See: https://w3c.github.io/webrtc-priority/#enumdef-rtcprioritytype
445 // "very-low" = 0.5
446 // "low" = 1.0
447 // "medium" = 2.0
448 // "high" = 4.0
Seth Hampsona881ac02018-02-12 22:14:39449 // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
450 // Currently there is logic for how bitrate is distributed per simulcast layer
451 // in the VideoBitrateAllocator. This must be updated to incorporate relative
452 // bitrate priority.
Seth Hampson24722b32017-12-22 17:36:42453 double bitrate_priority = kDefaultBitratePriority;
deadbeefe702b302017-02-04 20:09:01454
Tim Haloun648d28a2018-10-18 23:52:22455 // The relative DiffServ Code Point priority for this encoding, allowing
456 // packets to be marked relatively higher or lower without affecting
Taylor Brandstettere3a294c2020-03-23 23:16:58457 // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ .
Tim Haloun648d28a2018-10-18 23:52:22458 // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
Taylor Brandstetter3f1aee32020-02-27 19:59:23459 // TODO(http://crbug.com/webrtc/11379): TCP connections should use a single
460 // DSCP value even if shared by multiple senders; this is not implemented.
461 Priority network_priority = Priority::kLow;
Tim Haloun648d28a2018-10-18 23:52:22462
deadbeefe702b302017-02-04 20:09:01463 // If set, this represents the Transport Independent Application Specific
464 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
Seth Hampsona881ac02018-02-12 22:14:39465 // bitrate. Currently this is implemented for the entire rtp sender by using
466 // the value of the first encoding parameter.
467 //
deadbeefe702b302017-02-04 20:09:01468 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-26 02:15:09469 //
470 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
471 // bandwidth for the entire bandwidth estimator (audio and video). This is
472 // just always how "b=AS" was handled, but it's not correct and should be
473 // fixed.
Danil Chapovalov0bc58cf2018-06-21 11:32:56474 absl::optional<int> max_bitrate_bps;
deadbeefe702b302017-02-04 20:09:01475
Åsa Persson55659812018-06-18 15:51:32476 // Specifies the minimum bitrate in bps for video.
Danil Chapovalov0bc58cf2018-06-21 11:32:56477 absl::optional<int> min_bitrate_bps;
Åsa Persson613591a2018-05-29 07:21:31478
Åsa Persson8c1bf952018-09-13 08:42:19479 // Specifies the maximum framerate in fps for video.
Florent Castelli907dc802019-12-06 14:03:19480 absl::optional<double> max_framerate;
deadbeefe702b302017-02-04 20:09:01481
Åsa Persson23eba222018-10-02 12:47:06482 // Specifies the number of temporal layers for video (if the feature is
483 // supported by the codec implementation).
Ilya Nikolaevskiy9f6a0d52019-02-05 09:29:41484 // Screencast support is experimental.
Åsa Persson23eba222018-10-02 12:47:06485 absl::optional<int> num_temporal_layers;
486
deadbeefe702b302017-02-04 20:09:01487 // For video, scale the resolution down by this factor.
Danil Chapovalov0bc58cf2018-06-21 11:32:56488 absl::optional<double> scale_resolution_down_by;
deadbeefe702b302017-02-04 20:09:01489
philipel87e99092020-11-18 10:52:04490 // https://w3c.github.io/webrtc-svc/#rtcrtpencodingparameters
491 absl::optional<std::string> scalability_mode;
492
Jonas Oreland0deda152022-09-23 10:08:57493 // Requested encode resolution.
494 //
495 // This field provides an alternative to `scale_resolution_down_by`
496 // that is not dependent on the video source.
497 //
498 // When setting requested_resolution it is not necessary to adapt the
499 // video source using OnOutputFormatRequest, since the VideoStreamEncoder
500 // will apply downscaling if necessary. requested_resolution will also be
501 // propagated to the video source, this allows downscaling earlier in the
502 // pipeline which can be beneficial if the source is consumed by multiple
503 // encoders, but is not strictly necessary.
504 //
505 // The `requested_resolution` is subject to resource adaptation.
506 //
507 // It is an error to set both `requested_resolution` and
508 // `scale_resolution_down_by`.
509 absl::optional<Resolution> requested_resolution;
510
Seth Hampsona881ac02018-02-12 22:14:39511 // For an RtpSender, set to true to cause this encoding to be encoded and
512 // sent, and false for it not to be encoded and sent. This allows control
513 // across multiple encodings of a sender for turning simulcast layers on and
514 // off.
515 // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
516 // reset, but this isn't necessarily required.
deadbeefdbe2b872016-03-22 22:42:00517 bool active = true;
deadbeefe702b302017-02-04 20:09:01518
519 // Value to use for RID RTP header extension.
520 // Called "encodingId" in ORTC.
deadbeefe702b302017-02-04 20:09:01521 std::string rid;
Philipp Hancke82c56ca2023-08-28 09:11:06522 bool request_key_frame = false;
deadbeefe702b302017-02-04 20:09:01523
Jakob Ivarsson39adce12020-06-25 12:09:58524 // Allow dynamic frame length changes for audio:
525 // https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime
526 bool adaptive_ptime = false;
527
Florent Castelli43a5dd82023-04-12 10:45:07528 // Allow changing the used codec for this encoding.
529 absl::optional<RtpCodec> codec;
530
Taylor Brandstetter0cd086b2016-04-20 23:23:10531 bool operator==(const RtpEncodingParameters& o) const {
Florent Castellia8c2f512019-11-28 14:48:24532 return ssrc == o.ssrc && bitrate_priority == o.bitrate_priority &&
533 network_priority == o.network_priority &&
Seth Hampson24722b32017-12-22 17:36:42534 max_bitrate_bps == o.max_bitrate_bps &&
Åsa Persson8c1bf952018-09-13 08:42:19535 min_bitrate_bps == o.min_bitrate_bps &&
deadbeefe702b302017-02-04 20:09:01536 max_framerate == o.max_framerate &&
Åsa Persson23eba222018-10-02 12:47:06537 num_temporal_layers == o.num_temporal_layers &&
deadbeefe702b302017-02-04 20:09:01538 scale_resolution_down_by == o.scale_resolution_down_by &&
Jakob Ivarsson39adce12020-06-25 12:09:58539 active == o.active && rid == o.rid &&
Jonas Oreland0deda152022-09-23 10:08:57540 adaptive_ptime == o.adaptive_ptime &&
Florent Castelli43a5dd82023-04-12 10:45:07541 requested_resolution == o.requested_resolution && codec == o.codec;
Taylor Brandstetter0cd086b2016-04-20 23:23:10542 }
Taylor Brandstetterdb0cd9e2016-05-16 18:40:30543 bool operator!=(const RtpEncodingParameters& o) const {
544 return !(*this == o);
545 }
Taylor Brandstetter0cd086b2016-04-20 23:23:10546};
547
Florent Castelli0a4a9842023-04-03 17:25:29548struct RTC_EXPORT RtpCodecParameters : public RtpCodec {
Stefan Holmer1acbd682017-09-01 13:29:28549 RtpCodecParameters();
Mirko Bonadei2ffed6d2018-07-20 09:09:32550 RtpCodecParameters(const RtpCodecParameters&);
Florent Castelli0a4a9842023-04-03 17:25:29551 virtual ~RtpCodecParameters();
deadbeefe702b302017-02-04 20:09:01552
553 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-26 02:15:09554 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 20:09:01555 // the same transport.
556 int payload_type = 0;
557
Taylor Brandstetter0cd086b2016-04-20 23:23:10558 bool operator==(const RtpCodecParameters& o) const {
Florent Castelli0a4a9842023-04-03 17:25:29559 return RtpCodec::operator==(o) && payload_type == o.payload_type;
Taylor Brandstetter0cd086b2016-04-20 23:23:10560 }
Taylor Brandstetterdb0cd9e2016-05-16 18:40:30561 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-17 02:07:43562};
563
Åsa Persson90bc1e12019-05-31 11:29:35564// RtpCapabilities is used to represent the static capabilities of an endpoint.
565// An application can use these capabilities to construct an RtpParameters.
Mirko Bonadei66e76792019-04-02 09:33:59566struct RTC_EXPORT RtpCapabilities {
Stefan Holmer1acbd682017-09-01 13:29:28567 RtpCapabilities();
568 ~RtpCapabilities();
569
deadbeefe702b302017-02-04 20:09:01570 // Supported codecs.
571 std::vector<RtpCodecCapability> codecs;
572
573 // Supported RTP header extensions.
574 std::vector<RtpHeaderExtensionCapability> header_extensions;
575
deadbeefe814a0d2017-02-26 02:15:09576 // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
577 // ulpfec and flexfec codecs used by these mechanisms will still appear in
Artem Titov0e61fdd2021-07-25 19:50:14578 // `codecs`.
deadbeefe702b302017-02-04 20:09:01579 std::vector<FecMechanism> fec;
580
581 bool operator==(const RtpCapabilities& o) const {
582 return codecs == o.codecs && header_extensions == o.header_extensions &&
583 fec == o.fec;
584 }
585 bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
586};
587
Florent Castellidacec712018-05-24 14:24:21588struct RtcpParameters final {
589 RtcpParameters();
Mirko Bonadei2ffed6d2018-07-20 09:09:32590 RtcpParameters(const RtcpParameters&);
Florent Castellidacec712018-05-24 14:24:21591 ~RtcpParameters();
592
593 // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
594 // will be chosen by the implementation.
595 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 11:32:56596 absl::optional<uint32_t> ssrc;
Florent Castellidacec712018-05-24 14:24:21597
598 // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
599 //
600 // If empty in the construction of the RtpTransport, one will be generated by
601 // the implementation, and returned in GetRtcpParameters. Multiple
602 // RtpTransports created by the same OrtcFactory will use the same generated
603 // CNAME.
604 //
605 // If empty when passed into SetParameters, the CNAME simply won't be
606 // modified.
607 std::string cname;
608
609 // Send reduced-size RTCP?
610 bool reduced_size = false;
611
612 // Send RTCP multiplexed on the RTP transport?
613 // Not used with PeerConnection senders/receivers
614 bool mux = true;
615
616 bool operator==(const RtcpParameters& o) const {
617 return ssrc == o.ssrc && cname == o.cname &&
618 reduced_size == o.reduced_size && mux == o.mux;
619 }
620 bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
621};
622
Mirko Bonadeiac194142018-10-22 15:08:37623struct RTC_EXPORT RtpParameters {
Stefan Holmer1acbd682017-09-01 13:29:28624 RtpParameters();
Mirko Bonadei2ffed6d2018-07-20 09:09:32625 RtpParameters(const RtpParameters&);
Stefan Holmer1acbd682017-09-01 13:29:28626 ~RtpParameters();
627
deadbeefe702b302017-02-04 20:09:01628 // Used when calling getParameters/setParameters with a PeerConnection
629 // RtpSender, to ensure that outdated parameters are not unintentionally
630 // applied successfully.
deadbeefe702b302017-02-04 20:09:01631 std::string transaction_id;
632
633 // Value to use for MID RTP header extension.
634 // Called "muxId" in ORTC.
635 // TODO(deadbeef): Not implemented.
636 std::string mid;
637
Taylor Brandstetter0cd086b2016-04-20 23:23:10638 std::vector<RtpCodecParameters> codecs;
639
Danil Chapovalovb19eb392019-12-23 16:55:05640 std::vector<RtpExtension> header_extensions;
deadbeefe702b302017-02-04 20:09:01641
642 std::vector<RtpEncodingParameters> encodings;
643
Florent Castellidacec712018-05-24 14:24:21644 // Only available with a Peerconnection RtpSender.
645 // In ORTC, our API includes an additional "RtpTransport"
646 // abstraction on which RTCP parameters are set.
647 RtcpParameters rtcp;
648
Florent Castelli87b3c512018-07-18 14:00:28649 // When bandwidth is constrained and the RtpSender needs to choose between
650 // degrading resolution or degrading framerate, degradationPreference
651 // indicates which is preferred. Only for video tracks.
Florent Castellib05ca4b2020-03-05 12:39:55652 absl::optional<DegradationPreference> degradation_preference;
deadbeefe702b302017-02-04 20:09:01653
Taylor Brandstetter0cd086b2016-04-20 23:23:10654 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 20:09:01655 return mid == o.mid && codecs == o.codecs &&
656 header_extensions == o.header_extensions &&
Florent Castellidacec712018-05-24 14:24:21657 encodings == o.encodings && rtcp == o.rtcp &&
deadbeefe702b302017-02-04 20:09:01658 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 23:23:10659 }
Taylor Brandstetterdb0cd9e2016-05-16 18:40:30660 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-17 02:07:43661};
662
663} // namespace webrtc
664
Steve Anton10542f22019-01-11 17:11:00665#endif // API_RTP_PARAMETERS_H_