| 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 |
| 13 | import androidx.annotation.Nullable; |
| 14 | import java.lang.Double; |
| 15 | import java.lang.String; |
| 16 | import java.util.List; |
| 17 | import java.util.Map; |
| 18 | import org.webrtc.MediaStreamTrack; |
| 19 |
| 20 | /** |
| 21 | * The parameters for an {@code RtpSender}, as defined in |
| 22 | * http://w3c.github.io/webrtc-pc/#rtcrtpsender-interface. |
| 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". |
| 28 | */ |
| 29 | public class RtpParameters { |
| 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 |
| 46 | public static class Encoding { |
| 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; |
| 50 | // Set to true to cause this encoding to be sent, and false for it not to |
| 51 | // be sent. |
| 52 | public boolean active = true; |
| 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 | public int networkPriority = 0; |
| 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. |
| 69 | @Nullable public Integer maxBitrateBps; |
| 70 | // The minimum bitrate in bps for video. |
| 71 | @Nullable public Integer minBitrateBps; |
| 72 | // The max framerate in fps for video. |
| 73 | @Nullable public Integer maxFramerate; |
| 74 | // The number of temporal layers for video. |
| 75 | @Nullable public Integer numTemporalLayers; |
| 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; |
| 79 | // SSRC to be used by this encoding. |
| 80 | // Can't be changed between getParameters/setParameters. |
| 81 | public Long ssrc; |
| 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; |
| 85 |
| 86 | // This constructor is useful for creating simulcast layers. |
| 87 | public Encoding(String rid, boolean active, Double scaleResolutionDownBy) { |
| 88 | this.rid = rid; |
| 89 | this.active = active; |
| 90 | this.scaleResolutionDownBy = scaleResolutionDownBy; |
| 91 | } |
| 92 |
| 93 | @CalledByNative("Encoding") |
| 94 | Encoding(String rid, boolean active, double bitratePriority, int networkPriority, |
| 95 | Integer maxBitrateBps, Integer minBitrateBps, Integer maxFramerate, |
| 96 | Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc, |
| 97 | boolean adaptiveAudioPacketTime) { |
| 98 | this.rid = rid; |
| 99 | this.active = active; |
| 100 | this.bitratePriority = bitratePriority; |
| 101 | this.networkPriority = networkPriority; |
| 102 | this.maxBitrateBps = maxBitrateBps; |
| 103 | this.minBitrateBps = minBitrateBps; |
| 104 | this.maxFramerate = maxFramerate; |
| 105 | this.numTemporalLayers = numTemporalLayers; |
| 106 | this.scaleResolutionDownBy = scaleResolutionDownBy; |
| 107 | this.ssrc = ssrc; |
| 108 | this.adaptiveAudioPacketTime = adaptiveAudioPacketTime; |
| 109 | } |
| 110 |
| 111 | @Nullable |
| 112 | @CalledByNative("Encoding") |
| 113 | String getRid() { |
| 114 | return rid; |
| 115 | } |
| 116 |
| 117 | @CalledByNative("Encoding") |
| 118 | boolean getActive() { |
| 119 | return active; |
| 120 | } |
| 121 |
| 122 | @CalledByNative("Encoding") |
| 123 | double getBitratePriority() { |
| 124 | return bitratePriority; |
| 125 | } |
| 126 |
| 127 | @CalledByNative("Encoding") |
| 128 | int getNetworkPriority() { |
| 129 | return networkPriority; |
| 130 | } |
| 131 |
| 132 | @Nullable |
| 133 | @CalledByNative("Encoding") |
| 134 | Integer getMaxBitrateBps() { |
| 135 | return maxBitrateBps; |
| 136 | } |
| 137 |
| 138 | @Nullable |
| 139 | @CalledByNative("Encoding") |
| 140 | Integer getMinBitrateBps() { |
| 141 | return minBitrateBps; |
| 142 | } |
| 143 |
| 144 | @Nullable |
| 145 | @CalledByNative("Encoding") |
| 146 | Integer getMaxFramerate() { |
| 147 | return maxFramerate; |
| 148 | } |
| 149 |
| 150 | @Nullable |
| 151 | @CalledByNative("Encoding") |
| 152 | Integer getNumTemporalLayers() { |
| 153 | return numTemporalLayers; |
| 154 | } |
| 155 |
| 156 | @Nullable |
| 157 | @CalledByNative("Encoding") |
| 158 | Double getScaleResolutionDownBy() { |
| 159 | return scaleResolutionDownBy; |
| 160 | } |
| 161 |
| 162 | @CalledByNative("Encoding") |
| 163 | Long getSsrc() { |
| 164 | return ssrc; |
| 165 | } |
| 166 |
| 167 | @CalledByNative("Encoding") |
| 168 | boolean getAdaptivePTime() { |
| 169 | return adaptiveAudioPacketTime; |
| 170 | } |
| 171 | } |
| 172 |
| 173 | public static class Codec { |
| 174 | // Payload type used to identify this codec in RTP packets. |
| 175 | public int payloadType; |
| 176 | // Name used to identify the codec. Equivalent to MIME subtype. |
| 177 | public String name; |
| 178 | // The media type of this codec. Equivalent to MIME top-level type. |
| 179 | MediaStreamTrack.MediaType kind; |
| 180 | // Clock rate in Hertz. |
| 181 | public Integer clockRate; |
| 182 | // The number of audio channels used. Set to null for video codecs. |
| 183 | public Integer numChannels; |
| 184 | // The "format specific parameters" field from the "a=fmtp" line in the SDP |
| 185 | public Map<String, String> parameters; |
| 186 |
| 187 | @CalledByNative("Codec") |
| 188 | Codec(int payloadType, String name, MediaStreamTrack.MediaType kind, Integer clockRate, |
| 189 | Integer numChannels, Map<String, String> parameters) { |
| 190 | this.payloadType = payloadType; |
| 191 | this.name = name; |
| 192 | this.kind = kind; |
| 193 | this.clockRate = clockRate; |
| 194 | this.numChannels = numChannels; |
| 195 | this.parameters = parameters; |
| 196 | } |
| 197 |
| 198 | @CalledByNative("Codec") |
| 199 | int getPayloadType() { |
| 200 | return payloadType; |
| 201 | } |
| 202 |
| 203 | @CalledByNative("Codec") |
| 204 | String getName() { |
| 205 | return name; |
| 206 | } |
| 207 |
| 208 | @CalledByNative("Codec") |
| 209 | MediaStreamTrack.MediaType getKind() { |
| 210 | return kind; |
| 211 | } |
| 212 |
| 213 | @CalledByNative("Codec") |
| 214 | Integer getClockRate() { |
| 215 | return clockRate; |
| 216 | } |
| 217 |
| 218 | @CalledByNative("Codec") |
| 219 | Integer getNumChannels() { |
| 220 | return numChannels; |
| 221 | } |
| 222 |
| 223 | @CalledByNative("Codec") |
| 224 | Map getParameters() { |
| 225 | return parameters; |
| 226 | } |
| 227 | } |
| 228 |
| 229 | public static class Rtcp { |
| 230 | /** The Canonical Name used by RTCP */ |
| 231 | private final String cname; |
| 232 | /** Whether reduced size RTCP is configured or compound RTCP */ |
| 233 | private final boolean reducedSize; |
| 234 |
| 235 | @CalledByNative("Rtcp") |
| 236 | Rtcp(String cname, boolean reducedSize) { |
| 237 | this.cname = cname; |
| 238 | this.reducedSize = reducedSize; |
| 239 | } |
| 240 |
| 241 | @CalledByNative("Rtcp") |
| 242 | public String getCname() { |
| 243 | return cname; |
| 244 | } |
| 245 |
| 246 | @CalledByNative("Rtcp") |
| 247 | public boolean getReducedSize() { |
| 248 | return reducedSize; |
| 249 | } |
| 250 | } |
| 251 |
| 252 | public static class HeaderExtension { |
| 253 | /** The URI of the RTP header extension, as defined in RFC5285. */ |
| 254 | private final String uri; |
| 255 | /** The value put in the RTP packet to identify the header extension. */ |
| 256 | private final int id; |
| 257 | /** Whether the header extension is encrypted or not. */ |
| 258 | private final boolean encrypted; |
| 259 |
| 260 | @CalledByNative("HeaderExtension") |
| 261 | HeaderExtension(String uri, int id, boolean encrypted) { |
| 262 | this.uri = uri; |
| 263 | this.id = id; |
| 264 | this.encrypted = encrypted; |
| 265 | } |
| 266 |
| 267 | @CalledByNative("HeaderExtension") |
| 268 | public String getUri() { |
| 269 | return uri; |
| 270 | } |
| 271 |
| 272 | @CalledByNative("HeaderExtension") |
| 273 | public int getId() { |
| 274 | return id; |
| 275 | } |
| 276 |
| 277 | @CalledByNative("HeaderExtension") |
| 278 | public boolean getEncrypted() { |
| 279 | return encrypted; |
| 280 | } |
| 281 | } |
| 282 |
| 283 | public final String transactionId; |
| 284 |
| 285 | /** |
| 286 | * When bandwidth is constrained and the RtpSender needs to choose between degrading resolution or |
| 287 | * degrading framerate, degradationPreference indicates which is preferred. |
| 288 | */ |
| 289 | @Nullable public DegradationPreference degradationPreference; |
| 290 |
| 291 | private final Rtcp rtcp; |
| 292 |
| 293 | private final List<HeaderExtension> headerExtensions; |
| 294 |
| 295 | public final List<Encoding> encodings; |
| 296 |
| 297 | public final List<Codec> codecs; |
| 298 |
| 299 | @CalledByNative |
| 300 | RtpParameters(String transactionId, DegradationPreference degradationPreference, Rtcp rtcp, |
| 301 | List<HeaderExtension> headerExtensions, List<Encoding> encodings, List<Codec> codecs) { |
| 302 | this.transactionId = transactionId; |
| 303 | this.degradationPreference = degradationPreference; |
| 304 | this.rtcp = rtcp; |
| 305 | this.headerExtensions = headerExtensions; |
| 306 | this.encodings = encodings; |
| 307 | this.codecs = codecs; |
| 308 | } |
| 309 |
| 310 | @CalledByNative |
| 311 | String getTransactionId() { |
| 312 | return transactionId; |
| 313 | } |
| 314 |
| 315 | @CalledByNative |
| 316 | DegradationPreference getDegradationPreference() { |
| 317 | return degradationPreference; |
| 318 | } |
| 319 |
| 320 | @CalledByNative |
| 321 | public Rtcp getRtcp() { |
| 322 | return rtcp; |
| 323 | } |
| 324 |
| 325 | @CalledByNative |
| 326 | public List<HeaderExtension> getHeaderExtensions() { |
| 327 | return headerExtensions; |
| 328 | } |
| 329 |
| 330 | @CalledByNative |
| 331 | List<Encoding> getEncodings() { |
| 332 | return encodings; |
| 333 | } |
| 334 |
| 335 | @CalledByNative |
| 336 | List<Codec> getCodecs() { |
| 337 | return codecs; |
| 338 | } |
| 339 | } |
| 340 |