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 : JavaCollection(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 Loading... |
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 : JavaCollection(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 Loading... |
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 JavaRtpEncodingParametersToJsepRtpEncodingParameters( |
| 2059 JNIEnv* jni, |
| 2060 jobject j_encodings, |
| 2061 std::vector<webrtc::RtpEncodingParameters>* encodings) { |
| 2062 const int kBitrateUnlimited = -1; |
| 2063 for (jobject j_encoding_parameters : JavaCollection(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"; |
| 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 = |
| 2097 FindClass(jni, "org/webrtc/RtpParameters$RtpEncodingParameters"); |
| 2098 jfieldID encodings_id = |
| 2099 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;"); |
| 2100 |
| 2101 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id); |
| 2102 webrtc::RtpParameters parameters; |
| 2103 JavaRtpEncodingParametersToJsepRtpEncodingParameters(jni, j_encodings, |
| 2104 ¶meters.encodings); |
| 2105 |
| 2106 return reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer) |
| 2107 ->SetParameters(parameters); |
| 2108 } |
| 2109 |
| 2110 JOW(jobject, RtpSender_nativeGetParameters) |
| 2111 (JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { |
| 2112 webrtc::RtpParameters parameters = |
| 2113 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer) |
| 2114 ->GetParameters(); |
| 2115 |
| 2116 jclass parameters_class = FindClass(jni, "org/webrtc/RtpParameters"); |
| 2117 jmethodID parameters_ctor = |
| 2118 GetMethodID(jni, parameters_class, "<init>", "()V"); |
| 2119 jobject j_parameters = jni->NewObject(parameters_class, parameters_ctor); |
| 2120 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 2121 |
| 2122 jclass encoding_class = |
| 2123 FindClass(jni, "org/webrtc/RtpParameters$RtpEncodingParameters"); |
| 2124 jmethodID encoding_ctor = GetMethodID(jni, encoding_class, "<init>", "()V"); |
| 2125 jfieldID encodings_id = |
| 2126 GetFieldID(jni, parameters_class, "encodings", "Ljava/util/LinkedList;"); |
| 2127 jobject j_encodings = GetObjectField(jni, j_parameters, encodings_id); |
| 2128 jmethodID add = GetMethodID(jni, GetObjectClass(jni, j_encodings), "add", |
| 2129 "(Ljava/lang/Object;)Z"); |
| 2130 jfieldID bitrate_id = |
| 2131 GetFieldID(jni, encoding_class, "maxBitrateBps", "Ljava/lang/Integer;"); |
| 2132 |
| 2133 jclass integer_class = FindClass(jni, "java/lang/Integer"); |
| 2134 jmethodID integer_ctor = GetMethodID(jni, integer_class, "<init>", "(I)V"); |
| 2135 |
| 2136 for (webrtc::RtpEncodingParameters encoding : parameters.encodings) { |
| 2137 jobject j_encoding_parameters = |
| 2138 jni->NewObject(encoding_class, encoding_ctor); |
| 2139 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 2140 if (encoding.max_bitrate_bps > 0) { |
| 2141 |
| 2142 jobject j_bitrate_value = jni->NewObject(integer_class, integer_ctor, |
| 2143 encoding.max_bitrate_bps); |
| 2144 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 2145 jni->SetObjectField(j_encoding_parameters, bitrate_id, j_bitrate_value); |
| 2146 CHECK_EXCEPTION(jni) << "error during SetObjectField"; |
| 2147 } |
| 2148 |
| 2149 jboolean added = |
| 2150 jni->CallBooleanMethod(j_encodings, add, j_encoding_parameters); |
| 2151 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; |
| 2152 } |
| 2153 return j_parameters; |
| 2154 } |
| 2155 |
2081 JOW(jstring, RtpSender_nativeId)( | 2156 JOW(jstring, RtpSender_nativeId)( |
2082 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { | 2157 JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { |
2083 return JavaStringFromStdString( | 2158 return JavaStringFromStdString( |
2084 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id()); | 2159 jni, reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->id()); |
2085 } | 2160 } |
2086 | 2161 |
2087 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { | 2162 JOW(void, RtpSender_free)(JNIEnv* jni, jclass, jlong j_rtp_sender_pointer) { |
2088 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release(); | 2163 reinterpret_cast<RtpSenderInterface*>(j_rtp_sender_pointer)->Release(); |
2089 } | 2164 } |
2090 | 2165 |
(...skipping 12 matching lines...) Expand all Loading... |
2103 return JavaStringFromStdString( | 2178 return JavaStringFromStdString( |
2104 jni, | 2179 jni, |
2105 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); | 2180 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); |
2106 } | 2181 } |
2107 | 2182 |
2108 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { | 2183 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { |
2109 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); | 2184 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); |
2110 } | 2185 } |
2111 | 2186 |
2112 } // namespace webrtc_jni | 2187 } // namespace webrtc_jni |
OLD | NEW |