OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 for (jobject j_encoding_parameters : Iterable(jni, j_encodings)) { | |
2062 jclass j_encoding_parameters_class = | |
2063 GetObjectClass(jni, j_encoding_parameters); | |
2064 jfieldID bitrate_id = GetFieldID(jni, j_encoding_parameters_class, | |
magjed_webrtc
2016/03/22 15:15:30
Can you move |j_encoding_parameters_class| and |bi
skvlad
2016/03/23 00:29:27
Done.
| |
2065 "maxBitrateBps", "Ljava/lang/Integer;"); | |
2066 jobject j_bitrate = GetObjectField(jni, j_encoding_parameters, bitrate_id); | |
2067 | |
2068 webrtc::RtpEncodingParameters encoding; | |
2069 | |
2070 if (j_bitrate) { | |
2071 jmethodID integer_int_value_id = | |
magjed_webrtc
2016/03/22 15:15:30
Move |integer_int_value_id| outside for loop. Stra
skvlad
2016/03/23 00:29:27
Done.
| |
2072 GetMethodID(jni, GetObjectClass(jni, j_bitrate), "intValue", "()I"); | |
2073 int bitrate_value = jni->CallIntMethod(j_bitrate, integer_int_value_id); | |
2074 CHECK_EXCEPTION(jni) << "error during CallIntMethod"; | |
2075 encoding.max_bitrate_bps = bitrate_value; | |
2076 } else { | |
2077 encoding.max_bitrate_bps = kBitrateUnlimited; | |
2078 } | |
2079 | |
2080 encodings->push_back(encoding); | |
2081 } | |
2082 return true; | |
2083 } | |
2084 | |
2085 JOW(jboolean, RtpSender_nativeSetParameters) | |
2086 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer, jobject j_parameters) { | |
2087 if (!j_parameters) { | |
2088 return false; | |
2089 } | |
2090 | |
2091 jclass parameters_class = FindClass(jni, "org/webrtc/RtpParameters"); | |
magjed_webrtc
2016/03/22 15:15:30
If you are not planning to store this jclass, then
skvlad
2016/03/23 00:29:27
Done. I previously assumed ClassReferenceHolder wa
| |
2092 | |
2093 jclass encoding_class = FindClass(jni, "org/webrtc/RtpParameters$Encoding"); | |
2094 jfieldID encodings_id = | |
2095 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;"); | |
2096 | |
2097 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id); | |
2098 webrtc::RtpParameters parameters; | |
2099 JavaEncodingToJsepRtpEncodingParameters(jni, j_encodings, | |
2100 ¶meters.encodings); | |
2101 | |
2102 return reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer) | |
2103 ->SetParameters(parameters); | |
2104 } | |
2105 | |
2106 JOW(jobject, RtpSender_nativeGetParameters) | |
2107 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { | |
2108 webrtc::RtpParameters parameters = | |
2109 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer) | |
2110 ->GetParameters(); | |
2111 | |
2112 jclass parameters_class = FindClass(jni, "org/webrtc/RtpParameters"); | |
2113 jmethodID parameters_ctor = | |
2114 GetMethodID(jni, parameters_class, "<init>", "()V"); | |
2115 jobject j_parameters = jni->NewObject(parameters_class, parameters_ctor); | |
2116 CHECK_EXCEPTION(jni) << "error during NewObject"; | |
2117 | |
2118 jclass encoding_class = FindClass(jni, "org/webrtc/RtpParameters$Encoding"); | |
2119 jmethodID encoding_ctor = GetMethodID(jni, encoding_class, "<init>", "()V"); | |
2120 jfieldID encodings_id = | |
2121 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;"); | |
2122 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id); | |
2123 jmethodID add = GetMethodID(jni, GetObjectClass(jni, j_encodings), "add", | |
2124 "(Ljava/lang/Object;)Z"); | |
2125 jfieldID bitrate_id = | |
2126 GetFieldID(jni, encoding_class, "maxBitrateBps", "Ljava/lang/Integer;"); | |
2127 | |
2128 jclass integer_class = FindClass(jni, "java/lang/Integer"); | |
2129 jmethodID integer_ctor = GetMethodID(jni, integer_class, "<init>", "(I)V"); | |
2130 | |
2131 for (webrtc::RtpEncodingParameters encoding : parameters.encodings) { | |
2132 jobject j_encoding_parameters = | |
2133 jni->NewObject(encoding_class, encoding_ctor); | |
2134 CHECK_EXCEPTION(jni) << "error during NewObject"; | |
2135 if (encoding.max_bitrate_bps > 0) { | |
2136 jobject j_bitrate_value = | |
2137 jni->NewObject(integer_class, integer_ctor, encoding.max_bitrate_bps); | |
2138 CHECK_EXCEPTION(jni) << "error during NewObject"; | |
2139 jni->SetObjectField(j_encoding_parameters, bitrate_id, j_bitrate_value); | |
2140 CHECK_EXCEPTION(jni) << "error during SetObjectField"; | |
2141 } | |
2142 | |
2143 jboolean added = | |
2144 jni->CallBooleanMethod(j_encodings, add, j_encoding_parameters); | |
2145 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; | |
2146 } | |
2147 return j_parameters; | |
2148 } | |
2149 | |
2081 JOW(jstring, RtpSender_nativeId)( | 2150 JOW(jstring, RtpSender_nativeId)( |
2082 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { | 2151 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { |
2083 return JavaStringFromStdString( | 2152 return JavaStringFromStdString( |
2084 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id()); | 2153 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id()); |
2085 } | 2154 } |
2086 | 2155 |
2087 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { | 2156 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { |
2088 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release(); | 2157 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release(); |
2089 } | 2158 } |
2090 | 2159 |
(...skipping 12 matching lines...) Expand all Loading... | |
2103 return JavaStringFromStdString( | 2172 return JavaStringFromStdString( |
2104 jni, | 2173 jni, |
2105 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); | 2174 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); |
2106 } | 2175 } |
2107 | 2176 |
2108 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { | 2177 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { |
2109 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); | 2178 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); |
2110 } | 2179 } |
2111 | 2180 |
2112 } // namespace webrtc_jni | 2181 } // namespace webrtc_jni |
OLD | NEW |