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 android.support.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 83 // This constructor is useful for creating simulcast layers. Encoding(String rid, boolean active, Double scaleResolutionDownBy)84 public Encoding(String rid, boolean active, Double scaleResolutionDownBy) { 85 this.rid = rid; 86 this.active = active; 87 this.scaleResolutionDownBy = scaleResolutionDownBy; 88 } 89 90 @CalledByNative("Encoding") Encoding(String rid, boolean active, double bitratePriority, @Priority int networkPriority, Integer maxBitrateBps, Integer minBitrateBps, Integer maxFramerate, Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc)91 Encoding(String rid, boolean active, double bitratePriority, @Priority int networkPriority, 92 Integer maxBitrateBps, Integer minBitrateBps, Integer maxFramerate, 93 Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc) { 94 this.rid = rid; 95 this.active = active; 96 this.bitratePriority = bitratePriority; 97 this.networkPriority = networkPriority; 98 this.maxBitrateBps = maxBitrateBps; 99 this.minBitrateBps = minBitrateBps; 100 this.maxFramerate = maxFramerate; 101 this.numTemporalLayers = numTemporalLayers; 102 this.scaleResolutionDownBy = scaleResolutionDownBy; 103 this.ssrc = ssrc; 104 } 105 106 @Nullable 107 @CalledByNative("Encoding") getRid()108 String getRid() { 109 return rid; 110 } 111 112 @CalledByNative("Encoding") getActive()113 boolean getActive() { 114 return active; 115 } 116 117 @CalledByNative("Encoding") getBitratePriority()118 double getBitratePriority() { 119 return bitratePriority; 120 } 121 122 @CalledByNative("Encoding") 123 @Priority getNetworkPriority()124 int getNetworkPriority() { 125 return networkPriority; 126 } 127 128 @Nullable 129 @CalledByNative("Encoding") getMaxBitrateBps()130 Integer getMaxBitrateBps() { 131 return maxBitrateBps; 132 } 133 134 @Nullable 135 @CalledByNative("Encoding") getMinBitrateBps()136 Integer getMinBitrateBps() { 137 return minBitrateBps; 138 } 139 140 @Nullable 141 @CalledByNative("Encoding") getMaxFramerate()142 Integer getMaxFramerate() { 143 return maxFramerate; 144 } 145 146 @Nullable 147 @CalledByNative("Encoding") getNumTemporalLayers()148 Integer getNumTemporalLayers() { 149 return numTemporalLayers; 150 } 151 152 @Nullable 153 @CalledByNative("Encoding") getScaleResolutionDownBy()154 Double getScaleResolutionDownBy() { 155 return scaleResolutionDownBy; 156 } 157 158 @CalledByNative("Encoding") getSsrc()159 Long getSsrc() { 160 return ssrc; 161 } 162 } 163 164 public static class Codec { 165 // 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; 175 // The "format specific parameters" field from the "a=fmtp" line in the SDP 176 public Map<String, String> parameters; 177 178 @CalledByNative("Codec") Codec(int payloadType, String name, MediaStreamTrack.MediaType kind, Integer clockRate, Integer numChannels, Map<String, String> parameters)179 Codec(int payloadType, String name, MediaStreamTrack.MediaType kind, Integer clockRate, 180 Integer numChannels, Map<String, String> parameters) { 181 this.payloadType = payloadType; 182 this.name = name; 183 this.kind = kind; 184 this.clockRate = clockRate; 185 this.numChannels = numChannels; 186 this.parameters = parameters; 187 } 188 189 @CalledByNative("Codec") getPayloadType()190 int getPayloadType() { 191 return payloadType; 192 } 193 194 @CalledByNative("Codec") getName()195 String getName() { 196 return name; 197 } 198 199 @CalledByNative("Codec") getKind()200 MediaStreamTrack.MediaType getKind() { 201 return kind; 202 } 203 204 @CalledByNative("Codec") getClockRate()205 Integer getClockRate() { 206 return clockRate; 207 } 208 209 @CalledByNative("Codec") getNumChannels()210 Integer getNumChannels() { 211 return numChannels; 212 } 213 214 @CalledByNative("Codec") getParameters()215 Map getParameters() { 216 return parameters; 217 } 218 } 219 220 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") Rtcp(String cname, boolean reducedSize)227 Rtcp(String cname, boolean reducedSize) { 228 this.cname = cname; 229 this.reducedSize = reducedSize; 230 } 231 232 @CalledByNative("Rtcp") getCname()233 public String getCname() { 234 return cname; 235 } 236 237 @CalledByNative("Rtcp") getReducedSize()238 public boolean getReducedSize() { 239 return reducedSize; 240 } 241 } 242 243 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") HeaderExtension(String uri, int id, boolean encrypted)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") getUri()259 public String getUri() { 260 return uri; 261 } 262 263 @CalledByNative("HeaderExtension") getId()264 public int getId() { 265 return id; 266 } 267 268 @CalledByNative("HeaderExtension") getEncrypted()269 public boolean getEncrypted() { 270 return encrypted; 271 } 272 } 273 274 public final String transactionId; 275 276 /** 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 282 private final Rtcp rtcp; 283 284 private final List<HeaderExtension> headerExtensions; 285 286 public final List<Encoding> encodings; 287 288 public final List<Codec> codecs; 289 290 @CalledByNative RtpParameters(String transactionId, DegradationPreference degradationPreference, Rtcp rtcp, List<HeaderExtension> headerExtensions, List<Encoding> encodings, List<Codec> codecs)291 RtpParameters(String transactionId, DegradationPreference degradationPreference, Rtcp rtcp, 292 List<HeaderExtension> headerExtensions, List<Encoding> encodings, List<Codec> codecs) { 293 this.transactionId = transactionId; 294 this.degradationPreference = degradationPreference; 295 this.rtcp = rtcp; 296 this.headerExtensions = headerExtensions; 297 this.encodings = encodings; 298 this.codecs = codecs; 299 } 300 301 @CalledByNative getTransactionId()302 String getTransactionId() { 303 return transactionId; 304 } 305 306 @CalledByNative getDegradationPreference()307 DegradationPreference getDegradationPreference() { 308 return degradationPreference; 309 } 310 311 @CalledByNative getRtcp()312 public Rtcp getRtcp() { 313 return rtcp; 314 } 315 316 @CalledByNative getHeaderExtensions()317 public List<HeaderExtension> getHeaderExtensions() { 318 return headerExtensions; 319 } 320 321 @CalledByNative getEncodings()322 List<Encoding> getEncodings() { 323 return encodings; 324 } 325 326 @CalledByNative getCodecs()327 List<Codec> getCodecs() { 328 return codecs; 329 } 330 } 331