xref: /aosp_15_r20/external/webrtc/api/rtp_parameters.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2015 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #ifndef API_RTP_PARAMETERS_H_
12*d9f75844SAndroid Build Coastguard Worker #define API_RTP_PARAMETERS_H_
13*d9f75844SAndroid Build Coastguard Worker 
14*d9f75844SAndroid Build Coastguard Worker #include <stdint.h>
15*d9f75844SAndroid Build Coastguard Worker 
16*d9f75844SAndroid Build Coastguard Worker #include <map>
17*d9f75844SAndroid Build Coastguard Worker #include <string>
18*d9f75844SAndroid Build Coastguard Worker #include <vector>
19*d9f75844SAndroid Build Coastguard Worker 
20*d9f75844SAndroid Build Coastguard Worker #include "absl/container/inlined_vector.h"
21*d9f75844SAndroid Build Coastguard Worker #include "absl/strings/string_view.h"
22*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h"
23*d9f75844SAndroid Build Coastguard Worker #include "api/media_types.h"
24*d9f75844SAndroid Build Coastguard Worker #include "api/priority.h"
25*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_transceiver_direction.h"
26*d9f75844SAndroid Build Coastguard Worker #include "api/video/resolution.h"
27*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/scalability_mode.h"
28*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/system/rtc_export.h"
29*d9f75844SAndroid Build Coastguard Worker 
30*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
31*d9f75844SAndroid Build Coastguard Worker 
32*d9f75844SAndroid Build Coastguard Worker // These structures are intended to mirror those defined by:
33*d9f75844SAndroid Build Coastguard Worker // http://draft.ortc.org/#rtcrtpdictionaries*
34*d9f75844SAndroid Build Coastguard Worker // Contains everything specified as of 2017 Jan 24.
35*d9f75844SAndroid Build Coastguard Worker //
36*d9f75844SAndroid Build Coastguard Worker // They are used when retrieving or modifying the parameters of an
37*d9f75844SAndroid Build Coastguard Worker // RtpSender/RtpReceiver, or retrieving capabilities.
38*d9f75844SAndroid Build Coastguard Worker //
39*d9f75844SAndroid Build Coastguard Worker // Note on conventions: Where ORTC may use "octet", "short" and "unsigned"
40*d9f75844SAndroid Build Coastguard Worker // types, we typically use "int", in keeping with our style guidelines. The
41*d9f75844SAndroid Build Coastguard Worker // parameter's actual valid range will be enforced when the parameters are set,
42*d9f75844SAndroid Build Coastguard Worker // rather than when the parameters struct is built. An exception is made for
43*d9f75844SAndroid Build Coastguard Worker // SSRCs, since they use the full unsigned 32-bit range, and aren't expected to
44*d9f75844SAndroid Build Coastguard Worker // be used for any numeric comparisons/operations.
45*d9f75844SAndroid Build Coastguard Worker //
46*d9f75844SAndroid Build Coastguard Worker // Additionally, where ORTC uses strings, we may use enums for things that have
47*d9f75844SAndroid Build Coastguard Worker // a fixed number of supported values. However, for things that can be extended
48*d9f75844SAndroid Build Coastguard Worker // (such as codecs, by providing an external encoder factory), a string
49*d9f75844SAndroid Build Coastguard Worker // identifier is used.
50*d9f75844SAndroid Build Coastguard Worker 
51*d9f75844SAndroid Build Coastguard Worker enum class FecMechanism {
52*d9f75844SAndroid Build Coastguard Worker   RED,
53*d9f75844SAndroid Build Coastguard Worker   RED_AND_ULPFEC,
54*d9f75844SAndroid Build Coastguard Worker   FLEXFEC,
55*d9f75844SAndroid Build Coastguard Worker };
56*d9f75844SAndroid Build Coastguard Worker 
57*d9f75844SAndroid Build Coastguard Worker // Used in RtcpFeedback struct.
58*d9f75844SAndroid Build Coastguard Worker enum class RtcpFeedbackType {
59*d9f75844SAndroid Build Coastguard Worker   CCM,
60*d9f75844SAndroid Build Coastguard Worker   LNTF,  // "goog-lntf"
61*d9f75844SAndroid Build Coastguard Worker   NACK,
62*d9f75844SAndroid Build Coastguard Worker   REMB,  // "goog-remb"
63*d9f75844SAndroid Build Coastguard Worker   TRANSPORT_CC,
64*d9f75844SAndroid Build Coastguard Worker };
65*d9f75844SAndroid Build Coastguard Worker 
66*d9f75844SAndroid Build Coastguard Worker // Used in RtcpFeedback struct when type is NACK or CCM.
67*d9f75844SAndroid Build Coastguard Worker enum class RtcpFeedbackMessageType {
68*d9f75844SAndroid Build Coastguard Worker   // Equivalent to {type: "nack", parameter: undefined} in ORTC.
69*d9f75844SAndroid Build Coastguard Worker   GENERIC_NACK,
70*d9f75844SAndroid Build Coastguard Worker   PLI,  // Usable with NACK.
71*d9f75844SAndroid Build Coastguard Worker   FIR,  // Usable with CCM.
72*d9f75844SAndroid Build Coastguard Worker };
73*d9f75844SAndroid Build Coastguard Worker 
74*d9f75844SAndroid Build Coastguard Worker enum class DtxStatus {
75*d9f75844SAndroid Build Coastguard Worker   DISABLED,
76*d9f75844SAndroid Build Coastguard Worker   ENABLED,
77*d9f75844SAndroid Build Coastguard Worker };
78*d9f75844SAndroid Build Coastguard Worker 
79*d9f75844SAndroid Build Coastguard Worker // Based on the spec in
80*d9f75844SAndroid Build Coastguard Worker // https://w3c.github.io/webrtc-pc/#idl-def-rtcdegradationpreference.
81*d9f75844SAndroid Build Coastguard Worker // These options are enforced on a best-effort basis. For instance, all of
82*d9f75844SAndroid Build Coastguard Worker // these options may suffer some frame drops in order to avoid queuing.
83*d9f75844SAndroid Build Coastguard Worker // TODO(sprang): Look into possibility of more strictly enforcing the
84*d9f75844SAndroid Build Coastguard Worker // maintain-framerate option.
85*d9f75844SAndroid Build Coastguard Worker // TODO(deadbeef): Default to "balanced", as the spec indicates?
86*d9f75844SAndroid Build Coastguard Worker enum class DegradationPreference {
87*d9f75844SAndroid Build Coastguard Worker   // Don't take any actions based on over-utilization signals. Not part of the
88*d9f75844SAndroid Build Coastguard Worker   // web API.
89*d9f75844SAndroid Build Coastguard Worker   DISABLED,
90*d9f75844SAndroid Build Coastguard Worker   // On over-use, request lower resolution, possibly causing down-scaling.
91*d9f75844SAndroid Build Coastguard Worker   MAINTAIN_FRAMERATE,
92*d9f75844SAndroid Build Coastguard Worker   // On over-use, request lower frame rate, possibly causing frame drops.
93*d9f75844SAndroid Build Coastguard Worker   MAINTAIN_RESOLUTION,
94*d9f75844SAndroid Build Coastguard Worker   // Try to strike a "pleasing" balance between frame rate or resolution.
95*d9f75844SAndroid Build Coastguard Worker   BALANCED,
96*d9f75844SAndroid Build Coastguard Worker };
97*d9f75844SAndroid Build Coastguard Worker 
98*d9f75844SAndroid Build Coastguard Worker RTC_EXPORT const char* DegradationPreferenceToString(
99*d9f75844SAndroid Build Coastguard Worker     DegradationPreference degradation_preference);
100*d9f75844SAndroid Build Coastguard Worker 
101*d9f75844SAndroid Build Coastguard Worker RTC_EXPORT extern const double kDefaultBitratePriority;
102*d9f75844SAndroid Build Coastguard Worker 
103*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtcpFeedback {
104*d9f75844SAndroid Build Coastguard Worker   RtcpFeedbackType type = RtcpFeedbackType::CCM;
105*d9f75844SAndroid Build Coastguard Worker 
106*d9f75844SAndroid Build Coastguard Worker   // Equivalent to ORTC "parameter" field with slight differences:
107*d9f75844SAndroid Build Coastguard Worker   // 1. It's an enum instead of a string.
108*d9f75844SAndroid Build Coastguard Worker   // 2. Generic NACK feedback is represented by a GENERIC_NACK message type,
109*d9f75844SAndroid Build Coastguard Worker   //    rather than an unset "parameter" value.
110*d9f75844SAndroid Build Coastguard Worker   absl::optional<RtcpFeedbackMessageType> message_type;
111*d9f75844SAndroid Build Coastguard Worker 
112*d9f75844SAndroid Build Coastguard Worker   // Constructors for convenience.
113*d9f75844SAndroid Build Coastguard Worker   RtcpFeedback();
114*d9f75844SAndroid Build Coastguard Worker   explicit RtcpFeedback(RtcpFeedbackType type);
115*d9f75844SAndroid Build Coastguard Worker   RtcpFeedback(RtcpFeedbackType type, RtcpFeedbackMessageType message_type);
116*d9f75844SAndroid Build Coastguard Worker   RtcpFeedback(const RtcpFeedback&);
117*d9f75844SAndroid Build Coastguard Worker   ~RtcpFeedback();
118*d9f75844SAndroid Build Coastguard Worker 
119*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtcpFeedback& o) const {
120*d9f75844SAndroid Build Coastguard Worker     return type == o.type && message_type == o.message_type;
121*d9f75844SAndroid Build Coastguard Worker   }
122*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtcpFeedback& o) const { return !(*this == o); }
123*d9f75844SAndroid Build Coastguard Worker };
124*d9f75844SAndroid Build Coastguard Worker 
125*d9f75844SAndroid Build Coastguard Worker // RtpCodecCapability is to RtpCodecParameters as RtpCapabilities is to
126*d9f75844SAndroid Build Coastguard Worker // RtpParameters. This represents the static capabilities of an endpoint's
127*d9f75844SAndroid Build Coastguard Worker // implementation of a codec.
128*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpCodecCapability {
129*d9f75844SAndroid Build Coastguard Worker   RtpCodecCapability();
130*d9f75844SAndroid Build Coastguard Worker   ~RtpCodecCapability();
131*d9f75844SAndroid Build Coastguard Worker 
132*d9f75844SAndroid Build Coastguard Worker   // Build MIME "type/subtype" string from `name` and `kind`.
mime_typeRtpCodecCapability133*d9f75844SAndroid Build Coastguard Worker   std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
134*d9f75844SAndroid Build Coastguard Worker 
135*d9f75844SAndroid Build Coastguard Worker   // Used to identify the codec. Equivalent to MIME subtype.
136*d9f75844SAndroid Build Coastguard Worker   std::string name;
137*d9f75844SAndroid Build Coastguard Worker 
138*d9f75844SAndroid Build Coastguard Worker   // The media type of this codec. Equivalent to MIME top-level type.
139*d9f75844SAndroid Build Coastguard Worker   cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
140*d9f75844SAndroid Build Coastguard Worker 
141*d9f75844SAndroid Build Coastguard Worker   // Clock rate in Hertz. If unset, the codec is applicable to any clock rate.
142*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> clock_rate;
143*d9f75844SAndroid Build Coastguard Worker 
144*d9f75844SAndroid Build Coastguard Worker   // Default payload type for this codec. Mainly needed for codecs that use
145*d9f75844SAndroid Build Coastguard Worker   // that have statically assigned payload types.
146*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> preferred_payload_type;
147*d9f75844SAndroid Build Coastguard Worker 
148*d9f75844SAndroid Build Coastguard Worker   // Maximum packetization time supported by an RtpReceiver for this codec.
149*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
150*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> max_ptime;
151*d9f75844SAndroid Build Coastguard Worker 
152*d9f75844SAndroid Build Coastguard Worker   // Preferred packetization time for an RtpReceiver or RtpSender of this codec.
153*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
154*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> ptime;
155*d9f75844SAndroid Build Coastguard Worker 
156*d9f75844SAndroid Build Coastguard Worker   // The number of audio channels supported. Unused for video codecs.
157*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> num_channels;
158*d9f75844SAndroid Build Coastguard Worker 
159*d9f75844SAndroid Build Coastguard Worker   // Feedback mechanisms supported for this codec.
160*d9f75844SAndroid Build Coastguard Worker   std::vector<RtcpFeedback> rtcp_feedback;
161*d9f75844SAndroid Build Coastguard Worker 
162*d9f75844SAndroid Build Coastguard Worker   // Codec-specific parameters that must be signaled to the remote party.
163*d9f75844SAndroid Build Coastguard Worker   //
164*d9f75844SAndroid Build Coastguard Worker   // Corresponds to "a=fmtp" parameters in SDP.
165*d9f75844SAndroid Build Coastguard Worker   //
166*d9f75844SAndroid Build Coastguard Worker   // Contrary to ORTC, these parameters are named using all lowercase strings.
167*d9f75844SAndroid Build Coastguard Worker   // This helps make the mapping to SDP simpler, if an application is using SDP.
168*d9f75844SAndroid Build Coastguard Worker   // Boolean values are represented by the string "1".
169*d9f75844SAndroid Build Coastguard Worker   std::map<std::string, std::string> parameters;
170*d9f75844SAndroid Build Coastguard Worker 
171*d9f75844SAndroid Build Coastguard Worker   // Codec-specific parameters that may optionally be signaled to the remote
172*d9f75844SAndroid Build Coastguard Worker   // party.
173*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
174*d9f75844SAndroid Build Coastguard Worker   std::map<std::string, std::string> options;
175*d9f75844SAndroid Build Coastguard Worker 
176*d9f75844SAndroid Build Coastguard Worker   // Maximum number of temporal layer extensions supported by this codec.
177*d9f75844SAndroid Build Coastguard Worker   // For example, a value of 1 indicates that 2 total layers are supported.
178*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
179*d9f75844SAndroid Build Coastguard Worker   int max_temporal_layer_extensions = 0;
180*d9f75844SAndroid Build Coastguard Worker 
181*d9f75844SAndroid Build Coastguard Worker   // Maximum number of spatial layer extensions supported by this codec.
182*d9f75844SAndroid Build Coastguard Worker   // For example, a value of 1 indicates that 2 total layers are supported.
183*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
184*d9f75844SAndroid Build Coastguard Worker   int max_spatial_layer_extensions = 0;
185*d9f75844SAndroid Build Coastguard Worker 
186*d9f75844SAndroid Build Coastguard Worker   // Whether the implementation can send/receive SVC layers with distinct SSRCs.
187*d9f75844SAndroid Build Coastguard Worker   // Always false for audio codecs. True for video codecs that support scalable
188*d9f75844SAndroid Build Coastguard Worker   // video coding with MRST.
189*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
190*d9f75844SAndroid Build Coastguard Worker   bool svc_multi_stream_support = false;
191*d9f75844SAndroid Build Coastguard Worker 
192*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-svc/#dom-rtcrtpcodeccapability-scalabilitymodes
193*d9f75844SAndroid Build Coastguard Worker   absl::InlinedVector<ScalabilityMode, kScalabilityModeCount> scalability_modes;
194*d9f75844SAndroid Build Coastguard Worker 
195*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtpCodecCapability& o) const {
196*d9f75844SAndroid Build Coastguard Worker     return name == o.name && kind == o.kind && clock_rate == o.clock_rate &&
197*d9f75844SAndroid Build Coastguard Worker            preferred_payload_type == o.preferred_payload_type &&
198*d9f75844SAndroid Build Coastguard Worker            max_ptime == o.max_ptime && ptime == o.ptime &&
199*d9f75844SAndroid Build Coastguard Worker            num_channels == o.num_channels && rtcp_feedback == o.rtcp_feedback &&
200*d9f75844SAndroid Build Coastguard Worker            parameters == o.parameters && options == o.options &&
201*d9f75844SAndroid Build Coastguard Worker            max_temporal_layer_extensions == o.max_temporal_layer_extensions &&
202*d9f75844SAndroid Build Coastguard Worker            max_spatial_layer_extensions == o.max_spatial_layer_extensions &&
203*d9f75844SAndroid Build Coastguard Worker            svc_multi_stream_support == o.svc_multi_stream_support &&
204*d9f75844SAndroid Build Coastguard Worker            scalability_modes == o.scalability_modes;
205*d9f75844SAndroid Build Coastguard Worker   }
206*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtpCodecCapability& o) const { return !(*this == o); }
207*d9f75844SAndroid Build Coastguard Worker };
208*d9f75844SAndroid Build Coastguard Worker 
209*d9f75844SAndroid Build Coastguard Worker // Used in RtpCapabilities and RtpTransceiverInterface's header extensions query
210*d9f75844SAndroid Build Coastguard Worker // and setup methods; represents the capabilities/preferences of an
211*d9f75844SAndroid Build Coastguard Worker // implementation for a header extension.
212*d9f75844SAndroid Build Coastguard Worker //
213*d9f75844SAndroid Build Coastguard Worker // Just called "RtpHeaderExtension" in ORTC, but the "Capability" suffix was
214*d9f75844SAndroid Build Coastguard Worker // added here for consistency and to avoid confusion with
215*d9f75844SAndroid Build Coastguard Worker // RtpHeaderExtensionParameters.
216*d9f75844SAndroid Build Coastguard Worker //
217*d9f75844SAndroid Build Coastguard Worker // Note that ORTC includes a "kind" field, but we omit this because it's
218*d9f75844SAndroid Build Coastguard Worker // redundant; if you call "RtpReceiver::GetCapabilities(MEDIA_TYPE_AUDIO)",
219*d9f75844SAndroid Build Coastguard Worker // you know you're getting audio capabilities.
220*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpHeaderExtensionCapability {
221*d9f75844SAndroid Build Coastguard Worker   // URI of this extension, as defined in RFC8285.
222*d9f75844SAndroid Build Coastguard Worker   std::string uri;
223*d9f75844SAndroid Build Coastguard Worker 
224*d9f75844SAndroid Build Coastguard Worker   // Preferred value of ID that goes in the packet.
225*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> preferred_id;
226*d9f75844SAndroid Build Coastguard Worker 
227*d9f75844SAndroid Build Coastguard Worker   // If true, it's preferred that the value in the header is encrypted.
228*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
229*d9f75844SAndroid Build Coastguard Worker   bool preferred_encrypt = false;
230*d9f75844SAndroid Build Coastguard Worker 
231*d9f75844SAndroid Build Coastguard Worker   // The direction of the extension. The kStopped value is only used with
232*d9f75844SAndroid Build Coastguard Worker   // RtpTransceiverInterface::HeaderExtensionsToOffer() and
233*d9f75844SAndroid Build Coastguard Worker   // SetOfferedRtpHeaderExtensions().
234*d9f75844SAndroid Build Coastguard Worker   RtpTransceiverDirection direction = RtpTransceiverDirection::kSendRecv;
235*d9f75844SAndroid Build Coastguard Worker 
236*d9f75844SAndroid Build Coastguard Worker   // Constructors for convenience.
237*d9f75844SAndroid Build Coastguard Worker   RtpHeaderExtensionCapability();
238*d9f75844SAndroid Build Coastguard Worker   explicit RtpHeaderExtensionCapability(absl::string_view uri);
239*d9f75844SAndroid Build Coastguard Worker   RtpHeaderExtensionCapability(absl::string_view uri, int preferred_id);
240*d9f75844SAndroid Build Coastguard Worker   RtpHeaderExtensionCapability(absl::string_view uri,
241*d9f75844SAndroid Build Coastguard Worker                                int preferred_id,
242*d9f75844SAndroid Build Coastguard Worker                                RtpTransceiverDirection direction);
243*d9f75844SAndroid Build Coastguard Worker   ~RtpHeaderExtensionCapability();
244*d9f75844SAndroid Build Coastguard Worker 
245*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtpHeaderExtensionCapability& o) const {
246*d9f75844SAndroid Build Coastguard Worker     return uri == o.uri && preferred_id == o.preferred_id &&
247*d9f75844SAndroid Build Coastguard Worker            preferred_encrypt == o.preferred_encrypt && direction == o.direction;
248*d9f75844SAndroid Build Coastguard Worker   }
249*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtpHeaderExtensionCapability& o) const {
250*d9f75844SAndroid Build Coastguard Worker     return !(*this == o);
251*d9f75844SAndroid Build Coastguard Worker   }
252*d9f75844SAndroid Build Coastguard Worker };
253*d9f75844SAndroid Build Coastguard Worker 
254*d9f75844SAndroid Build Coastguard Worker // RTP header extension, see RFC8285.
255*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpExtension {
256*d9f75844SAndroid Build Coastguard Worker   enum Filter {
257*d9f75844SAndroid Build Coastguard Worker     // Encrypted extensions will be ignored and only non-encrypted extensions
258*d9f75844SAndroid Build Coastguard Worker     // will be considered.
259*d9f75844SAndroid Build Coastguard Worker     kDiscardEncryptedExtension,
260*d9f75844SAndroid Build Coastguard Worker     // Encrypted extensions will be preferred but will fall back to
261*d9f75844SAndroid Build Coastguard Worker     // non-encrypted extensions if necessary.
262*d9f75844SAndroid Build Coastguard Worker     kPreferEncryptedExtension,
263*d9f75844SAndroid Build Coastguard Worker     // Encrypted extensions will be required, so any non-encrypted extensions
264*d9f75844SAndroid Build Coastguard Worker     // will be discarded.
265*d9f75844SAndroid Build Coastguard Worker     kRequireEncryptedExtension,
266*d9f75844SAndroid Build Coastguard Worker   };
267*d9f75844SAndroid Build Coastguard Worker 
268*d9f75844SAndroid Build Coastguard Worker   RtpExtension();
269*d9f75844SAndroid Build Coastguard Worker   RtpExtension(absl::string_view uri, int id);
270*d9f75844SAndroid Build Coastguard Worker   RtpExtension(absl::string_view uri, int id, bool encrypt);
271*d9f75844SAndroid Build Coastguard Worker   ~RtpExtension();
272*d9f75844SAndroid Build Coastguard Worker 
273*d9f75844SAndroid Build Coastguard Worker   std::string ToString() const;
274*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtpExtension& rhs) const {
275*d9f75844SAndroid Build Coastguard Worker     return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt;
276*d9f75844SAndroid Build Coastguard Worker   }
277*d9f75844SAndroid Build Coastguard Worker   static bool IsSupportedForAudio(absl::string_view uri);
278*d9f75844SAndroid Build Coastguard Worker   static bool IsSupportedForVideo(absl::string_view uri);
279*d9f75844SAndroid Build Coastguard Worker   // Return "true" if the given RTP header extension URI may be encrypted.
280*d9f75844SAndroid Build Coastguard Worker   static bool IsEncryptionSupported(absl::string_view uri);
281*d9f75844SAndroid Build Coastguard Worker 
282*d9f75844SAndroid Build Coastguard Worker   // Returns the header extension with the given URI or nullptr if not found.
283*d9f75844SAndroid Build Coastguard Worker   static const RtpExtension* FindHeaderExtensionByUri(
284*d9f75844SAndroid Build Coastguard Worker       const std::vector<RtpExtension>& extensions,
285*d9f75844SAndroid Build Coastguard Worker       absl::string_view uri,
286*d9f75844SAndroid Build Coastguard Worker       Filter filter);
287*d9f75844SAndroid Build Coastguard Worker 
288*d9f75844SAndroid Build Coastguard Worker   // Returns the header extension with the given URI and encrypt parameter,
289*d9f75844SAndroid Build Coastguard Worker   // if found, otherwise nullptr.
290*d9f75844SAndroid Build Coastguard Worker   static const RtpExtension* FindHeaderExtensionByUriAndEncryption(
291*d9f75844SAndroid Build Coastguard Worker       const std::vector<RtpExtension>& extensions,
292*d9f75844SAndroid Build Coastguard Worker       absl::string_view uri,
293*d9f75844SAndroid Build Coastguard Worker       bool encrypt);
294*d9f75844SAndroid Build Coastguard Worker 
295*d9f75844SAndroid Build Coastguard Worker   // Returns a list of extensions where any extension URI is unique.
296*d9f75844SAndroid Build Coastguard Worker   // The returned list will be sorted by uri first, then encrypt and id last.
297*d9f75844SAndroid Build Coastguard Worker   // Having the list sorted allows the caller fo compare filtered lists for
298*d9f75844SAndroid Build Coastguard Worker   // equality to detect when changes have been made.
299*d9f75844SAndroid Build Coastguard Worker   static const std::vector<RtpExtension> DeduplicateHeaderExtensions(
300*d9f75844SAndroid Build Coastguard Worker       const std::vector<RtpExtension>& extensions,
301*d9f75844SAndroid Build Coastguard Worker       Filter filter);
302*d9f75844SAndroid Build Coastguard Worker 
303*d9f75844SAndroid Build Coastguard Worker   // Encryption of Header Extensions, see RFC 6904 for details:
304*d9f75844SAndroid Build Coastguard Worker   // https://tools.ietf.org/html/rfc6904
305*d9f75844SAndroid Build Coastguard Worker   static constexpr char kEncryptHeaderExtensionsUri[] =
306*d9f75844SAndroid Build Coastguard Worker       "urn:ietf:params:rtp-hdrext:encrypt";
307*d9f75844SAndroid Build Coastguard Worker 
308*d9f75844SAndroid Build Coastguard Worker   // Header extension for audio levels, as defined in:
309*d9f75844SAndroid Build Coastguard Worker   // https://tools.ietf.org/html/rfc6464
310*d9f75844SAndroid Build Coastguard Worker   static constexpr char kAudioLevelUri[] =
311*d9f75844SAndroid Build Coastguard Worker       "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
312*d9f75844SAndroid Build Coastguard Worker 
313*d9f75844SAndroid Build Coastguard Worker   // Header extension for RTP timestamp offset, see RFC 5450 for details:
314*d9f75844SAndroid Build Coastguard Worker   // http://tools.ietf.org/html/rfc5450
315*d9f75844SAndroid Build Coastguard Worker   static constexpr char kTimestampOffsetUri[] =
316*d9f75844SAndroid Build Coastguard Worker       "urn:ietf:params:rtp-hdrext:toffset";
317*d9f75844SAndroid Build Coastguard Worker 
318*d9f75844SAndroid Build Coastguard Worker   // Header extension for absolute send time, see url for details:
319*d9f75844SAndroid Build Coastguard Worker   // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
320*d9f75844SAndroid Build Coastguard Worker   static constexpr char kAbsSendTimeUri[] =
321*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
322*d9f75844SAndroid Build Coastguard Worker 
323*d9f75844SAndroid Build Coastguard Worker   // Header extension for absolute capture time, see url for details:
324*d9f75844SAndroid Build Coastguard Worker   // http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time
325*d9f75844SAndroid Build Coastguard Worker   static constexpr char kAbsoluteCaptureTimeUri[] =
326*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time";
327*d9f75844SAndroid Build Coastguard Worker 
328*d9f75844SAndroid Build Coastguard Worker   // Header extension for coordination of video orientation, see url for
329*d9f75844SAndroid Build Coastguard Worker   // details:
330*d9f75844SAndroid Build Coastguard Worker   // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
331*d9f75844SAndroid Build Coastguard Worker   static constexpr char kVideoRotationUri[] = "urn:3gpp:video-orientation";
332*d9f75844SAndroid Build Coastguard Worker 
333*d9f75844SAndroid Build Coastguard Worker   // Header extension for video content type. E.g. default or screenshare.
334*d9f75844SAndroid Build Coastguard Worker   static constexpr char kVideoContentTypeUri[] =
335*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/video-content-type";
336*d9f75844SAndroid Build Coastguard Worker 
337*d9f75844SAndroid Build Coastguard Worker   // Header extension for video timing.
338*d9f75844SAndroid Build Coastguard Worker   static constexpr char kVideoTimingUri[] =
339*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/video-timing";
340*d9f75844SAndroid Build Coastguard Worker 
341*d9f75844SAndroid Build Coastguard Worker   // Experimental codec agnostic frame descriptor.
342*d9f75844SAndroid Build Coastguard Worker   static constexpr char kGenericFrameDescriptorUri00[] =
343*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/"
344*d9f75844SAndroid Build Coastguard Worker       "generic-frame-descriptor-00";
345*d9f75844SAndroid Build Coastguard Worker   static constexpr char kDependencyDescriptorUri[] =
346*d9f75844SAndroid Build Coastguard Worker       "https://aomediacodec.github.io/av1-rtp-spec/"
347*d9f75844SAndroid Build Coastguard Worker       "#dependency-descriptor-rtp-header-extension";
348*d9f75844SAndroid Build Coastguard Worker 
349*d9f75844SAndroid Build Coastguard Worker   // Experimental extension for signalling target bitrate per layer.
350*d9f75844SAndroid Build Coastguard Worker   static constexpr char kVideoLayersAllocationUri[] =
351*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/video-layers-allocation00";
352*d9f75844SAndroid Build Coastguard Worker 
353*d9f75844SAndroid Build Coastguard Worker   // Header extension for transport sequence number, see url for details:
354*d9f75844SAndroid Build Coastguard Worker   // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
355*d9f75844SAndroid Build Coastguard Worker   static constexpr char kTransportSequenceNumberUri[] =
356*d9f75844SAndroid Build Coastguard Worker       "http://www.ietf.org/id/"
357*d9f75844SAndroid Build Coastguard Worker       "draft-holmer-rmcat-transport-wide-cc-extensions-01";
358*d9f75844SAndroid Build Coastguard Worker   static constexpr char kTransportSequenceNumberV2Uri[] =
359*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/transport-wide-cc-02";
360*d9f75844SAndroid Build Coastguard Worker 
361*d9f75844SAndroid Build Coastguard Worker   // This extension allows applications to adaptively limit the playout delay
362*d9f75844SAndroid Build Coastguard Worker   // on frames as per the current needs. For example, a gaming application
363*d9f75844SAndroid Build Coastguard Worker   // has very different needs on end-to-end delay compared to a video-conference
364*d9f75844SAndroid Build Coastguard Worker   // application.
365*d9f75844SAndroid Build Coastguard Worker   static constexpr char kPlayoutDelayUri[] =
366*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
367*d9f75844SAndroid Build Coastguard Worker 
368*d9f75844SAndroid Build Coastguard Worker   // Header extension for color space information.
369*d9f75844SAndroid Build Coastguard Worker   static constexpr char kColorSpaceUri[] =
370*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/color-space";
371*d9f75844SAndroid Build Coastguard Worker 
372*d9f75844SAndroid Build Coastguard Worker   // Header extension for identifying media section within a transport.
373*d9f75844SAndroid Build Coastguard Worker   // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-bundle-negotiation-49#section-15
374*d9f75844SAndroid Build Coastguard Worker   static constexpr char kMidUri[] = "urn:ietf:params:rtp-hdrext:sdes:mid";
375*d9f75844SAndroid Build Coastguard Worker 
376*d9f75844SAndroid Build Coastguard Worker   // Header extension for RIDs and Repaired RIDs
377*d9f75844SAndroid Build Coastguard Worker   // https://tools.ietf.org/html/draft-ietf-avtext-rid-09
378*d9f75844SAndroid Build Coastguard Worker   // https://tools.ietf.org/html/draft-ietf-mmusic-rid-15
379*d9f75844SAndroid Build Coastguard Worker   static constexpr char kRidUri[] =
380*d9f75844SAndroid Build Coastguard Worker       "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id";
381*d9f75844SAndroid Build Coastguard Worker   static constexpr char kRepairedRidUri[] =
382*d9f75844SAndroid Build Coastguard Worker       "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id";
383*d9f75844SAndroid Build Coastguard Worker 
384*d9f75844SAndroid Build Coastguard Worker   // Header extension to propagate webrtc::VideoFrame id field
385*d9f75844SAndroid Build Coastguard Worker   static constexpr char kVideoFrameTrackingIdUri[] =
386*d9f75844SAndroid Build Coastguard Worker       "http://www.webrtc.org/experiments/rtp-hdrext/video-frame-tracking-id";
387*d9f75844SAndroid Build Coastguard Worker 
388*d9f75844SAndroid Build Coastguard Worker   // Header extension for Mixer-to-Client audio levels per CSRC as defined in
389*d9f75844SAndroid Build Coastguard Worker   // https://tools.ietf.org/html/rfc6465
390*d9f75844SAndroid Build Coastguard Worker   static constexpr char kCsrcAudioLevelsUri[] =
391*d9f75844SAndroid Build Coastguard Worker       "urn:ietf:params:rtp-hdrext:csrc-audio-level";
392*d9f75844SAndroid Build Coastguard Worker 
393*d9f75844SAndroid Build Coastguard Worker   // Inclusive min and max IDs for two-byte header extensions and one-byte
394*d9f75844SAndroid Build Coastguard Worker   // header extensions, per RFC8285 Section 4.2-4.3.
395*d9f75844SAndroid Build Coastguard Worker   static constexpr int kMinId = 1;
396*d9f75844SAndroid Build Coastguard Worker   static constexpr int kMaxId = 255;
397*d9f75844SAndroid Build Coastguard Worker   static constexpr int kMaxValueSize = 255;
398*d9f75844SAndroid Build Coastguard Worker   static constexpr int kOneByteHeaderExtensionMaxId = 14;
399*d9f75844SAndroid Build Coastguard Worker   static constexpr int kOneByteHeaderExtensionMaxValueSize = 16;
400*d9f75844SAndroid Build Coastguard Worker 
401*d9f75844SAndroid Build Coastguard Worker   std::string uri;
402*d9f75844SAndroid Build Coastguard Worker   int id = 0;
403*d9f75844SAndroid Build Coastguard Worker   bool encrypt = false;
404*d9f75844SAndroid Build Coastguard Worker };
405*d9f75844SAndroid Build Coastguard Worker 
406*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpFecParameters {
407*d9f75844SAndroid Build Coastguard Worker   // If unset, a value is chosen by the implementation.
408*d9f75844SAndroid Build Coastguard Worker   // Works just like RtpEncodingParameters::ssrc.
409*d9f75844SAndroid Build Coastguard Worker   absl::optional<uint32_t> ssrc;
410*d9f75844SAndroid Build Coastguard Worker 
411*d9f75844SAndroid Build Coastguard Worker   FecMechanism mechanism = FecMechanism::RED;
412*d9f75844SAndroid Build Coastguard Worker 
413*d9f75844SAndroid Build Coastguard Worker   // Constructors for convenience.
414*d9f75844SAndroid Build Coastguard Worker   RtpFecParameters();
415*d9f75844SAndroid Build Coastguard Worker   explicit RtpFecParameters(FecMechanism mechanism);
416*d9f75844SAndroid Build Coastguard Worker   RtpFecParameters(FecMechanism mechanism, uint32_t ssrc);
417*d9f75844SAndroid Build Coastguard Worker   RtpFecParameters(const RtpFecParameters&);
418*d9f75844SAndroid Build Coastguard Worker   ~RtpFecParameters();
419*d9f75844SAndroid Build Coastguard Worker 
420*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtpFecParameters& o) const {
421*d9f75844SAndroid Build Coastguard Worker     return ssrc == o.ssrc && mechanism == o.mechanism;
422*d9f75844SAndroid Build Coastguard Worker   }
423*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtpFecParameters& o) const { return !(*this == o); }
424*d9f75844SAndroid Build Coastguard Worker };
425*d9f75844SAndroid Build Coastguard Worker 
426*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpRtxParameters {
427*d9f75844SAndroid Build Coastguard Worker   // If unset, a value is chosen by the implementation.
428*d9f75844SAndroid Build Coastguard Worker   // Works just like RtpEncodingParameters::ssrc.
429*d9f75844SAndroid Build Coastguard Worker   absl::optional<uint32_t> ssrc;
430*d9f75844SAndroid Build Coastguard Worker 
431*d9f75844SAndroid Build Coastguard Worker   // Constructors for convenience.
432*d9f75844SAndroid Build Coastguard Worker   RtpRtxParameters();
433*d9f75844SAndroid Build Coastguard Worker   explicit RtpRtxParameters(uint32_t ssrc);
434*d9f75844SAndroid Build Coastguard Worker   RtpRtxParameters(const RtpRtxParameters&);
435*d9f75844SAndroid Build Coastguard Worker   ~RtpRtxParameters();
436*d9f75844SAndroid Build Coastguard Worker 
437*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtpRtxParameters& o) const { return ssrc == o.ssrc; }
438*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtpRtxParameters& o) const { return !(*this == o); }
439*d9f75844SAndroid Build Coastguard Worker };
440*d9f75844SAndroid Build Coastguard Worker 
441*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpEncodingParameters {
442*d9f75844SAndroid Build Coastguard Worker   RtpEncodingParameters();
443*d9f75844SAndroid Build Coastguard Worker   RtpEncodingParameters(const RtpEncodingParameters&);
444*d9f75844SAndroid Build Coastguard Worker   ~RtpEncodingParameters();
445*d9f75844SAndroid Build Coastguard Worker 
446*d9f75844SAndroid Build Coastguard Worker   // If unset, a value is chosen by the implementation.
447*d9f75844SAndroid Build Coastguard Worker   //
448*d9f75844SAndroid Build Coastguard Worker   // Note that the chosen value is NOT returned by GetParameters, because it
449*d9f75844SAndroid Build Coastguard Worker   // may change due to an SSRC conflict, in which case the conflict is handled
450*d9f75844SAndroid Build Coastguard Worker   // internally without any event. Another way of looking at this is that an
451*d9f75844SAndroid Build Coastguard Worker   // unset SSRC acts as a "wildcard" SSRC.
452*d9f75844SAndroid Build Coastguard Worker   absl::optional<uint32_t> ssrc;
453*d9f75844SAndroid Build Coastguard Worker 
454*d9f75844SAndroid Build Coastguard Worker   // The relative bitrate priority of this encoding. Currently this is
455*d9f75844SAndroid Build Coastguard Worker   // implemented for the entire rtp sender by using the value of the first
456*d9f75844SAndroid Build Coastguard Worker   // encoding parameter.
457*d9f75844SAndroid Build Coastguard Worker   // See: https://w3c.github.io/webrtc-priority/#enumdef-rtcprioritytype
458*d9f75844SAndroid Build Coastguard Worker   // "very-low" = 0.5
459*d9f75844SAndroid Build Coastguard Worker   // "low" = 1.0
460*d9f75844SAndroid Build Coastguard Worker   // "medium" = 2.0
461*d9f75844SAndroid Build Coastguard Worker   // "high" = 4.0
462*d9f75844SAndroid Build Coastguard Worker   // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
463*d9f75844SAndroid Build Coastguard Worker   // Currently there is logic for how bitrate is distributed per simulcast layer
464*d9f75844SAndroid Build Coastguard Worker   // in the VideoBitrateAllocator. This must be updated to incorporate relative
465*d9f75844SAndroid Build Coastguard Worker   // bitrate priority.
466*d9f75844SAndroid Build Coastguard Worker   double bitrate_priority = kDefaultBitratePriority;
467*d9f75844SAndroid Build Coastguard Worker 
468*d9f75844SAndroid Build Coastguard Worker   // The relative DiffServ Code Point priority for this encoding, allowing
469*d9f75844SAndroid Build Coastguard Worker   // packets to be marked relatively higher or lower without affecting
470*d9f75844SAndroid Build Coastguard Worker   // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ .
471*d9f75844SAndroid Build Coastguard Worker   // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
472*d9f75844SAndroid Build Coastguard Worker   // TODO(http://crbug.com/webrtc/11379): TCP connections should use a single
473*d9f75844SAndroid Build Coastguard Worker   // DSCP value even if shared by multiple senders; this is not implemented.
474*d9f75844SAndroid Build Coastguard Worker   Priority network_priority = Priority::kLow;
475*d9f75844SAndroid Build Coastguard Worker 
476*d9f75844SAndroid Build Coastguard Worker   // If set, this represents the Transport Independent Application Specific
477*d9f75844SAndroid Build Coastguard Worker   // maximum bandwidth defined in RFC3890. If unset, there is no maximum
478*d9f75844SAndroid Build Coastguard Worker   // bitrate. Currently this is implemented for the entire rtp sender by using
479*d9f75844SAndroid Build Coastguard Worker   // the value of the first encoding parameter.
480*d9f75844SAndroid Build Coastguard Worker   //
481*d9f75844SAndroid Build Coastguard Worker   // Just called "maxBitrate" in ORTC spec.
482*d9f75844SAndroid Build Coastguard Worker   //
483*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): With ORTC RtpSenders, this currently sets the total
484*d9f75844SAndroid Build Coastguard Worker   // bandwidth for the entire bandwidth estimator (audio and video). This is
485*d9f75844SAndroid Build Coastguard Worker   // just always how "b=AS" was handled, but it's not correct and should be
486*d9f75844SAndroid Build Coastguard Worker   // fixed.
487*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> max_bitrate_bps;
488*d9f75844SAndroid Build Coastguard Worker 
489*d9f75844SAndroid Build Coastguard Worker   // Specifies the minimum bitrate in bps for video.
490*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> min_bitrate_bps;
491*d9f75844SAndroid Build Coastguard Worker 
492*d9f75844SAndroid Build Coastguard Worker   // Specifies the maximum framerate in fps for video.
493*d9f75844SAndroid Build Coastguard Worker   absl::optional<double> max_framerate;
494*d9f75844SAndroid Build Coastguard Worker 
495*d9f75844SAndroid Build Coastguard Worker   // Specifies the number of temporal layers for video (if the feature is
496*d9f75844SAndroid Build Coastguard Worker   // supported by the codec implementation).
497*d9f75844SAndroid Build Coastguard Worker   // Screencast support is experimental.
498*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> num_temporal_layers;
499*d9f75844SAndroid Build Coastguard Worker 
500*d9f75844SAndroid Build Coastguard Worker   // For video, scale the resolution down by this factor.
501*d9f75844SAndroid Build Coastguard Worker   absl::optional<double> scale_resolution_down_by;
502*d9f75844SAndroid Build Coastguard Worker 
503*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-svc/#rtcrtpencodingparameters
504*d9f75844SAndroid Build Coastguard Worker   absl::optional<std::string> scalability_mode;
505*d9f75844SAndroid Build Coastguard Worker 
506*d9f75844SAndroid Build Coastguard Worker   // Requested encode resolution.
507*d9f75844SAndroid Build Coastguard Worker   //
508*d9f75844SAndroid Build Coastguard Worker   // This field provides an alternative to `scale_resolution_down_by`
509*d9f75844SAndroid Build Coastguard Worker   // that is not dependent on the video source.
510*d9f75844SAndroid Build Coastguard Worker   //
511*d9f75844SAndroid Build Coastguard Worker   // When setting requested_resolution it is not necessary to adapt the
512*d9f75844SAndroid Build Coastguard Worker   // video source using OnOutputFormatRequest, since the VideoStreamEncoder
513*d9f75844SAndroid Build Coastguard Worker   // will apply downscaling if necessary. requested_resolution will also be
514*d9f75844SAndroid Build Coastguard Worker   // propagated to the video source, this allows downscaling earlier in the
515*d9f75844SAndroid Build Coastguard Worker   // pipeline which can be beneficial if the source is consumed by multiple
516*d9f75844SAndroid Build Coastguard Worker   // encoders, but is not strictly necessary.
517*d9f75844SAndroid Build Coastguard Worker   //
518*d9f75844SAndroid Build Coastguard Worker   // The `requested_resolution` is subject to resource adaptation.
519*d9f75844SAndroid Build Coastguard Worker   //
520*d9f75844SAndroid Build Coastguard Worker   // It is an error to set both `requested_resolution` and
521*d9f75844SAndroid Build Coastguard Worker   // `scale_resolution_down_by`.
522*d9f75844SAndroid Build Coastguard Worker   absl::optional<Resolution> requested_resolution;
523*d9f75844SAndroid Build Coastguard Worker 
524*d9f75844SAndroid Build Coastguard Worker   // For an RtpSender, set to true to cause this encoding to be encoded and
525*d9f75844SAndroid Build Coastguard Worker   // sent, and false for it not to be encoded and sent. This allows control
526*d9f75844SAndroid Build Coastguard Worker   // across multiple encodings of a sender for turning simulcast layers on and
527*d9f75844SAndroid Build Coastguard Worker   // off.
528*d9f75844SAndroid Build Coastguard Worker   // TODO(webrtc.bugs.org/8807): Updating this parameter will trigger an encoder
529*d9f75844SAndroid Build Coastguard Worker   // reset, but this isn't necessarily required.
530*d9f75844SAndroid Build Coastguard Worker   bool active = true;
531*d9f75844SAndroid Build Coastguard Worker 
532*d9f75844SAndroid Build Coastguard Worker   // Value to use for RID RTP header extension.
533*d9f75844SAndroid Build Coastguard Worker   // Called "encodingId" in ORTC.
534*d9f75844SAndroid Build Coastguard Worker   std::string rid;
535*d9f75844SAndroid Build Coastguard Worker 
536*d9f75844SAndroid Build Coastguard Worker   // Allow dynamic frame length changes for audio:
537*d9f75844SAndroid Build Coastguard Worker   // https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime
538*d9f75844SAndroid Build Coastguard Worker   bool adaptive_ptime = false;
539*d9f75844SAndroid Build Coastguard Worker 
540*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtpEncodingParameters& o) const {
541*d9f75844SAndroid Build Coastguard Worker     return ssrc == o.ssrc && bitrate_priority == o.bitrate_priority &&
542*d9f75844SAndroid Build Coastguard Worker            network_priority == o.network_priority &&
543*d9f75844SAndroid Build Coastguard Worker            max_bitrate_bps == o.max_bitrate_bps &&
544*d9f75844SAndroid Build Coastguard Worker            min_bitrate_bps == o.min_bitrate_bps &&
545*d9f75844SAndroid Build Coastguard Worker            max_framerate == o.max_framerate &&
546*d9f75844SAndroid Build Coastguard Worker            num_temporal_layers == o.num_temporal_layers &&
547*d9f75844SAndroid Build Coastguard Worker            scale_resolution_down_by == o.scale_resolution_down_by &&
548*d9f75844SAndroid Build Coastguard Worker            active == o.active && rid == o.rid &&
549*d9f75844SAndroid Build Coastguard Worker            adaptive_ptime == o.adaptive_ptime &&
550*d9f75844SAndroid Build Coastguard Worker            requested_resolution == o.requested_resolution;
551*d9f75844SAndroid Build Coastguard Worker   }
552*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtpEncodingParameters& o) const {
553*d9f75844SAndroid Build Coastguard Worker     return !(*this == o);
554*d9f75844SAndroid Build Coastguard Worker   }
555*d9f75844SAndroid Build Coastguard Worker };
556*d9f75844SAndroid Build Coastguard Worker 
557*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpCodecParameters {
558*d9f75844SAndroid Build Coastguard Worker   RtpCodecParameters();
559*d9f75844SAndroid Build Coastguard Worker   RtpCodecParameters(const RtpCodecParameters&);
560*d9f75844SAndroid Build Coastguard Worker   ~RtpCodecParameters();
561*d9f75844SAndroid Build Coastguard Worker 
562*d9f75844SAndroid Build Coastguard Worker   // Build MIME "type/subtype" string from `name` and `kind`.
mime_typeRtpCodecParameters563*d9f75844SAndroid Build Coastguard Worker   std::string mime_type() const { return MediaTypeToString(kind) + "/" + name; }
564*d9f75844SAndroid Build Coastguard Worker 
565*d9f75844SAndroid Build Coastguard Worker   // Used to identify the codec. Equivalent to MIME subtype.
566*d9f75844SAndroid Build Coastguard Worker   std::string name;
567*d9f75844SAndroid Build Coastguard Worker 
568*d9f75844SAndroid Build Coastguard Worker   // The media type of this codec. Equivalent to MIME top-level type.
569*d9f75844SAndroid Build Coastguard Worker   cricket::MediaType kind = cricket::MEDIA_TYPE_AUDIO;
570*d9f75844SAndroid Build Coastguard Worker 
571*d9f75844SAndroid Build Coastguard Worker   // Payload type used to identify this codec in RTP packets.
572*d9f75844SAndroid Build Coastguard Worker   // This must always be present, and must be unique across all codecs using
573*d9f75844SAndroid Build Coastguard Worker   // the same transport.
574*d9f75844SAndroid Build Coastguard Worker   int payload_type = 0;
575*d9f75844SAndroid Build Coastguard Worker 
576*d9f75844SAndroid Build Coastguard Worker   // If unset, the implementation default is used.
577*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> clock_rate;
578*d9f75844SAndroid Build Coastguard Worker 
579*d9f75844SAndroid Build Coastguard Worker   // The number of audio channels used. Unset for video codecs. If unset for
580*d9f75844SAndroid Build Coastguard Worker   // audio, the implementation default is used.
581*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): The "implementation default" part isn't fully implemented.
582*d9f75844SAndroid Build Coastguard Worker   // Only defaults to 1, even though some codecs (such as opus) should really
583*d9f75844SAndroid Build Coastguard Worker   // default to 2.
584*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> num_channels;
585*d9f75844SAndroid Build Coastguard Worker 
586*d9f75844SAndroid Build Coastguard Worker   // The maximum packetization time to be used by an RtpSender.
587*d9f75844SAndroid Build Coastguard Worker   // If `ptime` is also set, this will be ignored.
588*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
589*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> max_ptime;
590*d9f75844SAndroid Build Coastguard Worker 
591*d9f75844SAndroid Build Coastguard Worker   // The packetization time to be used by an RtpSender.
592*d9f75844SAndroid Build Coastguard Worker   // If unset, will use any time up to max_ptime.
593*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
594*d9f75844SAndroid Build Coastguard Worker   absl::optional<int> ptime;
595*d9f75844SAndroid Build Coastguard Worker 
596*d9f75844SAndroid Build Coastguard Worker   // Feedback mechanisms to be used for this codec.
597*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented with PeerConnection senders/receivers.
598*d9f75844SAndroid Build Coastguard Worker   std::vector<RtcpFeedback> rtcp_feedback;
599*d9f75844SAndroid Build Coastguard Worker 
600*d9f75844SAndroid Build Coastguard Worker   // Codec-specific parameters that must be signaled to the remote party.
601*d9f75844SAndroid Build Coastguard Worker   //
602*d9f75844SAndroid Build Coastguard Worker   // Corresponds to "a=fmtp" parameters in SDP.
603*d9f75844SAndroid Build Coastguard Worker   //
604*d9f75844SAndroid Build Coastguard Worker   // Contrary to ORTC, these parameters are named using all lowercase strings.
605*d9f75844SAndroid Build Coastguard Worker   // This helps make the mapping to SDP simpler, if an application is using SDP.
606*d9f75844SAndroid Build Coastguard Worker   // Boolean values are represented by the string "1".
607*d9f75844SAndroid Build Coastguard Worker   std::map<std::string, std::string> parameters;
608*d9f75844SAndroid Build Coastguard Worker 
609*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtpCodecParameters& o) const {
610*d9f75844SAndroid Build Coastguard Worker     return name == o.name && kind == o.kind && payload_type == o.payload_type &&
611*d9f75844SAndroid Build Coastguard Worker            clock_rate == o.clock_rate && num_channels == o.num_channels &&
612*d9f75844SAndroid Build Coastguard Worker            max_ptime == o.max_ptime && ptime == o.ptime &&
613*d9f75844SAndroid Build Coastguard Worker            rtcp_feedback == o.rtcp_feedback && parameters == o.parameters;
614*d9f75844SAndroid Build Coastguard Worker   }
615*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtpCodecParameters& o) const { return !(*this == o); }
616*d9f75844SAndroid Build Coastguard Worker };
617*d9f75844SAndroid Build Coastguard Worker 
618*d9f75844SAndroid Build Coastguard Worker // RtpCapabilities is used to represent the static capabilities of an endpoint.
619*d9f75844SAndroid Build Coastguard Worker // An application can use these capabilities to construct an RtpParameters.
620*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpCapabilities {
621*d9f75844SAndroid Build Coastguard Worker   RtpCapabilities();
622*d9f75844SAndroid Build Coastguard Worker   ~RtpCapabilities();
623*d9f75844SAndroid Build Coastguard Worker 
624*d9f75844SAndroid Build Coastguard Worker   // Supported codecs.
625*d9f75844SAndroid Build Coastguard Worker   std::vector<RtpCodecCapability> codecs;
626*d9f75844SAndroid Build Coastguard Worker 
627*d9f75844SAndroid Build Coastguard Worker   // Supported RTP header extensions.
628*d9f75844SAndroid Build Coastguard Worker   std::vector<RtpHeaderExtensionCapability> header_extensions;
629*d9f75844SAndroid Build Coastguard Worker 
630*d9f75844SAndroid Build Coastguard Worker   // Supported Forward Error Correction (FEC) mechanisms. Note that the RED,
631*d9f75844SAndroid Build Coastguard Worker   // ulpfec and flexfec codecs used by these mechanisms will still appear in
632*d9f75844SAndroid Build Coastguard Worker   // `codecs`.
633*d9f75844SAndroid Build Coastguard Worker   std::vector<FecMechanism> fec;
634*d9f75844SAndroid Build Coastguard Worker 
635*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtpCapabilities& o) const {
636*d9f75844SAndroid Build Coastguard Worker     return codecs == o.codecs && header_extensions == o.header_extensions &&
637*d9f75844SAndroid Build Coastguard Worker            fec == o.fec;
638*d9f75844SAndroid Build Coastguard Worker   }
639*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtpCapabilities& o) const { return !(*this == o); }
640*d9f75844SAndroid Build Coastguard Worker };
641*d9f75844SAndroid Build Coastguard Worker 
642*d9f75844SAndroid Build Coastguard Worker struct RtcpParameters final {
643*d9f75844SAndroid Build Coastguard Worker   RtcpParameters();
644*d9f75844SAndroid Build Coastguard Worker   RtcpParameters(const RtcpParameters&);
645*d9f75844SAndroid Build Coastguard Worker   ~RtcpParameters();
646*d9f75844SAndroid Build Coastguard Worker 
647*d9f75844SAndroid Build Coastguard Worker   // The SSRC to be used in the "SSRC of packet sender" field. If not set, one
648*d9f75844SAndroid Build Coastguard Worker   // will be chosen by the implementation.
649*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
650*d9f75844SAndroid Build Coastguard Worker   absl::optional<uint32_t> ssrc;
651*d9f75844SAndroid Build Coastguard Worker 
652*d9f75844SAndroid Build Coastguard Worker   // The Canonical Name (CNAME) used by RTCP (e.g. in SDES messages).
653*d9f75844SAndroid Build Coastguard Worker   //
654*d9f75844SAndroid Build Coastguard Worker   // If empty in the construction of the RtpTransport, one will be generated by
655*d9f75844SAndroid Build Coastguard Worker   // the implementation, and returned in GetRtcpParameters. Multiple
656*d9f75844SAndroid Build Coastguard Worker   // RtpTransports created by the same OrtcFactory will use the same generated
657*d9f75844SAndroid Build Coastguard Worker   // CNAME.
658*d9f75844SAndroid Build Coastguard Worker   //
659*d9f75844SAndroid Build Coastguard Worker   // If empty when passed into SetParameters, the CNAME simply won't be
660*d9f75844SAndroid Build Coastguard Worker   // modified.
661*d9f75844SAndroid Build Coastguard Worker   std::string cname;
662*d9f75844SAndroid Build Coastguard Worker 
663*d9f75844SAndroid Build Coastguard Worker   // Send reduced-size RTCP?
664*d9f75844SAndroid Build Coastguard Worker   bool reduced_size = false;
665*d9f75844SAndroid Build Coastguard Worker 
666*d9f75844SAndroid Build Coastguard Worker   // Send RTCP multiplexed on the RTP transport?
667*d9f75844SAndroid Build Coastguard Worker   // Not used with PeerConnection senders/receivers
668*d9f75844SAndroid Build Coastguard Worker   bool mux = true;
669*d9f75844SAndroid Build Coastguard Worker 
670*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtcpParameters& o) const {
671*d9f75844SAndroid Build Coastguard Worker     return ssrc == o.ssrc && cname == o.cname &&
672*d9f75844SAndroid Build Coastguard Worker            reduced_size == o.reduced_size && mux == o.mux;
673*d9f75844SAndroid Build Coastguard Worker   }
674*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtcpParameters& o) const { return !(*this == o); }
675*d9f75844SAndroid Build Coastguard Worker };
676*d9f75844SAndroid Build Coastguard Worker 
677*d9f75844SAndroid Build Coastguard Worker struct RTC_EXPORT RtpParameters {
678*d9f75844SAndroid Build Coastguard Worker   RtpParameters();
679*d9f75844SAndroid Build Coastguard Worker   RtpParameters(const RtpParameters&);
680*d9f75844SAndroid Build Coastguard Worker   ~RtpParameters();
681*d9f75844SAndroid Build Coastguard Worker 
682*d9f75844SAndroid Build Coastguard Worker   // Used when calling getParameters/setParameters with a PeerConnection
683*d9f75844SAndroid Build Coastguard Worker   // RtpSender, to ensure that outdated parameters are not unintentionally
684*d9f75844SAndroid Build Coastguard Worker   // applied successfully.
685*d9f75844SAndroid Build Coastguard Worker   std::string transaction_id;
686*d9f75844SAndroid Build Coastguard Worker 
687*d9f75844SAndroid Build Coastguard Worker   // Value to use for MID RTP header extension.
688*d9f75844SAndroid Build Coastguard Worker   // Called "muxId" in ORTC.
689*d9f75844SAndroid Build Coastguard Worker   // TODO(deadbeef): Not implemented.
690*d9f75844SAndroid Build Coastguard Worker   std::string mid;
691*d9f75844SAndroid Build Coastguard Worker 
692*d9f75844SAndroid Build Coastguard Worker   std::vector<RtpCodecParameters> codecs;
693*d9f75844SAndroid Build Coastguard Worker 
694*d9f75844SAndroid Build Coastguard Worker   std::vector<RtpExtension> header_extensions;
695*d9f75844SAndroid Build Coastguard Worker 
696*d9f75844SAndroid Build Coastguard Worker   std::vector<RtpEncodingParameters> encodings;
697*d9f75844SAndroid Build Coastguard Worker 
698*d9f75844SAndroid Build Coastguard Worker   // Only available with a Peerconnection RtpSender.
699*d9f75844SAndroid Build Coastguard Worker   // In ORTC, our API includes an additional "RtpTransport"
700*d9f75844SAndroid Build Coastguard Worker   // abstraction on which RTCP parameters are set.
701*d9f75844SAndroid Build Coastguard Worker   RtcpParameters rtcp;
702*d9f75844SAndroid Build Coastguard Worker 
703*d9f75844SAndroid Build Coastguard Worker   // When bandwidth is constrained and the RtpSender needs to choose between
704*d9f75844SAndroid Build Coastguard Worker   // degrading resolution or degrading framerate, degradationPreference
705*d9f75844SAndroid Build Coastguard Worker   // indicates which is preferred. Only for video tracks.
706*d9f75844SAndroid Build Coastguard Worker   absl::optional<DegradationPreference> degradation_preference;
707*d9f75844SAndroid Build Coastguard Worker 
708*d9f75844SAndroid Build Coastguard Worker   bool operator==(const RtpParameters& o) const {
709*d9f75844SAndroid Build Coastguard Worker     return mid == o.mid && codecs == o.codecs &&
710*d9f75844SAndroid Build Coastguard Worker            header_extensions == o.header_extensions &&
711*d9f75844SAndroid Build Coastguard Worker            encodings == o.encodings && rtcp == o.rtcp &&
712*d9f75844SAndroid Build Coastguard Worker            degradation_preference == o.degradation_preference;
713*d9f75844SAndroid Build Coastguard Worker   }
714*d9f75844SAndroid Build Coastguard Worker   bool operator!=(const RtpParameters& o) const { return !(*this == o); }
715*d9f75844SAndroid Build Coastguard Worker };
716*d9f75844SAndroid Build Coastguard Worker 
717*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
718*d9f75844SAndroid Build Coastguard Worker 
719*d9f75844SAndroid Build Coastguard Worker #endif  // API_RTP_PARAMETERS_H_
720