OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 // Set in PeerConnectionFactory_initializeAndroidGlobals(). | 133 // Set in PeerConnectionFactory_initializeAndroidGlobals(). |
134 static bool factory_static_initialized = false; | 134 static bool factory_static_initialized = false; |
135 static bool video_hw_acceleration_enabled = true; | 135 static bool video_hw_acceleration_enabled = true; |
136 #endif | 136 #endif |
137 | 137 |
138 extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { | 138 extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) { |
139 jint ret = InitGlobalJniVariables(jvm); | 139 jint ret = InitGlobalJniVariables(jvm); |
140 if (ret < 0) | 140 if (ret < 0) |
141 return -1; | 141 return -1; |
142 | 142 |
143 CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()"; | 143 RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()"; |
144 LoadGlobalClassReferenceHolder(); | 144 LoadGlobalClassReferenceHolder(); |
145 | 145 |
146 return ret; | 146 return ret; |
147 } | 147 } |
148 | 148 |
149 extern "C" void JNIEXPORT JNICALL JNI_OnUnLoad(JavaVM *jvm, void *reserved) { | 149 extern "C" void JNIEXPORT JNICALL JNI_OnUnLoad(JavaVM *jvm, void *reserved) { |
150 FreeGlobalClassReferenceHolder(); | 150 FreeGlobalClassReferenceHolder(); |
151 CHECK(rtc::CleanupSSL()) << "Failed to CleanupSSL()"; | 151 RTC_CHECK(rtc::CleanupSSL()) << "Failed to CleanupSSL()"; |
152 } | 152 } |
153 | 153 |
154 // Return the (singleton) Java Enum object corresponding to |index|; | 154 // Return the (singleton) Java Enum object corresponding to |index|; |
155 // |state_class_fragment| is something like "MediaSource$State". | 155 // |state_class_fragment| is something like "MediaSource$State". |
156 static jobject JavaEnumFromIndex( | 156 static jobject JavaEnumFromIndex( |
157 JNIEnv* jni, const std::string& state_class_fragment, int index) { | 157 JNIEnv* jni, const std::string& state_class_fragment, int index) { |
158 const std::string state_class = "org/webrtc/" + state_class_fragment; | 158 const std::string state_class = "org/webrtc/" + state_class_fragment; |
159 return JavaEnumFromIndex(jni, FindClass(jni, state_class.c_str()), | 159 return JavaEnumFromIndex(jni, FindClass(jni, state_class.c_str()), |
160 state_class, index); | 160 state_class, index); |
161 } | 161 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 212 |
213 virtual ~PCOJava() { | 213 virtual ~PCOJava() { |
214 ScopedLocalRefFrame local_ref_frame(jni()); | 214 ScopedLocalRefFrame local_ref_frame(jni()); |
215 while (!remote_streams_.empty()) | 215 while (!remote_streams_.empty()) |
216 DisposeRemoteStream(remote_streams_.begin()); | 216 DisposeRemoteStream(remote_streams_.begin()); |
217 } | 217 } |
218 | 218 |
219 void OnIceCandidate(const IceCandidateInterface* candidate) override { | 219 void OnIceCandidate(const IceCandidateInterface* candidate) override { |
220 ScopedLocalRefFrame local_ref_frame(jni()); | 220 ScopedLocalRefFrame local_ref_frame(jni()); |
221 std::string sdp; | 221 std::string sdp; |
222 CHECK(candidate->ToString(&sdp)) << "got so far: " << sdp; | 222 RTC_CHECK(candidate->ToString(&sdp)) << "got so far: " << sdp; |
223 jclass candidate_class = FindClass(jni(), "org/webrtc/IceCandidate"); | 223 jclass candidate_class = FindClass(jni(), "org/webrtc/IceCandidate"); |
224 jmethodID ctor = GetMethodID(jni(), candidate_class, | 224 jmethodID ctor = GetMethodID(jni(), candidate_class, |
225 "<init>", "(Ljava/lang/String;ILjava/lang/String;)V"); | 225 "<init>", "(Ljava/lang/String;ILjava/lang/String;)V"); |
226 jstring j_mid = JavaStringFromStdString(jni(), candidate->sdp_mid()); | 226 jstring j_mid = JavaStringFromStdString(jni(), candidate->sdp_mid()); |
227 jstring j_sdp = JavaStringFromStdString(jni(), sdp); | 227 jstring j_sdp = JavaStringFromStdString(jni(), sdp); |
228 jobject j_candidate = jni()->NewObject( | 228 jobject j_candidate = jni()->NewObject( |
229 candidate_class, ctor, j_mid, candidate->sdp_mline_index(), j_sdp); | 229 candidate_class, ctor, j_mid, candidate->sdp_mline_index(), j_sdp); |
230 CHECK_EXCEPTION(jni()) << "error during NewObject"; | 230 CHECK_EXCEPTION(jni()) << "error during NewObject"; |
231 jmethodID m = GetMethodID(jni(), *j_observer_class_, | 231 jmethodID m = GetMethodID(jni(), *j_observer_class_, |
232 "onIceCandidate", "(Lorg/webrtc/IceCandidate;)V"); | 232 "onIceCandidate", "(Lorg/webrtc/IceCandidate;)V"); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 *j_media_stream_class_, | 301 *j_media_stream_class_, |
302 "audioTracks", | 302 "audioTracks", |
303 "Ljava/util/LinkedList;"); | 303 "Ljava/util/LinkedList;"); |
304 jobject audio_tracks = GetObjectField(jni(), j_stream, audio_tracks_id); | 304 jobject audio_tracks = GetObjectField(jni(), j_stream, audio_tracks_id); |
305 jmethodID add = GetMethodID(jni(), | 305 jmethodID add = GetMethodID(jni(), |
306 GetObjectClass(jni(), audio_tracks), | 306 GetObjectClass(jni(), audio_tracks), |
307 "add", | 307 "add", |
308 "(Ljava/lang/Object;)Z"); | 308 "(Ljava/lang/Object;)Z"); |
309 jboolean added = jni()->CallBooleanMethod(audio_tracks, add, j_track); | 309 jboolean added = jni()->CallBooleanMethod(audio_tracks, add, j_track); |
310 CHECK_EXCEPTION(jni()) << "error during CallBooleanMethod"; | 310 CHECK_EXCEPTION(jni()) << "error during CallBooleanMethod"; |
311 CHECK(added); | 311 RTC_CHECK(added); |
312 } | 312 } |
313 | 313 |
314 for (const auto& track : stream->GetVideoTracks()) { | 314 for (const auto& track : stream->GetVideoTracks()) { |
315 jstring id = JavaStringFromStdString(jni(), track->id()); | 315 jstring id = JavaStringFromStdString(jni(), track->id()); |
316 // Java VideoTrack holds one reference. Corresponding Release() is in | 316 // Java VideoTrack holds one reference. Corresponding Release() is in |
317 // MediaStreamTrack_free, triggered by VideoTrack.dispose(). | 317 // MediaStreamTrack_free, triggered by VideoTrack.dispose(). |
318 track->AddRef(); | 318 track->AddRef(); |
319 jobject j_track = | 319 jobject j_track = |
320 jni()->NewObject(*j_video_track_class_, j_video_track_ctor_, | 320 jni()->NewObject(*j_video_track_class_, j_video_track_ctor_, |
321 reinterpret_cast<jlong>(track.get()), id); | 321 reinterpret_cast<jlong>(track.get()), id); |
322 CHECK_EXCEPTION(jni()) << "error during NewObject"; | 322 CHECK_EXCEPTION(jni()) << "error during NewObject"; |
323 jfieldID video_tracks_id = GetFieldID(jni(), | 323 jfieldID video_tracks_id = GetFieldID(jni(), |
324 *j_media_stream_class_, | 324 *j_media_stream_class_, |
325 "videoTracks", | 325 "videoTracks", |
326 "Ljava/util/LinkedList;"); | 326 "Ljava/util/LinkedList;"); |
327 jobject video_tracks = GetObjectField(jni(), j_stream, video_tracks_id); | 327 jobject video_tracks = GetObjectField(jni(), j_stream, video_tracks_id); |
328 jmethodID add = GetMethodID(jni(), | 328 jmethodID add = GetMethodID(jni(), |
329 GetObjectClass(jni(), video_tracks), | 329 GetObjectClass(jni(), video_tracks), |
330 "add", | 330 "add", |
331 "(Ljava/lang/Object;)Z"); | 331 "(Ljava/lang/Object;)Z"); |
332 jboolean added = jni()->CallBooleanMethod(video_tracks, add, j_track); | 332 jboolean added = jni()->CallBooleanMethod(video_tracks, add, j_track); |
333 CHECK_EXCEPTION(jni()) << "error during CallBooleanMethod"; | 333 CHECK_EXCEPTION(jni()) << "error during CallBooleanMethod"; |
334 CHECK(added); | 334 RTC_CHECK(added); |
335 } | 335 } |
336 remote_streams_[stream] = NewGlobalRef(jni(), j_stream); | 336 remote_streams_[stream] = NewGlobalRef(jni(), j_stream); |
337 | 337 |
338 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onAddStream", | 338 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onAddStream", |
339 "(Lorg/webrtc/MediaStream;)V"); | 339 "(Lorg/webrtc/MediaStream;)V"); |
340 jni()->CallVoidMethod(*j_observer_global_, m, j_stream); | 340 jni()->CallVoidMethod(*j_observer_global_, m, j_stream); |
341 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 341 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
342 } | 342 } |
343 | 343 |
344 void OnRemoveStream(MediaStreamInterface* stream) override { | 344 void OnRemoveStream(MediaStreamInterface* stream) override { |
345 ScopedLocalRefFrame local_ref_frame(jni()); | 345 ScopedLocalRefFrame local_ref_frame(jni()); |
346 NativeToJavaStreamsMap::iterator it = remote_streams_.find(stream); | 346 NativeToJavaStreamsMap::iterator it = remote_streams_.find(stream); |
347 CHECK(it != remote_streams_.end()) << "unexpected stream: " << std::hex | 347 RTC_CHECK(it != remote_streams_.end()) << "unexpected stream: " << std::hex |
348 << stream; | 348 << stream; |
349 jobject j_stream = it->second; | 349 jobject j_stream = it->second; |
350 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onRemoveStream", | 350 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onRemoveStream", |
351 "(Lorg/webrtc/MediaStream;)V"); | 351 "(Lorg/webrtc/MediaStream;)V"); |
352 jni()->CallVoidMethod(*j_observer_global_, m, j_stream); | 352 jni()->CallVoidMethod(*j_observer_global_, m, j_stream); |
353 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 353 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
354 DisposeRemoteStream(it); | 354 DisposeRemoteStream(it); |
355 } | 355 } |
356 | 356 |
357 void OnDataChannel(DataChannelInterface* channel) override { | 357 void OnDataChannel(DataChannelInterface* channel) override { |
358 ScopedLocalRefFrame local_ref_frame(jni()); | 358 ScopedLocalRefFrame local_ref_frame(jni()); |
359 jobject j_channel = jni()->NewObject( | 359 jobject j_channel = jni()->NewObject( |
360 *j_data_channel_class_, j_data_channel_ctor_, (jlong)channel); | 360 *j_data_channel_class_, j_data_channel_ctor_, (jlong)channel); |
361 CHECK_EXCEPTION(jni()) << "error during NewObject"; | 361 CHECK_EXCEPTION(jni()) << "error during NewObject"; |
362 | 362 |
363 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onDataChannel", | 363 jmethodID m = GetMethodID(jni(), *j_observer_class_, "onDataChannel", |
364 "(Lorg/webrtc/DataChannel;)V"); | 364 "(Lorg/webrtc/DataChannel;)V"); |
365 jni()->CallVoidMethod(*j_observer_global_, m, j_channel); | 365 jni()->CallVoidMethod(*j_observer_global_, m, j_channel); |
366 | 366 |
367 // Channel is now owned by Java object, and will be freed from | 367 // Channel is now owned by Java object, and will be freed from |
368 // DataChannel.dispose(). Important that this be done _after_ the | 368 // DataChannel.dispose(). Important that this be done _after_ the |
369 // CallVoidMethod above as Java code might call back into native code and be | 369 // CallVoidMethod above as Java code might call back into native code and be |
370 // surprised to see a refcount of 2. | 370 // surprised to see a refcount of 2. |
371 int bumped_count = channel->AddRef(); | 371 int bumped_count = channel->AddRef(); |
372 CHECK(bumped_count == 2) << "Unexpected refcount OnDataChannel"; | 372 RTC_CHECK(bumped_count == 2) << "Unexpected refcount OnDataChannel"; |
373 | 373 |
374 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 374 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
375 } | 375 } |
376 | 376 |
377 void OnRenegotiationNeeded() override { | 377 void OnRenegotiationNeeded() override { |
378 ScopedLocalRefFrame local_ref_frame(jni()); | 378 ScopedLocalRefFrame local_ref_frame(jni()); |
379 jmethodID m = | 379 jmethodID m = |
380 GetMethodID(jni(), *j_observer_class_, "onRenegotiationNeeded", "()V"); | 380 GetMethodID(jni(), *j_observer_class_, "onRenegotiationNeeded", "()V"); |
381 jni()->CallVoidMethod(*j_observer_global_, m); | 381 jni()->CallVoidMethod(*j_observer_global_, m); |
382 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; | 382 CHECK_EXCEPTION(jni()) << "error during CallVoidMethod"; |
383 } | 383 } |
384 | 384 |
385 void SetConstraints(ConstraintsWrapper* constraints) { | 385 void SetConstraints(ConstraintsWrapper* constraints) { |
386 CHECK(!constraints_.get()) << "constraints already set!"; | 386 RTC_CHECK(!constraints_.get()) << "constraints already set!"; |
387 constraints_.reset(constraints); | 387 constraints_.reset(constraints); |
388 } | 388 } |
389 | 389 |
390 const ConstraintsWrapper* constraints() { return constraints_.get(); } | 390 const ConstraintsWrapper* constraints() { return constraints_.get(); } |
391 | 391 |
392 private: | 392 private: |
393 typedef std::map<MediaStreamInterface*, jobject> NativeToJavaStreamsMap; | 393 typedef std::map<MediaStreamInterface*, jobject> NativeToJavaStreamsMap; |
394 | 394 |
395 void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it) { | 395 void DisposeRemoteStream(const NativeToJavaStreamsMap::iterator& it) { |
396 jobject j_stream = it->second; | 396 jobject j_stream = it->second; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; | 475 CHECK_EXCEPTION(jni) << "error during CallBooleanMethod"; |
476 } | 476 } |
477 | 477 |
478 Constraints mandatory_; | 478 Constraints mandatory_; |
479 Constraints optional_; | 479 Constraints optional_; |
480 }; | 480 }; |
481 | 481 |
482 static jobject JavaSdpFromNativeSdp( | 482 static jobject JavaSdpFromNativeSdp( |
483 JNIEnv* jni, const SessionDescriptionInterface* desc) { | 483 JNIEnv* jni, const SessionDescriptionInterface* desc) { |
484 std::string sdp; | 484 std::string sdp; |
485 CHECK(desc->ToString(&sdp)) << "got so far: " << sdp; | 485 RTC_CHECK(desc->ToString(&sdp)) << "got so far: " << sdp; |
486 jstring j_description = JavaStringFromStdString(jni, sdp); | 486 jstring j_description = JavaStringFromStdString(jni, sdp); |
487 | 487 |
488 jclass j_type_class = FindClass( | 488 jclass j_type_class = FindClass( |
489 jni, "org/webrtc/SessionDescription$Type"); | 489 jni, "org/webrtc/SessionDescription$Type"); |
490 jmethodID j_type_from_canonical = GetStaticMethodID( | 490 jmethodID j_type_from_canonical = GetStaticMethodID( |
491 jni, j_type_class, "fromCanonicalForm", | 491 jni, j_type_class, "fromCanonicalForm", |
492 "(Ljava/lang/String;)Lorg/webrtc/SessionDescription$Type;"); | 492 "(Ljava/lang/String;)Lorg/webrtc/SessionDescription$Type;"); |
493 jstring j_type_string = JavaStringFromStdString(jni, desc->type()); | 493 jstring j_type_string = JavaStringFromStdString(jni, desc->type()); |
494 jobject j_type = jni->CallStaticObjectMethod( | 494 jobject j_type = jni->CallStaticObjectMethod( |
495 j_type_class, j_type_from_canonical, j_type_string); | 495 j_type_class, j_type_from_canonical, j_type_string); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 return JavaStringFromStdString(jni, ExtractNativeDC(jni, j_dc)->label()); | 864 return JavaStringFromStdString(jni, ExtractNativeDC(jni, j_dc)->label()); |
865 } | 865 } |
866 | 866 |
867 JOW(jobject, DataChannel_state)(JNIEnv* jni, jobject j_dc) { | 867 JOW(jobject, DataChannel_state)(JNIEnv* jni, jobject j_dc) { |
868 return JavaEnumFromIndex( | 868 return JavaEnumFromIndex( |
869 jni, "DataChannel$State", ExtractNativeDC(jni, j_dc)->state()); | 869 jni, "DataChannel$State", ExtractNativeDC(jni, j_dc)->state()); |
870 } | 870 } |
871 | 871 |
872 JOW(jlong, DataChannel_bufferedAmount)(JNIEnv* jni, jobject j_dc) { | 872 JOW(jlong, DataChannel_bufferedAmount)(JNIEnv* jni, jobject j_dc) { |
873 uint64 buffered_amount = ExtractNativeDC(jni, j_dc)->buffered_amount(); | 873 uint64 buffered_amount = ExtractNativeDC(jni, j_dc)->buffered_amount(); |
874 CHECK_LE(buffered_amount, std::numeric_limits<int64>::max()) | 874 RTC_CHECK_LE(buffered_amount, std::numeric_limits<int64>::max()) |
875 << "buffered_amount overflowed jlong!"; | 875 << "buffered_amount overflowed jlong!"; |
876 return static_cast<jlong>(buffered_amount); | 876 return static_cast<jlong>(buffered_amount); |
877 } | 877 } |
878 | 878 |
879 JOW(void, DataChannel_close)(JNIEnv* jni, jobject j_dc) { | 879 JOW(void, DataChannel_close)(JNIEnv* jni, jobject j_dc) { |
880 ExtractNativeDC(jni, j_dc)->Close(); | 880 ExtractNativeDC(jni, j_dc)->Close(); |
881 } | 881 } |
882 | 882 |
883 JOW(jboolean, DataChannel_sendNative)(JNIEnv* jni, jobject j_dc, | 883 JOW(jboolean, DataChannel_sendNative)(JNIEnv* jni, jobject j_dc, |
884 jbyteArray data, jboolean binary) { | 884 jbyteArray data, jboolean binary) { |
(...skipping 11 matching lines...) Expand all Loading... |
896 | 896 |
897 JOW(void, Logging_nativeEnableTracing)( | 897 JOW(void, Logging_nativeEnableTracing)( |
898 JNIEnv* jni, jclass, jstring j_path, jint nativeLevels, | 898 JNIEnv* jni, jclass, jstring j_path, jint nativeLevels, |
899 jint nativeSeverity) { | 899 jint nativeSeverity) { |
900 std::string path = JavaToStdString(jni, j_path); | 900 std::string path = JavaToStdString(jni, j_path); |
901 if (nativeLevels != webrtc::kTraceNone) { | 901 if (nativeLevels != webrtc::kTraceNone) { |
902 webrtc::Trace::set_level_filter(nativeLevels); | 902 webrtc::Trace::set_level_filter(nativeLevels); |
903 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) | 903 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
904 if (path != "logcat:") { | 904 if (path != "logcat:") { |
905 #endif | 905 #endif |
906 CHECK_EQ(0, webrtc::Trace::SetTraceFile(path.c_str(), false)) | 906 RTC_CHECK_EQ(0, webrtc::Trace::SetTraceFile(path.c_str(), false)) |
907 << "SetTraceFile failed"; | 907 << "SetTraceFile failed"; |
908 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) | 908 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
909 } else { | 909 } else { |
910 // Intentionally leak this to avoid needing to reason about its lifecycle. | 910 // Intentionally leak this to avoid needing to reason about its lifecycle. |
911 // It keeps no state and functions only as a dispatch point. | 911 // It keeps no state and functions only as a dispatch point. |
912 static LogcatTraceContext* g_trace_callback = new LogcatTraceContext(); | 912 static LogcatTraceContext* g_trace_callback = new LogcatTraceContext(); |
913 } | 913 } |
914 #endif | 914 #endif |
915 } | 915 } |
916 if (nativeSeverity >= rtc::LS_SENSITIVE && nativeSeverity <= rtc::LS_ERROR) { | 916 if (nativeSeverity >= rtc::LS_SENSITIVE && nativeSeverity <= rtc::LS_ERROR) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1080 // ThreadManager only WrapCurrentThread()s the thread where it is first | 1080 // ThreadManager only WrapCurrentThread()s the thread where it is first |
1081 // created. Since the semantics around when auto-wrapping happens in | 1081 // created. Since the semantics around when auto-wrapping happens in |
1082 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think | 1082 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think |
1083 // about ramifications of auto-wrapping there. | 1083 // about ramifications of auto-wrapping there. |
1084 rtc::ThreadManager::Instance()->WrapCurrentThread(); | 1084 rtc::ThreadManager::Instance()->WrapCurrentThread(); |
1085 webrtc::Trace::CreateTrace(); | 1085 webrtc::Trace::CreateTrace(); |
1086 Thread* worker_thread = new Thread(); | 1086 Thread* worker_thread = new Thread(); |
1087 worker_thread->SetName("worker_thread", NULL); | 1087 worker_thread->SetName("worker_thread", NULL); |
1088 Thread* signaling_thread = new Thread(); | 1088 Thread* signaling_thread = new Thread(); |
1089 signaling_thread->SetName("signaling_thread", NULL); | 1089 signaling_thread->SetName("signaling_thread", NULL); |
1090 CHECK(worker_thread->Start() && signaling_thread->Start()) | 1090 RTC_CHECK(worker_thread->Start() && signaling_thread->Start()) |
1091 << "Failed to start threads"; | 1091 << "Failed to start threads"; |
1092 WebRtcVideoEncoderFactory* encoder_factory = nullptr; | 1092 WebRtcVideoEncoderFactory* encoder_factory = nullptr; |
1093 WebRtcVideoDecoderFactory* decoder_factory = nullptr; | 1093 WebRtcVideoDecoderFactory* decoder_factory = nullptr; |
1094 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) | 1094 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
1095 if (video_hw_acceleration_enabled) { | 1095 if (video_hw_acceleration_enabled) { |
1096 encoder_factory = new MediaCodecVideoEncoderFactory(); | 1096 encoder_factory = new MediaCodecVideoEncoderFactory(); |
1097 decoder_factory = new MediaCodecVideoDecoderFactory(); | 1097 decoder_factory = new MediaCodecVideoDecoderFactory(); |
1098 } | 1098 } |
1099 #endif | 1099 #endif |
1100 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1100 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 | 1244 |
1245 if (enum_name == "RELAY") | 1245 if (enum_name == "RELAY") |
1246 return PeerConnectionInterface::kRelay; | 1246 return PeerConnectionInterface::kRelay; |
1247 | 1247 |
1248 if (enum_name == "NOHOST") | 1248 if (enum_name == "NOHOST") |
1249 return PeerConnectionInterface::kNoHost; | 1249 return PeerConnectionInterface::kNoHost; |
1250 | 1250 |
1251 if (enum_name == "NONE") | 1251 if (enum_name == "NONE") |
1252 return PeerConnectionInterface::kNone; | 1252 return PeerConnectionInterface::kNone; |
1253 | 1253 |
1254 CHECK(false) << "Unexpected IceTransportsType enum_name " << enum_name; | 1254 RTC_CHECK(false) << "Unexpected IceTransportsType enum_name " << enum_name; |
1255 return PeerConnectionInterface::kAll; | 1255 return PeerConnectionInterface::kAll; |
1256 } | 1256 } |
1257 | 1257 |
1258 static PeerConnectionInterface::BundlePolicy | 1258 static PeerConnectionInterface::BundlePolicy |
1259 JavaBundlePolicyToNativeType(JNIEnv* jni, jobject j_bundle_policy) { | 1259 JavaBundlePolicyToNativeType(JNIEnv* jni, jobject j_bundle_policy) { |
1260 std::string enum_name = GetJavaEnumName( | 1260 std::string enum_name = GetJavaEnumName( |
1261 jni, "org/webrtc/PeerConnection$BundlePolicy", | 1261 jni, "org/webrtc/PeerConnection$BundlePolicy", |
1262 j_bundle_policy); | 1262 j_bundle_policy); |
1263 | 1263 |
1264 if (enum_name == "BALANCED") | 1264 if (enum_name == "BALANCED") |
1265 return PeerConnectionInterface::kBundlePolicyBalanced; | 1265 return PeerConnectionInterface::kBundlePolicyBalanced; |
1266 | 1266 |
1267 if (enum_name == "MAXBUNDLE") | 1267 if (enum_name == "MAXBUNDLE") |
1268 return PeerConnectionInterface::kBundlePolicyMaxBundle; | 1268 return PeerConnectionInterface::kBundlePolicyMaxBundle; |
1269 | 1269 |
1270 if (enum_name == "MAXCOMPAT") | 1270 if (enum_name == "MAXCOMPAT") |
1271 return PeerConnectionInterface::kBundlePolicyMaxCompat; | 1271 return PeerConnectionInterface::kBundlePolicyMaxCompat; |
1272 | 1272 |
1273 CHECK(false) << "Unexpected BundlePolicy enum_name " << enum_name; | 1273 RTC_CHECK(false) << "Unexpected BundlePolicy enum_name " << enum_name; |
1274 return PeerConnectionInterface::kBundlePolicyBalanced; | 1274 return PeerConnectionInterface::kBundlePolicyBalanced; |
1275 } | 1275 } |
1276 | 1276 |
1277 static PeerConnectionInterface::RtcpMuxPolicy | 1277 static PeerConnectionInterface::RtcpMuxPolicy |
1278 JavaRtcpMuxPolicyToNativeType(JNIEnv* jni, jobject j_rtcp_mux_policy) { | 1278 JavaRtcpMuxPolicyToNativeType(JNIEnv* jni, jobject j_rtcp_mux_policy) { |
1279 std::string enum_name = GetJavaEnumName( | 1279 std::string enum_name = GetJavaEnumName( |
1280 jni, "org/webrtc/PeerConnection$RtcpMuxPolicy", | 1280 jni, "org/webrtc/PeerConnection$RtcpMuxPolicy", |
1281 j_rtcp_mux_policy); | 1281 j_rtcp_mux_policy); |
1282 | 1282 |
1283 if (enum_name == "NEGOTIATE") | 1283 if (enum_name == "NEGOTIATE") |
1284 return PeerConnectionInterface::kRtcpMuxPolicyNegotiate; | 1284 return PeerConnectionInterface::kRtcpMuxPolicyNegotiate; |
1285 | 1285 |
1286 if (enum_name == "REQUIRE") | 1286 if (enum_name == "REQUIRE") |
1287 return PeerConnectionInterface::kRtcpMuxPolicyRequire; | 1287 return PeerConnectionInterface::kRtcpMuxPolicyRequire; |
1288 | 1288 |
1289 CHECK(false) << "Unexpected RtcpMuxPolicy enum_name " << enum_name; | 1289 RTC_CHECK(false) << "Unexpected RtcpMuxPolicy enum_name " << enum_name; |
1290 return PeerConnectionInterface::kRtcpMuxPolicyNegotiate; | 1290 return PeerConnectionInterface::kRtcpMuxPolicyNegotiate; |
1291 } | 1291 } |
1292 | 1292 |
1293 static PeerConnectionInterface::TcpCandidatePolicy | 1293 static PeerConnectionInterface::TcpCandidatePolicy |
1294 JavaTcpCandidatePolicyToNativeType( | 1294 JavaTcpCandidatePolicyToNativeType( |
1295 JNIEnv* jni, jobject j_tcp_candidate_policy) { | 1295 JNIEnv* jni, jobject j_tcp_candidate_policy) { |
1296 std::string enum_name = GetJavaEnumName( | 1296 std::string enum_name = GetJavaEnumName( |
1297 jni, "org/webrtc/PeerConnection$TcpCandidatePolicy", | 1297 jni, "org/webrtc/PeerConnection$TcpCandidatePolicy", |
1298 j_tcp_candidate_policy); | 1298 j_tcp_candidate_policy); |
1299 | 1299 |
1300 if (enum_name == "ENABLED") | 1300 if (enum_name == "ENABLED") |
1301 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; | 1301 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; |
1302 | 1302 |
1303 if (enum_name == "DISABLED") | 1303 if (enum_name == "DISABLED") |
1304 return PeerConnectionInterface::kTcpCandidatePolicyDisabled; | 1304 return PeerConnectionInterface::kTcpCandidatePolicyDisabled; |
1305 | 1305 |
1306 CHECK(false) << "Unexpected TcpCandidatePolicy enum_name " << enum_name; | 1306 RTC_CHECK(false) << "Unexpected TcpCandidatePolicy enum_name " << enum_name; |
1307 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; | 1307 return PeerConnectionInterface::kTcpCandidatePolicyEnabled; |
1308 } | 1308 } |
1309 | 1309 |
1310 static rtc::KeyType JavaKeyTypeToNativeType(JNIEnv* jni, jobject j_key_type) { | 1310 static rtc::KeyType JavaKeyTypeToNativeType(JNIEnv* jni, jobject j_key_type) { |
1311 std::string enum_name = GetJavaEnumName( | 1311 std::string enum_name = GetJavaEnumName( |
1312 jni, "org/webrtc/PeerConnection$KeyType", j_key_type); | 1312 jni, "org/webrtc/PeerConnection$KeyType", j_key_type); |
1313 | 1313 |
1314 if (enum_name == "RSA") | 1314 if (enum_name == "RSA") |
1315 return rtc::KT_RSA; | 1315 return rtc::KT_RSA; |
1316 if (enum_name == "ECDSA") | 1316 if (enum_name == "ECDSA") |
1317 return rtc::KT_ECDSA; | 1317 return rtc::KT_ECDSA; |
1318 | 1318 |
1319 CHECK(false) << "Unexpected KeyType enum_name " << enum_name; | 1319 RTC_CHECK(false) << "Unexpected KeyType enum_name " << enum_name; |
1320 return rtc::KT_ECDSA; | 1320 return rtc::KT_ECDSA; |
1321 } | 1321 } |
1322 | 1322 |
1323 static void JavaIceServersToJsepIceServers( | 1323 static void JavaIceServersToJsepIceServers( |
1324 JNIEnv* jni, jobject j_ice_servers, | 1324 JNIEnv* jni, jobject j_ice_servers, |
1325 PeerConnectionInterface::IceServers* ice_servers) { | 1325 PeerConnectionInterface::IceServers* ice_servers) { |
1326 jclass list_class = GetObjectClass(jni, j_ice_servers); | 1326 jclass list_class = GetObjectClass(jni, j_ice_servers); |
1327 jmethodID iterator_id = GetMethodID( | 1327 jmethodID iterator_id = GetMethodID( |
1328 jni, list_class, "iterator", "()Ljava/util/Iterator;"); | 1328 jni, list_class, "iterator", "()Ljava/util/Iterator;"); |
1329 jobject iterator = jni->CallObjectMethod(j_ice_servers, iterator_id); | 1329 jobject iterator = jni->CallObjectMethod(j_ice_servers, iterator_id); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1470 JOW(jobject, PeerConnection_createDataChannel)( | 1470 JOW(jobject, PeerConnection_createDataChannel)( |
1471 JNIEnv* jni, jobject j_pc, jstring j_label, jobject j_init) { | 1471 JNIEnv* jni, jobject j_pc, jstring j_label, jobject j_init) { |
1472 DataChannelInit init = JavaDataChannelInitToNative(jni, j_init); | 1472 DataChannelInit init = JavaDataChannelInitToNative(jni, j_init); |
1473 rtc::scoped_refptr<DataChannelInterface> channel( | 1473 rtc::scoped_refptr<DataChannelInterface> channel( |
1474 ExtractNativePC(jni, j_pc)->CreateDataChannel( | 1474 ExtractNativePC(jni, j_pc)->CreateDataChannel( |
1475 JavaToStdString(jni, j_label), &init)); | 1475 JavaToStdString(jni, j_label), &init)); |
1476 // Mustn't pass channel.get() directly through NewObject to avoid reading its | 1476 // Mustn't pass channel.get() directly through NewObject to avoid reading its |
1477 // vararg parameter as 64-bit and reading memory that doesn't belong to the | 1477 // vararg parameter as 64-bit and reading memory that doesn't belong to the |
1478 // 32-bit parameter. | 1478 // 32-bit parameter. |
1479 jlong nativeChannelPtr = jlongFromPointer(channel.get()); | 1479 jlong nativeChannelPtr = jlongFromPointer(channel.get()); |
1480 CHECK(nativeChannelPtr) << "Failed to create DataChannel"; | 1480 RTC_CHECK(nativeChannelPtr) << "Failed to create DataChannel"; |
1481 jclass j_data_channel_class = FindClass(jni, "org/webrtc/DataChannel"); | 1481 jclass j_data_channel_class = FindClass(jni, "org/webrtc/DataChannel"); |
1482 jmethodID j_data_channel_ctor = GetMethodID( | 1482 jmethodID j_data_channel_ctor = GetMethodID( |
1483 jni, j_data_channel_class, "<init>", "(J)V"); | 1483 jni, j_data_channel_class, "<init>", "(J)V"); |
1484 jobject j_channel = jni->NewObject( | 1484 jobject j_channel = jni->NewObject( |
1485 j_data_channel_class, j_data_channel_ctor, nativeChannelPtr); | 1485 j_data_channel_class, j_data_channel_ctor, nativeChannelPtr); |
1486 CHECK_EXCEPTION(jni) << "error during NewObject"; | 1486 CHECK_EXCEPTION(jni) << "error during NewObject"; |
1487 // Channel is now owned by Java object, and will be freed from there. | 1487 // Channel is now owned by Java object, and will be freed from there. |
1488 int bumped_count = channel->AddRef(); | 1488 int bumped_count = channel->AddRef(); |
1489 CHECK(bumped_count == 2) << "Unexpected refcount"; | 1489 RTC_CHECK(bumped_count == 2) << "Unexpected refcount"; |
1490 return j_channel; | 1490 return j_channel; |
1491 } | 1491 } |
1492 | 1492 |
1493 JOW(void, PeerConnection_createOffer)( | 1493 JOW(void, PeerConnection_createOffer)( |
1494 JNIEnv* jni, jobject j_pc, jobject j_observer, jobject j_constraints) { | 1494 JNIEnv* jni, jobject j_pc, jobject j_observer, jobject j_constraints) { |
1495 ConstraintsWrapper* constraints = | 1495 ConstraintsWrapper* constraints = |
1496 new ConstraintsWrapper(jni, j_constraints); | 1496 new ConstraintsWrapper(jni, j_constraints); |
1497 rtc::scoped_refptr<CreateSdpObserverWrapper> observer( | 1497 rtc::scoped_refptr<CreateSdpObserverWrapper> observer( |
1498 new rtc::RefCountedObject<CreateSdpObserverWrapper>( | 1498 new rtc::RefCountedObject<CreateSdpObserverWrapper>( |
1499 jni, j_observer, constraints)); | 1499 jni, j_observer, constraints)); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1641 AndroidVideoCapturerJni::Create(jni, j_video_capturer, j_device_name); | 1641 AndroidVideoCapturerJni::Create(jni, j_video_capturer, j_device_name); |
1642 if (!delegate.get()) | 1642 if (!delegate.get()) |
1643 return nullptr; | 1643 return nullptr; |
1644 rtc::scoped_ptr<webrtc::AndroidVideoCapturer> capturer( | 1644 rtc::scoped_ptr<webrtc::AndroidVideoCapturer> capturer( |
1645 new webrtc::AndroidVideoCapturer(delegate)); | 1645 new webrtc::AndroidVideoCapturer(delegate)); |
1646 | 1646 |
1647 #else | 1647 #else |
1648 std::string device_name = JavaToStdString(jni, j_device_name); | 1648 std::string device_name = JavaToStdString(jni, j_device_name); |
1649 scoped_ptr<cricket::DeviceManagerInterface> device_manager( | 1649 scoped_ptr<cricket::DeviceManagerInterface> device_manager( |
1650 cricket::DeviceManagerFactory::Create()); | 1650 cricket::DeviceManagerFactory::Create()); |
1651 CHECK(device_manager->Init()) << "DeviceManager::Init() failed"; | 1651 RTC_CHECK(device_manager->Init()) << "DeviceManager::Init() failed"; |
1652 cricket::Device device; | 1652 cricket::Device device; |
1653 if (!device_manager->GetVideoCaptureDevice(device_name, &device)) { | 1653 if (!device_manager->GetVideoCaptureDevice(device_name, &device)) { |
1654 LOG(LS_ERROR) << "GetVideoCaptureDevice failed for " << device_name; | 1654 LOG(LS_ERROR) << "GetVideoCaptureDevice failed for " << device_name; |
1655 return 0; | 1655 return 0; |
1656 } | 1656 } |
1657 scoped_ptr<cricket::VideoCapturer> capturer( | 1657 scoped_ptr<cricket::VideoCapturer> capturer( |
1658 device_manager->CreateVideoCapturer(device)); | 1658 device_manager->CreateVideoCapturer(device)); |
1659 | 1659 |
1660 jclass j_video_capturer_class( | 1660 jclass j_video_capturer_class( |
1661 FindClass(jni, "org/webrtc/VideoCapturer")); | 1661 FindClass(jni, "org/webrtc/VideoCapturer")); |
(...skipping 26 matching lines...) Expand all Loading... |
1688 scoped_ptr<JavaVideoRendererWrapper> renderer( | 1688 scoped_ptr<JavaVideoRendererWrapper> renderer( |
1689 new JavaVideoRendererWrapper(jni, j_callbacks)); | 1689 new JavaVideoRendererWrapper(jni, j_callbacks)); |
1690 return (jlong)renderer.release(); | 1690 return (jlong)renderer.release(); |
1691 } | 1691 } |
1692 | 1692 |
1693 JOW(void, VideoRenderer_nativeCopyPlane)( | 1693 JOW(void, VideoRenderer_nativeCopyPlane)( |
1694 JNIEnv *jni, jclass, jobject j_src_buffer, jint width, jint height, | 1694 JNIEnv *jni, jclass, jobject j_src_buffer, jint width, jint height, |
1695 jint src_stride, jobject j_dst_buffer, jint dst_stride) { | 1695 jint src_stride, jobject j_dst_buffer, jint dst_stride) { |
1696 size_t src_size = jni->GetDirectBufferCapacity(j_src_buffer); | 1696 size_t src_size = jni->GetDirectBufferCapacity(j_src_buffer); |
1697 size_t dst_size = jni->GetDirectBufferCapacity(j_dst_buffer); | 1697 size_t dst_size = jni->GetDirectBufferCapacity(j_dst_buffer); |
1698 CHECK(src_stride >= width) << "Wrong source stride " << src_stride; | 1698 RTC_CHECK(src_stride >= width) << "Wrong source stride " << src_stride; |
1699 CHECK(dst_stride >= width) << "Wrong destination stride " << dst_stride; | 1699 RTC_CHECK(dst_stride >= width) << "Wrong destination stride " << dst_stride; |
1700 CHECK(src_size >= src_stride * height) | 1700 RTC_CHECK(src_size >= src_stride * height) |
1701 << "Insufficient source buffer capacity " << src_size; | 1701 << "Insufficient source buffer capacity " << src_size; |
1702 CHECK(dst_size >= dst_stride * height) | 1702 RTC_CHECK(dst_size >= dst_stride * height) |
1703 << "Isufficient destination buffer capacity " << dst_size; | 1703 << "Isufficient destination buffer capacity " << dst_size; |
1704 uint8_t *src = | 1704 uint8_t *src = |
1705 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer)); | 1705 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_src_buffer)); |
1706 uint8_t *dst = | 1706 uint8_t *dst = |
1707 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_buffer)); | 1707 reinterpret_cast<uint8_t*>(jni->GetDirectBufferAddress(j_dst_buffer)); |
1708 if (src_stride == dst_stride) { | 1708 if (src_stride == dst_stride) { |
1709 memcpy(dst, src, src_stride * height); | 1709 memcpy(dst, src, src_stride * height); |
1710 } else { | 1710 } else { |
1711 for (int i = 0; i < height; i++) { | 1711 for (int i = 0; i < height; i++) { |
1712 memcpy(dst, src, width); | 1712 memcpy(dst, src, width); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1820 rtc::scoped_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size))); | 1820 rtc::scoped_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size))); |
1821 stream->ReadAll(buffer.get(), log_size, &read, nullptr); | 1821 stream->ReadAll(buffer.get(), log_size, &read, nullptr); |
1822 | 1822 |
1823 jbyteArray result = jni->NewByteArray(read); | 1823 jbyteArray result = jni->NewByteArray(read); |
1824 jni->SetByteArrayRegion(result, 0, read, buffer.get()); | 1824 jni->SetByteArrayRegion(result, 0, read, buffer.get()); |
1825 | 1825 |
1826 return result; | 1826 return result; |
1827 } | 1827 } |
1828 | 1828 |
1829 } // namespace webrtc_jni | 1829 } // namespace webrtc_jni |
OLD | NEW |