From 60631775fa067042b025b04f4307ea16dd6311b0 Mon Sep 17 00:00:00 2001 From: deadbeef Date: Mon, 4 Apr 2016 10:21:02 -0700 Subject: [PATCH] Allowing a Java object field to be null in a new JNI helper method. Java objects in the API should be allowed to be null in some cases. Specifically, a null value for maxBitrateBps in RtpParameters.java has a specific meaning and doesn't imply an error has occurred. NOTRY=True Review URL: https://codereview.webrtc.org/1853523002 Cr-Commit-Position: refs/heads/master@{#12221} --- webrtc/api/java/jni/jni_helpers.cc | 8 +++++++- webrtc/api/java/jni/jni_helpers.h | 3 +++ webrtc/api/java/jni/peerconnection_jni.cc | 3 ++- webrtc/api/java/src/org/webrtc/RtpParameters.java | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/webrtc/api/java/jni/jni_helpers.cc b/webrtc/api/java/jni/jni_helpers.cc index f42abc703e..052dcf9a89 100644 --- a/webrtc/api/java/jni/jni_helpers.cc +++ b/webrtc/api/java/jni/jni_helpers.cc @@ -176,7 +176,13 @@ jclass GetObjectClass(JNIEnv* jni, jobject object) { jobject GetObjectField(JNIEnv* jni, jobject object, jfieldID id) { jobject o = jni->GetObjectField(object, id); CHECK_EXCEPTION(jni) << "error during GetObjectField"; - RTC_CHECK(o) << "GetObjectField returned NULL"; + RTC_CHECK(!IsNull(jni, o)) << "GetObjectField returned NULL"; + return o; +} + +jobject GetNullableObjectField(JNIEnv* jni, jobject object, jfieldID id) { + jobject o = jni->GetObjectField(object, id); + CHECK_EXCEPTION(jni) << "error during GetObjectField"; return o; } diff --git a/webrtc/api/java/jni/jni_helpers.h b/webrtc/api/java/jni/jni_helpers.h index 98dcc38b53..2832df14b3 100644 --- a/webrtc/api/java/jni/jni_helpers.h +++ b/webrtc/api/java/jni/jni_helpers.h @@ -64,8 +64,11 @@ jfieldID GetFieldID(JNIEnv* jni, jclass c, const char* name, jclass GetObjectClass(JNIEnv* jni, jobject object); +// Throws an exception if the object field is null. jobject GetObjectField(JNIEnv* jni, jobject object, jfieldID id); +jobject GetNullableObjectField(JNIEnv* jni, jobject object, jfieldID id); + jstring GetStringField(JNIEnv* jni, jobject object, jfieldID id); jlong GetLongField(JNIEnv* jni, jobject object, jfieldID id); diff --git a/webrtc/api/java/jni/peerconnection_jni.cc b/webrtc/api/java/jni/peerconnection_jni.cc index 2baff04ebe..a250b707e6 100644 --- a/webrtc/api/java/jni/peerconnection_jni.cc +++ b/webrtc/api/java/jni/peerconnection_jni.cc @@ -2044,7 +2044,8 @@ static bool JavaEncodingToJsepRtpEncodingParameters( for (jobject j_encoding_parameters : Iterable(jni, j_encodings)) { webrtc::RtpEncodingParameters encoding; encoding.active = GetBooleanField(jni, j_encoding_parameters, active_id); - jobject j_bitrate = GetObjectField(jni, j_encoding_parameters, bitrate_id); + jobject j_bitrate = + GetNullableObjectField(jni, j_encoding_parameters, bitrate_id); if (!IsNull(jni, j_bitrate)) { int bitrate_value = jni->CallIntMethod(j_bitrate, int_value_id); CHECK_EXCEPTION(jni) << "error during CallIntMethod"; diff --git a/webrtc/api/java/src/org/webrtc/RtpParameters.java b/webrtc/api/java/src/org/webrtc/RtpParameters.java index bd448994e2..d689517c3b 100644 --- a/webrtc/api/java/src/org/webrtc/RtpParameters.java +++ b/webrtc/api/java/src/org/webrtc/RtpParameters.java @@ -20,6 +20,7 @@ import java.util.LinkedList; public class RtpParameters { public static class Encoding { public boolean active = true; + // A null value means "no maximum bitrate". public Integer maxBitrateBps; }