diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-07-02 01:03:44 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-07-02 15:12:41 +0200 |
commit | da20ebf3970e311af4fa7a0e0b52a58041ceac3e (patch) | |
tree | 4264358c3618a6db142d4cef4c0452decc3188d0 /src | |
parent | 3711ad23f6c936b494041845254565efed8ca6f8 (diff) | |
download | fork-godot-webrtc-native-da20ebf3970e311af4fa7a0e0b52a58041ceac3e.tar.gz fork-godot-webrtc-native-da20ebf3970e311af4fa7a0e0b52a58041ceac3e.tar.bz2 fork-godot-webrtc-native-da20ebf3970e311af4fa7a0e0b52a58041ceac3e.zip |
Unified signalling thread.
Diffstat (limited to 'src')
-rw-r--r-- | src/WebRTCLibPeerConnection.cpp | 18 | ||||
-rw-r--r-- | src/WebRTCLibPeerConnection.hpp | 6 | ||||
-rw-r--r-- | src/init.cpp | 2 |
3 files changed, 22 insertions, 4 deletions
diff --git a/src/WebRTCLibPeerConnection.cpp b/src/WebRTCLibPeerConnection.cpp index d88760c..d95b1e6 100644 --- a/src/WebRTCLibPeerConnection.cpp +++ b/src/WebRTCLibPeerConnection.cpp @@ -5,6 +5,21 @@ using namespace godot_webrtc; +std::unique_ptr<rtc::Thread> WebRTCLibPeerConnection::signaling_thread = nullptr; + +void WebRTCLibPeerConnection::initialize_signaling() { + if (signaling_thread.get() == nullptr) { + signaling_thread = rtc::Thread::Create(); + } + signaling_thread->Start(); +} + +void WebRTCLibPeerConnection::deinitialize_signaling() { + if (signaling_thread.get() != nullptr) { + signaling_thread->Stop(); + } +} + godot_error _parse_ice_server(webrtc::PeerConnectionInterface::RTCConfiguration &r_config, godot::Dictionary p_server) { godot::Variant v; webrtc::PeerConnectionInterface::IceServer ice_server; @@ -193,8 +208,7 @@ void WebRTCLibPeerConnection::_init() { // create a PeerConnectionFactoryInterface: webrtc::PeerConnectionFactoryDependencies deps; - signaling_thread = rtc::Thread::Create(); - ERR_FAIL_COND(!signaling_thread->Start()); + ERR_FAIL_COND(signaling_thread.get() == nullptr); deps.signaling_thread = signaling_thread.get(); pc_factory = webrtc::CreateModularPeerConnectionFactory(std::move(deps)); diff --git a/src/WebRTCLibPeerConnection.hpp b/src/WebRTCLibPeerConnection.hpp index f6b0528..8c5d9b8 100644 --- a/src/WebRTCLibPeerConnection.hpp +++ b/src/WebRTCLibPeerConnection.hpp @@ -18,8 +18,11 @@ class WebRTCLibPeerConnection : public WebRTCPeerConnectionNative { private: godot_error _create_pc(webrtc::PeerConnectionInterface::RTCConfiguration &config); + static std::unique_ptr<rtc::Thread> signaling_thread; public: static void _register_methods(); + static void initialize_signaling(); + static void deinitialize_signaling(); void _init(); @@ -83,10 +86,9 @@ public: rtc::scoped_refptr<GodotSSDO> ptr_ssdo; rtc::scoped_refptr<GodotCSDO> ptr_csdo; - std::mutex *mutex_signal_queue; + std::mutex *mutex_signal_queue = nullptr; std::queue<std::function<void()> > signal_queue; - std::unique_ptr<rtc::Thread> signaling_thread; rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory; rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection; }; diff --git a/src/init.cpp b/src/init.cpp index 2b73cf1..a9a64ad 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -86,6 +86,7 @@ extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) { } } + godot_webrtc::WebRTCLibPeerConnection::initialize_signaling(); godot::Godot::gdnative_init(o); } @@ -93,6 +94,7 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt if (_singleton) { // If we are the active singleton, unregister WebRTCPeerConnectionNative::_net_api->godot_net_set_webrtc_library(NULL); } + godot_webrtc::WebRTCLibPeerConnection::deinitialize_signaling(); godot::Godot::gdnative_terminate(o); } |