blob: 4d99acf80d75be470258032c2d83ac72db9f1f98 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef API_RTPPARAMETERS_H_
12#define API_RTPPARAMETERS_H_
skvladdc1c62c2016-03-16 19:07:43 -070013
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -070014#include <string>
deadbeefe702b302017-02-04 12:09:01 -080015#include <unordered_map>
skvladdc1c62c2016-03-16 19:07:43 -070016#include <vector>
17
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020018#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "api/mediatypes.h"
Mirko Bonadeiac194142018-10-22 17:08:37 +020020#include "rtc_base/system/rtc_export.h"
sakal1fd95952016-06-22 00:46:15 -070021
skvladdc1c62c2016-03-16 19:07:43 -070022namespace webrtc {
23
deadbeefe702b302017-02-04 12:09:01 -080024// These structures are intended to mirror those defined by:
25// http://draft.ortc.org/#rtcrtpdictionaries*
26// Contains everything specified as of 2017 Jan 24.
27//
28// They are used when retrieving or modifying the parameters of an
29// RtpSender/RtpReceiver, or retrieving capabilities.
30//
31// Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
32// types, we typically use "int", in keeping with our style guidelines. The
33// parameter's actual valid range will be enforced when the parameters are set,
34// rather than when the parameters struct is built. An exception is made for
35// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
36// be used for any numeric comparisons/operations.
37//
38// Additionally, where ORTC uses strings, we may use enums for things that have
39// a fixed number of supported values. However, for things that can be extended
40// (such as codecs, by providing an external encoder factory), a string
41// identifier is used.
42
43enum class FecMechanism {
44 RED,
45 RED_AND_ULPFEC,
46 FLEXFEC,
47};
48
49// Used in RtcpFeedback struct.
50enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 12:09:01 -080051 CCM,
52 NACK,
53 REMB, // "goog-remb"
54 TRANSPORT_CC,
55};
56
deadbeefe814a0d2017-02-25 18:15:09 -080057// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 12:09:01 -080058enum class RtcpFeedbackMessageType {
59 // Equivalent to {type: "nack", parameter: undefined} in ORTC.
60 GENERIC_NACK,
61 PLI, // Usable with NACK.
62 FIR, // Usable with CCM.
63};
64
65enum class DtxStatus {
66 DISABLED,
67 ENABLED,
68};
69
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070070// Based on the spec in
71// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
72// These options are enforced on a best-effort basis. For instance, all of
73// these options may suffer some frame drops in order to avoid queuing.
74// TODO(sprang): Look into possibility of more strictly enforcing the
75// maintain-framerate option.
76// TODO(deadbeef): Default to "balanced", as the spec indicates?
deadbeefe702b302017-02-04 12:09:01 -080077enum class DegradationPreference {
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070078 // Don't take any actions based on over-utilization signals. Not part of the
79 // web API.
80 DISABLED,
81 // On over-use, request lower frame rate, possibly causing frame drops.
deadbeefe702b302017-02-04 12:09:01 -080082 MAINTAIN_FRAMERATE,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070083 // On over-use, request lower resolution, possibly causing down-scaling.
deadbeefe702b302017-02-04 12:09:01 -080084 MAINTAIN_RESOLUTION,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070085 // Try to strike a "pleasing" balance between frame rate or resolution.
deadbeefe702b302017-02-04 12:09:01 -080086 BALANCED,
87};
88
Seth Hampsonf32795e2017-12-19 11:37:41 -080089extern const double kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -080090
91struct RtcpFeedback {
deadbeefe814a0d2017-02-25 18:15:09 -080092 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 12:09:01 -080093
94 // Equivalent to ORTC "parameter" field with slight differences:
95 // 1. It's an enum instead of a string.
96 // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
97 // rather than an unset "parameter" value.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +020098 absl::optional<RtcpFeedbackMessageType> message_type;
deadbeefe702b302017-02-04 12:09:01 -080099
deadbeefe814a0d2017-02-25 18:15:09 -0800100 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200101 RtcpFeedback();
102 explicit RtcpFeedback(RtcpFeedbackType type);
103 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200104 RtcpFeedback(const RtcpFeedback&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200105 ~RtcpFeedback();
deadbeefe814a0d2017-02-25 18:15:09 -0800106
deadbeefe702b302017-02-04 12:09:01 -0800107 bool operator==(const RtcpFeedback& o) const {
108 return type == o.type && message_type == o.message_type;
109 }
110 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
111};
112
113// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
114// RtpParameters. This represents the static capabilities of an endpoint's
115// implementation of a codec.
116struct RtpCodecCapability {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200117 RtpCodecCapability();
118 ~RtpCodecCapability();
119
deadbeefe702b302017-02-04 12:09:01 -0800120 // Build MIME "type/subtype" string from |name| and |kind|.
121 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
122
123 // Used to identify the codec. Equivalent to MIME subtype.
124 std::string name;
125
126 // The media type of this codec. Equivalent to MIME top-level type.
127 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
128
129 // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200130 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800131
132 // Default payload type for this codec. Mainly needed for codecs that use
133 // that have statically assigned payload types.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200134 absl::optional<int> preferred_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800135
136 // Maximum packetization time supported by an RtpReceiver for this codec.
137 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200138 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800139
140 // Preferred packetization time for an RtpReceiver or RtpSender of this
141 // codec.
142 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200143 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800144
145 // The number of audio channels supported. Unused for video codecs.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200146 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800147
148 // Feedback mechanisms supported for this codec.
149 std::vector<RtcpFeedback> rtcp_feedback;
150
151 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800152 //
deadbeefe702b302017-02-04 12:09:01 -0800153 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800154 //
155 // Contrary to ORTC, these parameters are named using all lowercase strings.
156 // This helps make the mapping to SDP simpler, if an application is using
157 // SDP. Boolean values are represented by the string "1".
deadbeefe702b302017-02-04 12:09:01 -0800158 std::unordered_map<std::string, std::string> parameters;
159
160 // Codec-specific parameters that may optionally be signaled to the remote
161 // party.
162 // TODO(deadbeef): Not implemented.
163 std::unordered_map<std::string, std::string> options;
164
165 // Maximum number of temporal layer extensions supported by this codec.
166 // For example, a value of 1 indicates that 2 total layers are supported.
167 // TODO(deadbeef): Not implemented.
168 int max_temporal_layer_extensions = 0;
169
170 // Maximum number of spatial layer extensions supported by this codec.
171 // For example, a value of 1 indicates that 2 total layers are supported.
172 // TODO(deadbeef): Not implemented.
173 int max_spatial_layer_extensions = 0;
174
175 // Whether the implementation can send/receive SVC layers with distinct
176 // SSRCs. Always false for audio codecs. True for video codecs that support
177 // scalable video coding with MRST.
178 // TODO(deadbeef): Not implemented.
179 bool svc_multi_stream_support = false;
180
181 bool operator==(const RtpCodecCapability& o) const {
182 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
183 preferred_payload_type == o.preferred_payload_type &&
184 max_ptime == o.max_ptime && ptime == o.ptime &&
185 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
186 parameters == o.parameters && options == o.options &&
187 max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
188 max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
189 svc_multi_stream_support == o.svc_multi_stream_support;
190 }
191 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
192};
193
194// Used in RtpCapabilities; represents the capabilities/preferences of an
195// implementation for a header extension.
196//
197// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
198// added here for consistency and to avoid confusion with
199// RtpHeaderExtensionParameters.
200//
201// Note that ORTC includes a "kind" field, but we omit this because it's
202// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
203// you know you're getting audio capabilities.
204struct RtpHeaderExtensionCapability {
Johannes Kron07ba2b92018-09-26 13:33:35 +0200205 // URI of this extension, as defined in RFC8285.
deadbeefe702b302017-02-04 12:09:01 -0800206 std::string uri;
207
208 // Preferred value of ID that goes in the packet.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200209 absl::optional<int> preferred_id;
deadbeefe702b302017-02-04 12:09:01 -0800210
211 // If true, it's preferred that the value in the header is encrypted.
212 // TODO(deadbeef): Not implemented.
213 bool preferred_encrypt = false;
214
deadbeefe814a0d2017-02-25 18:15:09 -0800215 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200216 RtpHeaderExtensionCapability();
217 explicit RtpHeaderExtensionCapability(const std::string& uri);
218 RtpHeaderExtensionCapability(const std::string& uri, int preferred_id);
219 ~RtpHeaderExtensionCapability();
deadbeefe814a0d2017-02-25 18:15:09 -0800220
deadbeefe702b302017-02-04 12:09:01 -0800221 bool operator==(const RtpHeaderExtensionCapability& o) const {
222 return uri == o.uri && preferred_id == o.preferred_id &&
223 preferred_encrypt == o.preferred_encrypt;
224 }
225 bool operator!=(const RtpHeaderExtensionCapability& o) const {
226 return !(*this == o);
227 }
228};
229
Johannes Kron07ba2b92018-09-26 13:33:35 +0200230// RTP header extension, see RFC8285.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200231struct RtpExtension {
232 RtpExtension();
233 RtpExtension(const std::string& uri, int id);
234 RtpExtension(const std::string& uri, int id, bool encrypt);
235 ~RtpExtension();
236 std::string ToString() const;
237 bool operator==(const RtpExtension& rhs) const {
238 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
239 }
240 static bool IsSupportedForAudio(const std::string& uri);
241 static bool IsSupportedForVideo(const std::string& uri);
242 // Return "true" if the given RTP header extension URI may be encrypted.
243 static bool IsEncryptionSupported(const std::string& uri);
244
245 // Returns the named header extension if found among all extensions,
246 // nullptr otherwise.
247 static const RtpExtension* FindHeaderExtensionByUri(
248 const std::vector<RtpExtension>& extensions,
249 const std::string& uri);
250
251 // Return a list of RTP header extensions with the non-encrypted extensions
252 // removed if both the encrypted and non-encrypted extension is present for
253 // the same URI.
254 static std::vector<RtpExtension> FilterDuplicateNonEncrypted(
255 const std::vector<RtpExtension>& extensions);
256
257 // Header extension for audio levels, as defined in:
258 // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
259 static const char kAudioLevelUri[];
260 static const int kAudioLevelDefaultId;
261
262 // Header extension for RTP timestamp offset, see RFC 5450 for details:
263 // http://tools.ietf.org/html/rfc5450
264 static const char kTimestampOffsetUri[];
265 static const int kTimestampOffsetDefaultId;
266
267 // Header extension for absolute send time, see url for details:
268 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
269 static const char kAbsSendTimeUri[];
270 static const int kAbsSendTimeDefaultId;
271
272 // Header extension for coordination of video orientation, see url for
273 // details:
274 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
275 static const char kVideoRotationUri[];
276 static const int kVideoRotationDefaultId;
277
278 // Header extension for video content type. E.g. default or screenshare.
279 static const char kVideoContentTypeUri[];
280 static const int kVideoContentTypeDefaultId;
281
282 // Header extension for video timing.
283 static const char kVideoTimingUri[];
284 static const int kVideoTimingDefaultId;
285
Johnny Leee0c8b232018-09-11 16:50:49 -0400286 // Header extension for video frame marking.
287 static const char kFrameMarkingUri[];
288 static const int kFrameMarkingDefaultId;
289
Danil Chapovalovf3119ef2018-09-25 12:20:37 +0200290 // Experimental codec agnostic frame descriptor.
291 static const char kGenericFrameDescriptorUri[];
292 static const int kGenericFrameDescriptorDefaultId;
293
Stefan Holmer1acbd682017-09-01 15:29:28 +0200294 // Header extension for transport sequence number, see url for details:
295 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
296 static const char kTransportSequenceNumberUri[];
297 static const int kTransportSequenceNumberDefaultId;
298
299 static const char kPlayoutDelayUri[];
300 static const int kPlayoutDelayDefaultId;
301
Steve Antonbb50ce52018-03-26 10:24:32 -0700302 // Header extension for identifying media section within a transport.
303 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
304 static const char kMidUri[];
305 static const int kMidDefaultId;
306
Stefan Holmer1acbd682017-09-01 15:29:28 +0200307 // Encryption of Header Extensions, see RFC 6904 for details:
308 // https://tools.ietf.org/html/rfc6904
309 static const char kEncryptHeaderExtensionsUri[];
310
Johannes Kron07ba2b92018-09-26 13:33:35 +0200311 // Inclusive min and max IDs for two-byte header extensions and one-byte
312 // header extensions, per RFC8285 Section 4.2-4.3.
313 static constexpr int kMinId = 1;
314 static constexpr int kMaxId = 255;
Johannes Kron78cdde32018-10-05 10:00:46 +0200315 static constexpr int kMaxValueSize = 255;
Johannes Kron07ba2b92018-09-26 13:33:35 +0200316 static constexpr int kOneByteHeaderExtensionMaxId = 14;
Johannes Kron78cdde32018-10-05 10:00:46 +0200317 static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
Stefan Holmer1acbd682017-09-01 15:29:28 +0200318
319 std::string uri;
320 int id = 0;
321 bool encrypt = false;
322};
323
deadbeefe814a0d2017-02-25 18:15:09 -0800324// TODO(deadbeef): This is missing the "encrypt" flag, which is unimplemented.
325typedef RtpExtension RtpHeaderExtensionParameters;
deadbeefe702b302017-02-04 12:09:01 -0800326
327struct RtpFecParameters {
328 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800329 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200330 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800331
332 FecMechanism mechanism = FecMechanism::RED;
333
deadbeefe814a0d2017-02-25 18:15:09 -0800334 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200335 RtpFecParameters();
336 explicit RtpFecParameters(FecMechanism mechanism);
337 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200338 RtpFecParameters(const RtpFecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200339 ~RtpFecParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800340
deadbeefe702b302017-02-04 12:09:01 -0800341 bool operator==(const RtpFecParameters& o) const {
342 return ssrc == o.ssrc && mechanism == o.mechanism;
343 }
344 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
345};
346
347struct RtpRtxParameters {
348 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800349 // Works just like RtpEncodingParameters::ssrc.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200350 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800351
deadbeefe814a0d2017-02-25 18:15:09 -0800352 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200353 RtpRtxParameters();
354 explicit RtpRtxParameters(uint32_t ssrc);
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200355 RtpRtxParameters(const RtpRtxParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200356 ~RtpRtxParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800357
deadbeefe702b302017-02-04 12:09:01 -0800358 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
359 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
360};
361
362struct RtpEncodingParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200363 RtpEncodingParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200364 RtpEncodingParameters(const RtpEncodingParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200365 ~RtpEncodingParameters();
366
deadbeefe702b302017-02-04 12:09:01 -0800367 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800368 //
369 // Note that the chosen value is NOT returned by GetParameters, because it
370 // may change due to an SSRC conflict, in which case the conflict is handled
371 // internally without any event. Another way of looking at this is that an
372 // unset SSRC acts as a "wildcard" SSRC.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200373 absl::optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800374
375 // Can be used to reference a codec in the |codecs| member of the
376 // RtpParameters that contains this RtpEncodingParameters. If unset, the
deadbeefe814a0d2017-02-25 18:15:09 -0800377 // implementation will choose the first possible codec (if a sender), or
378 // prepare to receive any codec (for a receiver).
379 // TODO(deadbeef): Not implemented. Implementation of RtpSender will always
380 // choose the first codec from the list.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200381 absl::optional<int> codec_payload_type;
deadbeefe702b302017-02-04 12:09:01 -0800382
383 // Specifies the FEC mechanism, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800384 // TODO(deadbeef): Not implemented. Current implementation will use whatever
385 // FEC codecs are available, including red+ulpfec.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200386 absl::optional<RtpFecParameters> fec;
deadbeefe702b302017-02-04 12:09:01 -0800387
388 // Specifies the RTX parameters, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800389 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200390 absl::optional<RtpRtxParameters> rtx;
deadbeefe702b302017-02-04 12:09:01 -0800391
392 // Only used for audio. If set, determines whether or not discontinuous
393 // transmission will be used, if an available codec supports it. If not
394 // set, the implementation default setting will be used.
deadbeefe814a0d2017-02-25 18:15:09 -0800395 // TODO(deadbeef): Not implemented. Current implementation will use a CN
396 // codec as long as it's present.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200397 absl::optional<DtxStatus> dtx;
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.
414 double network_priority = kDefaultBitratePriority;
415
Seth Hampsonf209cb52018-02-06 14:28:16 -0800416 // Indicates the preferred duration of media represented by a packet in
417 // milliseconds for this encoding. If set, this will take precedence over the
418 // ptime set in the RtpCodecParameters. This could happen if SDP negotiation
419 // creates a ptime for a specific codec, which is later changed in the
420 // RtpEncodingParameters by the application.
421 // TODO(bugs.webrtc.org/8819): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200422 absl::optional<int> ptime;
Seth Hampsonf209cb52018-02-06 14:28:16 -0800423
deadbeefe702b302017-02-04 12:09:01 -0800424 // If set, this represents the Transport Independent Application Specific
425 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
Seth Hampsona881ac02018-02-12 14:14:39 -0800426 // bitrate. Currently this is implemented for the entire rtp sender by using
427 // the value of the first encoding parameter.
428 //
deadbeefe702b302017-02-04 12:09:01 -0800429 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-25 18:15:09 -0800430 //
431 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
432 // bandwidth for the entire bandwidth estimator (audio and video). This is
433 // just always how "b=AS" was handled, but it's not correct and should be
434 // fixed.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200435 absl::optional<int> max_bitrate_bps;
deadbeefe702b302017-02-04 12:09:01 -0800436
Ã…sa Persson55659812018-06-18 17:51:32 +0200437 // Specifies the minimum bitrate in bps for video.
438 // TODO(asapersson): Not implemented for ORTC API.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200439 absl::optional<int> min_bitrate_bps;
Ã…sa Persson613591a2018-05-29 09:21:31 +0200440
Ã…sa Persson8c1bf952018-09-13 10:42:19 +0200441 // Specifies the maximum framerate in fps for video.
Ã…sa Persson23eba222018-10-02 14:47:06 +0200442 // TODO(asapersson): Different framerates are not supported per simulcast
443 // layer. If set, the maximum |max_framerate| is currently used.
Ã…sa Persson8c1bf952018-09-13 10:42:19 +0200444 // Not supported for screencast.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200445 absl::optional<int> max_framerate;
deadbeefe702b302017-02-04 12:09:01 -0800446
Ã…sa Persson23eba222018-10-02 14:47:06 +0200447 // Specifies the number of temporal layers for video (if the feature is
448 // supported by the codec implementation).
449 // TODO(asapersson): Different number of temporal layers are not supported
450 // per simulcast layer.
451 // Not supported for screencast.
452 absl::optional<int> num_temporal_layers;
453
deadbeefe702b302017-02-04 12:09:01 -0800454 // For video, scale the resolution down by this factor.
455 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200456 absl::optional<double> scale_resolution_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800457
458 // Scale the framerate down by this factor.
459 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200460 absl::optional<double> scale_framerate_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800461
Seth Hampsona881ac02018-02-12 14:14:39 -0800462 // For an RtpSender, set to true to cause this encoding to be encoded and
463 // sent, and false for it not to be encoded and sent. This allows control
464 // across multiple encodings of a sender for turning simulcast layers on and
465 // off.
466 // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
467 // reset, but this isn't necessarily required.
deadbeefdbe2b872016-03-22 15:42:00 -0700468 bool active = true;
deadbeefe702b302017-02-04 12:09:01 -0800469
470 // Value to use for RID RTP header extension.
471 // Called "encodingId" in ORTC.
472 // TODO(deadbeef): Not implemented.
473 std::string rid;
474
475 // RIDs of encodings on which this layer depends.
476 // Called "dependencyEncodingIds" in ORTC spec.
477 // TODO(deadbeef): Not implemented.
478 std::vector<std::string> dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700479
480 bool operator==(const RtpEncodingParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800481 return ssrc == o.ssrc && codec_payload_type == o.codec_payload_type &&
482 fec == o.fec && rtx == o.rtx && dtx == o.dtx &&
Tim Haloun648d28a2018-10-18 16:52:22 -0700483 bitrate_priority == o.bitrate_priority &&
484 network_priority == o.network_priority && ptime == o.ptime &&
Seth Hampson24722b32017-12-22 09:36:42 -0800485 max_bitrate_bps == o.max_bitrate_bps &&
Ã…sa Persson8c1bf952018-09-13 10:42:19 +0200486 min_bitrate_bps == o.min_bitrate_bps &&
deadbeefe702b302017-02-04 12:09:01 -0800487 max_framerate == o.max_framerate &&
Ã…sa Persson23eba222018-10-02 14:47:06 +0200488 num_temporal_layers == o.num_temporal_layers &&
deadbeefe702b302017-02-04 12:09:01 -0800489 scale_resolution_down_by == o.scale_resolution_down_by &&
490 scale_framerate_down_by == o.scale_framerate_down_by &&
491 active == o.active && rid == o.rid &&
492 dependency_rids == o.dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700493 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700494 bool operator!=(const RtpEncodingParameters& o) const {
495 return !(*this == o);
496 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700497};
498
499struct RtpCodecParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200500 RtpCodecParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200501 RtpCodecParameters(const RtpCodecParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200502 ~RtpCodecParameters();
503
deadbeefe702b302017-02-04 12:09:01 -0800504 // Build MIME "type/subtype" string from |name| and |kind|.
505 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
506
507 // Used to identify the codec. Equivalent to MIME subtype.
508 std::string name;
509
510 // The media type of this codec. Equivalent to MIME top-level type.
511 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
512
513 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-25 18:15:09 -0800514 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 12:09:01 -0800515 // the same transport.
516 int payload_type = 0;
517
518 // If unset, the implementation default is used.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200519 absl::optional<int> clock_rate;
deadbeefe702b302017-02-04 12:09:01 -0800520
521 // The number of audio channels used. Unset for video codecs. If unset for
522 // audio, the implementation default is used.
deadbeefe814a0d2017-02-25 18:15:09 -0800523 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
524 // Only defaults to 1, even though some codecs (such as opus) should really
525 // default to 2.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200526 absl::optional<int> num_channels;
deadbeefe702b302017-02-04 12:09:01 -0800527
528 // The maximum packetization time to be used by an RtpSender.
529 // If |ptime| is also set, this will be ignored.
530 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200531 absl::optional<int> max_ptime;
deadbeefe702b302017-02-04 12:09:01 -0800532
533 // The packetization time to be used by an RtpSender.
534 // If unset, will use any time up to max_ptime.
535 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200536 absl::optional<int> ptime;
deadbeefe702b302017-02-04 12:09:01 -0800537
538 // Feedback mechanisms to be used for this codec.
deadbeefe814a0d2017-02-25 18:15:09 -0800539 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800540 std::vector<RtcpFeedback> rtcp_feedback;
541
542 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800543 //
deadbeefe702b302017-02-04 12:09:01 -0800544 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800545 //
546 // Contrary to ORTC, these parameters are named using all lowercase strings.
547 // This helps make the mapping to SDP simpler, if an application is using
548 // SDP. Boolean values are represented by the string "1".
deadbeefe702b302017-02-04 12:09:01 -0800549 std::unordered_map<std::string, std::string> parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700550
551 bool operator==(const RtpCodecParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800552 return name == o.name && kind == o.kind && payload_type == o.payload_type &&
553 clock_rate == o.clock_rate && num_channels == o.num_channels &&
554 max_ptime == o.max_ptime && ptime == o.ptime &&
555 rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700556 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700557 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700558};
559
deadbeefe702b302017-02-04 12:09:01 -0800560// RtpCapabilities is used to represent the static capabilities of an
561// endpoint. An application can use these capabilities to construct an
562// RtpParameters.
563struct RtpCapabilities {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200564 RtpCapabilities();
565 ~RtpCapabilities();
566
deadbeefe702b302017-02-04 12:09:01 -0800567 // Supported codecs.
568 std::vector<RtpCodecCapability> codecs;
569
570 // Supported RTP header extensions.
571 std::vector<RtpHeaderExtensionCapability> header_extensions;
572
deadbeefe814a0d2017-02-25 18:15:09 -0800573 // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
574 // ulpfec and flexfec codecs used by these mechanisms will still appear in
575 // |codecs|.
deadbeefe702b302017-02-04 12:09:01 -0800576 std::vector<FecMechanism> fec;
577
578 bool operator==(const RtpCapabilities& o) const {
579 return codecs == o.codecs && header_extensions == o.header_extensions &&
580 fec == o.fec;
581 }
582 bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
583};
584
Florent Castellidacec712018-05-24 16:24:21 +0200585struct RtcpParameters final {
586 RtcpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200587 RtcpParameters(const RtcpParameters&);
Florent Castellidacec712018-05-24 16:24:21 +0200588 ~RtcpParameters();
589
590 // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
591 // will be chosen by the implementation.
592 // TODO(deadbeef): Not implemented.
Danil Chapovalov0bc58cf2018-06-21 13:32:56 +0200593 absl::optional<uint32_t> ssrc;
Florent Castellidacec712018-05-24 16:24:21 +0200594
595 // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
596 //
597 // If empty in the construction of the RtpTransport, one will be generated by
598 // the implementation, and returned in GetRtcpParameters. Multiple
599 // RtpTransports created by the same OrtcFactory will use the same generated
600 // CNAME.
601 //
602 // If empty when passed into SetParameters, the CNAME simply won't be
603 // modified.
604 std::string cname;
605
606 // Send reduced-size RTCP?
607 bool reduced_size = false;
608
609 // Send RTCP multiplexed on the RTP transport?
610 // Not used with PeerConnection senders/receivers
611 bool mux = true;
612
613 bool operator==(const RtcpParameters& o) const {
614 return ssrc == o.ssrc && cname == o.cname &&
615 reduced_size == o.reduced_size && mux == o.mux;
616 }
617 bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
618};
619
Mirko Bonadeiac194142018-10-22 17:08:37 +0200620struct RTC_EXPORT RtpParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200621 RtpParameters();
Mirko Bonadei2ffed6d2018-07-20 11:09:32 +0200622 RtpParameters(const RtpParameters&);
Stefan Holmer1acbd682017-09-01 15:29:28 +0200623 ~RtpParameters();
624
deadbeefe702b302017-02-04 12:09:01 -0800625 // Used when calling getParameters/setParameters with a PeerConnection
626 // RtpSender, to ensure that outdated parameters are not unintentionally
627 // applied successfully.
deadbeefe702b302017-02-04 12:09:01 -0800628 std::string transaction_id;
629
630 // Value to use for MID RTP header extension.
631 // Called "muxId" in ORTC.
632 // TODO(deadbeef): Not implemented.
633 std::string mid;
634
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700635 std::vector<RtpCodecParameters> codecs;
636
deadbeefe702b302017-02-04 12:09:01 -0800637 std::vector<RtpHeaderExtensionParameters> header_extensions;
638
639 std::vector<RtpEncodingParameters> encodings;
640
Florent Castellidacec712018-05-24 16:24:21 +0200641 // Only available with a Peerconnection RtpSender.
642 // In ORTC, our API includes an additional "RtpTransport"
643 // abstraction on which RTCP parameters are set.
644 RtcpParameters rtcp;
645
Florent Castelli87b3c512018-07-18 16:00:28 +0200646 // When bandwidth is constrained and the RtpSender needs to choose between
647 // degrading resolution or degrading framerate, degradationPreference
648 // indicates which is preferred. Only for video tracks.
deadbeefe702b302017-02-04 12:09:01 -0800649 DegradationPreference degradation_preference =
650 DegradationPreference::BALANCED;
651
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700652 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800653 return mid == o.mid && codecs == o.codecs &&
654 header_extensions == o.header_extensions &&
Florent Castellidacec712018-05-24 16:24:21 +0200655 encodings == o.encodings && rtcp == o.rtcp &&
deadbeefe702b302017-02-04 12:09:01 -0800656 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700657 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700658 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700659};
660
661} // namespace webrtc
662
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200663#endif // API_RTPPARAMETERS_H_