diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-07-02 15:50:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-02 15:50:08 +0200 |
commit | e120cc7ed6fb2413743d1ade59c50a55c3c9511b (patch) | |
tree | 4264358c3618a6db142d4cef4c0452decc3188d0 | |
parent | 001be7850090f88e0ff760eddadbe1c03004fd0f (diff) | |
parent | da20ebf3970e311af4fa7a0e0b52a58041ceac3e (diff) | |
download | fork-godot-webrtc-native-e120cc7ed6fb2413743d1ade59c50a55c3c9511b.tar.gz fork-godot-webrtc-native-e120cc7ed6fb2413743d1ade59c50a55c3c9511b.tar.bz2 fork-godot-webrtc-native-e120cc7ed6fb2413743d1ade59c50a55c3c9511b.zip |
Merge pull request #33 from Faless/bump/webrtc_4472
Bump webrtc to branch-heads/4472. Fixes signalling.
-rw-r--r-- | SConstruct | 4 | ||||
-rw-r--r-- | src/WebRTCLibDataChannel.hpp | 4 | ||||
-rw-r--r-- | src/WebRTCLibObservers.cpp | 4 | ||||
-rw-r--r-- | src/WebRTCLibPeerConnection.cpp | 34 | ||||
-rw-r--r-- | src/WebRTCLibPeerConnection.hpp | 14 | ||||
-rw-r--r-- | src/init.cpp | 2 |
6 files changed, 38 insertions, 24 deletions
@@ -115,7 +115,7 @@ if target_platform == 'linux': else: env.Prepend(CCFLAGS=['-O3']) - env.Append(CCFLAGS=['-fPIC', '-std=c++11']) + env.Append(CCFLAGS=['-fPIC', '-std=c++14']) if target_arch == '32': env.Append(CCFLAGS = [ '-m32' ]) @@ -276,7 +276,7 @@ if target == 'debug': else: lib_path += '/Release' -env.Append(CPPPATH=[webrtc_dir + "/include"]) +env.Append(CPPPATH=[webrtc_dir + "/include", webrtc_dir + "/include/third_party/abseil-cpp"]) if target_platform == "linux": env.Append(LIBS=[lib_name, "atomic"]) diff --git a/src/WebRTCLibDataChannel.hpp b/src/WebRTCLibDataChannel.hpp index 557d1da..decba98 100644 --- a/src/WebRTCLibDataChannel.hpp +++ b/src/WebRTCLibDataChannel.hpp @@ -3,8 +3,8 @@ #include <Godot.hpp> // Godot.hpp must go first, or windows builds breaks -#include "api/peerconnectioninterface.h" // interface for all things needed from WebRTC -#include "media/base/mediaengine.h" // needed for CreateModularPeerConnectionFactory +#include "api/peer_connection_interface.h" // interface for all things needed from WebRTC +#include "media/base/media_engine.h" // needed for CreateModularPeerConnectionFactory #include "net/WebRTCDataChannelNative.hpp" #include "PoolArrays.hpp" diff --git a/src/WebRTCLibObservers.cpp b/src/WebRTCLibObservers.cpp index 4564195..6d8f15f 100644 --- a/src/WebRTCLibObservers.cpp +++ b/src/WebRTCLibObservers.cpp @@ -15,7 +15,7 @@ void WebRTCLibPeerConnection::GodotCSDO::OnSuccess(webrtc::SessionDescriptionInt parent->queue_signal("session_description_created", 2, desc->type().c_str(), sdp.c_str()); }; -void WebRTCLibPeerConnection::GodotCSDO::OnFailure(const std::string &error){}; +void WebRTCLibPeerConnection::GodotCSDO::OnFailure(webrtc::RTCError error){}; // SetSessionObseerver WebRTCLibPeerConnection::GodotSSDO::GodotSSDO(WebRTCLibPeerConnection *parent) { @@ -23,7 +23,7 @@ WebRTCLibPeerConnection::GodotSSDO::GodotSSDO(WebRTCLibPeerConnection *parent) { } void WebRTCLibPeerConnection::GodotSSDO::OnSuccess(){}; -void WebRTCLibPeerConnection::GodotSSDO::OnFailure(const std::string &error){}; +void WebRTCLibPeerConnection::GodotSSDO::OnFailure(webrtc::RTCError error){}; // PeerConnectionObserver WebRTCLibPeerConnection::GodotPCO::GodotPCO(WebRTCLibPeerConnection *parent) { diff --git a/src/WebRTCLibPeerConnection.cpp b/src/WebRTCLibPeerConnection.cpp index 6e81a7c..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; @@ -57,7 +72,7 @@ godot_error _parse_channel_config(webrtc::DataChannelInit &r_config, godot::Dict // ID makes sense only when negotiated is true (and must be set in that case) ERR_FAIL_COND_V(r_config.negotiated ? r_config.id == -1 : r_config.id != -1, GODOT_ERR_INVALID_PARAMETER); // Only one of maxRetransmits and maxRetransmitTime can be set on a channel. - ERR_FAIL_COND_V(r_config.maxRetransmits != -1 && r_config.maxRetransmitTime != -1, GODOT_ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(r_config.maxRetransmits && r_config.maxRetransmitTime, GODOT_ERR_INVALID_PARAMETER); return GODOT_OK; } @@ -119,7 +134,7 @@ godot_object *WebRTCLibPeerConnection::create_data_channel(const char *p_channel godot_error WebRTCLibPeerConnection::create_offer() { ERR_FAIL_COND_V(peer_connection.get() == nullptr, GODOT_ERR_UNCONFIGURED); - peer_connection->CreateOffer(ptr_csdo, nullptr); + peer_connection->CreateOffer(ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions()); return GODOT_OK; } @@ -191,16 +206,11 @@ void WebRTCLibPeerConnection::_init() { mutex_signal_queue = new std::mutex; // create a PeerConnectionFactoryInterface: - signaling_thread = new rtc::Thread; - signaling_thread->Start(); - pc_factory = webrtc::CreateModularPeerConnectionFactory( - nullptr, // rtc::Thread* network_thread, - nullptr, // rtc::Thread* worker_thread, - signaling_thread, - nullptr, // std::unique_ptr<cricket::MediaEngineInterface> media_engine, - nullptr, // std::unique_ptr<CallFactoryInterface> call_factory, - nullptr // std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory - ); + webrtc::PeerConnectionFactoryDependencies deps; + + ERR_FAIL_COND(signaling_thread.get() == nullptr); + deps.signaling_thread = signaling_thread.get(); + pc_factory = webrtc::CreateModularPeerConnectionFactory(std::move(deps)); // Create peer connection with default configuration. webrtc::PeerConnectionInterface::RTCConfiguration config; diff --git a/src/WebRTCLibPeerConnection.hpp b/src/WebRTCLibPeerConnection.hpp index b46d606..8c5d9b8 100644 --- a/src/WebRTCLibPeerConnection.hpp +++ b/src/WebRTCLibPeerConnection.hpp @@ -3,8 +3,8 @@ #include <Godot.hpp> // Godot.hpp must go first, or windows builds breaks -#include "api/peerconnectioninterface.h" // interface for all things needed from WebRTC -#include "media/base/mediaengine.h" // needed for CreateModularPeerConnectionFactory +#include "api/peer_connection_interface.h" // interface for all things needed from WebRTC +#include "media/base/media_engine.h" // needed for CreateModularPeerConnectionFactory #include <functional> // std::function #include <mutex> // mutex @TODO replace std::mutex with Godot mutex @@ -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(); @@ -66,7 +69,7 @@ public: GodotCSDO(WebRTCLibPeerConnection *parent); void OnSuccess(webrtc::SessionDescriptionInterface *desc) override; - void OnFailure(const std::string &error) override; + void OnFailure(webrtc::RTCError error) override; }; /** SetSessionDescriptionObserver callback functions **/ @@ -76,17 +79,16 @@ public: GodotSSDO(WebRTCLibPeerConnection *parent); void OnSuccess() override; - void OnFailure(const std::string &error) override; + void OnFailure(webrtc::RTCError error) override; }; GodotPCO pco; 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; - 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); } |