skvlad | 303b3c2 | 2016-03-24 19:36:46 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 11 | package org.webrtc; |
| 12 | |
Artem Titarenko | 69540f4 | 2018-12-10 12:30:46 +0100 | [diff] [blame] | 13 | import android.support.annotation.Nullable; |
Mirta Dvornicic | d8b9804 | 2019-02-04 16:38:46 +0100 | [diff] [blame] | 14 | import java.lang.Double; |
Amit Hilbuch | ae4b623 | 2019-03-29 14:02:42 -0700 | [diff] [blame] | 15 | import java.lang.String; |
Florent Castelli | b7d9d83 | 2018-05-15 18:14:14 +0200 | [diff] [blame] | 16 | import java.util.List; |
| 17 | import java.util.Map; |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 18 | import org.webrtc.MediaStreamTrack; |
skvlad | 303b3c2 | 2016-03-24 19:36:46 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * The parameters for an {@code RtpSender}, as defined in |
| 22 | * http://w3c.github.io/webrtc-pc/#rtcrtpsender-interface. |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 23 | * |
| 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". |
skvlad | 303b3c2 | 2016-03-24 19:36:46 -0700 | [diff] [blame] | 28 | */ |
| 29 | public class RtpParameters { |
Florent Castelli | 266021d | 2020-01-07 17:43:52 +0100 | [diff] [blame] | 30 | 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 Brandstetter | f8711c0 | 2016-03-29 17:21:29 -0700 | [diff] [blame] | 46 | public static class Encoding { |
Amit Hilbuch | ae4b623 | 2019-03-29 14:02:42 -0700 | [diff] [blame] | 47 | // 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; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 50 | // Set to true to cause this encoding to be sent, and false for it not to |
| 51 | // be sent. |
Taylor Brandstetter | f8711c0 | 2016-03-29 17:21:29 -0700 | [diff] [blame] | 52 | public boolean active = true; |
Taylor Brandstetter | e3a294c | 2020-03-23 23:16:58 +0000 | [diff] [blame] | 53 | // 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; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 66 | // 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äki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 69 | @Nullable public Integer maxBitrateBps; |
Åsa Persson | 4e5342f | 2018-08-13 16:46:57 +0200 | [diff] [blame] | 70 | // The minimum bitrate in bps for video. |
Åsa Persson | 613591a | 2018-05-29 09:21:31 +0200 | [diff] [blame] | 71 | @Nullable public Integer minBitrateBps; |
Åsa Persson | 4e5342f | 2018-08-13 16:46:57 +0200 | [diff] [blame] | 72 | // The max framerate in fps for video. |
| 73 | @Nullable public Integer maxFramerate; |
Åsa Persson | 23eba22 | 2018-10-02 14:47:06 +0200 | [diff] [blame] | 74 | // The number of temporal layers for video. |
| 75 | @Nullable public Integer numTemporalLayers; |
Mirta Dvornicic | d8b9804 | 2019-02-04 16:38:46 +0100 | [diff] [blame] | 76 | // 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; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 79 | // SSRC to be used by this encoding. |
| 80 | // Can't be changed between getParameters/setParameters. |
deadbeef | 8014c75 | 2017-01-06 16:53:00 -0800 | [diff] [blame] | 81 | public Long ssrc; |
Yura Yaroshevich | d29c689 | 2021-04-19 10:14:03 +0300 | [diff] [blame] | 82 | // 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 Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 85 | |
Amit Hilbuch | ae4b623 | 2019-03-29 14:02:42 -0700 | [diff] [blame] | 86 | // This constructor is useful for creating simulcast layers. |
Amit Hilbuch | e725fdb | 2019-12-02 13:54:01 -0800 | [diff] [blame] | 87 | public Encoding(String rid, boolean active, Double scaleResolutionDownBy) { |
Amit Hilbuch | ae4b623 | 2019-03-29 14:02:42 -0700 | [diff] [blame] | 88 | this.rid = rid; |
| 89 | this.active = active; |
| 90 | this.scaleResolutionDownBy = scaleResolutionDownBy; |
| 91 | } |
| 92 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 93 | @CalledByNative("Encoding") |
Taylor Brandstetter | e3a294c | 2020-03-23 23:16:58 +0000 | [diff] [blame] | 94 | Encoding(String rid, boolean active, double bitratePriority, @Priority int networkPriority, |
| 95 | Integer maxBitrateBps, Integer minBitrateBps, Integer maxFramerate, |
Yura Yaroshevich | d29c689 | 2021-04-19 10:14:03 +0300 | [diff] [blame] | 96 | Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc, |
| 97 | boolean adaptiveAudioPacketTime) { |
Amit Hilbuch | ae4b623 | 2019-03-29 14:02:42 -0700 | [diff] [blame] | 98 | this.rid = rid; |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 99 | this.active = active; |
Taylor Brandstetter | e3a294c | 2020-03-23 23:16:58 +0000 | [diff] [blame] | 100 | this.bitratePriority = bitratePriority; |
| 101 | this.networkPriority = networkPriority; |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 102 | this.maxBitrateBps = maxBitrateBps; |
Åsa Persson | 613591a | 2018-05-29 09:21:31 +0200 | [diff] [blame] | 103 | this.minBitrateBps = minBitrateBps; |
Åsa Persson | 4e5342f | 2018-08-13 16:46:57 +0200 | [diff] [blame] | 104 | this.maxFramerate = maxFramerate; |
Åsa Persson | 23eba22 | 2018-10-02 14:47:06 +0200 | [diff] [blame] | 105 | this.numTemporalLayers = numTemporalLayers; |
Mirta Dvornicic | d8b9804 | 2019-02-04 16:38:46 +0100 | [diff] [blame] | 106 | this.scaleResolutionDownBy = scaleResolutionDownBy; |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 107 | this.ssrc = ssrc; |
Yura Yaroshevich | d29c689 | 2021-04-19 10:14:03 +0300 | [diff] [blame] | 108 | this.adaptiveAudioPacketTime = adaptiveAudioPacketTime; |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Amit Hilbuch | ae4b623 | 2019-03-29 14:02:42 -0700 | [diff] [blame] | 111 | @Nullable |
| 112 | @CalledByNative("Encoding") |
| 113 | String getRid() { |
| 114 | return rid; |
| 115 | } |
| 116 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 117 | @CalledByNative("Encoding") |
| 118 | boolean getActive() { |
| 119 | return active; |
| 120 | } |
| 121 | |
Taylor Brandstetter | e3a294c | 2020-03-23 23:16:58 +0000 | [diff] [blame] | 122 | @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äki | e7592d8 | 2018-03-22 13:32:44 +0100 | [diff] [blame] | 133 | @Nullable |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 134 | @CalledByNative("Encoding") |
| 135 | Integer getMaxBitrateBps() { |
| 136 | return maxBitrateBps; |
| 137 | } |
| 138 | |
Åsa Persson | 613591a | 2018-05-29 09:21:31 +0200 | [diff] [blame] | 139 | @Nullable |
| 140 | @CalledByNative("Encoding") |
| 141 | Integer getMinBitrateBps() { |
| 142 | return minBitrateBps; |
| 143 | } |
| 144 | |
Åsa Persson | 4e5342f | 2018-08-13 16:46:57 +0200 | [diff] [blame] | 145 | @Nullable |
| 146 | @CalledByNative("Encoding") |
| 147 | Integer getMaxFramerate() { |
| 148 | return maxFramerate; |
| 149 | } |
| 150 | |
Åsa Persson | 23eba22 | 2018-10-02 14:47:06 +0200 | [diff] [blame] | 151 | @Nullable |
| 152 | @CalledByNative("Encoding") |
| 153 | Integer getNumTemporalLayers() { |
| 154 | return numTemporalLayers; |
| 155 | } |
| 156 | |
Mirta Dvornicic | d8b9804 | 2019-02-04 16:38:46 +0100 | [diff] [blame] | 157 | @Nullable |
| 158 | @CalledByNative("Encoding") |
| 159 | Double getScaleResolutionDownBy() { |
| 160 | return scaleResolutionDownBy; |
| 161 | } |
| 162 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 163 | @CalledByNative("Encoding") |
| 164 | Long getSsrc() { |
| 165 | return ssrc; |
| 166 | } |
Yura Yaroshevich | d29c689 | 2021-04-19 10:14:03 +0300 | [diff] [blame] | 167 | |
| 168 | @CalledByNative("Encoding") |
| 169 | boolean getAdaptivePTime() { |
| 170 | return adaptiveAudioPacketTime; |
| 171 | } |
Taylor Brandstetter | f8711c0 | 2016-03-29 17:21:29 -0700 | [diff] [blame] | 172 | } |
skvlad | 303b3c2 | 2016-03-24 19:36:46 -0700 | [diff] [blame] | 173 | |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 174 | public static class Codec { |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 175 | // 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 Castelli | b7d9d83 | 2018-05-15 18:14:14 +0200 | [diff] [blame] | 185 | // The "format specific parameters" field from the "a=fmtp" line in the SDP |
| 186 | public Map<String, String> parameters; |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 187 | |
| 188 | @CalledByNative("Codec") |
| 189 | Codec(int payloadType, String name, MediaStreamTrack.MediaType kind, Integer clockRate, |
Florent Castelli | b7d9d83 | 2018-05-15 18:14:14 +0200 | [diff] [blame] | 190 | Integer numChannels, Map<String, String> parameters) { |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 191 | this.payloadType = payloadType; |
| 192 | this.name = name; |
| 193 | this.kind = kind; |
| 194 | this.clockRate = clockRate; |
| 195 | this.numChannels = numChannels; |
Florent Castelli | b7d9d83 | 2018-05-15 18:14:14 +0200 | [diff] [blame] | 196 | this.parameters = parameters; |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 197 | } |
| 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 Castelli | b7d9d83 | 2018-05-15 18:14:14 +0200 | [diff] [blame] | 223 | |
| 224 | @CalledByNative("Codec") |
| 225 | Map getParameters() { |
| 226 | return parameters; |
| 227 | } |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 230 | 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 Castelli | abe301f | 2018-06-12 18:33:49 +0200 | [diff] [blame] | 253 | 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 Castelli | cebf50f | 2018-05-03 15:31:53 +0200 | [diff] [blame] | 284 | public final String transactionId; |
| 285 | |
Florent Castelli | 266021d | 2020-01-07 17:43:52 +0100 | [diff] [blame] | 286 | /** |
| 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 Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 292 | private final Rtcp rtcp; |
| 293 | |
Florent Castelli | abe301f | 2018-06-12 18:33:49 +0200 | [diff] [blame] | 294 | private final List<HeaderExtension> headerExtensions; |
| 295 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 296 | public final List<Encoding> encodings; |
Florent Castelli | 266021d | 2020-01-07 17:43:52 +0100 | [diff] [blame] | 297 | |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 298 | public final List<Codec> codecs; |
| 299 | |
Florent Castelli | cebf50f | 2018-05-03 15:31:53 +0200 | [diff] [blame] | 300 | @CalledByNative |
Florent Castelli | 266021d | 2020-01-07 17:43:52 +0100 | [diff] [blame] | 301 | RtpParameters(String transactionId, DegradationPreference degradationPreference, Rtcp rtcp, |
| 302 | List<HeaderExtension> headerExtensions, List<Encoding> encodings, List<Codec> codecs) { |
Florent Castelli | cebf50f | 2018-05-03 15:31:53 +0200 | [diff] [blame] | 303 | this.transactionId = transactionId; |
Florent Castelli | 266021d | 2020-01-07 17:43:52 +0100 | [diff] [blame] | 304 | this.degradationPreference = degradationPreference; |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 305 | this.rtcp = rtcp; |
Florent Castelli | abe301f | 2018-06-12 18:33:49 +0200 | [diff] [blame] | 306 | this.headerExtensions = headerExtensions; |
Florent Castelli | cebf50f | 2018-05-03 15:31:53 +0200 | [diff] [blame] | 307 | this.encodings = encodings; |
| 308 | this.codecs = codecs; |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | @CalledByNative |
Florent Castelli | cebf50f | 2018-05-03 15:31:53 +0200 | [diff] [blame] | 312 | String getTransactionId() { |
| 313 | return transactionId; |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | @CalledByNative |
Florent Castelli | 266021d | 2020-01-07 17:43:52 +0100 | [diff] [blame] | 317 | DegradationPreference getDegradationPreference() { |
| 318 | return degradationPreference; |
| 319 | } |
| 320 | |
| 321 | @CalledByNative |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 322 | public Rtcp getRtcp() { |
| 323 | return rtcp; |
| 324 | } |
| 325 | |
| 326 | @CalledByNative |
Florent Castelli | abe301f | 2018-06-12 18:33:49 +0200 | [diff] [blame] | 327 | public List<HeaderExtension> getHeaderExtensions() { |
| 328 | return headerExtensions; |
| 329 | } |
| 330 | |
| 331 | @CalledByNative |
Magnus Jedvert | 9060eb1 | 2017-12-12 12:52:54 +0100 | [diff] [blame] | 332 | List<Encoding> getEncodings() { |
| 333 | return encodings; |
| 334 | } |
| 335 | |
| 336 | @CalledByNative |
| 337 | List<Codec> getCodecs() { |
| 338 | return codecs; |
| 339 | } |
skvlad | 303b3c2 | 2016-03-24 19:36:46 -0700 | [diff] [blame] | 340 | } |