blob: cd7f029ce8b2d9af9db7d8c99114163de76c0b7f [file] [log] [blame]
skvladdc1c62c2016-03-16 19:07:43 -07001/*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef API_RTP_PARAMETERS_H_
12#define API_RTP_PARAMETERS_H_
skvladdc1c62c2016-03-16 19:07:43 -070013
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stdint.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020015
Johannes Kron72d69152020-02-10 14:05:55 +010016#include <map>
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -070017#include <string>
skvladdc1c62c2016-03-16 19:07:43 -070018#include <vector>
19
Markus Handelldfeb0df2020-03-16 22:20:47 +010020#include "absl/strings/string_view.h"
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020021#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080022#include "api/media_types.h"
Markus Handell0357b3e2020-03-16 13:40:51 +010023#include "api/rtp_transceiver_direction.h"
Mirko Bonadeiac194142018-10-22 17:08:37 +020024#include "rtc_base/system/rtc_export.h"
sakal1fd95952016-06-22 00:46:15 -070025
skvladdc1c62c2016-03-16 19:07:43 -070026namespace webrtc {
27
deadbeefe702b302017-02-04 12:09:01 -080028// These structures are intended to mirror those defined by:
29// http://draft.ortc.org/#rtcrtpdictionaries*
30// Contains everything specified as of 2017 Jan 24.
31//
32// They are used when retrieving or modifying the parameters of an
33// RtpSender/RtpReceiver, or retrieving capabilities.
34//
35// Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
36// types, we typically use "int", in keeping with our style guidelines. The
37// parameter's actual valid range will be enforced when the parameters are set,
38// rather than when the parameters struct is built. An exception is made for
39// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
40// be used for any numeric comparisons/operations.
41//
42// Additionally, where ORTC uses strings, we may use enums for things that have
43// a fixed number of supported values. However, for things that can be extended
44// (such as codecs, by providing an external encoder factory), a string
45// identifier is used.
46
47enum class FecMechanism {
48 RED,
49 RED_AND_ULPFEC,
50 FLEXFEC,
51};
52
53// Used in RtcpFeedback struct.
54enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 12:09:01 -080055 CCM,
Elad Alonfadb1812019-05-24 13:40:02 +020056 LNTF, // "goog-lntf"
deadbeefe702b302017-02-04 12:09:01 -080057 NACK,
58 REMB, // "goog-remb"
59 TRANSPORT_CC,
60};
61
deadbeefe814a0d2017-02-25 18:15:09 -080062// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 12:09:01 -080063enum class RtcpFeedbackMessageType {
64 // Equivalent to {type: "nack", parameter: undefined} in ORTC.
65 GENERIC_NACK,
66 PLI, // Usable with NACK.
67 FIR, // Usable with CCM.
68};
69
70enum class DtxStatus {
71 DISABLED,
72 ENABLED,
73};
74
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070075// Based on the spec in
76// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
77// These options are enforced on a best-effort basis. For instance, all of
78// these options may suffer some frame drops in order to avoid queuing.
79// TODO(sprang): Look into possibility of more strictly enforcing the
80// maintain-framerate option.
81// TODO(deadbeef): Default to "balanced", as the spec indicates?
deadbeefe702b302017-02-04 12:09:01 -080082enum class DegradationPreference {
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070083 // Don't take any actions based on over-utilization signals. Not part of the
84 // web API.
85 DISABLED,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070086 // On over-use, request lower resolution, possibly causing down-scaling.
Åsa Persson90bc1e12019-05-31 13:29:35 +020087 MAINTAIN_FRAMERATE,
88 // On over-use, request lower frame rate, possibly causing frame drops.
deadbeefe702b302017-02-04 12:09:01 -080089 MAINTAIN_RESOLUTION,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070090 // Try to strike a "pleasing" balance between frame rate or resolution.
deadbeefe702b302017-02-04 12:09:01 -080091 BALANCED,
92};
93
Mirko Bonadei66e76792019-04-02 11:33:59 +020094RTC_EXPORT extern const double kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -080095
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -080096enum class Priority {
97 kVeryLow,
98 kLow,
99 kMedium,
100 kHigh,
Taylor Brandstetter567f03f2020-02-18 13:41:54 -0800101};
102
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200103struct RTC_EXPORT RtcpFeedback {
deadbeefe814a0d2017-02-25 18:15:09 -0800104 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 12:09:01 -0800105
106 // Equivalent to ORTC "parameter" field with slight differences:
107 // 1. It's an enum instead of a string.
108 // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
109 // rather than an unset "parameter" value.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200110 absl::optional<RtcpFeedbackMessageType> message_type;
deadbeefe702b302017-02-04 12:09:01 -0800111
deadbeefe814a0d2017-02-25 18:15:09 -0800112 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200113 RtcpFeedback();
114 explicit RtcpFeedback(RtcpFeedbackType type);
115 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200116 RtcpFeedback(const RtcpFeedback&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200117 ~RtcpFeedback();
deadbeefe814a0d2017-02-25 18:15:09 -0800118
deadbeefe702b302017-02-04 12:09:01 -0800119 bool operator==(const RtcpFeedback& o) const {
120 return type == o.type && message_type == o.message_type;
121 }
122 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
123};
124
125// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
126// RtpParameters. This represents the static capabilities of an endpoint's
127// implementation of a codec.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200128struct RTC_EXPORT RtpCodecCapability {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200129 RtpCodecCapability();
130 ~RtpCodecCapability();
131
deadbeefe702b302017-02-04 12:09:01 -0800132 // Build MIME "type/subtype" string from |name| and |kind|.
133 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
141 // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200142 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800143
144 // Default payload type for this codec. Mainly needed for codecs that use
145 // that have statically assigned payload types.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200146 absl::optional<int> preferred_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800147
148 // Maximum packetization time supported by an RtpReceiver for this codec.
149 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200150 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800151
Åsa Persson90bc1e12019-05-31 13:29:35 +0200152 // Preferred packetization time for an RtpReceiver or RtpSender of this codec.
deadbeefe702b302017-02-04 12:09:01 -0800153 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200154 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800155
156 // The number of audio channels supported. Unused for video codecs.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200157 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800158
159 // Feedback mechanisms supported for this codec.
160 std::vector<RtcpFeedback> rtcp_feedback;
161
162 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800163 //
deadbeefe702b302017-02-04 12:09:01 -0800164 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800165 //
166 // Contrary to ORTC, these parameters are named using all lowercase strings.
Åsa Persson90bc1e12019-05-31 13:29:35 +0200167 // This helps make the mapping to SDP simpler, if an application is using SDP.
168 // Boolean values are represented by the string "1".
Johannes Kron72d69152020-02-10 14:05:55 +0100169 std::map<std::string, std::string> parameters;
deadbeefe702b302017-02-04 12:09:01 -0800170
171 // Codec-specific parameters that may optionally be signaled to the remote
172 // party.
173 // TODO(deadbeef): Not implemented.
Johannes Kron72d69152020-02-10 14:05:55 +0100174 std::map<std::string, std::string> options;
deadbeefe702b302017-02-04 12:09:01 -0800175
176 // Maximum number of temporal layer extensions supported by this codec.
177 // For example, a value of 1 indicates that 2 total layers are supported.
178 // TODO(deadbeef): Not implemented.
179 int max_temporal_layer_extensions = 0;
180
181 // Maximum number of spatial layer extensions supported by this codec.
182 // For example, a value of 1 indicates that 2 total layers are supported.
183 // TODO(deadbeef): Not implemented.
184 int max_spatial_layer_extensions = 0;
185
Åsa Persson90bc1e12019-05-31 13:29:35 +0200186 // Whether the implementation can send/receive SVC layers with distinct SSRCs.
187 // Always false for audio codecs. True for video codecs that support scalable
188 // video coding with MRST.
deadbeefe702b302017-02-04 12:09:01 -0800189 // TODO(deadbeef): Not implemented.
190 bool svc_multi_stream_support = false;
191
192 bool operator==(const RtpCodecCapability& o) const {
193 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
194 preferred_payload_type == o.preferred_payload_type &&
195 max_ptime == o.max_ptime && ptime == o.ptime &&
196 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
197 parameters == o.parameters && options == o.options &&
198 max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
199 max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
200 svc_multi_stream_support == o.svc_multi_stream_support;
201 }
202 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
203};
204
Markus Handell0357b3e2020-03-16 13:40:51 +0100205// Used in RtpCapabilities and RtpTransceiverInterface's header extensions query
206// and setup methods; represents the capabilities/preferences of an
deadbeefe702b302017-02-04 12:09:01 -0800207// implementation for a header extension.
208//
209// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
210// added here for consistency and to avoid confusion with
211// RtpHeaderExtensionParameters.
212//
213// Note that ORTC includes a "kind" field, but we omit this because it's
214// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
215// you know you're getting audio capabilities.
Markus Handell0357b3e2020-03-16 13:40:51 +0100216struct RTC_EXPORT RtpHeaderExtensionCapability {
Johannes Kron07ba2b92018-09-26 13:33:35 +0200217 // URI of this extension, as defined in RFC8285.
deadbeefe702b302017-02-04 12:09:01 -0800218 std::string uri;
219
220 // Preferred value of ID that goes in the packet.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200221 absl::optional<int> preferred_id;
deadbeefe702b302017-02-04 12:09:01 -0800222
223 // If true, it's preferred that the value in the header is encrypted.
224 // TODO(deadbeef): Not implemented.
225 bool preferred_encrypt = false;
226
Markus Handell0357b3e2020-03-16 13:40:51 +0100227 // The direction of the extension. The kStopped value is only used with
228 // RtpTransceiverInterface::header_extensions_offered() and
229 // SetOfferedRtpHeaderExtensions().
230 RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
231
deadbeefe814a0d2017-02-25 18:15:09 -0800232 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200233 RtpHeaderExtensionCapability();
Markus Handelldfeb0df2020-03-16 22:20:47 +0100234 explicit RtpHeaderExtensionCapability(std::string uri);
235 RtpHeaderExtensionCapability(std::string uri, int preferred_id);
236 RtpHeaderExtensionCapability(std::string uri,
Markus Handell0357b3e2020-03-16 13:40:51 +0100237 int preferred_id,
238 RtpTransceiverDirection direction);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200239 ~RtpHeaderExtensionCapability();
deadbeefe814a0d2017-02-25 18:15:09 -0800240
deadbeefe702b302017-02-04 12:09:01 -0800241 bool operator==(const RtpHeaderExtensionCapability& o) const {
242 return uri == o.uri && preferred_id == o.preferred_id &&
Markus Handell0357b3e2020-03-16 13:40:51 +0100243 preferred_encrypt == o.preferred_encrypt && direction == o.direction;
deadbeefe702b302017-02-04 12:09:01 -0800244 }
245 bool operator!=(const RtpHeaderExtensionCapability& o) const {
246 return !(*this == o);
247 }
248};
249
Johannes Kron07ba2b92018-09-26 13:33:35 +0200250// RTP header extension, see RFC8285.
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200251struct RTC_EXPORT RtpExtension {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200252 RtpExtension();
Markus Handelldfeb0df2020-03-16 22:20:47 +0100253 RtpExtension(std::string uri, int id);
254 RtpExtension(std::string uri, int id, bool encrypt);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200255 ~RtpExtension();
256 std::string ToString() const;
257 bool operator==(const RtpExtension& rhs) const {
258 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
259 }
Markus Handelldfeb0df2020-03-16 22:20:47 +0100260 static bool IsSupportedForAudio(absl::string_view uri);
261 static bool IsSupportedForVideo(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200262 // Return "true" if the given RTP header extension URI may be encrypted.
Markus Handelldfeb0df2020-03-16 22:20:47 +0100263 static bool IsEncryptionSupported(absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200264
265 // Returns the named header extension if found among all extensions,
266 // nullptr otherwise.
267 static const RtpExtension* FindHeaderExtensionByUri(
268 const std::vector<RtpExtension>& extensions,
Markus Handelldfeb0df2020-03-16 22:20:47 +0100269 absl::string_view uri);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200270
271 // Return a list of RTP header extensions with the non-encrypted extensions
272 // removed if both the encrypted and non-encrypted extension is present for
273 // the same URI.
274 static std::vector<RtpExtension> FilterDuplicateNonEncrypted(
275 const std::vector<RtpExtension>& extensions);
276
277 // Header extension for audio levels, as defined in:
278 // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
279 static const char kAudioLevelUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200280
281 // Header extension for RTP timestamp offset, see RFC 5450 for details:
282 // http://tools.ietf.org/html/rfc5450
283 static const char kTimestampOffsetUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200284
285 // Header extension for absolute send time, see url for details:
286 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
287 static const char kAbsSendTimeUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200288
Chen Xingcd8a6e22019-07-01 10:56:51 +0200289 // Header extension for absolute capture time, see url for details:
290 // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
291 static const char kAbsoluteCaptureTimeUri[];
292
Stefan Holmer1acbd682017-09-01 15:29:28 +0200293 // Header extension for coordination of video orientation, see url for
294 // details:
295 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
296 static const char kVideoRotationUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200297
298 // Header extension for video content type. E.g. default or screenshare.
299 static const char kVideoContentTypeUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200300
301 // Header extension for video timing.
302 static const char kVideoTimingUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200303
Johnny Leee0c8b232018-09-11 16:50:49 -0400304 // Header extension for video frame marking.
305 static const char kFrameMarkingUri[];
Johnny Leee0c8b232018-09-11 16:50:49 -0400306
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200307 // Experimental codec agnostic frame descriptor.
Elad Alonccb9b752019-02-19 13:01:31 +0100308 static const char kGenericFrameDescriptorUri00[];
309 static const char kGenericFrameDescriptorUri01[];
Danil Chapovalov2272f202020-02-18 12:09:43 +0100310 static const char kDependencyDescriptorUri[];
Elad Alonccb9b752019-02-19 13:01:31 +0100311 // TODO(bugs.webrtc.org/10243): Remove once dependencies have been updated.
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200312 static const char kGenericFrameDescriptorUri[];
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200313
Stefan Holmer1acbd682017-09-01 15:29:28 +0200314 // Header extension for transport sequence number, see url for details:
315 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
316 static const char kTransportSequenceNumberUri[];
Johannes Kron7ff164e2019-02-07 12:50:18 +0100317 static const char kTransportSequenceNumberV2Uri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200318
319 static const char kPlayoutDelayUri[];
Stefan Holmer1acbd682017-09-01 15:29:28 +0200320
Steve Antonbb50ce52018-03-26 10:24:32 -0700321 // Header extension for identifying media section within a transport.
322 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
323 static const char kMidUri[];
Steve Antonbb50ce52018-03-26 10:24:32 -0700324
Stefan Holmer1acbd682017-09-01 15:29:28 +0200325 // Encryption of Header Extensions, see RFC 6904 for details:
326 // https://tools.ietf.org/html/rfc6904
327 static const char kEncryptHeaderExtensionsUri[];
328
Johannes Krond0b69a82018-12-03 14:18:53 +0100329 // Header extension for color space information.
330 static const char kColorSpaceUri[];
Johannes Krond0b69a82018-12-03 14:18:53 +0100331
Amit Hilbuch77938e62018-12-21 09:23:38 -0800332 // Header extension for RIDs and Repaired RIDs
333 // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
334 // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
335 static const char kRidUri[];
Amit Hilbuch77938e62018-12-21 09:23:38 -0800336 static const char kRepairedRidUri[];
Amit Hilbuch77938e62018-12-21 09:23:38 -0800337
Johannes Kron07ba2b92018-09-26 13:33:35 +0200338 // Inclusive min and max IDs for two-byte header extensions and one-byte
339 // header extensions, per RFC8285 Section 4.2-4.3.
340 static constexpr int kMinId = 1;
341 static constexpr int kMaxId = 255;
Johannes Kron78cdde32018-10-05 10:00:46 +0200342 static constexpr int kMaxValueSize = 255;
Johannes Kron07ba2b92018-09-26 13:33:35 +0200343 static constexpr int kOneByteHeaderExtensionMaxId = 14;
Johannes Kron78cdde32018-10-05 10:00:46 +0200344 static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200345
346 std::string uri;
347 int id = 0;
348 bool encrypt = false;
349};
350
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200351struct RTC_EXPORT RtpFecParameters {
deadbeefe702b302017-02-04 12:09:01 -0800352 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800353 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200354 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800355
356 FecMechanism mechanism = FecMechanism::RED;
357
deadbeefe814a0d2017-02-25 18:15:09 -0800358 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200359 RtpFecParameters();
360 explicit RtpFecParameters(FecMechanism mechanism);
361 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200362 RtpFecParameters(const RtpFecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200363 ~RtpFecParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800364
deadbeefe702b302017-02-04 12:09:01 -0800365 bool operator==(const RtpFecParameters& o) const {
366 return ssrc == o.ssrc && mechanism == o.mechanism;
367 }
368 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
369};
370
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200371struct RTC_EXPORT RtpRtxParameters {
deadbeefe702b302017-02-04 12:09:01 -0800372 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800373 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200374 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800375
deadbeefe814a0d2017-02-25 18:15:09 -0800376 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200377 RtpRtxParameters();
378 explicit RtpRtxParameters(uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200379 RtpRtxParameters(const RtpRtxParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200380 ~RtpRtxParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800381
deadbeefe702b302017-02-04 12:09:01 -0800382 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
383 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
384};
385
Mirko Bonadei66e76792019-04-02 11:33:59 +0200386struct RTC_EXPORT RtpEncodingParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200387 RtpEncodingParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200388 RtpEncodingParameters(const RtpEncodingParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200389 ~RtpEncodingParameters();
390
deadbeefe702b302017-02-04 12:09:01 -0800391 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800392 //
393 // Note that the chosen value is NOT returned by GetParameters, because it
394 // may change due to an SSRC conflict, in which case the conflict is handled
395 // internally without any event. Another way of looking at this is that an
396 // unset SSRC acts as a "wildcard" SSRC.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200397 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800398
Seth Hampson24722b32017-12-22 09:36:42 -0800399 // The relative bitrate priority of this encoding. Currently this is
Seth Hampsona881ac02018-02-12 14:14:39 -0800400 // implemented for the entire rtp sender by using the value of the first
401 // encoding parameter.
402 // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
403 // Currently there is logic for how bitrate is distributed per simulcast layer
404 // in the VideoBitrateAllocator. This must be updated to incorporate relative
405 // bitrate priority.
Seth Hampson24722b32017-12-22 09:36:42 -0800406 double bitrate_priority = kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -0800407
Tim Haloun648d28a2018-10-18 16:52:22 -0700408 // The relative DiffServ Code Point priority for this encoding, allowing
409 // packets to be marked relatively higher or lower without affecting
410 // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ . NB
411 // we follow chromium's translation of the allowed string enum values for
412 // this field to 1.0, 0.5, et cetera, similar to bitrate_priority above.
413 // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
Taylor Brandstetter3f1aee32020-02-27 11:59:23 -0800414 // TODO(http://crbug.com/webrtc/11379): TCP connections should use a single
415 // DSCP value even if shared by multiple senders; this is not implemented.
416 Priority network_priority = Priority::kLow;
Tim Haloun648d28a2018-10-18 16:52:22 -0700417
deadbeefe702b302017-02-04 12:09:01 -0800418 // If set, this represents the Transport Independent Application Specific
419 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
Seth Hampsona881ac02018-02-12 14:14:39 -0800420 // bitrate. Currently this is implemented for the entire rtp sender by using
421 // the value of the first encoding parameter.
422 //
deadbeefe702b302017-02-04 12:09:01 -0800423 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-25 18:15:09 -0800424 //
425 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
426 // bandwidth for the entire bandwidth estimator (audio and video). This is
427 // just always how "b=AS" was handled, but it's not correct and should be
428 // fixed.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200429 absl::optional<int> max_bitrate_bps;
deadbeefe702b302017-02-04 12:09:01 -0800430
Åsa Persson55659812018-06-18 17:51:32 +0200431 // Specifies the minimum bitrate in bps for video.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200432 absl::optional<int> min_bitrate_bps;
Åsa Persson613591a2018-05-29 09:21:31 +0200433
Åsa Persson8c1bf952018-09-13 10:42:19 +0200434 // Specifies the maximum framerate in fps for video.
Florent Castelli907dc802019-12-06 15:03:19 +0100435 absl::optional<double> max_framerate;
deadbeefe702b302017-02-04 12:09:01 -0800436
Åsa Persson23eba222018-10-02 14:47:06 +0200437 // Specifies the number of temporal layers for video (if the feature is
438 // supported by the codec implementation).
439 // TODO(asapersson): Different number of temporal layers are not supported
440 // per simulcast layer.
Ilya Nikolaevskiy9f6a0d52019-02-05 10:29:41 +0100441 // Screencast support is experimental.
Åsa Persson23eba222018-10-02 14:47:06 +0200442 absl::optional<int> num_temporal_layers;
443
deadbeefe702b302017-02-04 12:09:01 -0800444 // For video, scale the resolution down by this factor.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200445 absl::optional<double> scale_resolution_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800446
Seth Hampsona881ac02018-02-12 14:14:39 -0800447 // For an RtpSender, set to true to cause this encoding to be encoded and
448 // sent, and false for it not to be encoded and sent. This allows control
449 // across multiple encodings of a sender for turning simulcast layers on and
450 // off.
451 // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
452 // reset, but this isn't necessarily required.
deadbeefdbe2b872016-03-22 15:42:00 -0700453 bool active = true;
deadbeefe702b302017-02-04 12:09:01 -0800454
455 // Value to use for RID RTP header extension.
456 // Called "encodingId" in ORTC.
deadbeefe702b302017-02-04 12:09:01 -0800457 std::string rid;
458
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700459 bool operator==(const RtpEncodingParameters& o) const {
Florent Castellia8c2f512019-11-28 15:48:24 +0100460 return ssrc == o.ssrc && bitrate_priority == o.bitrate_priority &&
461 network_priority == o.network_priority &&
Seth Hampson24722b32017-12-22 09:36:42 -0800462 max_bitrate_bps == o.max_bitrate_bps &&
Åsa Persson8c1bf952018-09-13 10:42:19 +0200463 min_bitrate_bps == o.min_bitrate_bps &&
deadbeefe702b302017-02-04 12:09:01 -0800464 max_framerate == o.max_framerate &&
Åsa Persson23eba222018-10-02 14:47:06 +0200465 num_temporal_layers == o.num_temporal_layers &&
deadbeefe702b302017-02-04 12:09:01 -0800466 scale_resolution_down_by == o.scale_resolution_down_by &&
Florent Castellia8c2f512019-11-28 15:48:24 +0100467 active == o.active && rid == o.rid;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700468 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700469 bool operator!=(const RtpEncodingParameters& o) const {
470 return !(*this == o);
471 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700472};
473
Mirko Bonadei35214fc2019-09-23 14:54:28 +0200474struct RTC_EXPORT RtpCodecParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200475 RtpCodecParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200476 RtpCodecParameters(const RtpCodecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200477 ~RtpCodecParameters();
478
deadbeefe702b302017-02-04 12:09:01 -0800479 // Build MIME "type/subtype" string from |name| and |kind|.
480 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
481
482 // Used to identify the codec. Equivalent to MIME subtype.
483 std::string name;
484
485 // The media type of this codec. Equivalent to MIME top-level type.
486 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
487
488 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-25 18:15:09 -0800489 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 12:09:01 -0800490 // the same transport.
491 int payload_type = 0;
492
493 // If unset, the implementation default is used.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200494 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800495
496 // The number of audio channels used. Unset for video codecs. If unset for
497 // audio, the implementation default is used.
deadbeefe814a0d2017-02-25 18:15:09 -0800498 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
499 // Only defaults to 1, even though some codecs (such as opus) should really
500 // default to 2.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200501 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800502
503 // The maximum packetization time to be used by an RtpSender.
504 // If |ptime| is also set, this will be ignored.
505 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200506 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800507
508 // The packetization time to be used by an RtpSender.
509 // If unset, will use any time up to max_ptime.
510 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200511 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800512
513 // Feedback mechanisms to be used for this codec.
deadbeefe814a0d2017-02-25 18:15:09 -0800514 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800515 std::vector<RtcpFeedback> rtcp_feedback;
516
517 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800518 //
deadbeefe702b302017-02-04 12:09:01 -0800519 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800520 //
521 // Contrary to ORTC, these parameters are named using all lowercase strings.
Åsa Persson90bc1e12019-05-31 13:29:35 +0200522 // This helps make the mapping to SDP simpler, if an application is using SDP.
523 // Boolean values are represented by the string "1".
Johannes Kron72d69152020-02-10 14:05:55 +0100524 std::map<std::string, std::string> parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700525
526 bool operator==(const RtpCodecParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800527 return name == o.name && kind == o.kind && payload_type == o.payload_type &&
528 clock_rate == o.clock_rate && num_channels == o.num_channels &&
529 max_ptime == o.max_ptime && ptime == o.ptime &&
530 rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700531 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700532 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700533};
534
Åsa Persson90bc1e12019-05-31 13:29:35 +0200535// RtpCapabilities is used to represent the static capabilities of an endpoint.
536// An application can use these capabilities to construct an RtpParameters.
Mirko Bonadei66e76792019-04-02 11:33:59 +0200537struct RTC_EXPORT RtpCapabilities {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200538 RtpCapabilities();
539 ~RtpCapabilities();
540
deadbeefe702b302017-02-04 12:09:01 -0800541 // Supported codecs.
542 std::vector<RtpCodecCapability> codecs;
543
544 // Supported RTP header extensions.
545 std::vector<RtpHeaderExtensionCapability> header_extensions;
546
deadbeefe814a0d2017-02-25 18:15:09 -0800547 // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
548 // ulpfec and flexfec codecs used by these mechanisms will still appear in
549 // |codecs|.
deadbeefe702b302017-02-04 12:09:01 -0800550 std::vector<FecMechanism> fec;
551
552 bool operator==(const RtpCapabilities& o) const {
553 return codecs == o.codecs && header_extensions == o.header_extensions &&
554 fec == o.fec;
555 }
556 bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
557};
558
Florent Castellidacec712018-05-24 16:24:21 +0200559struct RtcpParameters final {
560 RtcpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200561 RtcpParameters(const RtcpParameters&);
Florent Castellidacec712018-05-24 16:24:21 +0200562 ~RtcpParameters();
563
564 // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
565 // will be chosen by the implementation.
566 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200567 absl::optional<uint32_t> ssrc;
Florent Castellidacec712018-05-24 16:24:21 +0200568
569 // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
570 //
571 // If empty in the construction of the RtpTransport, one will be generated by
572 // the implementation, and returned in GetRtcpParameters. Multiple
573 // RtpTransports created by the same OrtcFactory will use the same generated
574 // CNAME.
575 //
576 // If empty when passed into SetParameters, the CNAME simply won't be
577 // modified.
578 std::string cname;
579
580 // Send reduced-size RTCP?
581 bool reduced_size = false;
582
583 // Send RTCP multiplexed on the RTP transport?
584 // Not used with PeerConnection senders/receivers
585 bool mux = true;
586
587 bool operator==(const RtcpParameters& o) const {
588 return ssrc == o.ssrc && cname == o.cname &&
589 reduced_size == o.reduced_size && mux == o.mux;
590 }
591 bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
592};
593
Mirko Bonadeiac194142018-10-22 17:08:37 +0200594struct RTC_EXPORT RtpParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200595 RtpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200596 RtpParameters(const RtpParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200597 ~RtpParameters();
598
deadbeefe702b302017-02-04 12:09:01 -0800599 // Used when calling getParameters/setParameters with a PeerConnection
600 // RtpSender, to ensure that outdated parameters are not unintentionally
601 // applied successfully.
deadbeefe702b302017-02-04 12:09:01 -0800602 std::string transaction_id;
603
604 // Value to use for MID RTP header extension.
605 // Called "muxId" in ORTC.
606 // TODO(deadbeef): Not implemented.
607 std::string mid;
608
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700609 std::vector<RtpCodecParameters> codecs;
610
Danil Chapovalovb19eb392019-12-23 17:55:05 +0100611 std::vector<RtpExtension> header_extensions;
deadbeefe702b302017-02-04 12:09:01 -0800612
613 std::vector<RtpEncodingParameters> encodings;
614
Florent Castellidacec712018-05-24 16:24:21 +0200615 // Only available with a Peerconnection RtpSender.
616 // In ORTC, our API includes an additional "RtpTransport"
617 // abstraction on which RTCP parameters are set.
618 RtcpParameters rtcp;
619
Florent Castelli87b3c512018-07-18 16:00:28 +0200620 // When bandwidth is constrained and the RtpSender needs to choose between
621 // degrading resolution or degrading framerate, degradationPreference
622 // indicates which is preferred. Only for video tracks.
Florent Castellib05ca4b2020-03-05 13:39:55 +0100623 absl::optional<DegradationPreference> degradation_preference;
deadbeefe702b302017-02-04 12:09:01 -0800624
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700625 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800626 return mid == o.mid && codecs == o.codecs &&
627 header_extensions == o.header_extensions &&
Florent Castellidacec712018-05-24 16:24:21 +0200628 encodings == o.encodings && rtcp == o.rtcp &&
deadbeefe702b302017-02-04 12:09:01 -0800629 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700630 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700631 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700632};
633
634} // namespace webrtc
635
Steve Anton10542f22019-01-11 09:11:00 -0800636#endif // API_RTP_PARAMETERS_H_