From e3a294c2d6cc40f8717e9088510d3a03c11ed311 Mon Sep 17 00:00:00 2001 From: Taylor Brandstetter Date: Mon, 23 Mar 2020 23:16:58 +0000 Subject: [PATCH] Expose bitrate_priority and network_priority in Android API. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=webrtc:5658 Change-Id: Ie4fcad0a379bed17c41efffde044fa51f51a14b1 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168360 Commit-Queue: Taylor Reviewed-by: Sami Kalliomäki Reviewed-by: Qingsi Wang Cr-Commit-Position: refs/heads/master@{#30861} --- api/BUILD.gn | 6 ++++ api/rtp_parameters.h | 10 ++++-- sdk/android/BUILD.gn | 5 ++- sdk/android/api/org/webrtc/RtpParameters.java | 31 +++++++++++++++++-- sdk/android/src/jni/pc/rtp_parameters.cc | 5 +++ 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/api/BUILD.gn b/api/BUILD.gn index 6e53178d42..58b39d5a68 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -322,6 +322,12 @@ rtc_library("rtp_parameters") { ] } +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 cd7f029ce8..4719f90a94 100644 --- a/api/rtp_parameters.h +++ b/api/rtp_parameters.h @@ -93,6 +93,7 @@ enum class DegradationPreference { RTC_EXPORT extern const double kDefaultBitratePriority; +// GENERATED_JAVA_ENUM_PACKAGE: org.webrtc enum class Priority { kVeryLow, kLow, @@ -399,6 +400,11 @@ struct RTC_EXPORT RtpEncodingParameters { // 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 @@ struct RTC_EXPORT RtpEncodingParameters { // 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 9ee4216bdf..013cbbe35b 100644 --- a/sdk/android/BUILD.gn +++ b/sdk/android/BUILD.gn @@ -327,7 +327,10 @@ if (is_android) { "//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 4293ce77d2..e4e09304e9 100644 --- a/sdk/android/api/org/webrtc/RtpParameters.java +++ b/sdk/android/api/org/webrtc/RtpParameters.java @@ -50,6 +50,19 @@ public class RtpParameters { // 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 @@ public class RtpParameters { } @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 @@ public class RtpParameters { 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 5b394ab3a1..a65fa6eaa9 100644 --- a/sdk/android/src/jni/pc/rtp_parameters.cc +++ b/sdk/android/src/jni/pc/rtp_parameters.cc @@ -47,6 +47,7 @@ ScopedJavaLocalRef NativeToJavaRtpEncodingParameter( const RtpEncodingParameters& encoding) { return Java_Encoding_Constructor( env, NativeToJavaString(env, encoding.rid), encoding.active, + encoding.bitrate_priority, static_cast(encoding.network_priority), NativeToJavaInteger(env, encoding.max_bitrate_bps), NativeToJavaInteger(env, encoding.min_bitrate_bps), NativeToJavaInteger(env, encoding.max_framerate), @@ -95,6 +96,10 @@ RtpEncodingParameters JavaToNativeRtpEncodingParameters( encoding.active = Java_Encoding_getActive(jni, j_encoding_parameters); ScopedJavaLocalRef 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( + Java_Encoding_getNetworkPriority(jni, j_encoding_parameters)); encoding.max_bitrate_bps = JavaToNativeOptionalInt(jni, j_max_bitrate); ScopedJavaLocalRef j_min_bitrate = Java_Encoding_getMinBitrateBps(jni, j_encoding_parameters);