| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 static rtc::scoped_refptr<webrtc::PeerConnectionInterface> ExtractNativePC( | 50 static rtc::scoped_refptr<webrtc::PeerConnectionInterface> ExtractNativePC( |
| 51 JNIEnv* jni, | 51 JNIEnv* jni, |
| 52 jobject j_pc) { | 52 jobject j_pc) { |
| 53 jfieldID native_pc_id = | 53 jfieldID native_pc_id = |
| 54 GetFieldID(jni, GetObjectClass(jni, j_pc), "nativePeerConnection", "J"); | 54 GetFieldID(jni, GetObjectClass(jni, j_pc), "nativePeerConnection", "J"); |
| 55 jlong j_p = GetLongField(jni, j_pc, native_pc_id); | 55 jlong j_p = GetLongField(jni, j_pc, native_pc_id); |
| 56 return rtc::scoped_refptr<webrtc::PeerConnectionInterface>( | 56 return rtc::scoped_refptr<webrtc::PeerConnectionInterface>( |
| 57 reinterpret_cast<webrtc::PeerConnectionInterface*>(j_p)); | 57 reinterpret_cast<webrtc::PeerConnectionInterface*>(j_p)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 JOW(void, PeerConnection_freePeerConnection)(JNIEnv*, jclass, jlong j_p) { | 60 JNI_FUNCTION_DECLARATION(void, |
| 61 PeerConnection_freePeerConnection, |
| 62 JNIEnv*, |
| 63 jclass, |
| 64 jlong j_p) { |
| 61 CHECK_RELEASE(reinterpret_cast<webrtc::PeerConnectionInterface*>(j_p)); | 65 CHECK_RELEASE(reinterpret_cast<webrtc::PeerConnectionInterface*>(j_p)); |
| 62 } | 66 } |
| 63 | 67 |
| 64 JOW(void, PeerConnection_freeObserver)(JNIEnv*, jclass, jlong j_p) { | 68 JNI_FUNCTION_DECLARATION(void, |
| 69 PeerConnection_freeObserver, |
| 70 JNIEnv*, |
| 71 jclass, |
| 72 jlong j_p) { |
| 65 PeerConnectionObserverJni* p = | 73 PeerConnectionObserverJni* p = |
| 66 reinterpret_cast<PeerConnectionObserverJni*>(j_p); | 74 reinterpret_cast<PeerConnectionObserverJni*>(j_p); |
| 67 delete p; | 75 delete p; |
| 68 } | 76 } |
| 69 | 77 |
| 70 JOW(jobject, PeerConnection_getLocalDescription)(JNIEnv* jni, jobject j_pc) { | 78 JNI_FUNCTION_DECLARATION(jobject, |
| 79 PeerConnection_getLocalDescription, |
| 80 JNIEnv* jni, |
| 81 jobject j_pc) { |
| 71 const webrtc::SessionDescriptionInterface* sdp = | 82 const webrtc::SessionDescriptionInterface* sdp = |
| 72 ExtractNativePC(jni, j_pc)->local_description(); | 83 ExtractNativePC(jni, j_pc)->local_description(); |
| 73 return sdp ? NativeToJavaSessionDescription(jni, sdp) : NULL; | 84 return sdp ? NativeToJavaSessionDescription(jni, sdp) : NULL; |
| 74 } | 85 } |
| 75 | 86 |
| 76 JOW(jobject, PeerConnection_getRemoteDescription)(JNIEnv* jni, jobject j_pc) { | 87 JNI_FUNCTION_DECLARATION(jobject, |
| 88 PeerConnection_getRemoteDescription, |
| 89 JNIEnv* jni, |
| 90 jobject j_pc) { |
| 77 const webrtc::SessionDescriptionInterface* sdp = | 91 const webrtc::SessionDescriptionInterface* sdp = |
| 78 ExtractNativePC(jni, j_pc)->remote_description(); | 92 ExtractNativePC(jni, j_pc)->remote_description(); |
| 79 return sdp ? NativeToJavaSessionDescription(jni, sdp) : NULL; | 93 return sdp ? NativeToJavaSessionDescription(jni, sdp) : NULL; |
| 80 } | 94 } |
| 81 | 95 |
| 82 JOW(jobject, PeerConnection_createDataChannel) | 96 JNI_FUNCTION_DECLARATION(jobject, |
| 83 (JNIEnv* jni, jobject j_pc, jstring j_label, jobject j_init) { | 97 PeerConnection_createDataChannel, |
| 98 JNIEnv* jni, |
| 99 jobject j_pc, |
| 100 jstring j_label, |
| 101 jobject j_init) { |
| 84 webrtc::DataChannelInit init = JavaToNativeDataChannelInit(jni, j_init); | 102 webrtc::DataChannelInit init = JavaToNativeDataChannelInit(jni, j_init); |
| 85 rtc::scoped_refptr<webrtc::DataChannelInterface> channel( | 103 rtc::scoped_refptr<webrtc::DataChannelInterface> channel( |
| 86 ExtractNativePC(jni, j_pc)->CreateDataChannel( | 104 ExtractNativePC(jni, j_pc)->CreateDataChannel( |
| 87 JavaToStdString(jni, j_label), &init)); | 105 JavaToStdString(jni, j_label), &init)); |
| 88 // Mustn't pass channel.get() directly through NewObject to avoid reading its | 106 // Mustn't pass channel.get() directly through NewObject to avoid reading its |
| 89 // vararg parameter as 64-bit and reading memory that doesn't belong to the | 107 // vararg parameter as 64-bit and reading memory that doesn't belong to the |
| 90 // 32-bit parameter. | 108 // 32-bit parameter. |
| 91 jlong nativeChannelPtr = jlongFromPointer(channel.get()); | 109 jlong nativeChannelPtr = jlongFromPointer(channel.get()); |
| 92 if (!nativeChannelPtr) { | 110 if (!nativeChannelPtr) { |
| 93 LOG(LS_ERROR) << "Failed to create DataChannel"; | 111 LOG(LS_ERROR) << "Failed to create DataChannel"; |
| 94 return nullptr; | 112 return nullptr; |
| 95 } | 113 } |
| 96 jclass j_data_channel_class = FindClass(jni, "org/webrtc/DataChannel"); | 114 jclass j_data_channel_class = FindClass(jni, "org/webrtc/DataChannel"); |
| 97 jmethodID j_data_channel_ctor = | 115 jmethodID j_data_channel_ctor = |
| 98 GetMethodID(jni, j_data_channel_class, "<init>", "(J)V"); | 116 GetMethodID(jni, j_data_channel_class, "<init>", "(J)V"); |
| 99 jobject j_channel = jni->NewObject(j_data_channel_class, j_data_channel_ctor, | 117 jobject j_channel = jni->NewObject(j_data_channel_class, j_data_channel_ctor, |
| 100 nativeChannelPtr); | 118 nativeChannelPtr); |
| 101 CHECK_EXCEPTION(jni) << "error during NewObject"; | 119 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 102 // Channel is now owned by Java object, and will be freed from there. | 120 // Channel is now owned by Java object, and will be freed from there. |
| 103 int bumped_count = channel->AddRef(); | 121 int bumped_count = channel->AddRef(); |
| 104 RTC_CHECK(bumped_count == 2) << "Unexpected refcount"; | 122 RTC_CHECK(bumped_count == 2) << "Unexpected refcount"; |
| 105 return j_channel; | 123 return j_channel; |
| 106 } | 124 } |
| 107 | 125 |
| 108 JOW(void, PeerConnection_createOffer) | 126 JNI_FUNCTION_DECLARATION(void, |
| 109 (JNIEnv* jni, jobject j_pc, jobject j_observer, jobject j_constraints) { | 127 PeerConnection_createOffer, |
| 128 JNIEnv* jni, |
| 129 jobject j_pc, |
| 130 jobject j_observer, |
| 131 jobject j_constraints) { |
| 110 MediaConstraintsJni* constraints = | 132 MediaConstraintsJni* constraints = |
| 111 new MediaConstraintsJni(jni, j_constraints); | 133 new MediaConstraintsJni(jni, j_constraints); |
| 112 rtc::scoped_refptr<CreateSdpObserverJni> observer( | 134 rtc::scoped_refptr<CreateSdpObserverJni> observer( |
| 113 new rtc::RefCountedObject<CreateSdpObserverJni>(jni, j_observer, | 135 new rtc::RefCountedObject<CreateSdpObserverJni>(jni, j_observer, |
| 114 constraints)); | 136 constraints)); |
| 115 ExtractNativePC(jni, j_pc)->CreateOffer(observer, constraints); | 137 ExtractNativePC(jni, j_pc)->CreateOffer(observer, constraints); |
| 116 } | 138 } |
| 117 | 139 |
| 118 JOW(void, PeerConnection_createAnswer) | 140 JNI_FUNCTION_DECLARATION(void, |
| 119 (JNIEnv* jni, jobject j_pc, jobject j_observer, jobject j_constraints) { | 141 PeerConnection_createAnswer, |
| 142 JNIEnv* jni, |
| 143 jobject j_pc, |
| 144 jobject j_observer, |
| 145 jobject j_constraints) { |
| 120 MediaConstraintsJni* constraints = | 146 MediaConstraintsJni* constraints = |
| 121 new MediaConstraintsJni(jni, j_constraints); | 147 new MediaConstraintsJni(jni, j_constraints); |
| 122 rtc::scoped_refptr<CreateSdpObserverJni> observer( | 148 rtc::scoped_refptr<CreateSdpObserverJni> observer( |
| 123 new rtc::RefCountedObject<CreateSdpObserverJni>(jni, j_observer, | 149 new rtc::RefCountedObject<CreateSdpObserverJni>(jni, j_observer, |
| 124 constraints)); | 150 constraints)); |
| 125 ExtractNativePC(jni, j_pc)->CreateAnswer(observer, constraints); | 151 ExtractNativePC(jni, j_pc)->CreateAnswer(observer, constraints); |
| 126 } | 152 } |
| 127 | 153 |
| 128 JOW(void, PeerConnection_setLocalDescription) | 154 JNI_FUNCTION_DECLARATION(void, |
| 129 (JNIEnv* jni, jobject j_pc, jobject j_observer, jobject j_sdp) { | 155 PeerConnection_setLocalDescription, |
| 156 JNIEnv* jni, |
| 157 jobject j_pc, |
| 158 jobject j_observer, |
| 159 jobject j_sdp) { |
| 130 rtc::scoped_refptr<SetSdpObserverJni> observer( | 160 rtc::scoped_refptr<SetSdpObserverJni> observer( |
| 131 new rtc::RefCountedObject<SetSdpObserverJni>(jni, j_observer, nullptr)); | 161 new rtc::RefCountedObject<SetSdpObserverJni>(jni, j_observer, nullptr)); |
| 132 ExtractNativePC(jni, j_pc)->SetLocalDescription( | 162 ExtractNativePC(jni, j_pc)->SetLocalDescription( |
| 133 observer, JavaToNativeSessionDescription(jni, j_sdp)); | 163 observer, JavaToNativeSessionDescription(jni, j_sdp)); |
| 134 } | 164 } |
| 135 | 165 |
| 136 JOW(void, PeerConnection_setRemoteDescription) | 166 JNI_FUNCTION_DECLARATION(void, |
| 137 (JNIEnv* jni, jobject j_pc, jobject j_observer, jobject j_sdp) { | 167 PeerConnection_setRemoteDescription, |
| 168 JNIEnv* jni, |
| 169 jobject j_pc, |
| 170 jobject j_observer, |
| 171 jobject j_sdp) { |
| 138 rtc::scoped_refptr<SetSdpObserverJni> observer( | 172 rtc::scoped_refptr<SetSdpObserverJni> observer( |
| 139 new rtc::RefCountedObject<SetSdpObserverJni>(jni, j_observer, nullptr)); | 173 new rtc::RefCountedObject<SetSdpObserverJni>(jni, j_observer, nullptr)); |
| 140 ExtractNativePC(jni, j_pc)->SetRemoteDescription( | 174 ExtractNativePC(jni, j_pc)->SetRemoteDescription( |
| 141 observer, JavaToNativeSessionDescription(jni, j_sdp)); | 175 observer, JavaToNativeSessionDescription(jni, j_sdp)); |
| 142 } | 176 } |
| 143 | 177 |
| 144 JOW(jboolean, PeerConnection_nativeSetConfiguration) | 178 JNI_FUNCTION_DECLARATION(jboolean, |
| 145 (JNIEnv* jni, jobject j_pc, jobject j_rtc_config, jlong native_observer) { | 179 PeerConnection_nativeSetConfiguration, |
| 180 JNIEnv* jni, |
| 181 jobject j_pc, |
| 182 jobject j_rtc_config, |
| 183 jlong native_observer) { |
| 146 // Need to merge constraints into RTCConfiguration again, which are stored | 184 // Need to merge constraints into RTCConfiguration again, which are stored |
| 147 // in the observer object. | 185 // in the observer object. |
| 148 PeerConnectionObserverJni* observer = | 186 PeerConnectionObserverJni* observer = |
| 149 reinterpret_cast<PeerConnectionObserverJni*>(native_observer); | 187 reinterpret_cast<PeerConnectionObserverJni*>(native_observer); |
| 150 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config( | 188 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config( |
| 151 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive); | 189 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive); |
| 152 JavaToNativeRTCConfiguration(jni, j_rtc_config, &rtc_config); | 190 JavaToNativeRTCConfiguration(jni, j_rtc_config, &rtc_config); |
| 153 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config); | 191 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config); |
| 154 return ExtractNativePC(jni, j_pc)->SetConfiguration(rtc_config); | 192 return ExtractNativePC(jni, j_pc)->SetConfiguration(rtc_config); |
| 155 } | 193 } |
| 156 | 194 |
| 157 JOW(jboolean, PeerConnection_nativeAddIceCandidate) | 195 JNI_FUNCTION_DECLARATION(jboolean, |
| 158 (JNIEnv* jni, | 196 PeerConnection_nativeAddIceCandidate, |
| 159 jobject j_pc, | 197 JNIEnv* jni, |
| 160 jstring j_sdp_mid, | 198 jobject j_pc, |
| 161 jint j_sdp_mline_index, | 199 jstring j_sdp_mid, |
| 162 jstring j_candidate_sdp) { | 200 jint j_sdp_mline_index, |
| 201 jstring j_candidate_sdp) { |
| 163 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid); | 202 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid); |
| 164 std::string sdp = JavaToStdString(jni, j_candidate_sdp); | 203 std::string sdp = JavaToStdString(jni, j_candidate_sdp); |
| 165 std::unique_ptr<webrtc::IceCandidateInterface> candidate( | 204 std::unique_ptr<webrtc::IceCandidateInterface> candidate( |
| 166 webrtc::CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, nullptr)); | 205 webrtc::CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, nullptr)); |
| 167 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get()); | 206 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get()); |
| 168 } | 207 } |
| 169 | 208 |
| 170 JOW(jboolean, PeerConnection_nativeRemoveIceCandidates) | 209 JNI_FUNCTION_DECLARATION(jboolean, |
| 171 (JNIEnv* jni, jobject j_pc, jobjectArray j_candidates) { | 210 PeerConnection_nativeRemoveIceCandidates, |
| 211 JNIEnv* jni, |
| 212 jobject j_pc, |
| 213 jobjectArray j_candidates) { |
| 172 std::vector<cricket::Candidate> candidates; | 214 std::vector<cricket::Candidate> candidates; |
| 173 size_t num_candidates = jni->GetArrayLength(j_candidates); | 215 size_t num_candidates = jni->GetArrayLength(j_candidates); |
| 174 for (size_t i = 0; i < num_candidates; ++i) { | 216 for (size_t i = 0; i < num_candidates; ++i) { |
| 175 jobject j_candidate = jni->GetObjectArrayElement(j_candidates, i); | 217 jobject j_candidate = jni->GetObjectArrayElement(j_candidates, i); |
| 176 candidates.push_back(JavaToNativeCandidate(jni, j_candidate)); | 218 candidates.push_back(JavaToNativeCandidate(jni, j_candidate)); |
| 177 } | 219 } |
| 178 return ExtractNativePC(jni, j_pc)->RemoveIceCandidates(candidates); | 220 return ExtractNativePC(jni, j_pc)->RemoveIceCandidates(candidates); |
| 179 } | 221 } |
| 180 | 222 |
| 181 JOW(jboolean, PeerConnection_nativeAddLocalStream) | 223 JNI_FUNCTION_DECLARATION(jboolean, |
| 182 (JNIEnv* jni, jobject j_pc, jlong native_stream) { | 224 PeerConnection_nativeAddLocalStream, |
| 225 JNIEnv* jni, |
| 226 jobject j_pc, |
| 227 jlong native_stream) { |
| 183 return ExtractNativePC(jni, j_pc)->AddStream( | 228 return ExtractNativePC(jni, j_pc)->AddStream( |
| 184 reinterpret_cast<webrtc::MediaStreamInterface*>(native_stream)); | 229 reinterpret_cast<webrtc::MediaStreamInterface*>(native_stream)); |
| 185 } | 230 } |
| 186 | 231 |
| 187 JOW(void, PeerConnection_nativeRemoveLocalStream) | 232 JNI_FUNCTION_DECLARATION(void, |
| 188 (JNIEnv* jni, jobject j_pc, jlong native_stream) { | 233 PeerConnection_nativeRemoveLocalStream, |
| 234 JNIEnv* jni, |
| 235 jobject j_pc, |
| 236 jlong native_stream) { |
| 189 ExtractNativePC(jni, j_pc)->RemoveStream( | 237 ExtractNativePC(jni, j_pc)->RemoveStream( |
| 190 reinterpret_cast<webrtc::MediaStreamInterface*>(native_stream)); | 238 reinterpret_cast<webrtc::MediaStreamInterface*>(native_stream)); |
| 191 } | 239 } |
| 192 | 240 |
| 193 JOW(jobject, PeerConnection_nativeCreateSender) | 241 JNI_FUNCTION_DECLARATION(jobject, |
| 194 (JNIEnv* jni, jobject j_pc, jstring j_kind, jstring j_stream_id) { | 242 PeerConnection_nativeCreateSender, |
| 243 JNIEnv* jni, |
| 244 jobject j_pc, |
| 245 jstring j_kind, |
| 246 jstring j_stream_id) { |
| 195 jclass j_rtp_sender_class = FindClass(jni, "org/webrtc/RtpSender"); | 247 jclass j_rtp_sender_class = FindClass(jni, "org/webrtc/RtpSender"); |
| 196 jmethodID j_rtp_sender_ctor = | 248 jmethodID j_rtp_sender_ctor = |
| 197 GetMethodID(jni, j_rtp_sender_class, "<init>", "(J)V"); | 249 GetMethodID(jni, j_rtp_sender_class, "<init>", "(J)V"); |
| 198 | 250 |
| 199 std::string kind = JavaToStdString(jni, j_kind); | 251 std::string kind = JavaToStdString(jni, j_kind); |
| 200 std::string stream_id = JavaToStdString(jni, j_stream_id); | 252 std::string stream_id = JavaToStdString(jni, j_stream_id); |
| 201 rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = | 253 rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = |
| 202 ExtractNativePC(jni, j_pc)->CreateSender(kind, stream_id); | 254 ExtractNativePC(jni, j_pc)->CreateSender(kind, stream_id); |
| 203 if (!sender.get()) { | 255 if (!sender.get()) { |
| 204 return nullptr; | 256 return nullptr; |
| 205 } | 257 } |
| 206 jlong nativeSenderPtr = jlongFromPointer(sender.get()); | 258 jlong nativeSenderPtr = jlongFromPointer(sender.get()); |
| 207 jobject j_sender = | 259 jobject j_sender = |
| 208 jni->NewObject(j_rtp_sender_class, j_rtp_sender_ctor, nativeSenderPtr); | 260 jni->NewObject(j_rtp_sender_class, j_rtp_sender_ctor, nativeSenderPtr); |
| 209 CHECK_EXCEPTION(jni) << "error during NewObject"; | 261 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 210 // Sender is now owned by the Java object, and will be freed from | 262 // Sender is now owned by the Java object, and will be freed from |
| 211 // RtpSender.dispose(), called by PeerConnection.dispose() or getSenders(). | 263 // RtpSender.dispose(), called by PeerConnection.dispose() or getSenders(). |
| 212 sender->AddRef(); | 264 sender->AddRef(); |
| 213 return j_sender; | 265 return j_sender; |
| 214 } | 266 } |
| 215 | 267 |
| 216 JOW(jobject, PeerConnection_nativeGetSenders)(JNIEnv* jni, jobject j_pc) { | 268 JNI_FUNCTION_DECLARATION(jobject, |
| 269 PeerConnection_nativeGetSenders, |
| 270 JNIEnv* jni, |
| 271 jobject j_pc) { |
| 217 jclass j_array_list_class = FindClass(jni, "java/util/ArrayList"); | 272 jclass j_array_list_class = FindClass(jni, "java/util/ArrayList"); |
| 218 jmethodID j_array_list_ctor = | 273 jmethodID j_array_list_ctor = |
| 219 GetMethodID(jni, j_array_list_class, "<init>", "()V"); | 274 GetMethodID(jni, j_array_list_class, "<init>", "()V"); |
| 220 jmethodID j_array_list_add = | 275 jmethodID j_array_list_add = |
| 221 GetMethodID(jni, j_array_list_class, "add", "(Ljava/lang/Object;)Z"); | 276 GetMethodID(jni, j_array_list_class, "add", "(Ljava/lang/Object;)Z"); |
| 222 jobject j_senders = jni->NewObject(j_array_list_class, j_array_list_ctor); | 277 jobject j_senders = jni->NewObject(j_array_list_class, j_array_list_ctor); |
| 223 CHECK_EXCEPTION(jni) << "error during NewObject"; | 278 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 224 | 279 |
| 225 jclass j_rtp_sender_class = FindClass(jni, "org/webrtc/RtpSender"); | 280 jclass j_rtp_sender_class = FindClass(jni, "org/webrtc/RtpSender"); |
| 226 jmethodID j_rtp_sender_ctor = | 281 jmethodID j_rtp_sender_ctor = |
| 227 GetMethodID(jni, j_rtp_sender_class, "<init>", "(J)V"); | 282 GetMethodID(jni, j_rtp_sender_class, "<init>", "(J)V"); |
| 228 | 283 |
| 229 auto senders = ExtractNativePC(jni, j_pc)->GetSenders(); | 284 auto senders = ExtractNativePC(jni, j_pc)->GetSenders(); |
| 230 for (const auto& sender : senders) { | 285 for (const auto& sender : senders) { |
| 231 jlong nativeSenderPtr = jlongFromPointer(sender.get()); | 286 jlong nativeSenderPtr = jlongFromPointer(sender.get()); |
| 232 jobject j_sender = | 287 jobject j_sender = |
| 233 jni->NewObject(j_rtp_sender_class, j_rtp_sender_ctor, nativeSenderPtr); | 288 jni->NewObject(j_rtp_sender_class, j_rtp_sender_ctor, nativeSenderPtr); |
| 234 CHECK_EXCEPTION(jni) << "error during NewObject"; | 289 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 235 // Sender is now owned by the Java object, and will be freed from | 290 // Sender is now owned by the Java object, and will be freed from |
| 236 // RtpSender.dispose(), called by PeerConnection.dispose() or getSenders(). | 291 // RtpSender.dispose(), called by PeerConnection.dispose() or getSenders(). |
| 237 sender->AddRef(); | 292 sender->AddRef(); |
| 238 jni->CallBooleanMethod(j_senders, j_array_list_add, j_sender); | 293 jni->CallBooleanMethod(j_senders, j_array_list_add, j_sender); |
| 239 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; | 294 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; |
| 240 } | 295 } |
| 241 return j_senders; | 296 return j_senders; |
| 242 } | 297 } |
| 243 | 298 |
| 244 JOW(jobject, PeerConnection_nativeGetReceivers)(JNIEnv* jni, jobject j_pc) { | 299 JNI_FUNCTION_DECLARATION(jobject, |
| 300 PeerConnection_nativeGetReceivers, |
| 301 JNIEnv* jni, |
| 302 jobject j_pc) { |
| 245 jclass j_array_list_class = FindClass(jni, "java/util/ArrayList"); | 303 jclass j_array_list_class = FindClass(jni, "java/util/ArrayList"); |
| 246 jmethodID j_array_list_ctor = | 304 jmethodID j_array_list_ctor = |
| 247 GetMethodID(jni, j_array_list_class, "<init>", "()V"); | 305 GetMethodID(jni, j_array_list_class, "<init>", "()V"); |
| 248 jmethodID j_array_list_add = | 306 jmethodID j_array_list_add = |
| 249 GetMethodID(jni, j_array_list_class, "add", "(Ljava/lang/Object;)Z"); | 307 GetMethodID(jni, j_array_list_class, "add", "(Ljava/lang/Object;)Z"); |
| 250 jobject j_receivers = jni->NewObject(j_array_list_class, j_array_list_ctor); | 308 jobject j_receivers = jni->NewObject(j_array_list_class, j_array_list_ctor); |
| 251 CHECK_EXCEPTION(jni) << "error during NewObject"; | 309 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 252 | 310 |
| 253 jclass j_rtp_receiver_class = FindClass(jni, "org/webrtc/RtpReceiver"); | 311 jclass j_rtp_receiver_class = FindClass(jni, "org/webrtc/RtpReceiver"); |
| 254 jmethodID j_rtp_receiver_ctor = | 312 jmethodID j_rtp_receiver_ctor = |
| 255 GetMethodID(jni, j_rtp_receiver_class, "<init>", "(J)V"); | 313 GetMethodID(jni, j_rtp_receiver_class, "<init>", "(J)V"); |
| 256 | 314 |
| 257 auto receivers = ExtractNativePC(jni, j_pc)->GetReceivers(); | 315 auto receivers = ExtractNativePC(jni, j_pc)->GetReceivers(); |
| 258 for (const auto& receiver : receivers) { | 316 for (const auto& receiver : receivers) { |
| 259 jlong nativeReceiverPtr = jlongFromPointer(receiver.get()); | 317 jlong nativeReceiverPtr = jlongFromPointer(receiver.get()); |
| 260 jobject j_receiver = jni->NewObject(j_rtp_receiver_class, | 318 jobject j_receiver = jni->NewObject(j_rtp_receiver_class, |
| 261 j_rtp_receiver_ctor, nativeReceiverPtr); | 319 j_rtp_receiver_ctor, nativeReceiverPtr); |
| 262 CHECK_EXCEPTION(jni) << "error during NewObject"; | 320 CHECK_EXCEPTION(jni) << "error during NewObject"; |
| 263 // Receiver is now owned by Java object, and will be freed from there. | 321 // Receiver is now owned by Java object, and will be freed from there. |
| 264 receiver->AddRef(); | 322 receiver->AddRef(); |
| 265 jni->CallBooleanMethod(j_receivers, j_array_list_add, j_receiver); | 323 jni->CallBooleanMethod(j_receivers, j_array_list_add, j_receiver); |
| 266 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; | 324 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; |
| 267 } | 325 } |
| 268 return j_receivers; | 326 return j_receivers; |
| 269 } | 327 } |
| 270 | 328 |
| 271 JOW(bool, PeerConnection_nativeOldGetStats) | 329 JNI_FUNCTION_DECLARATION(bool, |
| 272 (JNIEnv* jni, jobject j_pc, jobject j_observer, jlong native_track) { | 330 PeerConnection_nativeOldGetStats, |
| 331 JNIEnv* jni, |
| 332 jobject j_pc, |
| 333 jobject j_observer, |
| 334 jlong native_track) { |
| 273 rtc::scoped_refptr<StatsObserverJni> observer( | 335 rtc::scoped_refptr<StatsObserverJni> observer( |
| 274 new rtc::RefCountedObject<StatsObserverJni>(jni, j_observer)); | 336 new rtc::RefCountedObject<StatsObserverJni>(jni, j_observer)); |
| 275 return ExtractNativePC(jni, j_pc)->GetStats( | 337 return ExtractNativePC(jni, j_pc)->GetStats( |
| 276 observer, | 338 observer, |
| 277 reinterpret_cast<webrtc::MediaStreamTrackInterface*>(native_track), | 339 reinterpret_cast<webrtc::MediaStreamTrackInterface*>(native_track), |
| 278 webrtc::PeerConnectionInterface::kStatsOutputLevelStandard); | 340 webrtc::PeerConnectionInterface::kStatsOutputLevelStandard); |
| 279 } | 341 } |
| 280 | 342 |
| 281 JOW(void, PeerConnection_nativeNewGetStats) | 343 JNI_FUNCTION_DECLARATION(void, |
| 282 (JNIEnv* jni, jobject j_pc, jobject j_callback) { | 344 PeerConnection_nativeNewGetStats, |
| 345 JNIEnv* jni, |
| 346 jobject j_pc, |
| 347 jobject j_callback) { |
| 283 rtc::scoped_refptr<RTCStatsCollectorCallbackWrapper> callback( | 348 rtc::scoped_refptr<RTCStatsCollectorCallbackWrapper> callback( |
| 284 new rtc::RefCountedObject<RTCStatsCollectorCallbackWrapper>(jni, | 349 new rtc::RefCountedObject<RTCStatsCollectorCallbackWrapper>(jni, |
| 285 j_callback)); | 350 j_callback)); |
| 286 ExtractNativePC(jni, j_pc)->GetStats(callback); | 351 ExtractNativePC(jni, j_pc)->GetStats(callback); |
| 287 } | 352 } |
| 288 | 353 |
| 289 JOW(jboolean, PeerConnection_setBitrate) | 354 JNI_FUNCTION_DECLARATION(jboolean, |
| 290 (JNIEnv* jni, jobject j_pc, jobject j_min, jobject j_current, jobject j_max) { | 355 PeerConnection_setBitrate, |
| 356 JNIEnv* jni, |
| 357 jobject j_pc, |
| 358 jobject j_min, |
| 359 jobject j_current, |
| 360 jobject j_max) { |
| 291 webrtc::PeerConnectionInterface::BitrateParameters params; | 361 webrtc::PeerConnectionInterface::BitrateParameters params; |
| 292 jclass j_integer_class = jni->FindClass("java/lang/Integer"); | 362 jclass j_integer_class = jni->FindClass("java/lang/Integer"); |
| 293 jmethodID int_value_id = GetMethodID(jni, j_integer_class, "intValue", "()I"); | 363 jmethodID int_value_id = GetMethodID(jni, j_integer_class, "intValue", "()I"); |
| 294 if (!IsNull(jni, j_min)) { | 364 if (!IsNull(jni, j_min)) { |
| 295 int min_value = jni->CallIntMethod(j_min, int_value_id); | 365 int min_value = jni->CallIntMethod(j_min, int_value_id); |
| 296 params.min_bitrate_bps = rtc::Optional<int>(min_value); | 366 params.min_bitrate_bps = rtc::Optional<int>(min_value); |
| 297 } | 367 } |
| 298 if (!IsNull(jni, j_current)) { | 368 if (!IsNull(jni, j_current)) { |
| 299 int current_value = jni->CallIntMethod(j_current, int_value_id); | 369 int current_value = jni->CallIntMethod(j_current, int_value_id); |
| 300 params.current_bitrate_bps = rtc::Optional<int>(current_value); | 370 params.current_bitrate_bps = rtc::Optional<int>(current_value); |
| 301 } | 371 } |
| 302 if (!IsNull(jni, j_max)) { | 372 if (!IsNull(jni, j_max)) { |
| 303 int max_value = jni->CallIntMethod(j_max, int_value_id); | 373 int max_value = jni->CallIntMethod(j_max, int_value_id); |
| 304 params.max_bitrate_bps = rtc::Optional<int>(max_value); | 374 params.max_bitrate_bps = rtc::Optional<int>(max_value); |
| 305 } | 375 } |
| 306 return ExtractNativePC(jni, j_pc)->SetBitrate(params).ok(); | 376 return ExtractNativePC(jni, j_pc)->SetBitrate(params).ok(); |
| 307 } | 377 } |
| 308 | 378 |
| 309 JOW(bool, PeerConnection_nativeStartRtcEventLog) | 379 JNI_FUNCTION_DECLARATION(bool, |
| 310 (JNIEnv* jni, jobject j_pc, int file_descriptor, int max_size_bytes) { | 380 PeerConnection_nativeStartRtcEventLog, |
| 381 JNIEnv* jni, |
| 382 jobject j_pc, |
| 383 int file_descriptor, |
| 384 int max_size_bytes) { |
| 311 return ExtractNativePC(jni, j_pc)->StartRtcEventLog(file_descriptor, | 385 return ExtractNativePC(jni, j_pc)->StartRtcEventLog(file_descriptor, |
| 312 max_size_bytes); | 386 max_size_bytes); |
| 313 } | 387 } |
| 314 | 388 |
| 315 JOW(void, PeerConnection_nativeStopRtcEventLog)(JNIEnv* jni, jobject j_pc) { | 389 JNI_FUNCTION_DECLARATION(void, |
| 390 PeerConnection_nativeStopRtcEventLog, |
| 391 JNIEnv* jni, |
| 392 jobject j_pc) { |
| 316 ExtractNativePC(jni, j_pc)->StopRtcEventLog(); | 393 ExtractNativePC(jni, j_pc)->StopRtcEventLog(); |
| 317 } | 394 } |
| 318 | 395 |
| 319 JOW(jobject, PeerConnection_signalingState)(JNIEnv* jni, jobject j_pc) { | 396 JNI_FUNCTION_DECLARATION(jobject, |
| 397 PeerConnection_signalingState, |
| 398 JNIEnv* jni, |
| 399 jobject j_pc) { |
| 320 webrtc::PeerConnectionInterface::SignalingState state = | 400 webrtc::PeerConnectionInterface::SignalingState state = |
| 321 ExtractNativePC(jni, j_pc)->signaling_state(); | 401 ExtractNativePC(jni, j_pc)->signaling_state(); |
| 322 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$SignalingState", | 402 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$SignalingState", |
| 323 state); | 403 state); |
| 324 } | 404 } |
| 325 | 405 |
| 326 JOW(jobject, PeerConnection_iceConnectionState)(JNIEnv* jni, jobject j_pc) { | 406 JNI_FUNCTION_DECLARATION(jobject, |
| 407 PeerConnection_iceConnectionState, |
| 408 JNIEnv* jni, |
| 409 jobject j_pc) { |
| 327 webrtc::PeerConnectionInterface::IceConnectionState state = | 410 webrtc::PeerConnectionInterface::IceConnectionState state = |
| 328 ExtractNativePC(jni, j_pc)->ice_connection_state(); | 411 ExtractNativePC(jni, j_pc)->ice_connection_state(); |
| 329 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$IceConnectionState", | 412 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$IceConnectionState", |
| 330 state); | 413 state); |
| 331 } | 414 } |
| 332 | 415 |
| 333 JOW(jobject, PeerConnection_iceGatheringState)(JNIEnv* jni, jobject j_pc) { | 416 JNI_FUNCTION_DECLARATION(jobject, |
| 417 PeerConnection_iceGatheringState, |
| 418 JNIEnv* jni, |
| 419 jobject j_pc) { |
| 334 webrtc::PeerConnectionInterface::IceGatheringState state = | 420 webrtc::PeerConnectionInterface::IceGatheringState state = |
| 335 ExtractNativePC(jni, j_pc)->ice_gathering_state(); | 421 ExtractNativePC(jni, j_pc)->ice_gathering_state(); |
| 336 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$IceGatheringState", | 422 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$IceGatheringState", |
| 337 state); | 423 state); |
| 338 } | 424 } |
| 339 | 425 |
| 340 JOW(void, PeerConnection_close)(JNIEnv* jni, jobject j_pc) { | 426 JNI_FUNCTION_DECLARATION(void, |
| 427 PeerConnection_close, |
| 428 JNIEnv* jni, |
| 429 jobject j_pc) { |
| 341 ExtractNativePC(jni, j_pc)->Close(); | 430 ExtractNativePC(jni, j_pc)->Close(); |
| 342 return; | 431 return; |
| 343 } | 432 } |
| 344 | 433 |
| 345 } // namespace webrtc_jni | 434 } // namespace webrtc_jni |
| OLD | NEW |