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

Side by Side Diff: talk/app/webrtc/java/jni/peerconnection_jni.cc

Issue 1391703003: Create network change notifier. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 2 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 * 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 #include "talk/app/webrtc/videosourceinterface.h" 67 #include "talk/app/webrtc/videosourceinterface.h"
68 #include "talk/media/base/videocapturer.h" 68 #include "talk/media/base/videocapturer.h"
69 #include "talk/media/base/videorenderer.h" 69 #include "talk/media/base/videorenderer.h"
70 #include "talk/media/devices/videorendererfactory.h" 70 #include "talk/media/devices/videorendererfactory.h"
71 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" 71 #include "talk/media/webrtc/webrtcvideodecoderfactory.h"
72 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" 72 #include "talk/media/webrtc/webrtcvideoencoderfactory.h"
73 #include "webrtc/base/bind.h" 73 #include "webrtc/base/bind.h"
74 #include "webrtc/base/checks.h" 74 #include "webrtc/base/checks.h"
75 #include "webrtc/base/logging.h" 75 #include "webrtc/base/logging.h"
76 #include "webrtc/base/logsinks.h" 76 #include "webrtc/base/logsinks.h"
77 #include "webrtc/base/networkmonitor.h"
77 #include "webrtc/base/messagequeue.h" 78 #include "webrtc/base/messagequeue.h"
78 #include "webrtc/base/ssladapter.h" 79 #include "webrtc/base/ssladapter.h"
79 #include "webrtc/base/stringutils.h" 80 #include "webrtc/base/stringutils.h"
80 #include "webrtc/system_wrappers/interface/field_trial_default.h" 81 #include "webrtc/system_wrappers/interface/field_trial_default.h"
81 #include "webrtc/system_wrappers/interface/trace.h" 82 #include "webrtc/system_wrappers/interface/trace.h"
82 #include "webrtc/voice_engine/include/voe_base.h" 83 #include "webrtc/voice_engine/include/voe_base.h"
83 84
84 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 85 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
85 #include "talk/app/webrtc/androidvideocapturer.h" 86 #include "talk/app/webrtc/androidvideocapturer.h"
86 #include "talk/app/webrtc/java/jni/androidmediadecoder_jni.h" 87 #include "talk/app/webrtc/java/jni/androidmediadecoder_jni.h"
87 #include "talk/app/webrtc/java/jni/androidmediaencoder_jni.h" 88 #include "talk/app/webrtc/java/jni/androidmediaencoder_jni.h"
88 #include "talk/app/webrtc/java/jni/androidvideocapturer_jni.h" 89 #include "talk/app/webrtc/java/jni/androidvideocapturer_jni.h"
90 #include "talk/app/webrtc/java/jni/androidnetworkmonitor_jni.h"
89 #include "webrtc/modules/video_render/video_render_internal.h" 91 #include "webrtc/modules/video_render/video_render_internal.h"
90 #include "webrtc/system_wrappers/interface/logcat_trace_context.h" 92 #include "webrtc/system_wrappers/interface/logcat_trace_context.h"
91 using webrtc::LogcatTraceContext; 93 using webrtc::LogcatTraceContext;
92 #endif 94 #endif
93 95
94 using cricket::WebRtcVideoDecoderFactory; 96 using cricket::WebRtcVideoDecoderFactory;
95 using cricket::WebRtcVideoEncoderFactory; 97 using cricket::WebRtcVideoEncoderFactory;
96 using rtc::Bind; 98 using rtc::Bind;
97 using rtc::Thread; 99 using rtc::Thread;
98 using rtc::ThreadManager; 100 using rtc::ThreadManager;
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 return (jlong)new PCOJava(jni, j_observer); 1014 return (jlong)new PCOJava(jni, j_observer);
1013 } 1015 }
1014 1016
1015 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 1017 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
1016 JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)( 1018 JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)(
1017 JNIEnv* jni, jclass, jobject context, 1019 JNIEnv* jni, jclass, jobject context,
1018 jboolean initialize_audio, jboolean initialize_video, 1020 jboolean initialize_audio, jboolean initialize_video,
1019 jboolean video_hw_acceleration) { 1021 jboolean video_hw_acceleration) {
1020 bool failure = false; 1022 bool failure = false;
1021 video_hw_acceleration_enabled = video_hw_acceleration; 1023 video_hw_acceleration_enabled = video_hw_acceleration;
1024 AndroidNetworkMonitor::SetAndroidContext(jni, context);
1022 if (!factory_static_initialized) { 1025 if (!factory_static_initialized) {
1023 if (initialize_video) { 1026 if (initialize_video) {
1024 failure |= webrtc::SetRenderAndroidVM(GetJVM()); 1027 failure |= webrtc::SetRenderAndroidVM(GetJVM());
1025 failure |= AndroidVideoCapturerJni::SetAndroidObjects(jni, context); 1028 failure |= AndroidVideoCapturerJni::SetAndroidObjects(jni, context);
1026 } 1029 }
1027 if (initialize_audio) 1030 if (initialize_audio)
1028 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context); 1031 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context);
1029 factory_static_initialized = true; 1032 factory_static_initialized = true;
1030 } 1033 }
1031 return !failure; 1034 return !failure;
(...skipping 20 matching lines...) Expand all
1052 // threads and deleting them on teardown, but no external codec factory support) 1055 // threads and deleting them on teardown, but no external codec factory support)
1053 // or entirely manual (requires caller to delete threads after factory 1056 // or entirely manual (requires caller to delete threads after factory
1054 // teardown). This struct takes ownership of its ctor's arguments to present a 1057 // teardown). This struct takes ownership of its ctor's arguments to present a
1055 // single thing for Java to hold and eventually free. 1058 // single thing for Java to hold and eventually free.
1056 class OwnedFactoryAndThreads { 1059 class OwnedFactoryAndThreads {
1057 public: 1060 public:
1058 OwnedFactoryAndThreads(Thread* worker_thread, 1061 OwnedFactoryAndThreads(Thread* worker_thread,
1059 Thread* signaling_thread, 1062 Thread* signaling_thread,
1060 WebRtcVideoEncoderFactory* encoder_factory, 1063 WebRtcVideoEncoderFactory* encoder_factory,
1061 WebRtcVideoDecoderFactory* decoder_factory, 1064 WebRtcVideoDecoderFactory* decoder_factory,
1065 rtc::NetworkMonitorFactory* network_monitor_factory,
1062 PeerConnectionFactoryInterface* factory) 1066 PeerConnectionFactoryInterface* factory)
1063 : worker_thread_(worker_thread), 1067 : worker_thread_(worker_thread),
1064 signaling_thread_(signaling_thread), 1068 signaling_thread_(signaling_thread),
1065 encoder_factory_(encoder_factory), 1069 encoder_factory_(encoder_factory),
1066 decoder_factory_(decoder_factory), 1070 decoder_factory_(decoder_factory),
1071 network_monitor_factory_(network_monitor_factory),
1067 factory_(factory) {} 1072 factory_(factory) {}
1068 1073
1069 ~OwnedFactoryAndThreads() { CHECK_RELEASE(factory_); } 1074 ~OwnedFactoryAndThreads() {
1075 CHECK_RELEASE(factory_);
1076 // Release the network monitor factory instance if it was created.
1077 if (network_monitor_factory_ != nullptr) {
1078 rtc::NetworkMonitorFactory::SetFactory(nullptr);
1079 }
pthatcher1 2015/10/15 08:11:43 Shouldn't this be more like if (network_monitor_f
honghaiz3 2015/10/15 19:02:41 Done.
1080 }
1070 1081
1071 PeerConnectionFactoryInterface* factory() { return factory_; } 1082 PeerConnectionFactoryInterface* factory() { return factory_; }
1072 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } 1083 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; }
1073 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } 1084 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; }
1074 1085
1075 private: 1086 private:
1076 const scoped_ptr<Thread> worker_thread_; 1087 const scoped_ptr<Thread> worker_thread_;
1077 const scoped_ptr<Thread> signaling_thread_; 1088 const scoped_ptr<Thread> signaling_thread_;
1078 WebRtcVideoEncoderFactory* encoder_factory_; 1089 WebRtcVideoEncoderFactory* encoder_factory_;
1079 WebRtcVideoDecoderFactory* decoder_factory_; 1090 WebRtcVideoDecoderFactory* decoder_factory_;
1091 const rtc::NetworkMonitorFactory* network_monitor_factory_;
1080 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. 1092 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor.
1081 }; 1093 };
1082 1094
1083 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)( 1095 JOW(jlong, PeerConnectionFactory_nativeCreatePeerConnectionFactory)(
1084 JNIEnv* jni, jclass) { 1096 JNIEnv* jni, jclass) {
1085 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but 1097 // talk/ assumes pretty widely that the current Thread is ThreadManager'd, but
1086 // ThreadManager only WrapCurrentThread()s the thread where it is first 1098 // ThreadManager only WrapCurrentThread()s the thread where it is first
1087 // created. Since the semantics around when auto-wrapping happens in 1099 // created. Since the semantics around when auto-wrapping happens in
1088 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think 1100 // webrtc/base/ are convoluted, we simply wrap here to avoid having to think
1089 // about ramifications of auto-wrapping there. 1101 // about ramifications of auto-wrapping there.
1090 rtc::ThreadManager::Instance()->WrapCurrentThread(); 1102 rtc::ThreadManager::Instance()->WrapCurrentThread();
1091 webrtc::Trace::CreateTrace(); 1103 webrtc::Trace::CreateTrace();
1092 Thread* worker_thread = new Thread(); 1104 Thread* worker_thread = new Thread();
1093 worker_thread->SetName("worker_thread", NULL); 1105 worker_thread->SetName("worker_thread", NULL);
1094 Thread* signaling_thread = new Thread(); 1106 Thread* signaling_thread = new Thread();
1095 signaling_thread->SetName("signaling_thread", NULL); 1107 signaling_thread->SetName("signaling_thread", NULL);
1096 RTC_CHECK(worker_thread->Start() && signaling_thread->Start()) 1108 RTC_CHECK(worker_thread->Start() && signaling_thread->Start())
1097 << "Failed to start threads"; 1109 << "Failed to start threads";
1098 WebRtcVideoEncoderFactory* encoder_factory = nullptr; 1110 WebRtcVideoEncoderFactory* encoder_factory = nullptr;
1099 WebRtcVideoDecoderFactory* decoder_factory = nullptr; 1111 WebRtcVideoDecoderFactory* decoder_factory = nullptr;
1112 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr;
1113
1100 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) 1114 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD)
1101 if (video_hw_acceleration_enabled) { 1115 if (video_hw_acceleration_enabled) {
1102 encoder_factory = new MediaCodecVideoEncoderFactory(); 1116 encoder_factory = new MediaCodecVideoEncoderFactory();
1103 decoder_factory = new MediaCodecVideoDecoderFactory(); 1117 decoder_factory = new MediaCodecVideoDecoderFactory();
1104 } 1118 }
1119 network_monitor_factory = AndroidNetworkMonitorFactory::CreateFactory();
pthatcher1 2015/10/15 08:11:43 I think this would be more clear as: network_moni
honghaiz3 2015/10/15 19:02:41 Done.
1105 #endif 1120 #endif
1106 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( 1121 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory(
1107 webrtc::CreatePeerConnectionFactory(worker_thread, 1122 webrtc::CreatePeerConnectionFactory(worker_thread,
1108 signaling_thread, 1123 signaling_thread,
1109 NULL, 1124 NULL,
1110 encoder_factory, 1125 encoder_factory,
1111 decoder_factory)); 1126 decoder_factory));
1112 RTC_CHECK(factory) << "Failed to create the peer connection factory; " 1127 RTC_CHECK(factory) << "Failed to create the peer connection factory; "
1113 << "WebRTC/libjingle init likely failed on this device"; 1128 << "WebRTC/libjingle init likely failed on this device";
1114 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( 1129 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads(
1115 worker_thread, signaling_thread, 1130 worker_thread, signaling_thread, encoder_factory, decoder_factory,
1116 encoder_factory, decoder_factory, 1131 network_monitor_factory, factory.release());
1117 factory.release());
1118 return jlongFromPointer(owned_factory); 1132 return jlongFromPointer(owned_factory);
1119 } 1133 }
1120 1134
1121 JOW(void, PeerConnectionFactory_freeFactory)(JNIEnv*, jclass, jlong j_p) { 1135 JOW(void, PeerConnectionFactory_freeFactory)(JNIEnv*, jclass, jlong j_p) {
1122 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); 1136 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p);
1123 if (field_trials_init_string) { 1137 if (field_trials_init_string) {
1124 webrtc::field_trial::InitFieldTrialsFromString(NULL); 1138 webrtc::field_trial::InitFieldTrialsFromString(NULL);
1125 delete field_trials_init_string; 1139 delete field_trials_init_string;
1126 field_trials_init_string = NULL; 1140 field_trials_init_string = NULL;
1127 } 1141 }
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1865 rtc::scoped_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size))); 1879 rtc::scoped_ptr<jbyte> buffer(static_cast<jbyte*>(malloc(log_size)));
1866 stream->ReadAll(buffer.get(), log_size, &read, nullptr); 1880 stream->ReadAll(buffer.get(), log_size, &read, nullptr);
1867 1881
1868 jbyteArray result = jni->NewByteArray(read); 1882 jbyteArray result = jni->NewByteArray(read);
1869 jni->SetByteArrayRegion(result, 0, read, buffer.get()); 1883 jni->SetByteArrayRegion(result, 0, read, buffer.get());
1870 1884
1871 return result; 1885 return result;
1872 } 1886 }
1873 1887
1874 } // namespace webrtc_jni 1888 } // namespace webrtc_jni
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698