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

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: Code review feedback 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
« no previous file with comments | « webrtc/api/java/jni/jni_helpers.cc ('k') | webrtc/api/java/src/org/webrtc/RtpParameters.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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";
483 field->push_back(Constraint(JavaToStdString(jni, j_key), 472 field->push_back(Constraint(JavaToStdString(jni, j_key),
484 JavaToStdString(jni, j_value))); 473 JavaToStdString(jni, j_value)));
485 } 474 }
486 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
487 } 475 }
488 476
489 Constraints mandatory_; 477 Constraints mandatory_;
490 Constraints optional_; 478 Constraints optional_;
491 }; 479 };
492 480
493 static jobject JavaSdpFromNativeSdp( 481 static jobject JavaSdpFromNativeSdp(
494 JNIEnv* jni, const SessionDescriptionInterface* desc) { 482 JNIEnv* jni, const SessionDescriptionInterface* desc) {
495 std::string sdp; 483 std::string sdp;
496 RTC_CHECK(desc->ToString(&sdp)) << "got so far: " << sdp; 484 RTC_CHECK(desc->ToString(&sdp)) << "got so far: " << sdp;
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1481 return PeerConnectionInterface::GATHER_CONTINUALLY; 1469 return PeerConnectionInterface::GATHER_CONTINUALLY;
1482 1470
1483 RTC_CHECK(false) << "Unexpected ContinualGatheringPolicy enum name " 1471 RTC_CHECK(false) << "Unexpected ContinualGatheringPolicy enum name "
1484 << enum_name; 1472 << enum_name;
1485 return PeerConnectionInterface::GATHER_ONCE; 1473 return PeerConnectionInterface::GATHER_ONCE;
1486 } 1474 }
1487 1475
1488 static void JavaIceServersToJsepIceServers( 1476 static void JavaIceServersToJsepIceServers(
1489 JNIEnv* jni, jobject j_ice_servers, 1477 JNIEnv* jni, jobject j_ice_servers,
1490 PeerConnectionInterface::IceServers* ice_servers) { 1478 PeerConnectionInterface::IceServers* ice_servers) {
1491 jclass list_class = GetObjectClass(jni, j_ice_servers); 1479 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); 1480 jclass j_ice_server_class = GetObjectClass(jni, j_ice_server);
1505 jfieldID j_ice_server_uri_id = 1481 jfieldID j_ice_server_uri_id =
1506 GetFieldID(jni, j_ice_server_class, "uri", "Ljava/lang/String;"); 1482 GetFieldID(jni, j_ice_server_class, "uri", "Ljava/lang/String;");
1507 jfieldID j_ice_server_username_id = 1483 jfieldID j_ice_server_username_id =
1508 GetFieldID(jni, j_ice_server_class, "username", "Ljava/lang/String;"); 1484 GetFieldID(jni, j_ice_server_class, "username", "Ljava/lang/String;");
1509 jfieldID j_ice_server_password_id = 1485 jfieldID j_ice_server_password_id =
1510 GetFieldID(jni, j_ice_server_class, "password", "Ljava/lang/String;"); 1486 GetFieldID(jni, j_ice_server_class, "password", "Ljava/lang/String;");
1511 jstring uri = reinterpret_cast<jstring>( 1487 jstring uri = reinterpret_cast<jstring>(
1512 GetObjectField(jni, j_ice_server, j_ice_server_uri_id)); 1488 GetObjectField(jni, j_ice_server, j_ice_server_uri_id));
1513 jstring username = reinterpret_cast<jstring>( 1489 jstring username = reinterpret_cast<jstring>(
1514 GetObjectField(jni, j_ice_server, j_ice_server_username_id)); 1490 GetObjectField(jni, j_ice_server, j_ice_server_username_id));
1515 jstring password = reinterpret_cast<jstring>( 1491 jstring password = reinterpret_cast<jstring>(
1516 GetObjectField(jni, j_ice_server, j_ice_server_password_id)); 1492 GetObjectField(jni, j_ice_server, j_ice_server_password_id));
1517 PeerConnectionInterface::IceServer server; 1493 PeerConnectionInterface::IceServer server;
1518 server.uri = JavaToStdString(jni, uri); 1494 server.uri = JavaToStdString(jni, uri);
1519 server.username = JavaToStdString(jni, username); 1495 server.username = JavaToStdString(jni, username);
1520 server.password = JavaToStdString(jni, password); 1496 server.password = JavaToStdString(jni, password);
1521 ice_servers->push_back(server); 1497 ice_servers->push_back(server);
1522 } 1498 }
1523 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
1524 } 1499 }
1525 1500
1526 static void JavaRTCConfigurationToJsepRTCConfiguration( 1501 static void JavaRTCConfigurationToJsepRTCConfiguration(
1527 JNIEnv* jni, 1502 JNIEnv* jni,
1528 jobject j_rtc_config, 1503 jobject j_rtc_config,
1529 PeerConnectionInterface::RTCConfiguration* rtc_config) { 1504 PeerConnectionInterface::RTCConfiguration* rtc_config) {
1530 jclass j_rtc_config_class = GetObjectClass(jni, j_rtc_config); 1505 jclass j_rtc_config_class = GetObjectClass(jni, j_rtc_config);
1531 1506
1532 jfieldID j_ice_transports_type_id = GetFieldID( 1507 jfieldID j_ice_transports_type_id = GetFieldID(
1533 jni, j_rtc_config_class, "iceTransportsType", 1508 jni, j_rtc_config_class, "iceTransportsType",
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 JOW(jlong, RtpSender_nativeGetTrack)(JNIEnv* jni, 2046 JOW(jlong, RtpSender_nativeGetTrack)(JNIEnv* jni,
2072 jclass, 2047 jclass,
2073 jlong j_rtp_sender_pointer, 2048 jlong j_rtp_sender_pointer,
2074 jlong j_track_pointer) { 2049 jlong j_track_pointer) {
2075 return jlongFromPointer( 2050 return jlongFromPointer(
2076 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer) 2051 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2077 ->track() 2052 ->track()
2078 .release()); 2053 .release());
2079 } 2054 }
2080 2055
2056 static bool JavaEncodingToJsepRtpEncodingParameters(
2057 JNIEnv* jni,
2058 jobject j_encodings,
2059 std::vector<webrtc::RtpEncodingParameters>* encodings) {
2060 const int kBitrateUnlimited = -1;
2061 jclass j_encoding_parameters_class =
2062 jni->FindClass("org/webrtc/RtpParameters$Encoding");
2063 jfieldID bitrate_id = GetFieldID(jni, j_encoding_parameters_class,
2064 "maxBitrateBps", "Ljava/lang/Integer;");
2065 jclass j_integer_class = jni->FindClass("java/lang/Integer");
2066 jmethodID int_value_id = GetMethodID(jni, j_integer_class, "intValue", "()I");
2067
2068 for (jobject j_encoding_parameters : Iterable(jni, j_encodings)) {
2069 webrtc::RtpEncodingParameters encoding;
2070 jobject j_bitrate = GetObjectField(jni, j_encoding_parameters, bitrate_id);
2071 if (!IsNull(jni, j_bitrate)) {
2072 int bitrate_value = jni->CallIntMethod(j_bitrate, int_value_id);
2073 CHECK_EXCEPTION(jni) << "error during CallIntMethod";
2074 encoding.max_bitrate_bps = bitrate_value;
2075 } else {
2076 encoding.max_bitrate_bps = kBitrateUnlimited;
2077 }
2078 encodings->push_back(encoding);
2079 }
2080 return true;
2081 }
2082
2083 JOW(jboolean, RtpSender_nativeSetParameters)
2084 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer, jobject j_parameters) {
2085 if (IsNull(jni, j_parameters)) {
2086 return false;
2087 }
2088 jclass parameters_class = jni->FindClass("org/webrtc/RtpParameters");
2089 jclass encoding_class = jni->FindClass("org/webrtc/RtpParameters$Encoding");
2090 jfieldID encodings_id =
2091 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
2092
2093 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
2094 webrtc::RtpParameters parameters;
2095 JavaEncodingToJsepRtpEncodingParameters(jni, j_encodings,
2096 &parameters.encodings);
2097 return reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2098 ->SetParameters(parameters);
2099 }
2100
2101 JOW(jobject, RtpSender_nativeGetParameters)
2102 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2103 webrtc::RtpParameters parameters =
2104 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)
2105 ->GetParameters();
2106
2107 jclass parameters_class = jni->FindClass("org/webrtc/RtpParameters");
2108 jmethodID parameters_ctor =
2109 GetMethodID(jni, parameters_class, "<init>", "()V");
2110 jobject j_parameters = jni->NewObject(parameters_class, parameters_ctor);
2111 CHECK_EXCEPTION(jni) << "error during NewObject";
2112
2113 jclass encoding_class = jni->FindClass("org/webrtc/RtpParameters$Encoding");
2114 jmethodID encoding_ctor = GetMethodID(jni, encoding_class, "<init>", "()V");
2115 jfieldID encodings_id =
2116 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;");
2117 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id);
2118 jmethodID add = GetMethodID(jni, GetObjectClass(jni, j_encodings), "add",
2119 "(Ljava/lang/Object;)Z");
2120 jfieldID bitrate_id =
2121 GetFieldID(jni, encoding_class, "maxBitrateBps", "Ljava/lang/Integer;");
2122
2123 jclass integer_class = jni->FindClass("java/lang/Integer");
2124 jmethodID integer_ctor = GetMethodID(jni, integer_class, "<init>", "(I)V");
2125
2126 for (webrtc::RtpEncodingParameters encoding : parameters.encodings) {
2127 jobject j_encoding_parameters =
2128 jni->NewObject(encoding_class, encoding_ctor);
2129 CHECK_EXCEPTION(jni) << "error during NewObject";
2130 if (encoding.max_bitrate_bps > 0) {
2131 jobject j_bitrate_value =
2132 jni->NewObject(integer_class, integer_ctor, encoding.max_bitrate_bps);
2133 CHECK_EXCEPTION(jni) << "error during NewObject";
2134 jni->SetObjectField(j_encoding_parameters, bitrate_id, j_bitrate_value);
2135 CHECK_EXCEPTION(jni) << "error during SetObjectField";
2136 }
2137 jboolean added =
2138 jni->CallBooleanMethod(j_encodings, add, j_encoding_parameters);
2139 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod";
2140 }
2141 return j_parameters;
2142 }
2143
2081 JOW(jstring, RtpSender_nativeId)( 2144 JOW(jstring, RtpSender_nativeId)(
2082 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { 2145 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2083 return JavaStringFromStdString( 2146 return JavaStringFromStdString(
2084 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id()); 2147 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id());
2085 } 2148 }
2086 2149
2087 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { 2150 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) {
2088 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release(); 2151 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release();
2089 } 2152 }
2090 2153
(...skipping 12 matching lines...) Expand all
2103 return JavaStringFromStdString( 2166 return JavaStringFromStdString(
2104 jni, 2167 jni,
2105 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); 2168 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id());
2106 } 2169 }
2107 2170
2108 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { 2171 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) {
2109 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); 2172 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release();
2110 } 2173 }
2111 2174
2112 } // namespace webrtc_jni 2175 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « webrtc/api/java/jni/jni_helpers.cc ('k') | webrtc/api/java/src/org/webrtc/RtpParameters.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698