blob: 4293ce77d261e5e71d761620a6950d5112d0e16c [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;
deadbeefe702b302017-02-04 12:09:01 -080053 // If non-null, this represents the Transport Independent Application
54 // Specific maximum bandwidth defined in RFC3890. If null, there is no
55 // maximum bitrate.
Sami Kalliomäkie7592d82018-03-22 13:32:44 +010056 @Nullable public Integer maxBitrateBps;
Åsa Persson4e5342f2018-08-13 16:46:57 +020057 // The minimum bitrate in bps for video.
Åsa Persson613591a2018-05-29 09:21:31 +020058 @Nullable public Integer minBitrateBps;
Åsa Persson4e5342f2018-08-13 16:46:57 +020059 // The max framerate in fps for video.
60 @Nullable public Integer maxFramerate;
Åsa Persson23eba222018-10-02 14:47:06 +020061 // The number of temporal layers for video.
62 @Nullable public Integer numTemporalLayers;
Mirta Dvornicicd8b98042019-02-04 16:38:46 +010063 // If non-null, scale the width and height down by this factor for video. If null,
64 // implementation default scaling factor will be used.
65 @Nullable public Double scaleResolutionDownBy;
deadbeefe702b302017-02-04 12:09:01 -080066 // SSRC to be used by this encoding.
67 // Can't be changed between getParameters/setParameters.
deadbeef8014c752017-01-06 16:53:00 -080068 public Long ssrc;
Magnus Jedvert9060eb12017-12-12 12:52:54 +010069
Amit Hilbuchae4b6232019-03-29 14:02:42 -070070 // This constructor is useful for creating simulcast layers.
Amit Hilbuche725fdb2019-12-02 13:54:01 -080071 public Encoding(String rid, boolean active, Double scaleResolutionDownBy) {
Amit Hilbuchae4b6232019-03-29 14:02:42 -070072 this.rid = rid;
73 this.active = active;
74 this.scaleResolutionDownBy = scaleResolutionDownBy;
75 }
76
Magnus Jedvert9060eb12017-12-12 12:52:54 +010077 @CalledByNative("Encoding")
Amit Hilbuchae4b6232019-03-29 14:02:42 -070078 Encoding(String rid, boolean active, Integer maxBitrateBps, Integer minBitrateBps,
79 Integer maxFramerate, Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc) {
80 this.rid = rid;
Magnus Jedvert9060eb12017-12-12 12:52:54 +010081 this.active = active;
82 this.maxBitrateBps = maxBitrateBps;
Åsa Persson613591a2018-05-29 09:21:31 +020083 this.minBitrateBps = minBitrateBps;
Åsa Persson4e5342f2018-08-13 16:46:57 +020084 this.maxFramerate = maxFramerate;
Åsa Persson23eba222018-10-02 14:47:06 +020085 this.numTemporalLayers = numTemporalLayers;
Mirta Dvornicicd8b98042019-02-04 16:38:46 +010086 this.scaleResolutionDownBy = scaleResolutionDownBy;
Magnus Jedvert9060eb12017-12-12 12:52:54 +010087 this.ssrc = ssrc;
88 }
89
Amit Hilbuchae4b6232019-03-29 14:02:42 -070090 @Nullable
91 @CalledByNative("Encoding")
92 String getRid() {
93 return rid;
94 }
95
Magnus Jedvert9060eb12017-12-12 12:52:54 +010096 @CalledByNative("Encoding")
97 boolean getActive() {
98 return active;
99 }
100
Sami Kalliomäkie7592d82018-03-22 13:32:44 +0100101 @Nullable
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100102 @CalledByNative("Encoding")
103 Integer getMaxBitrateBps() {
104 return maxBitrateBps;
105 }
106
Åsa Persson613591a2018-05-29 09:21:31 +0200107 @Nullable
108 @CalledByNative("Encoding")
109 Integer getMinBitrateBps() {
110 return minBitrateBps;
111 }
112
Åsa Persson4e5342f2018-08-13 16:46:57 +0200113 @Nullable
114 @CalledByNative("Encoding")
115 Integer getMaxFramerate() {
116 return maxFramerate;
117 }
118
Åsa Persson23eba222018-10-02 14:47:06 +0200119 @Nullable
120 @CalledByNative("Encoding")
121 Integer getNumTemporalLayers() {
122 return numTemporalLayers;
123 }
124
Mirta Dvornicicd8b98042019-02-04 16:38:46 +0100125 @Nullable
126 @CalledByNative("Encoding")
127 Double getScaleResolutionDownBy() {
128 return scaleResolutionDownBy;
129 }
130
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100131 @CalledByNative("Encoding")
132 Long getSsrc() {
133 return ssrc;
134 }
Taylor Brandstetterf8711c02016-03-29 17:21:29 -0700135 }
skvlad303b3c22016-03-24 19:36:46 -0700136
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700137 public static class Codec {
deadbeefe702b302017-02-04 12:09:01 -0800138 // Payload type used to identify this codec in RTP packets.
139 public int payloadType;
140 // Name used to identify the codec. Equivalent to MIME subtype.
141 public String name;
142 // The media type of this codec. Equivalent to MIME top-level type.
143 MediaStreamTrack.MediaType kind;
144 // Clock rate in Hertz.
145 public Integer clockRate;
146 // The number of audio channels used. Set to null for video codecs.
147 public Integer numChannels;
Florent Castellib7d9d832018-05-15 18:14:14 +0200148 // The "format specific parameters" field from the "a=fmtp" line in the SDP
149 public Map<String, String> parameters;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100150
151 @CalledByNative("Codec")
152 Codec(int payloadType, String name, MediaStreamTrack.MediaType kind, Integer clockRate,
Florent Castellib7d9d832018-05-15 18:14:14 +0200153 Integer numChannels, Map<String, String> parameters) {
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100154 this.payloadType = payloadType;
155 this.name = name;
156 this.kind = kind;
157 this.clockRate = clockRate;
158 this.numChannels = numChannels;
Florent Castellib7d9d832018-05-15 18:14:14 +0200159 this.parameters = parameters;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100160 }
161
162 @CalledByNative("Codec")
163 int getPayloadType() {
164 return payloadType;
165 }
166
167 @CalledByNative("Codec")
168 String getName() {
169 return name;
170 }
171
172 @CalledByNative("Codec")
173 MediaStreamTrack.MediaType getKind() {
174 return kind;
175 }
176
177 @CalledByNative("Codec")
178 Integer getClockRate() {
179 return clockRate;
180 }
181
182 @CalledByNative("Codec")
183 Integer getNumChannels() {
184 return numChannels;
185 }
Florent Castellib7d9d832018-05-15 18:14:14 +0200186
187 @CalledByNative("Codec")
188 Map getParameters() {
189 return parameters;
190 }
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700191 }
192
Florent Castellidacec712018-05-24 16:24:21 +0200193 public static class Rtcp {
194 /** The Canonical Name used by RTCP */
195 private final String cname;
196 /** Whether reduced size RTCP is configured or compound RTCP */
197 private final boolean reducedSize;
198
199 @CalledByNative("Rtcp")
200 Rtcp(String cname, boolean reducedSize) {
201 this.cname = cname;
202 this.reducedSize = reducedSize;
203 }
204
205 @CalledByNative("Rtcp")
206 public String getCname() {
207 return cname;
208 }
209
210 @CalledByNative("Rtcp")
211 public boolean getReducedSize() {
212 return reducedSize;
213 }
214 }
215
Florent Castelliabe301f2018-06-12 18:33:49 +0200216 public static class HeaderExtension {
217 /** The URI of the RTP header extension, as defined in RFC5285. */
218 private final String uri;
219 /** The value put in the RTP packet to identify the header extension. */
220 private final int id;
221 /** Whether the header extension is encrypted or not. */
222 private final boolean encrypted;
223
224 @CalledByNative("HeaderExtension")
225 HeaderExtension(String uri, int id, boolean encrypted) {
226 this.uri = uri;
227 this.id = id;
228 this.encrypted = encrypted;
229 }
230
231 @CalledByNative("HeaderExtension")
232 public String getUri() {
233 return uri;
234 }
235
236 @CalledByNative("HeaderExtension")
237 public int getId() {
238 return id;
239 }
240
241 @CalledByNative("HeaderExtension")
242 public boolean getEncrypted() {
243 return encrypted;
244 }
245 }
246
Florent Castellicebf50f2018-05-03 15:31:53 +0200247 public final String transactionId;
248
Florent Castelli266021d2020-01-07 17:43:52 +0100249 /**
250 * When bandwidth is constrained and the RtpSender needs to choose between degrading resolution or
251 * degrading framerate, degradationPreference indicates which is preferred.
252 */
253 @Nullable public DegradationPreference degradationPreference;
254
Florent Castellidacec712018-05-24 16:24:21 +0200255 private final Rtcp rtcp;
256
Florent Castelliabe301f2018-06-12 18:33:49 +0200257 private final List<HeaderExtension> headerExtensions;
258
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100259 public final List<Encoding> encodings;
Florent Castelli266021d2020-01-07 17:43:52 +0100260
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100261 public final List<Codec> codecs;
262
Florent Castellicebf50f2018-05-03 15:31:53 +0200263 @CalledByNative
Florent Castelli266021d2020-01-07 17:43:52 +0100264 RtpParameters(String transactionId, DegradationPreference degradationPreference, Rtcp rtcp,
265 List<HeaderExtension> headerExtensions, List<Encoding> encodings, List<Codec> codecs) {
Florent Castellicebf50f2018-05-03 15:31:53 +0200266 this.transactionId = transactionId;
Florent Castelli266021d2020-01-07 17:43:52 +0100267 this.degradationPreference = degradationPreference;
Florent Castellidacec712018-05-24 16:24:21 +0200268 this.rtcp = rtcp;
Florent Castelliabe301f2018-06-12 18:33:49 +0200269 this.headerExtensions = headerExtensions;
Florent Castellicebf50f2018-05-03 15:31:53 +0200270 this.encodings = encodings;
271 this.codecs = codecs;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100272 }
273
274 @CalledByNative
Florent Castellicebf50f2018-05-03 15:31:53 +0200275 String getTransactionId() {
276 return transactionId;
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100277 }
278
279 @CalledByNative
Florent Castelli266021d2020-01-07 17:43:52 +0100280 DegradationPreference getDegradationPreference() {
281 return degradationPreference;
282 }
283
284 @CalledByNative
Florent Castellidacec712018-05-24 16:24:21 +0200285 public Rtcp getRtcp() {
286 return rtcp;
287 }
288
289 @CalledByNative
Florent Castelliabe301f2018-06-12 18:33:49 +0200290 public List<HeaderExtension> getHeaderExtensions() {
291 return headerExtensions;
292 }
293
294 @CalledByNative
Magnus Jedvert9060eb12017-12-12 12:52:54 +0100295 List<Encoding> getEncodings() {
296 return encodings;
297 }
298
299 @CalledByNative
300 List<Codec> getCodecs() {
301 return codecs;
302 }
skvlad303b3c22016-03-24 19:36:46 -0700303}