blob: ba02fd24d6a479a32516ea90b2e2b8e385a7f2e4 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/mediatypes.h"
19#include "api/optional.h"
sakal1fd95952016-06-22 00:46:15 -070020
skvladdc1c62c2016-03-16 19:07:43 -070021namespace webrtc {
22
deadbeefe702b302017-02-04 12:09:01 -080023// These structures are intended to mirror those defined by:
24// http://draft.ortc.org/#rtcrtpdictionaries*
25// Contains everything specified as of 2017 Jan 24.
26//
27// They are used when retrieving or modifying the parameters of an
28// RtpSender/RtpReceiver, or retrieving capabilities.
29//
30// Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
31// types, we typically use "int", in keeping with our style guidelines. The
32// parameter's actual valid range will be enforced when the parameters are set,
33// rather than when the parameters struct is built. An exception is made for
34// SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
35// be used for any numeric comparisons/operations.
36//
37// Additionally, where ORTC uses strings, we may use enums for things that have
38// a fixed number of supported values. However, for things that can be extended
39// (such as codecs, by providing an external encoder factory), a string
40// identifier is used.
41
42enum class FecMechanism {
43 RED,
44 RED_AND_ULPFEC,
45 FLEXFEC,
46};
47
48// Used in RtcpFeedback struct.
49enum class RtcpFeedbackType {
deadbeefe702b302017-02-04 12:09:01 -080050 CCM,
51 NACK,
52 REMB, // "goog-remb"
53 TRANSPORT_CC,
54};
55
deadbeefe814a0d2017-02-25 18:15:09 -080056// Used in RtcpFeedback struct when type is NACK or CCM.
deadbeefe702b302017-02-04 12:09:01 -080057enum class RtcpFeedbackMessageType {
58 // Equivalent to {type: "nack", parameter: undefined} in ORTC.
59 GENERIC_NACK,
60 PLI, // Usable with NACK.
61 FIR, // Usable with CCM.
62};
63
64enum class DtxStatus {
65 DISABLED,
66 ENABLED,
67};
68
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070069// Based on the spec in
70// https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
71// These options are enforced on a best-effort basis. For instance, all of
72// these options may suffer some frame drops in order to avoid queuing.
73// TODO(sprang): Look into possibility of more strictly enforcing the
74// maintain-framerate option.
75// TODO(deadbeef): Default to "balanced", as the spec indicates?
deadbeefe702b302017-02-04 12:09:01 -080076enum class DegradationPreference {
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070077 // Don't take any actions based on over-utilization signals. Not part of the
78 // web API.
79 DISABLED,
80 // On over-use, request lower frame rate, possibly causing frame drops.
deadbeefe702b302017-02-04 12:09:01 -080081 MAINTAIN_FRAMERATE,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070082 // On over-use, request lower resolution, possibly causing down-scaling.
deadbeefe702b302017-02-04 12:09:01 -080083 MAINTAIN_RESOLUTION,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070084 // Try to strike a "pleasing" balance between frame rate or resolution.
deadbeefe702b302017-02-04 12:09:01 -080085 BALANCED,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070086 // TODO(deadbeef): Remove once downstream code referencing
87 // "webrtc::VideoSendStream::DegradationPreference::kMaintainResolution" is
88 // updated.
89 kMaintainResolution = MAINTAIN_RESOLUTION
deadbeefe702b302017-02-04 12:09:01 -080090};
91
Seth Hampsonf32795e2017-12-19 11:37:41 -080092extern const double kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -080093
94struct RtcpFeedback {
deadbeefe814a0d2017-02-25 18:15:09 -080095 RtcpFeedbackType type = RtcpFeedbackType::CCM;
deadbeefe702b302017-02-04 12:09:01 -080096
97 // Equivalent to ORTC "parameter" field with slight differences:
98 // 1. It's an enum instead of a string.
99 // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
100 // rather than an unset "parameter" value.
101 rtc::Optional<RtcpFeedbackMessageType> message_type;
102
deadbeefe814a0d2017-02-25 18:15:09 -0800103 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200104 RtcpFeedback();
105 explicit RtcpFeedback(RtcpFeedbackType type);
106 RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
107 ~RtcpFeedback();
deadbeefe814a0d2017-02-25 18:15:09 -0800108
deadbeefe702b302017-02-04 12:09:01 -0800109 bool operator==(const RtcpFeedback& o) const {
110 return type == o.type && message_type == o.message_type;
111 }
112 bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
113};
114
115// RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
116// RtpParameters. This represents the static capabilities of an endpoint's
117// implementation of a codec.
118struct RtpCodecCapability {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200119 RtpCodecCapability();
120 ~RtpCodecCapability();
121
deadbeefe702b302017-02-04 12:09:01 -0800122 // Build MIME "type/subtype" string from |name| and |kind|.
123 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
124
125 // Used to identify the codec. Equivalent to MIME subtype.
126 std::string name;
127
128 // The media type of this codec. Equivalent to MIME top-level type.
129 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
130
131 // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
132 rtc::Optional<int> clock_rate;
133
134 // Default payload type for this codec. Mainly needed for codecs that use
135 // that have statically assigned payload types.
136 rtc::Optional<int> preferred_payload_type;
137
138 // Maximum packetization time supported by an RtpReceiver for this codec.
139 // TODO(deadbeef): Not implemented.
140 rtc::Optional<int> max_ptime;
141
142 // Preferred packetization time for an RtpReceiver or RtpSender of this
143 // codec.
144 // TODO(deadbeef): Not implemented.
145 rtc::Optional<int> ptime;
146
147 // The number of audio channels supported. Unused for video codecs.
148 rtc::Optional<int> num_channels;
149
150 // Feedback mechanisms supported for this codec.
151 std::vector<RtcpFeedback> rtcp_feedback;
152
153 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800154 //
deadbeefe702b302017-02-04 12:09:01 -0800155 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800156 //
157 // Contrary to ORTC, these parameters are named using all lowercase strings.
158 // This helps make the mapping to SDP simpler, if an application is using
159 // SDP. Boolean values are represented by the string "1".
deadbeefe702b302017-02-04 12:09:01 -0800160 std::unordered_map<std::string, std::string> parameters;
161
162 // Codec-specific parameters that may optionally be signaled to the remote
163 // party.
164 // TODO(deadbeef): Not implemented.
165 std::unordered_map<std::string, std::string> options;
166
167 // Maximum number of temporal layer extensions supported by this codec.
168 // For example, a value of 1 indicates that 2 total layers are supported.
169 // TODO(deadbeef): Not implemented.
170 int max_temporal_layer_extensions = 0;
171
172 // Maximum number of spatial layer extensions supported by this codec.
173 // For example, a value of 1 indicates that 2 total layers are supported.
174 // TODO(deadbeef): Not implemented.
175 int max_spatial_layer_extensions = 0;
176
177 // Whether the implementation can send/receive SVC layers with distinct
178 // SSRCs. Always false for audio codecs. True for video codecs that support
179 // scalable video coding with MRST.
180 // TODO(deadbeef): Not implemented.
181 bool svc_multi_stream_support = false;
182
183 bool operator==(const RtpCodecCapability& o) const {
184 return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
185 preferred_payload_type == o.preferred_payload_type &&
186 max_ptime == o.max_ptime && ptime == o.ptime &&
187 num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
188 parameters == o.parameters && options == o.options &&
189 max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
190 max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
191 svc_multi_stream_support == o.svc_multi_stream_support;
192 }
193 bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
194};
195
196// Used in RtpCapabilities; represents the capabilities/preferences of an
197// implementation for a header extension.
198//
199// Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
200// added here for consistency and to avoid confusion with
201// RtpHeaderExtensionParameters.
202//
203// Note that ORTC includes a "kind" field, but we omit this because it's
204// redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
205// you know you're getting audio capabilities.
206struct RtpHeaderExtensionCapability {
207 // URI of this extension, as defined in RFC5285.
208 std::string uri;
209
210 // Preferred value of ID that goes in the packet.
211 rtc::Optional<int> preferred_id;
212
213 // If true, it's preferred that the value in the header is encrypted.
214 // TODO(deadbeef): Not implemented.
215 bool preferred_encrypt = false;
216
deadbeefe814a0d2017-02-25 18:15:09 -0800217 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200218 RtpHeaderExtensionCapability();
219 explicit RtpHeaderExtensionCapability(const std::string& uri);
220 RtpHeaderExtensionCapability(const std::string& uri, int preferred_id);
221 ~RtpHeaderExtensionCapability();
deadbeefe814a0d2017-02-25 18:15:09 -0800222
deadbeefe702b302017-02-04 12:09:01 -0800223 bool operator==(const RtpHeaderExtensionCapability& o) const {
224 return uri == o.uri && preferred_id == o.preferred_id &&
225 preferred_encrypt == o.preferred_encrypt;
226 }
227 bool operator!=(const RtpHeaderExtensionCapability& o) const {
228 return !(*this == o);
229 }
230};
231
Stefan Holmer1acbd682017-09-01 15:29:28 +0200232// RTP header extension, see RFC 5285.
233struct RtpExtension {
234 RtpExtension();
235 RtpExtension(const std::string& uri, int id);
236 RtpExtension(const std::string& uri, int id, bool encrypt);
237 ~RtpExtension();
238 std::string ToString() const;
239 bool operator==(const RtpExtension& rhs) const {
240 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
241 }
242 static bool IsSupportedForAudio(const std::string& uri);
243 static bool IsSupportedForVideo(const std::string& uri);
244 // Return "true" if the given RTP header extension URI may be encrypted.
245 static bool IsEncryptionSupported(const std::string& uri);
246
247 // Returns the named header extension if found among all extensions,
248 // nullptr otherwise.
249 static const RtpExtension* FindHeaderExtensionByUri(
250 const std::vector<RtpExtension>& extensions,
251 const std::string& uri);
252
253 // Return a list of RTP header extensions with the non-encrypted extensions
254 // removed if both the encrypted and non-encrypted extension is present for
255 // the same URI.
256 static std::vector<RtpExtension> FilterDuplicateNonEncrypted(
257 const std::vector<RtpExtension>& extensions);
258
259 // Header extension for audio levels, as defined in:
260 // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
261 static const char kAudioLevelUri[];
262 static const int kAudioLevelDefaultId;
263
264 // Header extension for RTP timestamp offset, see RFC 5450 for details:
265 // http://tools.ietf.org/html/rfc5450
266 static const char kTimestampOffsetUri[];
267 static const int kTimestampOffsetDefaultId;
268
269 // Header extension for absolute send time, see url for details:
270 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
271 static const char kAbsSendTimeUri[];
272 static const int kAbsSendTimeDefaultId;
273
274 // Header extension for coordination of video orientation, see url for
275 // details:
276 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
277 static const char kVideoRotationUri[];
278 static const int kVideoRotationDefaultId;
279
280 // Header extension for video content type. E.g. default or screenshare.
281 static const char kVideoContentTypeUri[];
282 static const int kVideoContentTypeDefaultId;
283
284 // Header extension for video timing.
285 static const char kVideoTimingUri[];
286 static const int kVideoTimingDefaultId;
287
288 // Header extension for transport sequence number, see url for details:
289 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
290 static const char kTransportSequenceNumberUri[];
291 static const int kTransportSequenceNumberDefaultId;
292
293 static const char kPlayoutDelayUri[];
294 static const int kPlayoutDelayDefaultId;
295
Steve Antonbb50ce52018-03-26 10:24:32 -0700296 // Header extension for identifying media section within a transport.
297 // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
298 static const char kMidUri[];
299 static const int kMidDefaultId;
300
Stefan Holmer1acbd682017-09-01 15:29:28 +0200301 // Encryption of Header Extensions, see RFC 6904 for details:
302 // https://tools.ietf.org/html/rfc6904
303 static const char kEncryptHeaderExtensionsUri[];
304
305 // Inclusive min and max IDs for one-byte header extensions, per RFC5285.
306 static const int kMinId;
307 static const int kMaxId;
308
309 std::string uri;
310 int id = 0;
311 bool encrypt = false;
312};
313
deadbeefe814a0d2017-02-25 18:15:09 -0800314// TODO(deadbeef): This is missing the "encrypt" flag, which is unimplemented.
315typedef RtpExtension RtpHeaderExtensionParameters;
deadbeefe702b302017-02-04 12:09:01 -0800316
317struct RtpFecParameters {
318 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800319 // Works just like RtpEncodingParameters::ssrc.
sakal1fd95952016-06-22 00:46:15 -0700320 rtc::Optional<uint32_t> ssrc;
deadbeefe702b302017-02-04 12:09:01 -0800321
322 FecMechanism mechanism = FecMechanism::RED;
323
deadbeefe814a0d2017-02-25 18:15:09 -0800324 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200325 RtpFecParameters();
326 explicit RtpFecParameters(FecMechanism mechanism);
327 RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
328 ~RtpFecParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800329
deadbeefe702b302017-02-04 12:09:01 -0800330 bool operator==(const RtpFecParameters& o) const {
331 return ssrc == o.ssrc && mechanism == o.mechanism;
332 }
333 bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
334};
335
336struct RtpRtxParameters {
337 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800338 // Works just like RtpEncodingParameters::ssrc.
deadbeefe702b302017-02-04 12:09:01 -0800339 rtc::Optional<uint32_t> ssrc;
340
deadbeefe814a0d2017-02-25 18:15:09 -0800341 // Constructors for convenience.
Stefan Holmer1acbd682017-09-01 15:29:28 +0200342 RtpRtxParameters();
343 explicit RtpRtxParameters(uint32_t ssrc);
344 ~RtpRtxParameters();
deadbeefe814a0d2017-02-25 18:15:09 -0800345
deadbeefe702b302017-02-04 12:09:01 -0800346 bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
347 bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
348};
349
350struct RtpEncodingParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200351 RtpEncodingParameters();
352 ~RtpEncodingParameters();
353
deadbeefe702b302017-02-04 12:09:01 -0800354 // If unset, a value is chosen by the implementation.
deadbeefe814a0d2017-02-25 18:15:09 -0800355 //
356 // Note that the chosen value is NOT returned by GetParameters, because it
357 // may change due to an SSRC conflict, in which case the conflict is handled
358 // internally without any event. Another way of looking at this is that an
359 // unset SSRC acts as a "wildcard" SSRC.
deadbeefe702b302017-02-04 12:09:01 -0800360 rtc::Optional<uint32_t> ssrc;
361
362 // Can be used to reference a codec in the |codecs| member of the
363 // RtpParameters that contains this RtpEncodingParameters. If unset, the
deadbeefe814a0d2017-02-25 18:15:09 -0800364 // implementation will choose the first possible codec (if a sender), or
365 // prepare to receive any codec (for a receiver).
366 // TODO(deadbeef): Not implemented. Implementation of RtpSender will always
367 // choose the first codec from the list.
deadbeefe702b302017-02-04 12:09:01 -0800368 rtc::Optional<int> codec_payload_type;
369
370 // Specifies the FEC mechanism, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800371 // TODO(deadbeef): Not implemented. Current implementation will use whatever
372 // FEC codecs are available, including red+ulpfec.
deadbeefe702b302017-02-04 12:09:01 -0800373 rtc::Optional<RtpFecParameters> fec;
374
375 // Specifies the RTX parameters, if set.
deadbeefe814a0d2017-02-25 18:15:09 -0800376 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800377 rtc::Optional<RtpRtxParameters> rtx;
378
379 // Only used for audio. If set, determines whether or not discontinuous
380 // transmission will be used, if an available codec supports it. If not
381 // set, the implementation default setting will be used.
deadbeefe814a0d2017-02-25 18:15:09 -0800382 // TODO(deadbeef): Not implemented. Current implementation will use a CN
383 // codec as long as it's present.
deadbeefe702b302017-02-04 12:09:01 -0800384 rtc::Optional<DtxStatus> dtx;
385
Seth Hampson24722b32017-12-22 09:36:42 -0800386 // The relative bitrate priority of this encoding. Currently this is
Seth Hampsona881ac02018-02-12 14:14:39 -0800387 // implemented for the entire rtp sender by using the value of the first
388 // encoding parameter.
389 // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
390 // Currently there is logic for how bitrate is distributed per simulcast layer
391 // in the VideoBitrateAllocator. This must be updated to incorporate relative
392 // bitrate priority.
Seth Hampson24722b32017-12-22 09:36:42 -0800393 double bitrate_priority = kDefaultBitratePriority;
deadbeefe702b302017-02-04 12:09:01 -0800394
Seth Hampsonf209cb52018-02-06 14:28:16 -0800395 // Indicates the preferred duration of media represented by a packet in
396 // milliseconds for this encoding. If set, this will take precedence over the
397 // ptime set in the RtpCodecParameters. This could happen if SDP negotiation
398 // creates a ptime for a specific codec, which is later changed in the
399 // RtpEncodingParameters by the application.
400 // TODO(bugs.webrtc.org/8819): Not implemented.
401 rtc::Optional<int> ptime;
402
deadbeefe702b302017-02-04 12:09:01 -0800403 // If set, this represents the Transport Independent Application Specific
404 // maximum bandwidth defined in RFC3890. If unset, there is no maximum
Seth Hampsona881ac02018-02-12 14:14:39 -0800405 // bitrate. Currently this is implemented for the entire rtp sender by using
406 // the value of the first encoding parameter.
407 //
408 // TODO(webrtc.bugs.org/8655): Implement this per encoding parameter.
409 // Current implementation for a sender:
410 // The max bitrate is decided by taking the minimum of the first encoding
411 // parameter's max_bitrate_bps and the max bitrate specified by the sdp with
412 // the b=AS attribute. In the case of simulcast video, default values are used
413 // for each simulcast layer, and if there is some bitrate left over from the
414 // sender's max bitrate then it will roll over into the highest quality layer.
deadbeefe814a0d2017-02-25 18:15:09 -0800415 //
deadbeefe702b302017-02-04 12:09:01 -0800416 // Just called "maxBitrate" in ORTC spec.
deadbeefe814a0d2017-02-25 18:15:09 -0800417 //
418 // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
419 // bandwidth for the entire bandwidth estimator (audio and video). This is
420 // just always how "b=AS" was handled, but it's not correct and should be
421 // fixed.
deadbeefe702b302017-02-04 12:09:01 -0800422 rtc::Optional<int> max_bitrate_bps;
423
424 // TODO(deadbeef): Not implemented.
425 rtc::Optional<int> max_framerate;
426
427 // For video, scale the resolution down by this factor.
428 // TODO(deadbeef): Not implemented.
Seth Hampson2d2c8882018-05-16 16:02:32 -0700429 rtc::Optional<double> scale_resolution_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800430
431 // Scale the framerate down by this factor.
432 // TODO(deadbeef): Not implemented.
Seth Hampson2d2c8882018-05-16 16:02:32 -0700433 rtc::Optional<double> scale_framerate_down_by;
deadbeefe702b302017-02-04 12:09:01 -0800434
Seth Hampsona881ac02018-02-12 14:14:39 -0800435 // For an RtpSender, set to true to cause this encoding to be encoded and
436 // sent, and false for it not to be encoded and sent. This allows control
437 // across multiple encodings of a sender for turning simulcast layers on and
438 // off.
439 // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
440 // reset, but this isn't necessarily required.
deadbeefdbe2b872016-03-22 15:42:00 -0700441 bool active = true;
deadbeefe702b302017-02-04 12:09:01 -0800442
443 // Value to use for RID RTP header extension.
444 // Called "encodingId" in ORTC.
445 // TODO(deadbeef): Not implemented.
446 std::string rid;
447
448 // RIDs of encodings on which this layer depends.
449 // Called "dependencyEncodingIds" in ORTC spec.
450 // TODO(deadbeef): Not implemented.
451 std::vector<std::string> dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700452
453 bool operator==(const RtpEncodingParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800454 return ssrc == o.ssrc && codec_payload_type == o.codec_payload_type &&
455 fec == o.fec && rtx == o.rtx && dtx == o.dtx &&
Seth Hampsonf209cb52018-02-06 14:28:16 -0800456 bitrate_priority == o.bitrate_priority && ptime == o.ptime &&
Seth Hampson24722b32017-12-22 09:36:42 -0800457 max_bitrate_bps == o.max_bitrate_bps &&
deadbeefe702b302017-02-04 12:09:01 -0800458 max_framerate == o.max_framerate &&
459 scale_resolution_down_by == o.scale_resolution_down_by &&
460 scale_framerate_down_by == o.scale_framerate_down_by &&
461 active == o.active && rid == o.rid &&
462 dependency_rids == o.dependency_rids;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700463 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700464 bool operator!=(const RtpEncodingParameters& o) const {
465 return !(*this == o);
466 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700467};
468
469struct RtpCodecParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200470 RtpCodecParameters();
471 ~RtpCodecParameters();
472
deadbeefe702b302017-02-04 12:09:01 -0800473 // Build MIME "type/subtype" string from |name| and |kind|.
474 std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
475
476 // Used to identify the codec. Equivalent to MIME subtype.
477 std::string name;
478
479 // The media type of this codec. Equivalent to MIME top-level type.
480 cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
481
482 // Payload type used to identify this codec in RTP packets.
deadbeefe814a0d2017-02-25 18:15:09 -0800483 // This must always be present, and must be unique across all codecs using
deadbeefe702b302017-02-04 12:09:01 -0800484 // the same transport.
485 int payload_type = 0;
486
487 // If unset, the implementation default is used.
488 rtc::Optional<int> clock_rate;
489
490 // The number of audio channels used. Unset for video codecs. If unset for
491 // audio, the implementation default is used.
deadbeefe814a0d2017-02-25 18:15:09 -0800492 // TODO(deadbeef): The "implementation default" part isn't fully implemented.
493 // Only defaults to 1, even though some codecs (such as opus) should really
494 // default to 2.
deadbeefe702b302017-02-04 12:09:01 -0800495 rtc::Optional<int> num_channels;
496
497 // The maximum packetization time to be used by an RtpSender.
498 // If |ptime| is also set, this will be ignored.
499 // TODO(deadbeef): Not implemented.
500 rtc::Optional<int> max_ptime;
501
502 // The packetization time to be used by an RtpSender.
503 // If unset, will use any time up to max_ptime.
504 // TODO(deadbeef): Not implemented.
505 rtc::Optional<int> ptime;
506
507 // Feedback mechanisms to be used for this codec.
deadbeefe814a0d2017-02-25 18:15:09 -0800508 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800509 std::vector<RtcpFeedback> rtcp_feedback;
510
511 // Codec-specific parameters that must be signaled to the remote party.
deadbeefe814a0d2017-02-25 18:15:09 -0800512 //
deadbeefe702b302017-02-04 12:09:01 -0800513 // Corresponds to "a=fmtp" parameters in SDP.
deadbeefe814a0d2017-02-25 18:15:09 -0800514 //
515 // Contrary to ORTC, these parameters are named using all lowercase strings.
516 // This helps make the mapping to SDP simpler, if an application is using
517 // SDP. Boolean values are represented by the string "1".
deadbeefe702b302017-02-04 12:09:01 -0800518 std::unordered_map<std::string, std::string> parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700519
520 bool operator==(const RtpCodecParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800521 return name == o.name && kind == o.kind && payload_type == o.payload_type &&
522 clock_rate == o.clock_rate && num_channels == o.num_channels &&
523 max_ptime == o.max_ptime && ptime == o.ptime &&
524 rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700525 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700526 bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700527};
528
deadbeefe702b302017-02-04 12:09:01 -0800529// RtpCapabilities is used to represent the static capabilities of an
530// endpoint. An application can use these capabilities to construct an
531// RtpParameters.
532struct RtpCapabilities {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200533 RtpCapabilities();
534 ~RtpCapabilities();
535
deadbeefe702b302017-02-04 12:09:01 -0800536 // Supported codecs.
537 std::vector<RtpCodecCapability> codecs;
538
539 // Supported RTP header extensions.
540 std::vector<RtpHeaderExtensionCapability> header_extensions;
541
deadbeefe814a0d2017-02-25 18:15:09 -0800542 // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
543 // ulpfec and flexfec codecs used by these mechanisms will still appear in
544 // |codecs|.
deadbeefe702b302017-02-04 12:09:01 -0800545 std::vector<FecMechanism> fec;
546
547 bool operator==(const RtpCapabilities& o) const {
548 return codecs == o.codecs && header_extensions == o.header_extensions &&
549 fec == o.fec;
550 }
551 bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
552};
553
deadbeefe814a0d2017-02-25 18:15:09 -0800554// Note that unlike in ORTC, an RtcpParameters structure is not included in
555// RtpParameters, because our API includes an additional "RtpTransport"
deadbeefe702b302017-02-04 12:09:01 -0800556// abstraction on which RTCP parameters are set.
skvladdc1c62c2016-03-16 19:07:43 -0700557struct RtpParameters {
Stefan Holmer1acbd682017-09-01 15:29:28 +0200558 RtpParameters();
559 ~RtpParameters();
560
deadbeefe702b302017-02-04 12:09:01 -0800561 // Used when calling getParameters/setParameters with a PeerConnection
562 // RtpSender, to ensure that outdated parameters are not unintentionally
563 // applied successfully.
deadbeefe702b302017-02-04 12:09:01 -0800564 std::string transaction_id;
565
566 // Value to use for MID RTP header extension.
567 // Called "muxId" in ORTC.
568 // TODO(deadbeef): Not implemented.
569 std::string mid;
570
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700571 std::vector<RtpCodecParameters> codecs;
572
deadbeefe814a0d2017-02-25 18:15:09 -0800573 // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
deadbeefe702b302017-02-04 12:09:01 -0800574 std::vector<RtpHeaderExtensionParameters> header_extensions;
575
576 std::vector<RtpEncodingParameters> encodings;
577
578 // TODO(deadbeef): Not implemented.
579 DegradationPreference degradation_preference =
580 DegradationPreference::BALANCED;
581
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700582 bool operator==(const RtpParameters& o) const {
deadbeefe702b302017-02-04 12:09:01 -0800583 return mid == o.mid && codecs == o.codecs &&
584 header_extensions == o.header_extensions &&
585 encodings == o.encodings &&
586 degradation_preference == o.degradation_preference;
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700587 }
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -0700588 bool operator!=(const RtpParameters& o) const { return !(*this == o); }
skvladdc1c62c2016-03-16 19:07:43 -0700589};
590
591} // namespace webrtc
592
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200593#endif // API_RTPPARAMETERS_H_