blob: 673ef475892ad25da8b2c512d8fd44abdc87c141 [file] [log] [blame]
skvlad303b3c22016-03-24 19:36:46 -07001/*
2 * Copyright 2013 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
11package org.webrtc;
12
Artem Titarenko69540f42018-12-10 12:30:46 +010013import android.support.annotation.Nullable;
Mirta Dvornicicd8b98042019-02-04 16:38:46 +010014import java.lang.Double;
Amit Hilbuchae4b6232019-03-29 14:02:42 -070015import java.lang.String;
Florent Castellib7d9d832018-05-15 18:14:14 +020016import java.util.List;
17import java.util.Map;
Magnus Jedvert9060eb12017-12-12 12:52:54 +010018import org.webrtc.MediaStreamTrack;
skvlad303b3c22016-03-24 19:36:46 -070019
20/**
21 * The parameters for an {@code RtpSender}, as defined in
22 * http://w3c.github.io/webrtc-pc/#rtcrtpsender-interface.
deadbeefe702b302017-02-04 12:09:01 -080023 *
24 * Note: These structures use nullable Integer/etc. types because in the
25 * future, they may be used to construct ORTC RtpSender/RtpReceivers, in
26 * which case "null" will be used to represent "choose the implementation
27 * default value".
skvlad303b3c22016-03-24 19:36:46 -070028 */
29public class RtpParameters {
Florent Castelli266021d2020-01-07 17:43:52 +010030 public enum DegradationPreference {
31 /** Does not degrade resolution or framerate. */
32 DISABLED,
33 /** Degrade resolution in order to maintain framerate. */
34 MAINTAIN_FRAMERATE,
35 /** Degrade framerate in order to maintain resolution. */
36 MAINTAIN_RESOLUTION,
37 /** Degrade a balance of framerate and resolution. */
38 BALANCED;
39
40 @CalledByNative("DegradationPreference")
41 static DegradationPreference fromNativeIndex(int nativeIndex) {
42 return values()[nativeIndex];
43 }
44 }
45
Taylor Brandstetterf8711c02016-03-29 17:21:29 -070046 public static class Encoding {
Amit Hilbuchae4b6232019-03-29 14:02:42 -070047 // If non-null, this represents the RID that identifies this encoding layer.
48 // RIDs are used to identify layers in simulcast.
49 @Nullable public String rid;
deadbeefe702b302017-02-04 12:09:01 -080050 // Set to true to cause this encoding to be sent, and false for it not to
51 // be sent.
Taylor Brandstetterf8711c02016-03-29 17:21:29 -070052 public boolean active = true;
Taylor Brandstettere3a294c2020-03-23 23:16:58 +000053 // The relative bitrate priority of this encoding. Currently this is
54 // implemented for the entire RTP sender by using the value of the first
55 // encoding parameter.
56 // See: https://w3c.github.io/webrtc-priority/#enumdef-rtcprioritytype
57 // "very-low" = 0.5
58 // "low" = 1.0
59 // "medium" = 2.0
60 // "high" = 4.0
61 public double bitratePriority = 1.0;
62 // The relative DiffServ Code Point priority for this encoding, allowing
63 // packets to be marked relatively higher or lower without affecting
64 // bandwidth allocations.
65 @Priority public int networkPriority = Priority.LOW;
deadbeefe702b302017-02-04 12:09:01 -080066 // If non-null, this represents the Transport Independent Application
67 // Specific maximum bandwidth defined in RFC3890. If null, there is no
68 // maximum bitrate.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +010069 @Nullable public Integer maxBitrateBps;
Åsa Persson4e5342f2018-08-13 16:46:57 +020070 // The minimum bitrate in bps for video.
Åsa Persson613591a2018-05-29 09:21:31 +020071 @Nullable public Integer minBitrateBps;
Åsa Persson4e5342f2018-08-13 16:46:57 +020072 // The max framerate in fps for video.
73 @Nullable public Integer maxFramerate;
Åsa Persson23eba222018-10-02 14:47:06 +020074 // The number of temporal layers for video.
75 @Nullable public Integer numTemporalLayers;
Mirta Dvornicicd8b98042019-02-04 16:38:46 +010076 // If non-null, scale the width and height down by this factor for video. If null,
77 // implementation default scaling factor will be used.
78 @Nullable public Double scaleResolutionDownBy;
deadbeefe702b302017-02-04 12:09:01 -080079 // SSRC to be used by this encoding.
80 // Can't be changed between getParameters/setParameters.
deadbeef8014c752017-01-06 16:53:00 -080081 public Long ssrc;
Yura Yaroshevichd29c6892021-04-19 10:14:03 +030082 // Set to true to allow dynamic frame length changes for audio:
83 // https://w3c.github.io/webrtc-extensions/#dom-rtcrtpencodingparameters-adaptiveptime
84 public boolean adaptiveAudioPacketTime;
Magnus Jedvert9060eb12017-12-12 12:52:54 +010085
Amit Hilbuchae4b6232019-03-29 14:02:42 -070086 // This constructor is useful for creating simulcast layers.
Amit Hilbuche725fdb2019-12-02 13:54:01 -080087 public Encoding(String rid, boolean active, Double scaleResolutionDownBy) {
Amit Hilbuchae4b6232019-03-29 14:02:42 -070088 this.rid = rid;
89 this.active = active;
90 this.scaleResolutionDownBy = scaleResolutionDownBy;
91 }
92
Magnus Jedvert9060eb12017-12-12 12:52:54 +010093 @CalledByNative("Encoding")
Taylor Brandstettere3a294c2020-03-23 23:16:58 +000094 Encoding(String rid, boolean active, double bitratePriority, @Priority int networkPriority,
95 Integer maxBitrateBps, Integer minBitrateBps, Integer maxFramerate,
Yura Yaroshevichd29c6892021-04-19 10:14:03 +030096 Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc,
97 boolean adaptiveAudioPacketTime) {
Amit Hilbuchae4b6232019-03-29 14:02:42 -070098 this.rid = rid;
Magnus Jedvert9060eb12017-12-12 12:52:54 +010099 this.active = active;
Taylor Brandstettere3a294c2020-03-23 23:16:58 +0000100 this.bitratePriority = bitratePriority;
101 this.networkPriority = networkPriority;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100102 this.maxBitrateBps = maxBitrateBps;
Åsa Persson613591a2018-05-29 09:21:31 +0200103 this.minBitrateBps = minBitrateBps;
Åsa Persson4e5342f2018-08-13 16:46:57 +0200104 this.maxFramerate = maxFramerate;
Åsa Persson23eba222018-10-02 14:47:06 +0200105 this.numTemporalLayers = numTemporalLayers;
Mirta Dvornicicd8b98042019-02-04 16:38:46 +0100106 this.scaleResolutionDownBy = scaleResolutionDownBy;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100107 this.ssrc = ssrc;
Yura Yaroshevichd29c6892021-04-19 10:14:03 +0300108 this.adaptiveAudioPacketTime = adaptiveAudioPacketTime;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100109 }
110
Amit Hilbuchae4b6232019-03-29 14:02:42 -0700111 @Nullable
112 @CalledByNative("Encoding")
113 String getRid() {
114 return rid;
115 }
116
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100117 @CalledByNative("Encoding")
118 boolean getActive() {
119 return active;
120 }
121
Taylor Brandstettere3a294c2020-03-23 23:16:58 +0000122 @CalledByNative("Encoding")
123 double getBitratePriority() {
124 return bitratePriority;
125 }
126
127 @CalledByNative("Encoding")
128 @Priority
129 int getNetworkPriority() {
130 return networkPriority;
131 }
132
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100133 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100134 @CalledByNative("Encoding")
135 Integer getMaxBitrateBps() {
136 return maxBitrateBps;
137 }
138
Åsa Persson613591a2018-05-29 09:21:31 +0200139 @Nullable
140 @CalledByNative("Encoding")
141 Integer getMinBitrateBps() {
142 return minBitrateBps;
143 }
144
Åsa Persson4e5342f2018-08-13 16:46:57 +0200145 @Nullable
146 @CalledByNative("Encoding")
147 Integer getMaxFramerate() {
148 return maxFramerate;
149 }
150
Åsa Persson23eba222018-10-02 14:47:06 +0200151 @Nullable
152 @CalledByNative("Encoding")
153 Integer getNumTemporalLayers() {
154 return numTemporalLayers;
155 }
156
Mirta Dvornicicd8b98042019-02-04 16:38:46 +0100157 @Nullable
158 @CalledByNative("Encoding")
159 Double getScaleResolutionDownBy() {
160 return scaleResolutionDownBy;
161 }
162
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100163 @CalledByNative("Encoding")
164 Long getSsrc() {
165 return ssrc;
166 }
Yura Yaroshevichd29c6892021-04-19 10:14:03 +0300167
168 @CalledByNative("Encoding")
169 boolean getAdaptivePTime() {
170 return adaptiveAudioPacketTime;
171 }
Taylor Brandstetterf8711c02016-03-29 17:21:29 -0700172 }
skvlad303b3c22016-03-24 19:36:46 -0700173
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700174 public static class Codec {
deadbeefe702b302017-02-04 12:09:01 -0800175 // Payload type used to identify this codec in RTP packets.
176 public int payloadType;
177 // Name used to identify the codec. Equivalent to MIME subtype.
178 public String name;
179 // The media type of this codec. Equivalent to MIME top-level type.
180 MediaStreamTrack.MediaType kind;
181 // Clock rate in Hertz.
182 public Integer clockRate;
183 // The number of audio channels used. Set to null for video codecs.
184 public Integer numChannels;
Florent Castellib7d9d832018-05-15 18:14:14 +0200185 // The "format specific parameters" field from the "a=fmtp" line in the SDP
186 public Map<String, String> parameters;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100187
188 @CalledByNative("Codec")
189 Codec(int payloadType, String name, MediaStreamTrack.MediaType kind, Integer clockRate,
Florent Castellib7d9d832018-05-15 18:14:14 +0200190 Integer numChannels, Map<String, String> parameters) {
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100191 this.payloadType = payloadType;
192 this.name = name;
193 this.kind = kind;
194 this.clockRate = clockRate;
195 this.numChannels = numChannels;
Florent Castellib7d9d832018-05-15 18:14:14 +0200196 this.parameters = parameters;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100197 }
198
199 @CalledByNative("Codec")
200 int getPayloadType() {
201 return payloadType;
202 }
203
204 @CalledByNative("Codec")
205 String getName() {
206 return name;
207 }
208
209 @CalledByNative("Codec")
210 MediaStreamTrack.MediaType getKind() {
211 return kind;
212 }
213
214 @CalledByNative("Codec")
215 Integer getClockRate() {
216 return clockRate;
217 }
218
219 @CalledByNative("Codec")
220 Integer getNumChannels() {
221 return numChannels;
222 }
Florent Castellib7d9d832018-05-15 18:14:14 +0200223
224 @CalledByNative("Codec")
225 Map getParameters() {
226 return parameters;
227 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700228 }
229
Florent Castellidacec712018-05-24 16:24:21 +0200230 public static class Rtcp {
231 /** The Canonical Name used by RTCP */
232 private final String cname;
233 /** Whether reduced size RTCP is configured or compound RTCP */
234 private final boolean reducedSize;
235
236 @CalledByNative("Rtcp")
237 Rtcp(String cname, boolean reducedSize) {
238 this.cname = cname;
239 this.reducedSize = reducedSize;
240 }
241
242 @CalledByNative("Rtcp")
243 public String getCname() {
244 return cname;
245 }
246
247 @CalledByNative("Rtcp")
248 public boolean getReducedSize() {
249 return reducedSize;
250 }
251 }
252
Florent Castelliabe301f2018-06-12 18:33:49 +0200253 public static class HeaderExtension {
254 /** The URI of the RTP header extension, as defined in RFC5285. */
255 private final String uri;
256 /** The value put in the RTP packet to identify the header extension. */
257 private final int id;
258 /** Whether the header extension is encrypted or not. */
259 private final boolean encrypted;
260
261 @CalledByNative("HeaderExtension")
262 HeaderExtension(String uri, int id, boolean encrypted) {
263 this.uri = uri;
264 this.id = id;
265 this.encrypted = encrypted;
266 }
267
268 @CalledByNative("HeaderExtension")
269 public String getUri() {
270 return uri;
271 }
272
273 @CalledByNative("HeaderExtension")
274 public int getId() {
275 return id;
276 }
277
278 @CalledByNative("HeaderExtension")
279 public boolean getEncrypted() {
280 return encrypted;
281 }
282 }
283
Florent Castellicebf50f2018-05-03 15:31:53 +0200284 public final String transactionId;
285
Florent Castelli266021d2020-01-07 17:43:52 +0100286 /**
287 * When bandwidth is constrained and the RtpSender needs to choose between degrading resolution or
288 * degrading framerate, degradationPreference indicates which is preferred.
289 */
290 @Nullable public DegradationPreference degradationPreference;
291
Florent Castellidacec712018-05-24 16:24:21 +0200292 private final Rtcp rtcp;
293
Florent Castelliabe301f2018-06-12 18:33:49 +0200294 private final List<HeaderExtension> headerExtensions;
295
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100296 public final List<Encoding> encodings;
Florent Castelli266021d2020-01-07 17:43:52 +0100297
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100298 public final List<Codec> codecs;
299
Florent Castellicebf50f2018-05-03 15:31:53 +0200300 @CalledByNative
Florent Castelli266021d2020-01-07 17:43:52 +0100301 RtpParameters(String transactionId, DegradationPreference degradationPreference, Rtcp rtcp,
302 List<HeaderExtension> headerExtensions, List<Encoding> encodings, List<Codec> codecs) {
Florent Castellicebf50f2018-05-03 15:31:53 +0200303 this.transactionId = transactionId;
Florent Castelli266021d2020-01-07 17:43:52 +0100304 this.degradationPreference = degradationPreference;
Florent Castellidacec712018-05-24 16:24:21 +0200305 this.rtcp = rtcp;
Florent Castelliabe301f2018-06-12 18:33:49 +0200306 this.headerExtensions = headerExtensions;
Florent Castellicebf50f2018-05-03 15:31:53 +0200307 this.encodings = encodings;
308 this.codecs = codecs;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100309 }
310
311 @CalledByNative
Florent Castellicebf50f2018-05-03 15:31:53 +0200312 String getTransactionId() {
313 return transactionId;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100314 }
315
316 @CalledByNative
Florent Castelli266021d2020-01-07 17:43:52 +0100317 DegradationPreference getDegradationPreference() {
318 return degradationPreference;
319 }
320
321 @CalledByNative
Florent Castellidacec712018-05-24 16:24:21 +0200322 public Rtcp getRtcp() {
323 return rtcp;
324 }
325
326 @CalledByNative
Florent Castelliabe301f2018-06-12 18:33:49 +0200327 public List<HeaderExtension> getHeaderExtensions() {
328 return headerExtensions;
329 }
330
331 @CalledByNative
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100332 List<Encoding> getEncodings() {
333 return encodings;
334 }
335
336 @CalledByNative
337 List<Codec> getCodecs() {
338 return codecs;
339 }
skvlad303b3c22016-03-24 19:36:46 -0700340}