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 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") fromNativeIndex(int nativeIndex)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 @Priority public int networkPriority = Priority.LOW; 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. Encoding(String rid, boolean active, Double scaleResolutionDownBy)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") Encoding(String rid, boolean active, double bitratePriority, @Priority int networkPriority, Integer maxBitrateBps, Integer minBitrateBps, Integer maxFramerate, Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc, boolean adaptiveAudioPacketTime)94 Encoding(String rid, boolean active, double bitratePriority, @Priority 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") getRid()113 String getRid() { 114 return rid; 115 } 116 117 @CalledByNative("Encoding") getActive()118 boolean getActive() { 119 return active; 120 } 121 122 @CalledByNative("Encoding") getBitratePriority()123 double getBitratePriority() { 124 return bitratePriority; 125 } 126 127 @CalledByNative("Encoding") 128 @Priority getNetworkPriority()129 int getNetworkPriority() { 130 return networkPriority; 131 } 132 133 @Nullable 134 @CalledByNative("Encoding") getMaxBitrateBps()135 Integer getMaxBitrateBps() { 136 return maxBitrateBps; 137 } 138 139 @Nullable 140 @CalledByNative("Encoding") getMinBitrateBps()141 Integer getMinBitrateBps() { 142 return minBitrateBps; 143 } 144 145 @Nullable 146 @CalledByNative("Encoding") getMaxFramerate()147 Integer getMaxFramerate() { 148 return maxFramerate; 149 } 150 151 @Nullable 152 @CalledByNative("Encoding") getNumTemporalLayers()153 Integer getNumTemporalLayers() { 154 return numTemporalLayers; 155 } 156 157 @Nullable 158 @CalledByNative("Encoding") getScaleResolutionDownBy()159 Double getScaleResolutionDownBy() { 160 return scaleResolutionDownBy; 161 } 162 163 @CalledByNative("Encoding") getSsrc()164 Long getSsrc() { 165 return ssrc; 166 } 167 168 @CalledByNative("Encoding") getAdaptivePTime()169 boolean getAdaptivePTime() { 170 return adaptiveAudioPacketTime; 171 } 172 } 173 174 public static class Codec { 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; 185 // The "format specific parameters" field from the "a=fmtp" line in the SDP 186 public Map<String, String> parameters; 187 188 @CalledByNative("Codec") Codec(int payloadType, String name, MediaStreamTrack.MediaType kind, Integer clockRate, Integer numChannels, Map<String, String> parameters)189 Codec(int payloadType, String name, MediaStreamTrack.MediaType kind, Integer clockRate, 190 Integer numChannels, Map<String, String> parameters) { 191 this.payloadType = payloadType; 192 this.name = name; 193 this.kind = kind; 194 this.clockRate = clockRate; 195 this.numChannels = numChannels; 196 this.parameters = parameters; 197 } 198 199 @CalledByNative("Codec") getPayloadType()200 int getPayloadType() { 201 return payloadType; 202 } 203 204 @CalledByNative("Codec") getName()205 String getName() { 206 return name; 207 } 208 209 @CalledByNative("Codec") getKind()210 MediaStreamTrack.MediaType getKind() { 211 return kind; 212 } 213 214 @CalledByNative("Codec") getClockRate()215 Integer getClockRate() { 216 return clockRate; 217 } 218 219 @CalledByNative("Codec") getNumChannels()220 Integer getNumChannels() { 221 return numChannels; 222 } 223 224 @CalledByNative("Codec") getParameters()225 Map getParameters() { 226 return parameters; 227 } 228 } 229 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") Rtcp(String cname, boolean reducedSize)237 Rtcp(String cname, boolean reducedSize) { 238 this.cname = cname; 239 this.reducedSize = reducedSize; 240 } 241 242 @CalledByNative("Rtcp") getCname()243 public String getCname() { 244 return cname; 245 } 246 247 @CalledByNative("Rtcp") getReducedSize()248 public boolean getReducedSize() { 249 return reducedSize; 250 } 251 } 252 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") HeaderExtension(String uri, int id, boolean encrypted)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") getUri()269 public String getUri() { 270 return uri; 271 } 272 273 @CalledByNative("HeaderExtension") getId()274 public int getId() { 275 return id; 276 } 277 278 @CalledByNative("HeaderExtension") getEncrypted()279 public boolean getEncrypted() { 280 return encrypted; 281 } 282 } 283 284 public final String transactionId; 285 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 292 private final Rtcp rtcp; 293 294 private final List<HeaderExtension> headerExtensions; 295 296 public final List<Encoding> encodings; 297 298 public final List<Codec> codecs; 299 300 @CalledByNative RtpParameters(String transactionId, DegradationPreference degradationPreference, Rtcp rtcp, List<HeaderExtension> headerExtensions, List<Encoding> encodings, List<Codec> codecs)301 RtpParameters(String transactionId, DegradationPreference degradationPreference, Rtcp rtcp, 302 List<HeaderExtension> headerExtensions, List<Encoding> encodings, List<Codec> codecs) { 303 this.transactionId = transactionId; 304 this.degradationPreference = degradationPreference; 305 this.rtcp = rtcp; 306 this.headerExtensions = headerExtensions; 307 this.encodings = encodings; 308 this.codecs = codecs; 309 } 310 311 @CalledByNative getTransactionId()312 String getTransactionId() { 313 return transactionId; 314 } 315 316 @CalledByNative getDegradationPreference()317 DegradationPreference getDegradationPreference() { 318 return degradationPreference; 319 } 320 321 @CalledByNative getRtcp()322 public Rtcp getRtcp() { 323 return rtcp; 324 } 325 326 @CalledByNative getHeaderExtensions()327 public List<HeaderExtension> getHeaderExtensions() { 328 return headerExtensions; 329 } 330 331 @CalledByNative getEncodings()332 List<Encoding> getEncodings() { 333 return encodings; 334 } 335 336 @CalledByNative getCodecs()337 List<Codec> getCodecs() { 338 return codecs; 339 } 340 } 341