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

Side by Side Diff: webrtc/sdk/android/src/jni/pc/peerconnection_jni.cc

Issue 3009613002: Android: Replace webrtc_jni namespace with nested jni namespace (Closed)
Patch Set: Rebase Created 3 years, 3 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 27 matching lines...) Expand all
38 #include "webrtc/sdk/android/src/jni/classreferenceholder.h" 38 #include "webrtc/sdk/android/src/jni/classreferenceholder.h"
39 #include "webrtc/sdk/android/src/jni/jni_helpers.h" 39 #include "webrtc/sdk/android/src/jni/jni_helpers.h"
40 #include "webrtc/sdk/android/src/jni/pc/java_native_conversion.h" 40 #include "webrtc/sdk/android/src/jni/pc/java_native_conversion.h"
41 #include "webrtc/sdk/android/src/jni/pc/mediaconstraints_jni.h" 41 #include "webrtc/sdk/android/src/jni/pc/mediaconstraints_jni.h"
42 #include "webrtc/sdk/android/src/jni/pc/peerconnectionobserver_jni.h" 42 #include "webrtc/sdk/android/src/jni/pc/peerconnectionobserver_jni.h"
43 #include "webrtc/sdk/android/src/jni/pc/rtcstatscollectorcallbackwrapper.h" 43 #include "webrtc/sdk/android/src/jni/pc/rtcstatscollectorcallbackwrapper.h"
44 #include "webrtc/sdk/android/src/jni/pc/sdpobserver_jni.h" 44 #include "webrtc/sdk/android/src/jni/pc/sdpobserver_jni.h"
45 #include "webrtc/sdk/android/src/jni/pc/statsobserver_jni.h" 45 #include "webrtc/sdk/android/src/jni/pc/statsobserver_jni.h"
46 #include "webrtc/system_wrappers/include/trace.h" 46 #include "webrtc/system_wrappers/include/trace.h"
47 47
48 namespace webrtc_jni { 48 namespace webrtc {
49 namespace jni {
49 50
50 static rtc::scoped_refptr<webrtc::PeerConnectionInterface> ExtractNativePC( 51 static rtc::scoped_refptr<PeerConnectionInterface> ExtractNativePC(
51 JNIEnv* jni, 52 JNIEnv* jni,
52 jobject j_pc) { 53 jobject j_pc) {
53 jfieldID native_pc_id = 54 jfieldID native_pc_id =
54 GetFieldID(jni, GetObjectClass(jni, j_pc), "nativePeerConnection", "J"); 55 GetFieldID(jni, GetObjectClass(jni, j_pc), "nativePeerConnection", "J");
55 jlong j_p = GetLongField(jni, j_pc, native_pc_id); 56 jlong j_p = GetLongField(jni, j_pc, native_pc_id);
56 return rtc::scoped_refptr<webrtc::PeerConnectionInterface>( 57 return rtc::scoped_refptr<PeerConnectionInterface>(
57 reinterpret_cast<webrtc::PeerConnectionInterface*>(j_p)); 58 reinterpret_cast<PeerConnectionInterface*>(j_p));
58 } 59 }
59 60
60 JNI_FUNCTION_DECLARATION(void, 61 JNI_FUNCTION_DECLARATION(void,
61 PeerConnection_freeObserver, 62 PeerConnection_freeObserver,
62 JNIEnv*, 63 JNIEnv*,
63 jclass, 64 jclass,
64 jlong j_p) { 65 jlong j_p) {
65 PeerConnectionObserverJni* p = 66 PeerConnectionObserverJni* p =
66 reinterpret_cast<PeerConnectionObserverJni*>(j_p); 67 reinterpret_cast<PeerConnectionObserverJni*>(j_p);
67 delete p; 68 delete p;
68 } 69 }
69 70
70 JNI_FUNCTION_DECLARATION(jobject, 71 JNI_FUNCTION_DECLARATION(jobject,
71 PeerConnection_getLocalDescription, 72 PeerConnection_getLocalDescription,
72 JNIEnv* jni, 73 JNIEnv* jni,
73 jobject j_pc) { 74 jobject j_pc) {
74 const webrtc::SessionDescriptionInterface* sdp = 75 const SessionDescriptionInterface* sdp =
75 ExtractNativePC(jni, j_pc)->local_description(); 76 ExtractNativePC(jni, j_pc)->local_description();
76 return sdp ? NativeToJavaSessionDescription(jni, sdp) : NULL; 77 return sdp ? NativeToJavaSessionDescription(jni, sdp) : NULL;
77 } 78 }
78 79
79 JNI_FUNCTION_DECLARATION(jobject, 80 JNI_FUNCTION_DECLARATION(jobject,
80 PeerConnection_getRemoteDescription, 81 PeerConnection_getRemoteDescription,
81 JNIEnv* jni, 82 JNIEnv* jni,
82 jobject j_pc) { 83 jobject j_pc) {
83 const webrtc::SessionDescriptionInterface* sdp = 84 const SessionDescriptionInterface* sdp =
84 ExtractNativePC(jni, j_pc)->remote_description(); 85 ExtractNativePC(jni, j_pc)->remote_description();
85 return sdp ? NativeToJavaSessionDescription(jni, sdp) : NULL; 86 return sdp ? NativeToJavaSessionDescription(jni, sdp) : NULL;
86 } 87 }
87 88
88 JNI_FUNCTION_DECLARATION(jobject, 89 JNI_FUNCTION_DECLARATION(jobject,
89 PeerConnection_createDataChannel, 90 PeerConnection_createDataChannel,
90 JNIEnv* jni, 91 JNIEnv* jni,
91 jobject j_pc, 92 jobject j_pc,
92 jstring j_label, 93 jstring j_label,
93 jobject j_init) { 94 jobject j_init) {
94 webrtc::DataChannelInit init = JavaToNativeDataChannelInit(jni, j_init); 95 DataChannelInit init = JavaToNativeDataChannelInit(jni, j_init);
95 rtc::scoped_refptr<webrtc::DataChannelInterface> channel( 96 rtc::scoped_refptr<DataChannelInterface> channel(
96 ExtractNativePC(jni, j_pc)->CreateDataChannel( 97 ExtractNativePC(jni, j_pc)->CreateDataChannel(
97 JavaToStdString(jni, j_label), &init)); 98 JavaToStdString(jni, j_label), &init));
98 // Mustn't pass channel.get() directly through NewObject to avoid reading its 99 // Mustn't pass channel.get() directly through NewObject to avoid reading its
99 // vararg parameter as 64-bit and reading memory that doesn't belong to the 100 // vararg parameter as 64-bit and reading memory that doesn't belong to the
100 // 32-bit parameter. 101 // 32-bit parameter.
101 jlong nativeChannelPtr = jlongFromPointer(channel.get()); 102 jlong nativeChannelPtr = jlongFromPointer(channel.get());
102 if (!nativeChannelPtr) { 103 if (!nativeChannelPtr) {
103 LOG(LS_ERROR) << "Failed to create DataChannel"; 104 LOG(LS_ERROR) << "Failed to create DataChannel";
104 return nullptr; 105 return nullptr;
105 } 106 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 JNI_FUNCTION_DECLARATION(jboolean, 171 JNI_FUNCTION_DECLARATION(jboolean,
171 PeerConnection_nativeSetConfiguration, 172 PeerConnection_nativeSetConfiguration,
172 JNIEnv* jni, 173 JNIEnv* jni,
173 jobject j_pc, 174 jobject j_pc,
174 jobject j_rtc_config, 175 jobject j_rtc_config,
175 jlong native_observer) { 176 jlong native_observer) {
176 // Need to merge constraints into RTCConfiguration again, which are stored 177 // Need to merge constraints into RTCConfiguration again, which are stored
177 // in the observer object. 178 // in the observer object.
178 PeerConnectionObserverJni* observer = 179 PeerConnectionObserverJni* observer =
179 reinterpret_cast<PeerConnectionObserverJni*>(native_observer); 180 reinterpret_cast<PeerConnectionObserverJni*>(native_observer);
180 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config( 181 PeerConnectionInterface::RTCConfiguration rtc_config(
181 webrtc::PeerConnectionInterface::RTCConfigurationType::kAggressive); 182 PeerConnectionInterface::RTCConfigurationType::kAggressive);
182 JavaToNativeRTCConfiguration(jni, j_rtc_config, &rtc_config); 183 JavaToNativeRTCConfiguration(jni, j_rtc_config, &rtc_config);
183 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config); 184 CopyConstraintsIntoRtcConfiguration(observer->constraints(), &rtc_config);
184 return ExtractNativePC(jni, j_pc)->SetConfiguration(rtc_config); 185 return ExtractNativePC(jni, j_pc)->SetConfiguration(rtc_config);
185 } 186 }
186 187
187 JNI_FUNCTION_DECLARATION(jboolean, 188 JNI_FUNCTION_DECLARATION(jboolean,
188 PeerConnection_nativeAddIceCandidate, 189 PeerConnection_nativeAddIceCandidate,
189 JNIEnv* jni, 190 JNIEnv* jni,
190 jobject j_pc, 191 jobject j_pc,
191 jstring j_sdp_mid, 192 jstring j_sdp_mid,
192 jint j_sdp_mline_index, 193 jint j_sdp_mline_index,
193 jstring j_candidate_sdp) { 194 jstring j_candidate_sdp) {
194 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid); 195 std::string sdp_mid = JavaToStdString(jni, j_sdp_mid);
195 std::string sdp = JavaToStdString(jni, j_candidate_sdp); 196 std::string sdp = JavaToStdString(jni, j_candidate_sdp);
196 std::unique_ptr<webrtc::IceCandidateInterface> candidate( 197 std::unique_ptr<IceCandidateInterface> candidate(
197 webrtc::CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, nullptr)); 198 CreateIceCandidate(sdp_mid, j_sdp_mline_index, sdp, nullptr));
198 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get()); 199 return ExtractNativePC(jni, j_pc)->AddIceCandidate(candidate.get());
199 } 200 }
200 201
201 JNI_FUNCTION_DECLARATION(jboolean, 202 JNI_FUNCTION_DECLARATION(jboolean,
202 PeerConnection_nativeRemoveIceCandidates, 203 PeerConnection_nativeRemoveIceCandidates,
203 JNIEnv* jni, 204 JNIEnv* jni,
204 jobject j_pc, 205 jobject j_pc,
205 jobjectArray j_candidates) { 206 jobjectArray j_candidates) {
206 std::vector<cricket::Candidate> candidates; 207 std::vector<cricket::Candidate> candidates;
207 size_t num_candidates = jni->GetArrayLength(j_candidates); 208 size_t num_candidates = jni->GetArrayLength(j_candidates);
208 for (size_t i = 0; i < num_candidates; ++i) { 209 for (size_t i = 0; i < num_candidates; ++i) {
209 jobject j_candidate = jni->GetObjectArrayElement(j_candidates, i); 210 jobject j_candidate = jni->GetObjectArrayElement(j_candidates, i);
210 candidates.push_back(JavaToNativeCandidate(jni, j_candidate)); 211 candidates.push_back(JavaToNativeCandidate(jni, j_candidate));
211 } 212 }
212 return ExtractNativePC(jni, j_pc)->RemoveIceCandidates(candidates); 213 return ExtractNativePC(jni, j_pc)->RemoveIceCandidates(candidates);
213 } 214 }
214 215
215 JNI_FUNCTION_DECLARATION(jboolean, 216 JNI_FUNCTION_DECLARATION(jboolean,
216 PeerConnection_nativeAddLocalStream, 217 PeerConnection_nativeAddLocalStream,
217 JNIEnv* jni, 218 JNIEnv* jni,
218 jobject j_pc, 219 jobject j_pc,
219 jlong native_stream) { 220 jlong native_stream) {
220 return ExtractNativePC(jni, j_pc)->AddStream( 221 return ExtractNativePC(jni, j_pc)->AddStream(
221 reinterpret_cast<webrtc::MediaStreamInterface*>(native_stream)); 222 reinterpret_cast<MediaStreamInterface*>(native_stream));
222 } 223 }
223 224
224 JNI_FUNCTION_DECLARATION(void, 225 JNI_FUNCTION_DECLARATION(void,
225 PeerConnection_nativeRemoveLocalStream, 226 PeerConnection_nativeRemoveLocalStream,
226 JNIEnv* jni, 227 JNIEnv* jni,
227 jobject j_pc, 228 jobject j_pc,
228 jlong native_stream) { 229 jlong native_stream) {
229 ExtractNativePC(jni, j_pc)->RemoveStream( 230 ExtractNativePC(jni, j_pc)->RemoveStream(
230 reinterpret_cast<webrtc::MediaStreamInterface*>(native_stream)); 231 reinterpret_cast<MediaStreamInterface*>(native_stream));
231 } 232 }
232 233
233 JNI_FUNCTION_DECLARATION(jobject, 234 JNI_FUNCTION_DECLARATION(jobject,
234 PeerConnection_nativeCreateSender, 235 PeerConnection_nativeCreateSender,
235 JNIEnv* jni, 236 JNIEnv* jni,
236 jobject j_pc, 237 jobject j_pc,
237 jstring j_kind, 238 jstring j_kind,
238 jstring j_stream_id) { 239 jstring j_stream_id) {
239 jclass j_rtp_sender_class = FindClass(jni, "org/webrtc/RtpSender"); 240 jclass j_rtp_sender_class = FindClass(jni, "org/webrtc/RtpSender");
240 jmethodID j_rtp_sender_ctor = 241 jmethodID j_rtp_sender_ctor =
241 GetMethodID(jni, j_rtp_sender_class, "<init>", "(J)V"); 242 GetMethodID(jni, j_rtp_sender_class, "<init>", "(J)V");
242 243
243 std::string kind = JavaToStdString(jni, j_kind); 244 std::string kind = JavaToStdString(jni, j_kind);
244 std::string stream_id = JavaToStdString(jni, j_stream_id); 245 std::string stream_id = JavaToStdString(jni, j_stream_id);
245 rtc::scoped_refptr<webrtc::RtpSenderInterface> sender = 246 rtc::scoped_refptr<RtpSenderInterface> sender =
246 ExtractNativePC(jni, j_pc)->CreateSender(kind, stream_id); 247 ExtractNativePC(jni, j_pc)->CreateSender(kind, stream_id);
247 if (!sender.get()) { 248 if (!sender.get()) {
248 return nullptr; 249 return nullptr;
249 } 250 }
250 jlong nativeSenderPtr = jlongFromPointer(sender.get()); 251 jlong nativeSenderPtr = jlongFromPointer(sender.get());
251 jobject j_sender = 252 jobject j_sender =
252 jni->NewObject(j_rtp_sender_class, j_rtp_sender_ctor, nativeSenderPtr); 253 jni->NewObject(j_rtp_sender_class, j_rtp_sender_ctor, nativeSenderPtr);
253 CHECK_EXCEPTION(jni) << "error during NewObject"; 254 CHECK_EXCEPTION(jni) << "error during NewObject";
254 // Sender is now owned by the Java object, and will be freed from 255 // Sender is now owned by the Java object, and will be freed from
255 // RtpSender.dispose(), called by PeerConnection.dispose() or getSenders(). 256 // RtpSender.dispose(), called by PeerConnection.dispose() or getSenders().
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 321
321 JNI_FUNCTION_DECLARATION(bool, 322 JNI_FUNCTION_DECLARATION(bool,
322 PeerConnection_nativeOldGetStats, 323 PeerConnection_nativeOldGetStats,
323 JNIEnv* jni, 324 JNIEnv* jni,
324 jobject j_pc, 325 jobject j_pc,
325 jobject j_observer, 326 jobject j_observer,
326 jlong native_track) { 327 jlong native_track) {
327 rtc::scoped_refptr<StatsObserverJni> observer( 328 rtc::scoped_refptr<StatsObserverJni> observer(
328 new rtc::RefCountedObject<StatsObserverJni>(jni, j_observer)); 329 new rtc::RefCountedObject<StatsObserverJni>(jni, j_observer));
329 return ExtractNativePC(jni, j_pc)->GetStats( 330 return ExtractNativePC(jni, j_pc)->GetStats(
330 observer, 331 observer, reinterpret_cast<MediaStreamTrackInterface*>(native_track),
331 reinterpret_cast<webrtc::MediaStreamTrackInterface*>(native_track), 332 PeerConnectionInterface::kStatsOutputLevelStandard);
332 webrtc::PeerConnectionInterface::kStatsOutputLevelStandard);
333 } 333 }
334 334
335 JNI_FUNCTION_DECLARATION(void, 335 JNI_FUNCTION_DECLARATION(void,
336 PeerConnection_nativeNewGetStats, 336 PeerConnection_nativeNewGetStats,
337 JNIEnv* jni, 337 JNIEnv* jni,
338 jobject j_pc, 338 jobject j_pc,
339 jobject j_callback) { 339 jobject j_callback) {
340 rtc::scoped_refptr<RTCStatsCollectorCallbackWrapper> callback( 340 rtc::scoped_refptr<RTCStatsCollectorCallbackWrapper> callback(
341 new rtc::RefCountedObject<RTCStatsCollectorCallbackWrapper>(jni, 341 new rtc::RefCountedObject<RTCStatsCollectorCallbackWrapper>(jni,
342 j_callback)); 342 j_callback));
343 ExtractNativePC(jni, j_pc)->GetStats(callback); 343 ExtractNativePC(jni, j_pc)->GetStats(callback);
344 } 344 }
345 345
346 JNI_FUNCTION_DECLARATION(jboolean, 346 JNI_FUNCTION_DECLARATION(jboolean,
347 PeerConnection_setBitrate, 347 PeerConnection_setBitrate,
348 JNIEnv* jni, 348 JNIEnv* jni,
349 jobject j_pc, 349 jobject j_pc,
350 jobject j_min, 350 jobject j_min,
351 jobject j_current, 351 jobject j_current,
352 jobject j_max) { 352 jobject j_max) {
353 webrtc::PeerConnectionInterface::BitrateParameters params; 353 PeerConnectionInterface::BitrateParameters params;
354 jclass j_integer_class = jni->FindClass("java/lang/Integer"); 354 jclass j_integer_class = jni->FindClass("java/lang/Integer");
355 jmethodID int_value_id = GetMethodID(jni, j_integer_class, "intValue", "()I"); 355 jmethodID int_value_id = GetMethodID(jni, j_integer_class, "intValue", "()I");
356 if (!IsNull(jni, j_min)) { 356 if (!IsNull(jni, j_min)) {
357 int min_value = jni->CallIntMethod(j_min, int_value_id); 357 int min_value = jni->CallIntMethod(j_min, int_value_id);
358 params.min_bitrate_bps = rtc::Optional<int>(min_value); 358 params.min_bitrate_bps = rtc::Optional<int>(min_value);
359 } 359 }
360 if (!IsNull(jni, j_current)) { 360 if (!IsNull(jni, j_current)) {
361 int current_value = jni->CallIntMethod(j_current, int_value_id); 361 int current_value = jni->CallIntMethod(j_current, int_value_id);
362 params.current_bitrate_bps = rtc::Optional<int>(current_value); 362 params.current_bitrate_bps = rtc::Optional<int>(current_value);
363 } 363 }
(...skipping 18 matching lines...) Expand all
382 PeerConnection_nativeStopRtcEventLog, 382 PeerConnection_nativeStopRtcEventLog,
383 JNIEnv* jni, 383 JNIEnv* jni,
384 jobject j_pc) { 384 jobject j_pc) {
385 ExtractNativePC(jni, j_pc)->StopRtcEventLog(); 385 ExtractNativePC(jni, j_pc)->StopRtcEventLog();
386 } 386 }
387 387
388 JNI_FUNCTION_DECLARATION(jobject, 388 JNI_FUNCTION_DECLARATION(jobject,
389 PeerConnection_signalingState, 389 PeerConnection_signalingState,
390 JNIEnv* jni, 390 JNIEnv* jni,
391 jobject j_pc) { 391 jobject j_pc) {
392 webrtc::PeerConnectionInterface::SignalingState state = 392 PeerConnectionInterface::SignalingState state =
393 ExtractNativePC(jni, j_pc)->signaling_state(); 393 ExtractNativePC(jni, j_pc)->signaling_state();
394 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$SignalingState", 394 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$SignalingState",
395 state); 395 state);
396 } 396 }
397 397
398 JNI_FUNCTION_DECLARATION(jobject, 398 JNI_FUNCTION_DECLARATION(jobject,
399 PeerConnection_iceConnectionState, 399 PeerConnection_iceConnectionState,
400 JNIEnv* jni, 400 JNIEnv* jni,
401 jobject j_pc) { 401 jobject j_pc) {
402 webrtc::PeerConnectionInterface::IceConnectionState state = 402 PeerConnectionInterface::IceConnectionState state =
403 ExtractNativePC(jni, j_pc)->ice_connection_state(); 403 ExtractNativePC(jni, j_pc)->ice_connection_state();
404 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$IceConnectionState", 404 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$IceConnectionState",
405 state); 405 state);
406 } 406 }
407 407
408 JNI_FUNCTION_DECLARATION(jobject, 408 JNI_FUNCTION_DECLARATION(jobject,
409 PeerConnection_iceGatheringState, 409 PeerConnection_iceGatheringState,
410 JNIEnv* jni, 410 JNIEnv* jni,
411 jobject j_pc) { 411 jobject j_pc) {
412 webrtc::PeerConnectionInterface::IceGatheringState state = 412 PeerConnectionInterface::IceGatheringState state =
413 ExtractNativePC(jni, j_pc)->ice_gathering_state(); 413 ExtractNativePC(jni, j_pc)->ice_gathering_state();
414 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$IceGatheringState", 414 return JavaEnumFromIndexAndClassName(jni, "PeerConnection$IceGatheringState",
415 state); 415 state);
416 } 416 }
417 417
418 JNI_FUNCTION_DECLARATION(void, 418 JNI_FUNCTION_DECLARATION(void,
419 PeerConnection_close, 419 PeerConnection_close,
420 JNIEnv* jni, 420 JNIEnv* jni,
421 jobject j_pc) { 421 jobject j_pc) {
422 ExtractNativePC(jni, j_pc)->Close(); 422 ExtractNativePC(jni, j_pc)->Close();
423 return; 423 return;
424 } 424 }
425 425
426 } // namespace webrtc_jni 426 } // namespace jni
427 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/sdk/android/src/jni/pc/ownedfactoryandthreads.cc ('k') | webrtc/sdk/android/src/jni/pc/peerconnectionfactory_jni.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698