| 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..2aec51f5e77a20c22fa6e05fdecba72367befb7d 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 : JavaCollection(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 : JavaCollection(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,104 @@ JOW(jlong, RtpSender_nativeGetTrack)(JNIEnv* jni,
|
| .release());
|
| }
|
|
|
| +static bool JavaRtpEncodingParametersToJsepRtpEncodingParameters(
|
| + JNIEnv* jni,
|
| + jobject j_encodings,
|
| + std::vector<webrtc::RtpEncodingParameters>* encodings) {
|
| + const int kBitrateUnlimited = -1;
|
| + for (jobject j_encoding_parameters : JavaCollection(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";
|
| + 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$RtpEncodingParameters");
|
| + jfieldID encodings_id =
|
| + GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
|
| +
|
| + jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
|
| + webrtc::RtpParameters parameters;
|
| + JavaRtpEncodingParametersToJsepRtpEncodingParameters(jni, j_encodings,
|
| + ¶meters.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$RtpEncodingParameters");
|
| + 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(
|
|
|