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}
This commit is contained in:
deadbeef 2016-04-04 10:21:02 -07:00 committed by Commit bot
parent bc37fc8418
commit 60631775fa
4 changed files with 13 additions and 2 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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";

View File

@ -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;
}