Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Unified Diff: webrtc/api/java/jni/peerconnection_jni.cc

Issue 1819553002: Added the JNI interface to get and set RtpParameters and the maximum bitrate limits. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: One more rename Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/api/java/jni/peerconnection_jni.cc
diff --git a/webrtc/api/java/jni/peerconnection_jni.cc b/webrtc/api/java/jni/peerconnection_jni.cc
index 74fb473399d36f3499c2a67efa32d1c7653345e8..1a131c1867f8823b1bc9b291b56fd182f67ceecd 100644
--- a/webrtc/api/java/jni/peerconnection_jni.cc
+++ b/webrtc/api/java/jni/peerconnection_jni.cc
@@ -458,18 +458,7 @@ class ConstraintsWrapper : public MediaConstraintsInterface {
jfieldID j_id = GetFieldID(jni,
GetObjectClass(jni, j_constraints), field_name, "Ljava/util/List;");
jobject j_list = GetObjectField(jni, j_constraints, j_id);
- jmethodID j_iterator_id = GetMethodID(jni,
- GetObjectClass(jni, j_list), "iterator", "()Ljava/util/Iterator;");
- jobject j_iterator = jni->CallObjectMethod(j_list, j_iterator_id);
- CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
- jmethodID j_has_next = GetMethodID(jni,
- GetObjectClass(jni, j_iterator), "hasNext", "()Z");
- jmethodID j_next = GetMethodID(jni,
- GetObjectClass(jni, j_iterator), "next", "()Ljava/lang/Object;");
- while (jni->CallBooleanMethod(j_iterator, j_has_next)) {
- CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
- jobject entry = jni->CallObjectMethod(j_iterator, j_next);
- CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
+ for (jobject entry : Iterable(jni, j_list)) {
jmethodID get_key = GetMethodID(jni,
GetObjectClass(jni, entry), "getKey", "()Ljava/lang/String;");
jstring j_key = reinterpret_cast<jstring>(
@@ -1488,19 +1477,7 @@ static PeerConnectionInterface::ContinualGatheringPolicy
static void JavaIceServersToJsepIceServers(
JNIEnv* jni, jobject j_ice_servers,
PeerConnectionInterface::IceServers* ice_servers) {
- jclass list_class = GetObjectClass(jni, j_ice_servers);
- jmethodID iterator_id = GetMethodID(
- jni, list_class, "iterator", "()Ljava/util/Iterator;");
- jobject iterator = jni->CallObjectMethod(j_ice_servers, iterator_id);
- CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
- jmethodID iterator_has_next = GetMethodID(
- jni, GetObjectClass(jni, iterator), "hasNext", "()Z");
- jmethodID iterator_next = GetMethodID(
- jni, GetObjectClass(jni, iterator), "next", "()Ljava/lang/Object;");
- while (jni->CallBooleanMethod(iterator, iterator_has_next)) {
- CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
- jobject j_ice_server = jni->CallObjectMethod(iterator, iterator_next);
- CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
+ for (jobject j_ice_server : Iterable(jni, j_ice_servers)) {
jclass j_ice_server_class = GetObjectClass(jni, j_ice_server);
jfieldID j_ice_server_uri_id =
GetFieldID(jni, j_ice_server_class, "uri", "Ljava/lang/String;");
@@ -2078,6 +2055,101 @@ JOW(jlong, RtpSender_nativeGetTrack)(JNIEnv* jni,
.release());
}
+static bool JavaEncodingToJsepRtpEncodingParameters(
+ JNIEnv* jni,
+ jobject j_encodings,
+ std::vector<webrtc::RtpEncodingParameters>* encodings) {
+ const int kBitrateUnlimited = -1;
+ for (jobject j_encoding_parameters : Iterable(jni, j_encodings)) {
+ jclass j_encoding_parameters_class =
+ GetObjectClass(jni, j_encoding_parameters);
+ jfieldID bitrate_id = GetFieldID(jni, j_encoding_parameters_class,
+ "maxBitrateBps", "Ljava/lang/Integer;");
+ jobject j_bitrate = GetObjectField(jni, j_encoding_parameters, bitrate_id);
+
+ webrtc::RtpEncodingParameters encoding;
+
+ if (j_bitrate) {
+ jmethodID integer_int_value_id =
+ GetMethodID(jni, GetObjectClass(jni, j_bitrate), "intValue", "()I");
+ int bitrate_value = jni->CallIntMethod(j_bitrate, integer_int_value_id);
+ CHECK_EXCEPTION(jni) << "error during CallIntMethod";
+ encoding.max_bitrate_bps = bitrate_value;
+ } else {
+ encoding.max_bitrate_bps = kBitrateUnlimited;
+ }
+
+ encodings->push_back(encoding);
+ }
+ CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
Taylor Brandstetter 2016/03/22 01:16:36 I don't think this CHECK_EXCEPTION is necessary.
skvlad 2016/03/22 02:20:00 Good catch. This is a leftover from the previous v
+ return true;
+}
+
+JOW(jboolean, RtpSender_nativeSetParameters)
+(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer, jobject j_parameters) {
+ if (!j_parameters) {
+ return false;
+ }
+
+ jclass parameters_class = FindClass(jni, "org/webrtc/RtpParameters");
+
+ jclass encoding_class = FindClass(jni, "org/webrtc/RtpParameters$Encoding");
+ jfieldID encodings_id =
+ GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
+
+ jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
+ webrtc::RtpParameters parameters;
+ JavaEncodingToJsepRtpEncodingParameters(jni, j_encodings,
+ &parameters.encodings);
+
+ return reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
+ ->SetParameters(parameters);
+}
+
+JOW(jobject, RtpSender_nativeGetParameters)
+(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
+ webrtc::RtpParameters parameters =
+ reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
+ ->GetParameters();
+
+ jclass parameters_class = FindClass(jni, "org/webrtc/RtpParameters");
+ jmethodID parameters_ctor =
+ GetMethodID(jni, parameters_class, "<init>", "()V");
+ jobject j_parameters = jni->NewObject(parameters_class, parameters_ctor);
+ CHECK_EXCEPTION(jni) << "error during NewObject";
+
+ jclass encoding_class = FindClass(jni, "org/webrtc/RtpParameters$Encoding");
+ jmethodID encoding_ctor = GetMethodID(jni, encoding_class, "<init>", "()V");
+ jfieldID encodings_id =
+ GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
+ jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
+ jmethodID add = GetMethodID(jni, GetObjectClass(jni, j_encodings), "add",
+ "(Ljava/lang/Object;)Z");
+ jfieldID bitrate_id =
+ GetFieldID(jni, encoding_class, "maxBitrateBps", "Ljava/lang/Integer;");
+
+ jclass integer_class = FindClass(jni, "java/lang/Integer");
+ jmethodID integer_ctor = GetMethodID(jni, integer_class, "<init>", "(I)V");
+
+ for (webrtc::RtpEncodingParameters encoding : parameters.encodings) {
+ jobject j_encoding_parameters =
+ jni->NewObject(encoding_class, encoding_ctor);
+ CHECK_EXCEPTION(jni) << "error during NewObject";
+ if (encoding.max_bitrate_bps > 0) {
+ jobject j_bitrate_value =
+ jni->NewObject(integer_class, integer_ctor, encoding.max_bitrate_bps);
+ CHECK_EXCEPTION(jni) << "error during NewObject";
+ jni->SetObjectField(j_encoding_parameters, bitrate_id, j_bitrate_value);
+ CHECK_EXCEPTION(jni) << "error during SetObjectField";
+ }
+
+ jboolean added =
+ jni->CallBooleanMethod(j_encodings, add, j_encoding_parameters);
+ CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
+ }
+ return j_parameters;
+}
+
JOW(jstring, RtpSender_nativeId)(
JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
return JavaStringFromStdString(

Powered by Google App Engine
This is Rietveld 408576698