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_; } |
1078 void InvokeJavaCallbacksOnFactoryThreads(); | 1088 void InvokeJavaCallbacksOnFactoryThreads(); |
1079 | 1089 |
1080 private: | 1090 private: |
1081 void JavaCallbackOnFactoryThreads(); | 1091 void JavaCallbackOnFactoryThreads(); |
1082 | 1092 |
1083 const scoped_ptr<Thread> worker_thread_; | 1093 const scoped_ptr<Thread> worker_thread_; |
1084 const scoped_ptr<Thread> signaling_thread_; | 1094 const scoped_ptr<Thread> signaling_thread_; |
1085 WebRtcVideoEncoderFactory* encoder_factory_; | 1095 WebRtcVideoEncoderFactory* encoder_factory_; |
1086 WebRtcVideoDecoderFactory* decoder_factory_; | 1096 WebRtcVideoDecoderFactory* decoder_factory_; |
| 1097 rtc::NetworkMonitorFactory* network_monitor_factory_; |
1087 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. | 1098 PeerConnectionFactoryInterface* factory_; // Const after ctor except dtor. |
1088 }; | 1099 }; |
1089 | 1100 |
1090 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { | 1101 void OwnedFactoryAndThreads::JavaCallbackOnFactoryThreads() { |
1091 JNIEnv* jni = AttachCurrentThreadIfNeeded(); | 1102 JNIEnv* jni = AttachCurrentThreadIfNeeded(); |
1092 ScopedLocalRefFrame local_ref_frame(jni); | 1103 ScopedLocalRefFrame local_ref_frame(jni); |
1093 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); | 1104 jclass j_factory_class = FindClass(jni, "org/webrtc/PeerConnectionFactory"); |
1094 jmethodID m = nullptr; | 1105 jmethodID m = nullptr; |
1095 if (Thread::Current() == worker_thread_) { | 1106 if (Thread::Current() == worker_thread_) { |
1096 LOG(LS_INFO) << "Worker thread JavaCallback"; | 1107 LOG(LS_INFO) << "Worker thread JavaCallback"; |
(...skipping 28 matching lines...) Expand all Loading... |
1125 rtc::ThreadManager::Instance()->WrapCurrentThread(); | 1136 rtc::ThreadManager::Instance()->WrapCurrentThread(); |
1126 webrtc::Trace::CreateTrace(); | 1137 webrtc::Trace::CreateTrace(); |
1127 Thread* worker_thread = new Thread(); | 1138 Thread* worker_thread = new Thread(); |
1128 worker_thread->SetName("worker_thread", NULL); | 1139 worker_thread->SetName("worker_thread", NULL); |
1129 Thread* signaling_thread = new Thread(); | 1140 Thread* signaling_thread = new Thread(); |
1130 signaling_thread->SetName("signaling_thread", NULL); | 1141 signaling_thread->SetName("signaling_thread", NULL); |
1131 RTC_CHECK(worker_thread->Start() && signaling_thread->Start()) | 1142 RTC_CHECK(worker_thread->Start() && signaling_thread->Start()) |
1132 << "Failed to start threads"; | 1143 << "Failed to start threads"; |
1133 WebRtcVideoEncoderFactory* encoder_factory = nullptr; | 1144 WebRtcVideoEncoderFactory* encoder_factory = nullptr; |
1134 WebRtcVideoDecoderFactory* decoder_factory = nullptr; | 1145 WebRtcVideoDecoderFactory* decoder_factory = nullptr; |
| 1146 rtc::NetworkMonitorFactory* network_monitor_factory = nullptr; |
| 1147 |
1135 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) | 1148 #if defined(ANDROID) && !defined(WEBRTC_CHROMIUM_BUILD) |
1136 if (video_hw_acceleration_enabled) { | 1149 if (video_hw_acceleration_enabled) { |
1137 encoder_factory = new MediaCodecVideoEncoderFactory(); | 1150 encoder_factory = new MediaCodecVideoEncoderFactory(); |
1138 decoder_factory = new MediaCodecVideoDecoderFactory(); | 1151 decoder_factory = new MediaCodecVideoDecoderFactory(); |
1139 } | 1152 } |
| 1153 network_monitor_factory = new AndroidNetworkMonitorFactory(); |
| 1154 rtc::NetworkMonitorFactory::SetFactory(network_monitor_factory); |
1140 #endif | 1155 #endif |
1141 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( | 1156 rtc::scoped_refptr<PeerConnectionFactoryInterface> factory( |
1142 webrtc::CreatePeerConnectionFactory(worker_thread, | 1157 webrtc::CreatePeerConnectionFactory(worker_thread, |
1143 signaling_thread, | 1158 signaling_thread, |
1144 NULL, | 1159 NULL, |
1145 encoder_factory, | 1160 encoder_factory, |
1146 decoder_factory)); | 1161 decoder_factory)); |
1147 RTC_CHECK(factory) << "Failed to create the peer connection factory; " | 1162 RTC_CHECK(factory) << "Failed to create the peer connection factory; " |
1148 << "WebRTC/libjingle init likely failed on this device"; | 1163 << "WebRTC/libjingle init likely failed on this device"; |
1149 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( | 1164 OwnedFactoryAndThreads* owned_factory = new OwnedFactoryAndThreads( |
1150 worker_thread, signaling_thread, | 1165 worker_thread, signaling_thread, |
1151 encoder_factory, decoder_factory, | 1166 encoder_factory, decoder_factory, |
1152 factory.release()); | 1167 network_monitor_factory, factory.release()); |
1153 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); | 1168 owned_factory->InvokeJavaCallbacksOnFactoryThreads(); |
1154 return jlongFromPointer(owned_factory); | 1169 return jlongFromPointer(owned_factory); |
1155 } | 1170 } |
1156 | 1171 |
1157 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { | 1172 JOW(void, PeerConnectionFactory_nativeFreeFactory)(JNIEnv*, jclass, jlong j_p) { |
1158 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); | 1173 delete reinterpret_cast<OwnedFactoryAndThreads*>(j_p); |
1159 if (field_trials_init_string) { | 1174 if (field_trials_init_string) { |
1160 webrtc::field_trial::InitFieldTrialsFromString(NULL); | 1175 webrtc::field_trial::InitFieldTrialsFromString(NULL); |
1161 delete field_trials_init_string; | 1176 delete field_trials_init_string; |
1162 field_trials_init_string = NULL; | 1177 field_trials_init_string = NULL; |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2011 return JavaStringFromStdString( | 2026 return JavaStringFromStdString( |
2012 jni, | 2027 jni, |
2013 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); | 2028 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->id()); |
2014 } | 2029 } |
2015 | 2030 |
2016 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { | 2031 JOW(void, RtpReceiver_free)(JNIEnv* jni, jclass, jlong j_rtp_receiver_pointer) { |
2017 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); | 2032 reinterpret_cast<RtpReceiverInterface*>(j_rtp_receiver_pointer)->Release(); |
2018 } | 2033 } |
2019 | 2034 |
2020 } // namespace webrtc_jni | 2035 } // namespace webrtc_jni |
OLD | NEW |