blob: e4e09304e9b2c9ba248db9c1fb3cedb4e1b52bea [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;
Magnus Jedvert9060eb12017-12-12 12:52:54 +010082
Amit Hilbuchae4b6232019-03-29 14:02:42 -070083 // This constructor is useful for creating simulcast layers.
Amit Hilbuche725fdb2019-12-02 13:54:01 -080084 public Encoding(String rid, boolean active, Double scaleResolutionDownBy) {
Amit Hilbuchae4b6232019-03-29 14:02:42 -070085 this.rid = rid;
86 this.active = active;
87 this.scaleResolutionDownBy = scaleResolutionDownBy;
88 }
89
Magnus Jedvert9060eb12017-12-12 12:52:54 +010090 @CalledByNative("Encoding")
Taylor Brandstettere3a294c2020-03-23 23:16:58 +000091 Encoding(String rid, boolean active, double bitratePriority, @Priority int networkPriority,
92 Integer maxBitrateBps, Integer minBitrateBps, Integer maxFramerate,
93 Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc) {
Amit Hilbuchae4b6232019-03-29 14:02:42 -070094 this.rid = rid;
Magnus Jedvert9060eb12017-12-12 12:52:54 +010095 this.active = active;
Taylor Brandstettere3a294c2020-03-23 23:16:58 +000096 this.bitratePriority = bitratePriority;
97 this.networkPriority = networkPriority;
Magnus Jedvert9060eb12017-12-12 12:52:54 +010098 this.maxBitrateBps = maxBitrateBps;
Åsa Persson613591a2018-05-29 09:21:31 +020099 this.minBitrateBps = minBitrateBps;
Åsa Persson4e5342f2018-08-13 16:46:57 +0200100 this.maxFramerate = maxFramerate;
Åsa Persson23eba222018-10-02 14:47:06 +0200101 this.numTemporalLayers = numTemporalLayers;
Mirta Dvornicicd8b98042019-02-04 16:38:46 +0100102 this.scaleResolutionDownBy = scaleResolutionDownBy;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100103 this.ssrc = ssrc;
104 }
105
Amit Hilbuchae4b6232019-03-29 14:02:42 -0700106 @Nullable
107 @CalledByNative("Encoding")
108 String getRid() {
109 return rid;
110 }
111
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100112 @CalledByNative("Encoding")
113 boolean getActive() {
114 return active;
115 }
116
Taylor Brandstettere3a294c2020-03-23 23:16:58 +0000117 @CalledByNative("Encoding")
118 double getBitratePriority() {
119 return bitratePriority;
120 }
121
122 @CalledByNative("Encoding")
123 @Priority
124 int getNetworkPriority() {
125 return networkPriority;
126 }
127
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100128 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100129 @CalledByNative("Encoding")
130 Integer getMaxBitrateBps() {
131 return maxBitrateBps;
132 }
133
Åsa Persson613591a2018-05-29 09:21:31 +0200134 @Nullable
135 @CalledByNative("Encoding")
136 Integer getMinBitrateBps() {
137 return minBitrateBps;
138 }
139
Åsa Persson4e5342f2018-08-13 16:46:57 +0200140 @Nullable
141 @CalledByNative("Encoding")
142 Integer getMaxFramerate() {
143 return maxFramerate;
144 }
145
Åsa Persson23eba222018-10-02 14:47:06 +0200146 @Nullable
147 @CalledByNative("Encoding")
148 Integer getNumTemporalLayers() {
149 return numTemporalLayers;
150 }
151
Mirta Dvornicicd8b98042019-02-04 16:38:46 +0100152 @Nullable
153 @CalledByNative("Encoding")
154 Double getScaleResolutionDownBy() {
155 return scaleResolutionDownBy;
156 }
157
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100158 @CalledByNative("Encoding")
159 Long getSsrc() {
160 return ssrc;
161 }
Taylor Brandstetterf8711c02016-03-29 17:21:29 -0700162 }
skvlad303b3c22016-03-24 19:36:46 -0700163
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700164 public static class Codec {
deadbeefe702b302017-02-04 12:09:01 -0800165 // Payload type used to identify this codec in RTP packets.
166 public int payloadType;
167 // Name used to identify the codec. Equivalent to MIME subtype.
168 public String name;
169 // The media type of this codec. Equivalent to MIME top-level type.
170 MediaStreamTrack.MediaType kind;
171 // Clock rate in Hertz.
172 public Integer clockRate;
173 // The number of audio channels used. Set to null for video codecs.
174 public Integer numChannels;
Florent Castellib7d9d832018-05-15 18:14:14 +0200175 // The "format specific parameters" field from the "a=fmtp" line in the SDP
176 public Map<String, String> parameters;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100177
178 @CalledByNative("Codec")
179 Codec(int payloadType, String name, MediaStreamTrack.MediaType kind, Integer clockRate,
Florent Castellib7d9d832018-05-15 18:14:14 +0200180 Integer numChannels, Map<String, String> parameters) {
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100181 this.payloadType = payloadType;
182 this.name = name;
183 this.kind = kind;
184 this.clockRate = clockRate;
185 this.numChannels = numChannels;
Florent Castellib7d9d832018-05-15 18:14:14 +0200186 this.parameters = parameters;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100187 }
188
189 @CalledByNative("Codec")
190 int getPayloadType() {
191 return payloadType;
192 }
193
194 @CalledByNative("Codec")
195 String getName() {
196 return name;
197 }
198
199 @CalledByNative("Codec")
200 MediaStreamTrack.MediaType getKind() {
201 return kind;
202 }
203
204 @CalledByNative("Codec")
205 Integer getClockRate() {
206 return clockRate;
207 }
208
209 @CalledByNative("Codec")
210 Integer getNumChannels() {
211 return numChannels;
212 }
Florent Castellib7d9d832018-05-15 18:14:14 +0200213
214 @CalledByNative("Codec")
215 Map getParameters() {
216 return parameters;
217 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700218 }
219
Florent Castellidacec712018-05-24 16:24:21 +0200220 public static class Rtcp {
221 /** The Canonical Name used by RTCP */
222 private final String cname;
223 /** Whether reduced size RTCP is configured or compound RTCP */
224 private final boolean reducedSize;
225
226 @CalledByNative("Rtcp")
227 Rtcp(String cname, boolean reducedSize) {
228 this.cname = cname;
229 this.reducedSize = reducedSize;
230 }
231
232 @CalledByNative("Rtcp")
233 public String getCname() {
234 return cname;
235 }
236
237 @CalledByNative("Rtcp")
238 public boolean getReducedSize() {
239 return reducedSize;
240 }
241 }
242
Florent Castelliabe301f2018-06-12 18:33:49 +0200243 public static class HeaderExtension {
244 /** The URI of the RTP header extension, as defined in RFC5285. */
245 private final String uri;
246 /** The value put in the RTP packet to identify the header extension. */
247 private final int id;
248 /** Whether the header extension is encrypted or not. */
249 private final boolean encrypted;
250
251 @CalledByNative("HeaderExtension")
252 HeaderExtension(String uri, int id, boolean encrypted) {
253 this.uri = uri;
254 this.id = id;
255 this.encrypted = encrypted;
256 }
257
258 @CalledByNative("HeaderExtension")
259 public String getUri() {
260 return uri;
261 }
262
263 @CalledByNative("HeaderExtension")
264 public int getId() {
265 return id;
266 }
267
268 @CalledByNative("HeaderExtension")
269 public boolean getEncrypted() {
270 return encrypted;
271 }
272 }
273
Florent Castellicebf50f2018-05-03 15:31:53 +0200274 public final String transactionId;
275
Florent Castelli266021d2020-01-07 17:43:52 +0100276 /**
277 * When bandwidth is constrained and the RtpSender needs to choose between degrading resolution or
278 * degrading framerate, degradationPreference indicates which is preferred.
279 */
280 @Nullable public DegradationPreference degradationPreference;
281
Florent Castellidacec712018-05-24 16:24:21 +0200282 private final Rtcp rtcp;
283
Florent Castelliabe301f2018-06-12 18:33:49 +0200284 private final List<HeaderExtension> headerExtensions;
285
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100286 public final List<Encoding> encodings;
Florent Castelli266021d2020-01-07 17:43:52 +0100287
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100288 public final List<Codec> codecs;
289
Florent Castellicebf50f2018-05-03 15:31:53 +0200290 @CalledByNative
Florent Castelli266021d2020-01-07 17:43:52 +0100291 RtpParameters(String transactionId, DegradationPreference degradationPreference, Rtcp rtcp,
292 List<HeaderExtension> headerExtensions, List<Encoding> encodings, List<Codec> codecs) {
Florent Castellicebf50f2018-05-03 15:31:53 +0200293 this.transactionId = transactionId;
Florent Castelli266021d2020-01-07 17:43:52 +0100294 this.degradationPreference = degradationPreference;
Florent Castellidacec712018-05-24 16:24:21 +0200295 this.rtcp = rtcp;
Florent Castelliabe301f2018-06-12 18:33:49 +0200296 this.headerExtensions = headerExtensions;
Florent Castellicebf50f2018-05-03 15:31:53 +0200297 this.encodings = encodings;
298 this.codecs = codecs;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100299 }
300
301 @CalledByNative
Florent Castellicebf50f2018-05-03 15:31:53 +0200302 String getTransactionId() {
303 return transactionId;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100304 }
305
306 @CalledByNative
Florent Castelli266021d2020-01-07 17:43:52 +0100307 DegradationPreference getDegradationPreference() {
308 return degradationPreference;
309 }
310
311 @CalledByNative
Florent Castellidacec712018-05-24 16:24:21 +0200312 public Rtcp getRtcp() {
313 return rtcp;
314 }
315
316 @CalledByNative
Florent Castelliabe301f2018-06-12 18:33:49 +0200317 public List<HeaderExtension> getHeaderExtensions() {
318 return headerExtensions;
319 }
320
321 @CalledByNative
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100322 List<Encoding> getEncodings() {
323 return encodings;
324 }
325
326 @CalledByNative
327 List<Codec> getCodecs() {
328 return codecs;
329 }
skvlad303b3c22016-03-24 19:36:46 -0700330}