Expose bitrate_priority and network_priority in Android API.

BUG=webrtc:5658

Change-Id: Ie4fcad0a379bed17c41efffde044fa51f51a14b1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168360
Commit-Queue: Taylor <deadbeef@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30861}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 6e53178..58b39d5 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -322,6 +322,12 @@
   ]
 }
 
+if (is_android) {
+  java_cpp_enum("rtp_parameters_enums") {
+    sources = [ "rtp_parameters.h" ]
+  }
+}
+
 rtc_source_set("audio_quality_analyzer_api") {
   visibility = [ "*" ]
   testonly = true
diff --git a/api/rtp_parameters.h b/api/rtp_parameters.h
index cd7f029..4719f90 100644
--- a/api/rtp_parameters.h
+++ b/api/rtp_parameters.h
@@ -93,6 +93,7 @@
 
 RTC_EXPORT extern const double kDefaultBitratePriority;
 
+// GENERATED_JAVA_ENUM_PACKAGE: org.webrtc
 enum class Priority {
   kVeryLow,
   kLow,
@@ -399,6 +400,11 @@
   // The relative bitrate priority of this encoding. Currently this is
   // implemented for the entire rtp sender by using the value of the first
   // encoding parameter.
+  // See: https://w3c.github.io/webrtc-priority/#enumdef-rtcprioritytype
+  // "very-low" = 0.5
+  // "low" = 1.0
+  // "medium" = 2.0
+  // "high" = 4.0
   // TODO(webrtc.bugs.org/8630): Implement this per encoding parameter.
   // Currently there is logic for how bitrate is distributed per simulcast layer
   // in the VideoBitrateAllocator. This must be updated to incorporate relative
@@ -407,9 +413,7 @@
 
   // The relative DiffServ Code Point priority for this encoding, allowing
   // packets to be marked relatively higher or lower without affecting
-  // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ . NB
-  // we follow chromium's translation of the allowed string enum values for
-  // this field to 1.0, 0.5, et cetera, similar to bitrate_priority above.
+  // bandwidth allocations. See https://w3c.github.io/webrtc-dscp-exp/ .
   // TODO(http://crbug.com/webrtc/8630): Implement this per encoding parameter.
   // TODO(http://crbug.com/webrtc/11379): TCP connections should use a single
   // DSCP value even if shared by multiple senders; this is not implemented.
diff --git a/sdk/android/BUILD.gn b/sdk/android/BUILD.gn
index 9ee4216..013cbbe 100644
--- a/sdk/android/BUILD.gn
+++ b/sdk/android/BUILD.gn
@@ -327,7 +327,10 @@
       "//rtc_base:base_java",
       "//third_party/android_deps:com_android_support_support_annotations_java",
     ]
-    srcjar_deps = [ "//api/video:video_frame_enums" ]
+    srcjar_deps = [
+      "//api:rtp_parameters_enums",
+      "//api/video:video_frame_enums",
+    ]
   }
 
   # Modules, in alphabetical order.
diff --git a/sdk/android/api/org/webrtc/RtpParameters.java b/sdk/android/api/org/webrtc/RtpParameters.java
index 4293ce7..e4e0930 100644
--- a/sdk/android/api/org/webrtc/RtpParameters.java
+++ b/sdk/android/api/org/webrtc/RtpParameters.java
@@ -50,6 +50,19 @@
     // Set to true to cause this encoding to be sent, and false for it not to
     // be sent.
     public boolean active = true;
+    // The relative bitrate priority of this encoding. Currently this is
+    // implemented for the entire RTP sender by using the value of the first
+    // encoding parameter.
+    // See: https://w3c.github.io/webrtc-priority/#enumdef-rtcprioritytype
+    // "very-low" = 0.5
+    // "low" = 1.0
+    // "medium" = 2.0
+    // "high" = 4.0
+    public double bitratePriority = 1.0;
+    // The relative DiffServ Code Point priority for this encoding, allowing
+    // packets to be marked relatively higher or lower without affecting
+    // bandwidth allocations.
+    @Priority public int networkPriority = Priority.LOW;
     // If non-null, this represents the Transport Independent Application
     // Specific maximum bandwidth defined in RFC3890. If null, there is no
     // maximum bitrate.
@@ -75,10 +88,13 @@
     }
 
     @CalledByNative("Encoding")
-    Encoding(String rid, boolean active, Integer maxBitrateBps, Integer minBitrateBps,
-        Integer maxFramerate, Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc) {
+    Encoding(String rid, boolean active, double bitratePriority, @Priority int networkPriority,
+        Integer maxBitrateBps, Integer minBitrateBps, Integer maxFramerate,
+        Integer numTemporalLayers, Double scaleResolutionDownBy, Long ssrc) {
       this.rid = rid;
       this.active = active;
+      this.bitratePriority = bitratePriority;
+      this.networkPriority = networkPriority;
       this.maxBitrateBps = maxBitrateBps;
       this.minBitrateBps = minBitrateBps;
       this.maxFramerate = maxFramerate;
@@ -98,6 +114,17 @@
       return active;
     }
 
+    @CalledByNative("Encoding")
+    double getBitratePriority() {
+      return bitratePriority;
+    }
+
+    @CalledByNative("Encoding")
+    @Priority
+    int getNetworkPriority() {
+      return networkPriority;
+    }
+
     @Nullable
     @CalledByNative("Encoding")
     Integer getMaxBitrateBps() {
diff --git a/sdk/android/src/jni/pc/rtp_parameters.cc b/sdk/android/src/jni/pc/rtp_parameters.cc
index 5b394ab..a65fa6e 100644
--- a/sdk/android/src/jni/pc/rtp_parameters.cc
+++ b/sdk/android/src/jni/pc/rtp_parameters.cc
@@ -47,6 +47,7 @@
     const RtpEncodingParameters& encoding) {
   return Java_Encoding_Constructor(
       env, NativeToJavaString(env, encoding.rid), encoding.active,
+      encoding.bitrate_priority, static_cast<int>(encoding.network_priority),
       NativeToJavaInteger(env, encoding.max_bitrate_bps),
       NativeToJavaInteger(env, encoding.min_bitrate_bps),
       NativeToJavaInteger(env, encoding.max_framerate),
@@ -95,6 +96,10 @@
   encoding.active = Java_Encoding_getActive(jni, j_encoding_parameters);
   ScopedJavaLocalRef<jobject> j_max_bitrate =
       Java_Encoding_getMaxBitrateBps(jni, j_encoding_parameters);
+  encoding.bitrate_priority =
+      Java_Encoding_getBitratePriority(jni, j_encoding_parameters);
+  encoding.network_priority = static_cast<webrtc::Priority>(
+      Java_Encoding_getNetworkPriority(jni, j_encoding_parameters));
   encoding.max_bitrate_bps = JavaToNativeOptionalInt(jni, j_max_bitrate);
   ScopedJavaLocalRef<jobject> j_min_bitrate =
       Java_Encoding_getMinBitrateBps(jni, j_encoding_parameters);