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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "talk/app/webrtc/videosourceinterface.h" | 69 #include "talk/app/webrtc/videosourceinterface.h" |
70 #include "talk/media/base/videocapturer.h" | 70 #include "talk/media/base/videocapturer.h" |
71 #include "talk/media/base/videorenderer.h" | 71 #include "talk/media/base/videorenderer.h" |
72 #include "talk/media/devices/videorendererfactory.h" | 72 #include "talk/media/devices/videorendererfactory.h" |
73 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" | 73 #include "talk/media/webrtc/webrtcvideodecoderfactory.h" |
74 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" | 74 #include "talk/media/webrtc/webrtcvideoencoderfactory.h" |
75 #include "webrtc/base/bind.h" | 75 #include "webrtc/base/bind.h" |
76 #include "webrtc/base/checks.h" | 76 #include "webrtc/base/checks.h" |
77 #include "webrtc/base/logging.h" | 77 #include "webrtc/base/logging.h" |
78 #include "webrtc/base/logsinks.h" | 78 #include "webrtc/base/logsinks.h" |
| 79 #include "webrtc/base/networkmonitor.h" |
79 #include "webrtc/base/messagequeue.h" | 80 #include "webrtc/base/messagequeue.h" |
80 #include "webrtc/base/ssladapter.h" | 81 #include "webrtc/base/ssladapter.h" |
81 #include "webrtc/base/stringutils.h" | 82 #include "webrtc/base/stringutils.h" |
82 #include "webrtc/system_wrappers/interface/field_trial_default.h" | 83 #include "webrtc/system_wrappers/interface/field_trial_default.h" |
83 #include "webrtc/system_wrappers/interface/trace.h" | 84 #include "webrtc/system_wrappers/interface/trace.h" |
84 #include "webrtc/voice_engine/include/voe_base.h" | 85 #include "webrtc/voice_engine/include/voe_base.h" |
85 | 86 |
86 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) | 87 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
87 #include "talk/app/webrtc/androidvideocapturer.h" | 88 #include "talk/app/webrtc/androidvideocapturer.h" |
88 #include "talk/app/webrtc/java/jni/androidmediadecoder_jni.h" | 89 #include "talk/app/webrtc/java/jni/androidmediadecoder_jni.h" |
89 #include "talk/app/webrtc/java/jni/androidmediaencoder_jni.h" | 90 #include "talk/app/webrtc/java/jni/androidmediaencoder_jni.h" |
90 #include "talk/app/webrtc/java/jni/androidvideocapturer_jni.h" | 91 #include "talk/app/webrtc/java/jni/androidvideocapturer_jni.h" |
| 92 #include "talk/app/webrtc/java/jni/androidnetworkmonitor_jni.h" |
91 #include "webrtc/modules/video_render/video_render_internal.h" | 93 #include "webrtc/modules/video_render/video_render_internal.h" |
92 #include "webrtc/system_wrappers/interface/logcat_trace_context.h" | 94 #include "webrtc/system_wrappers/interface/logcat_trace_context.h" |
93 using webrtc::LogcatTraceContext; | 95 using webrtc::LogcatTraceContext; |
94 #endif | 96 #endif |
95 | 97 |
96 using cricket::WebRtcVideoDecoderFactory; | 98 using cricket::WebRtcVideoDecoderFactory; |
97 using cricket::WebRtcVideoEncoderFactory; | 99 using cricket::WebRtcVideoEncoderFactory; |
98 using rtc::Bind; | 100 using rtc::Bind; |
99 using rtc::Thread; | 101 using rtc::Thread; |
100 using rtc::ThreadManager; | 102 using rtc::ThreadManager; |
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 return (jlong)new PCOJava(jni, j_observer); | 1018 return (jlong)new PCOJava(jni, j_observer); |
1017 } | 1019 } |
1018 | 1020 |
1019 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) | 1021 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
1020 JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)( | 1022 JOW(jboolean, PeerConnectionFactory_initializeAndroidGlobals)( |
1021 JNIEnv* jni, jclass, jobject context, | 1023 JNIEnv* jni, jclass, jobject context, |
1022 jboolean initialize_audio, jboolean initialize_video, | 1024 jboolean initialize_audio, jboolean initialize_video, |
1023 jboolean video_hw_acceleration) { | 1025 jboolean video_hw_acceleration) { |
1024 bool failure = false; | 1026 bool failure = false; |
1025 video_hw_acceleration_enabled = video_hw_acceleration; | 1027 video_hw_acceleration_enabled = video_hw_acceleration; |
| 1028 AndroidNetworkMonitor::SetAndroidContext(jni, context); |
1026 if (!factory_static_initialized) { | 1029 if (!factory_static_initialized) { |
1027 if (initialize_video) { | 1030 if (initialize_video) { |
1028 failure |= webrtc::SetRenderAndroidVM(GetJVM()); | 1031 failure |= webrtc::SetRenderAndroidVM(GetJVM()); |
1029 failure |= AndroidVideoCapturerJni::SetAndroidObjects(jni, context); | 1032 failure |= AndroidVideoCapturerJni::SetAndroidObjects(jni, context); |
1030 } | 1033 } |
1031 if (initialize_audio) | 1034 if (initialize_audio) |
1032 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context); | 1035 failure |= webrtc::VoiceEngine::SetAndroidObjects(GetJVM(), context); |
1033 factory_static_initialized = true; | 1036 factory_static_initialized = true; |
1034 } | 1037 } |
1035 return !failure; | 1038 return !failure; |
(...skipping 20 matching lines...) Expand all Loading... |
1056 // threads and deleting them on teardown, but no external codec factory support) | 1059 // threads and deleting them on teardown, but no external codec factory support) |
1057 // or entirely manual (requires caller to delete threads after factory | 1060 // or entirely manual (requires caller to delete threads after factory |
1058 // teardown). This struct takes ownership of its ctor's arguments to present a | 1061 // teardown). This struct takes ownership of its ctor's arguments to present a |
1059 // single thing for Java to hold and eventually free. | 1062 // single thing for Java to hold and eventually free. |
1060 class OwnedFactoryAndThreads { | 1063 class OwnedFactoryAndThreads { |
1061 public: | 1064 public: |
1062 OwnedFactoryAndThreads(Thread* worker_thread, | 1065 OwnedFactoryAndThreads(Thread* worker_thread, |
1063 Thread* signaling_thread, | 1066 Thread* signaling_thread, |
1064 WebRtcVideoEncoderFactory* encoder_factory, | 1067 WebRtcVideoEncoderFactory* encoder_factory, |
1065 WebRtcVideoDecoderFactory* decoder_factory, | 1068 WebRtcVideoDecoderFactory* decoder_factory, |
| 1069 rtc::NetworkMonitorFactory* network_monitor_factory, |
1066 PeerConnectionFactoryInterface* factory) | 1070 PeerConnectionFactoryInterface* factory) |
1067 : worker_thread_(worker_thread), | 1071 : worker_thread_(worker_thread), |
1068 signaling_thread_(signaling_thread), | 1072 signaling_thread_(signaling_thread), |
1069 encoder_factory_(encoder_factory), | 1073 encoder_factory_(encoder_factory), |
1070 decoder_factory_(decoder_factory), | 1074 decoder_factory_(decoder_factory), |
| 1075 network_monitor_factory_(network_monitor_factory), |
1071 factory_(factory) {} | 1076 factory_(factory) {} |
1072 | 1077 |
1073 ~OwnedFactoryAndThreads() { CHECK_RELEASE(factory_); } | 1078 ~OwnedFactoryAndThreads() { |
| 1079 CHECK_RELEASE(factory_); |
| 1080 if (network_monitor_factory_ != nullptr) { |
| 1081 rtc::NetworkMonitorFactory::ReleaseFactory(network_monitor_factory_); |
| 1082 } |
| 1083 } |
1074 | 1084 |
1075 PeerConnectionFactoryInterface* factory() { return factory_; } | 1085 PeerConnectionFactoryInterface* factory() { return factory_; } |
1076 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } | 1086 WebRtcVideoEncoderFactory* encoder_factory() { return encoder_factory_; } |
1077 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } | 1087 WebRtcVideoDecoderFactory* decoder_factory() { return decoder_factory_; } |
| 1088 rtc::NetworkMonitorFactory* network_monitor_factory() { |
| 1089 return network_monitor_factory_; |
| 1090 } |
| 1091 void clear_network_monitor_factory() { network_monitor_factory_ = nullptr; } |
1078 void InvokeJavaCallbacksOnFactoryThreads(); | 1092 void InvokeJavaCallbacksOnFactoryThreads(); |
1079 | 1093 |
1080 private: | 1094 private: |
1081 void JavaCallbackOnFactoryThreads(); | 1095 void JavaCallbackOnFactoryThreads(); |
1082 | 1096 |
1083 const scoped_ptr<Thread> worker_thread_; | 1097 const scoped_ptr<Thread> worker_thread_; |
1084 const scoped_ptr<Thread> signaling_thread_; | 1098 const scoped_ptr<Thread> signaling_thread_; |
1085 WebRtcVideoEncoderFactory* encoder_factory_; | 1099 WebRtcVideoEncoderFactory* encoder_factory_; |
1086 WebRtcVideoDecoderFactory* decoder_factory_; | 1100 WebRtcVideoDecoderFactory* decoder_factory_; |
| 1101 rtc::NetworkMonitorFactory* network_monitor_factory_; |
1087 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. | 1102 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. |
1088 }; | 1103 }; |
1089 | 1104 |
1090 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { | 1105 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { |
1091 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 1106 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
1092 ScopedLocalRefFrame local_ref_frame(jni); | 1107 ScopedLocalRefFrame local_ref_frame(jni); |
1093 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); | 1108 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); |
1094 jmethodID m = nullptr; | 1109 jmethodID m = nullptr; |
1095 if (Thread::Current() == worker_thread_) { | 1110 if (Thread::Current() == worker_thread_) { |
1096 LOG(LS_INFO) << "Worker thread JavaCallback"; | 1111 LOG(LS_INFO) << "Worker thread JavaCallback"; |
(...skipping 28 matching lines...) Expand all Loading... |
1125 rtc::ThreadManager::Instance()->WrapCurrentThread(); | 1140 rtc::ThreadManager::Instance()->WrapCurrentThread(); |
1126 webrtc::Trace::CreateTrace(); | 1141 webrtc::Trace::CreateTrace(); |
1127 Thread* worker_thread = new Thread(); | 1142 Thread* worker_thread = new Thread(); |
1128 worker_thread->SetName("worker_thread", NULL); | 1143 worker_thread->SetName("worker_thread", NULL); |
1129 Thread* signaling_thread = new Thread(); | 1144 Thread* signaling_thread = new Thread(); |
1130 signaling_thread->SetName("signaling_thread", NULL); | 1145 signaling_thread->SetName("signaling_thread", NULL); |
1131 RTC_CHECK(worker_thread->Start() && signaling_thread->Start()) | 1146 RTC_CHECK(worker_thread->Start() && signaling_thread->Start()) |
1132 << "Failed to start threads"; | 1147 << "Failed to start threads"; |
1133 WebRtcVideoEncoderFactory* encoder_factory = nullptr; | 1148 WebRtcVideoEncoderFactory* encoder_factory = nullptr; |
1134 WebRtcVideoDecoderFactory* decoder_factory = nullptr; | 1149 WebRtcVideoDecoderFactory* decoder_factory = nullptr; |
| 1150 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; |
| 1151 |
1135 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) | 1152 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
1136 if (video_hw_acceleration_enabled) { | 1153 if (video_hw_acceleration_enabled) { |
1137 encoder_factory = new MediaCodecVideoEncoderFactory(); | 1154 encoder_factory = new MediaCodecVideoEncoderFactory(); |
1138 decoder_factory = new MediaCodecVideoDecoderFactory(); | 1155 decoder_factory = new MediaCodecVideoDecoderFactory(); |
1139 } | 1156 } |
| 1157 network_monitor_factory = new AndroidNetworkMonitorFactory(); |
| 1158 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); |
1140 #endif | 1159 #endif |
1141 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1160 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1142 webrtc::CreatePeerConnectionFactory(worker_thread, | 1161 webrtc::CreatePeerConnectionFactory(worker_thread, |
1143 signaling_thread, | 1162 signaling_thread, |
1144 NULL, | 1163 NULL, |
1145 encoder_factory, | 1164 encoder_factory, |
1146 decoder_factory)); | 1165 decoder_factory)); |
1147 RTC_CHECK(factory) << "Failed to create the peer connection factory; " | 1166 RTC_CHECK(factory) << "Failed to create the peer connection factory; " |
1148 << "WebRTC/libjingle init likely failed on this device"; | 1167 << "WebRTC/libjingle init likely failed on this device"; |
1149 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( | 1168 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( |
1150 worker_thread, signaling_thread, | 1169 worker_thread, signaling_thread, |
1151 encoder_factory, decoder_factory, | 1170 encoder_factory, decoder_factory, |
1152 factory.release()); | 1171 network_monitor_factory, factory.release()); |
1153 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); | 1172 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); |
1154 return jlongFromPointer(owned_factory); | 1173 return jlongFromPointer(owned_factory); |
1155 } | 1174 } |
1156 | 1175 |
1157 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { | 1176 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { |
1158 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1177 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1159 if (field_trials_init_string) { | 1178 if (field_trials_init_string) { |
1160 webrtc::field_trial::InitFieldTrialsFromString(NULL); | 1179 webrtc::field_trial::InitFieldTrialsFromString(NULL); |
1161 delete field_trials_init_string; | 1180 delete field_trials_init_string; |
1162 field_trials_init_string = NULL; | 1181 field_trials_init_string = NULL; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 jfieldID network_ignore_mask_field = | 1259 jfieldID network_ignore_mask_field = |
1241 jni->GetFieldID(options_class, "networkIgnoreMask", "I"); | 1260 jni->GetFieldID(options_class, "networkIgnoreMask", "I"); |
1242 int network_ignore_mask = | 1261 int network_ignore_mask = |
1243 jni->GetIntField(options, network_ignore_mask_field); | 1262 jni->GetIntField(options, network_ignore_mask_field); |
1244 | 1263 |
1245 jfieldID disable_encryption_field = | 1264 jfieldID disable_encryption_field = |
1246 jni->GetFieldID(options_class, "disableEncryption", "Z"); | 1265 jni->GetFieldID(options_class, "disableEncryption", "Z"); |
1247 bool disable_encryption = | 1266 bool disable_encryption = |
1248 jni->GetBooleanField(options, disable_encryption_field); | 1267 jni->GetBooleanField(options, disable_encryption_field); |
1249 | 1268 |
| 1269 jfieldID disable_network_monitor_field = |
| 1270 jni->GetFieldID(options_class, "disableNetworkMonitor", "Z"); |
| 1271 bool disable_network_monitor = |
| 1272 jni->GetBooleanField(options, disable_network_monitor_field); |
| 1273 |
1250 PeerConnectionFactoryInterface::Options options_to_set; | 1274 PeerConnectionFactoryInterface::Options options_to_set; |
1251 | 1275 |
1252 // This doesn't necessarily match the c++ version of this struct; feel free | 1276 // This doesn't necessarily match the c++ version of this struct; feel free |
1253 // to add more parameters as necessary. | 1277 // to add more parameters as necessary. |
1254 options_to_set.network_ignore_mask = network_ignore_mask; | 1278 options_to_set.network_ignore_mask = network_ignore_mask; |
1255 options_to_set.disable_encryption = disable_encryption; | 1279 options_to_set.disable_encryption = disable_encryption; |
| 1280 options_to_set.disable_network_monitor = disable_network_monitor; |
1256 factory->SetOptions(options_to_set); | 1281 factory->SetOptions(options_to_set); |
| 1282 |
| 1283 if (disable_network_monitor) { |
| 1284 OwnedFactoryAndThreads* owner = |
| 1285 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
| 1286 if (owner->network_monitor_factory()) { |
| 1287 rtc::NetworkMonitorFactory::ReleaseFactory( |
| 1288 owner->network_monitor_factory()); |
| 1289 owner->clear_network_monitor_factory(); |
| 1290 } |
| 1291 } |
1257 } | 1292 } |
1258 | 1293 |
1259 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)( | 1294 JOW(void, PeerConnectionFactory_nativeSetVideoHwAccelerationOptions)( |
1260 JNIEnv* jni, jclass, jlong native_factory, jobject render_egl_context) { | 1295 JNIEnv* jni, jclass, jlong native_factory, jobject render_egl_context) { |
1261 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) | 1296 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
1262 OwnedFactoryAndThreads* owned_factory = | 1297 OwnedFactoryAndThreads* owned_factory = |
1263 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); | 1298 reinterpret_cast<OwnedFactoryAndThreads*>(native_factory); |
1264 MediaCodecVideoDecoderFactory* decoder_factory = | 1299 MediaCodecVideoDecoderFactory* decoder_factory = |
1265 static_cast<MediaCodecVideoDecoderFactory*> | 1300 static_cast<MediaCodecVideoDecoderFactory*> |
1266 (owned_factory->decoder_factory()); | 1301 (owned_factory->decoder_factory()); |
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2011 return JavaStringFromStdString( | 2046 return JavaStringFromStdString( |
2012 jni, | 2047 jni, |
2013 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); | 2048 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); |
2014 } | 2049 } |
2015 | 2050 |
2016 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { | 2051 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { |
2017 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); | 2052 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); |
2018 } | 2053 } |
2019 | 2054 |
2020 } // namespace webrtc_jni | 2055 } // namespace webrtc_jni |
OLD | NEW |