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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 const Constraints& GetOptional() const override { return optional_; } 451 const Constraints& GetOptional() const override { return optional_; }
452 452
453 private: 453 private:
454 // Helper for translating a List<Pair<String, String>> to a Constraints. 454 // Helper for translating a List<Pair<String, String>> to a Constraints.
455 static void PopulateConstraintsFromJavaPairList( 455 static void PopulateConstraintsFromJavaPairList(
456 JNIEnv* jni, jobject j_constraints, 456 JNIEnv* jni, jobject j_constraints,
457 const char* field_name, Constraints* field) { 457 const char* field_name, Constraints* field) {
458 jfieldID j_id = GetFieldID(jni, 458 jfieldID j_id = GetFieldID(jni,
459 GetObjectClass(jni, j_constraints), field_name, "Ljava/util/List;"); 459 GetObjectClass(jni, j_constraints), field_name, "Ljava/util/List;");
460 jobject j_list = GetObjectField(jni, j_constraints, j_id); 460 jobject j_list = GetObjectField(jni, j_constraints, j_id);
461 jmethodID j_iterator_id = GetMethodID(jni, 461 for (jobject entry : Iterable(jni, j_list)) {
462 GetObjectClass(jni, j_list), "iterator", "()Ljava/util/Iterator;");
463 jobject j_iterator = jni->CallObjectMethod(j_list, j_iterator_id);
464 CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
465 jmethodID j_has_next = GetMethodID(jni,
466 GetObjectClass(jni, j_iterator), "hasNext", "()Z");
467 jmethodID j_next = GetMethodID(jni,
468 GetObjectClass(jni, j_iterator), "next", "()Ljava/lang/Object;");
469 while (jni->CallBooleanMethod(j_iterator, j_has_next)) {
470 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
471 jobject entry = jni->CallObjectMethod(j_iterator, j_next);
472 CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
473 jmethodID get_key = GetMethodID(jni, 462 jmethodID get_key = GetMethodID(jni,
474 GetObjectClass(jni, entry), "getKey", "()Ljava/lang/String;"); 463 GetObjectClass(jni, entry), "getKey", "()Ljava/lang/String;");
475 jstring j_key = reinterpret_cast<jstring>( 464 jstring j_key = reinterpret_cast<jstring>(
476 jni->CallObjectMethod(entry, get_key)); 465 jni->CallObjectMethod(entry, get_key));
477 CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; 466 CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
478 jmethodID get_value = GetMethodID(jni, 467 jmethodID get_value = GetMethodID(jni,
479 GetObjectClass(jni, entry), "getValue", "()Ljava/lang/String;"); 468 GetObjectClass(jni, entry), "getValue", "()Ljava/lang/String;");
480 jstring j_value = reinterpret_cast<jstring>( 469 jstring j_value = reinterpret_cast<jstring>(
481 jni->CallObjectMethod(entry, get_value)); 470 jni->CallObjectMethod(entry, get_value));
482 CHECK_EXCEPTION(jni) << "error during CallObjectMethod"; 471 CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
(...skipping 998 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 return PeerConnectionInterface::GATHER_CONTINUALLY; 1470 return PeerConnectionInterface::GATHER_CONTINUALLY;
1482 1471
1483 RTC_CHECK(false) << "Unexpected ContinualGatheringPolicy enum name " 1472 RTC_CHECK(false) << "Unexpected ContinualGatheringPolicy enum name "
1484 << enum_name; 1473 << enum_name;
1485 return PeerConnectionInterface::GATHER_ONCE; 1474 return PeerConnectionInterface::GATHER_ONCE;
1486 } 1475 }
1487 1476
1488 static void JavaIceServersToJsepIceServers( 1477 static void JavaIceServersToJsepIceServers(
1489 JNIEnv* jni, jobject j_ice_servers, 1478 JNIEnv* jni, jobject j_ice_servers,
1490 PeerConnectionInterface::IceServers* ice_servers) { 1479 PeerConnectionInterface::IceServers* ice_servers) {
1491 jclass list_class = GetObjectClass(jni, j_ice_servers); 1480 for (jobject j_ice_server : Iterable(jni, j_ice_servers)) {
1492 jmethodID iterator_id = GetMethodID(
1493 jni, list_class, "iterator", "()Ljava/util/Iterator;");
1494 jobject iterator = jni->CallObjectMethod(j_ice_servers, iterator_id);
1495 CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
1496 jmethodID iterator_has_next = GetMethodID(
1497 jni, GetObjectClass(jni, iterator), "hasNext", "()Z");
1498 jmethodID iterator_next = GetMethodID(
1499 jni, GetObjectClass(jni, iterator), "next", "()Ljava/lang/Object;");
1500 while (jni->CallBooleanMethod(iterator, iterator_has_next)) {
1501 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
1502 jobject j_ice_server = jni->CallObjectMethod(iterator, iterator_next);
1503 CHECK_EXCEPTION(jni) << "error during CallObjectMethod";
1504 jclass j_ice_server_class = GetObjectClass(jni, j_ice_server); 1481 jclass j_ice_server_class = GetObjectClass(jni, j_ice_server);
1505 jfieldID j_ice_server_uri_id = 1482 jfieldID j_ice_server_uri_id =
1506 GetFieldID(jni, j_ice_server_class, "uri", "Ljava/lang/String;"); 1483 GetFieldID(jni, j_ice_server_class, "uri", "Ljava/lang/String;");
1507 jfieldID j_ice_server_username_id = 1484 jfieldID j_ice_server_username_id =
1508 GetFieldID(jni, j_ice_server_class, "username", "Ljava/lang/String;"); 1485 GetFieldID(jni, j_ice_server_class, "username", "Ljava/lang/String;");
1509 jfieldID j_ice_server_password_id = 1486 jfieldID j_ice_server_password_id =
1510 GetFieldID(jni, j_ice_server_class, "password", "Ljava/lang/String;"); 1487 GetFieldID(jni, j_ice_server_class, "password", "Ljava/lang/String;");
1511 jstring uri = reinterpret_cast<jstring>( 1488 jstring uri = reinterpret_cast<jstring>(
1512 GetObjectField(jni, j_ice_server, j_ice_server_uri_id)); 1489 GetObjectField(jni, j_ice_server, j_ice_server_uri_id));
1513 jstring username = reinterpret_cast<jstring>( 1490 jstring username = reinterpret_cast<jstring>(
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 JOW(jlong, RtpSender_nativeGetTrack)(JNIEnv* jni, 2048 JOW(jlong, RtpSender_nativeGetTrack)(JNIEnv* jni,
2072 jclass, 2049 jclass,
2073 jlong j_rtp_sender_pointer, 2050 jlong j_rtp_sender_pointer,
2074 jlong j_track_pointer) { 2051 jlong j_track_pointer) {
2075 return jlongFromPointer( 2052 return jlongFromPointer(
2076 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer) 2053 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2077 ->track() 2054 ->track()
2078 .release()); 2055 .release());
2079 } 2056 }
2080 2057
2058 static bool JavaEncodingToJsepRtpEncodingParameters(
2059 JNIEnv* jni,
2060 jobject j_encodings,
2061 std::vector<webrtc::RtpEncodingParameters>* encodings) {
2062 const int kBitrateUnlimited = -1;
2063 for (jobject j_encoding_parameters : Iterable(jni, j_encodings)) {
2064 jclass j_encoding_parameters_class =
2065 GetObjectClass(jni, j_encoding_parameters);
2066 jfieldID bitrate_id = GetFieldID(jni, j_encoding_parameters_class,
2067 "maxBitrateBps", "Ljava/lang/Integer;");
2068 jobject j_bitrate = GetObjectField(jni, j_encoding_parameters, bitrate_id);
2069
2070 webrtc::RtpEncodingParameters encoding;
2071
2072 if (j_bitrate) {
2073 jmethodID integer_int_value_id =
2074 GetMethodID(jni, GetObjectClass(jni, j_bitrate), "intValue", "()I");
2075 int bitrate_value = jni->CallIntMethod(j_bitrate, integer_int_value_id);
2076 CHECK_EXCEPTION(jni) << "error during CallIntMethod";
2077 encoding.max_bitrate_bps = bitrate_value;
2078 } else {
2079 encoding.max_bitrate_bps = kBitrateUnlimited;
2080 }
2081
2082 encodings->push_back(encoding);
2083 }
2084 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
2085 return true;
2086 }
2087
2088 JOW(jboolean, RtpSender_nativeSetParameters)
2089 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer, jobject j_parameters) {
2090 if (!j_parameters) {
2091 return false;
2092 }
2093
2094 jclass parameters_class = FindClass(jni, "org/webrtc/RtpParameters");
2095
2096 jclass encoding_class = FindClass(jni, "org/webrtc/RtpParameters$Encoding");
2097 jfieldID encodings_id =
2098 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
2099
2100 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
2101 webrtc::RtpParameters parameters;
2102 JavaEncodingToJsepRtpEncodingParameters(jni, j_encodings,
2103 &parameters.encodings);
2104
2105 return reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2106 ->SetParameters(parameters);
2107 }
2108
2109 JOW(jobject, RtpSender_nativeGetParameters)
2110 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2111 webrtc::RtpParameters parameters =
2112 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2113 ->GetParameters();
2114
2115 jclass parameters_class = FindClass(jni, "org/webrtc/RtpParameters");
2116 jmethodID parameters_ctor =
2117 GetMethodID(jni, parameters_class, "<init>", "()V");
2118 jobject j_parameters = jni->NewObject(parameters_class, parameters_ctor);
2119 CHECK_EXCEPTION(jni) << "error during NewObject";
2120
2121 jclass encoding_class = FindClass(jni, "org/webrtc/RtpParameters$Encoding");
2122 jmethodID encoding_ctor = GetMethodID(jni, encoding_class, "<init>", "()V");
2123 jfieldID encodings_id =
2124 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
2125 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
2126 jmethodID add = GetMethodID(jni, GetObjectClass(jni, j_encodings), "add",
2127 "(Ljava/lang/Object;)Z");
2128 jfieldID bitrate_id =
2129 GetFieldID(jni, encoding_class, "maxBitrateBps", "Ljava/lang/Integer;");
2130
2131 jclass integer_class = FindClass(jni, "java/lang/Integer");
2132 jmethodID integer_ctor = GetMethodID(jni, integer_class, "<init>", "(I)V");
2133
2134 for (webrtc::RtpEncodingParameters encoding : parameters.encodings) {
2135 jobject j_encoding_parameters =
2136 jni->NewObject(encoding_class, encoding_ctor);
2137 CHECK_EXCEPTION(jni) << "error during NewObject";
2138 if (encoding.max_bitrate_bps > 0) {
2139 jobject j_bitrate_value =
2140 jni->NewObject(integer_class, integer_ctor, encoding.max_bitrate_bps);
2141 CHECK_EXCEPTION(jni) << "error during NewObject";
2142 jni->SetObjectField(j_encoding_parameters, bitrate_id, j_bitrate_value);
2143 CHECK_EXCEPTION(jni) << "error during SetObjectField";
2144 }
2145
2146 jboolean added =
2147 jni->CallBooleanMethod(j_encodings, add, j_encoding_parameters);
2148 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
2149 }
2150 return j_parameters;
2151 }
2152
2081 JOW(jstring, RtpSender_nativeId)( 2153 JOW(jstring, RtpSender_nativeId)(
2082 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { 2154 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2083 return JavaStringFromStdString( 2155 return JavaStringFromStdString(
2084 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id()); 2156 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id());
2085 } 2157 }
2086 2158
2087 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { 2159 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2088 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release(); 2160 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release();
2089 } 2161 }
2090 2162
(...skipping 12 matching lines...) Expand all
2103 return JavaStringFromStdString( 2175 return JavaStringFromStdString(
2104 jni, 2176 jni,
2105 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); 2177 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id());
2106 } 2178 }
2107 2179
2108 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { 2180 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) {
2109 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); 2181 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release();
2110 } 2182 }
2111 2183
2112 } // namespace webrtc_jni 2184 } // namespace webrtc_jni
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698