summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--SConstruct8
-rw-r--r--src/GodotCreateSessionDescriptionObserver.cpp16
-rw-r--r--src/GodotDataChannelObserver.cpp19
-rw-r--r--src/GodotPeerConnectionObserver.cpp46
-rw-r--r--src/GodotSetSessionDescriptionObserver.cpp11
-rw-r--r--src/WebRTCLibPeer.cpp202
-rw-r--r--src/WebRTCLibPeer.hpp116
-rw-r--r--src/WebRTCPeer.cpp77
-rw-r--r--src/WebRTCPeer.hpp41
-rw-r--r--src/init.cpp6
-rw-r--r--src/net/WebRTCPeerNative.cpp32
-rw-r--r--src/net/WebRTCPeerNative.hpp10
13 files changed, 438 insertions, 147 deletions
diff --git a/.gitignore b/.gitignore
index 282594c..1819662 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ bin/*
*.a
*.lib
.sconsign.dblite
+*.obj
diff --git a/SConstruct b/SConstruct
index e61f94a..54a06ca 100644
--- a/SConstruct
+++ b/SConstruct
@@ -110,13 +110,13 @@ if target_platform == "linux":
elif target_platform == "windows":
# Mostly VisualStudio
if env["CC"] == "cl":
- env.Append(CCFLAGS=["/DWEBRTC_WIN", "/D_WINSOCKAPI_", "/DNOMINMAX", "/DRTC_UNUSED=", "/DNO_RETURN="])
- env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in ["secur32", lib_name]])
+ env.Append(CCFLAGS=["/DWEBRTC_WIN", "/DWIN32_LEAN_AND_MEAN", "/DNOMINMAX", "/DRTC_UNUSED=", "/DNO_RETURN="])
+ env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in ["secur32", "advapi32", "winmm", lib_name]])
env.Append(LIBPATH=[lib_path])
# Mostly "gcc"
else:
- env.Append(CCFLAGS=["-DWEBRTC_WIN", "-D_WINSOCKAPI_", "-DNOMINMAX", "-DRTC_UNUSED=", "-DNO_RETURN="])
- env.Append(LIBS=["secur32", lib_name])
+ env.Append(CCFLAGS=["-DWINVER=0x0603", "-D_WIN32_WINNT=0x0603", "-DWEBRTC_WIN", "-DWIN32_LEAN_AND_MEAN", "-DNOMINMAX", "-DRTC_UNUSED=", "-DNO_RETURN="])
+ env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in ["secur32", "advapi32", "winmm", lib_name]])
env.Append(LIBPATH=[lib_path])
elif target_platform == "osx":
diff --git a/src/GodotCreateSessionDescriptionObserver.cpp b/src/GodotCreateSessionDescriptionObserver.cpp
new file mode 100644
index 0000000..77d1308
--- /dev/null
+++ b/src/GodotCreateSessionDescriptionObserver.cpp
@@ -0,0 +1,16 @@
+#include "WebRTCLibPeer.hpp"
+
+using namespace godot_webrtc;
+
+WebRTCLibPeer::GodotCSDO::GodotCSDO(WebRTCLibPeer *parent) {
+ this->parent = parent;
+}
+
+void WebRTCLibPeer::GodotCSDO::OnSuccess(webrtc::SessionDescriptionInterface *desc) {
+ // serialize this offer and send it to the remote peer:
+ std::string sdp; // sdp = session description protocol
+ desc->ToString(&sdp);
+ parent->queue_signal("offer_created", 2, desc->type().c_str(), sdp.c_str());
+};
+
+void WebRTCLibPeer::GodotCSDO::OnFailure(const std::string &error){};
diff --git a/src/GodotDataChannelObserver.cpp b/src/GodotDataChannelObserver.cpp
new file mode 100644
index 0000000..7a6cf96
--- /dev/null
+++ b/src/GodotDataChannelObserver.cpp
@@ -0,0 +1,19 @@
+#include "WebRTCLibPeer.hpp"
+
+using namespace godot_webrtc;
+
+WebRTCLibPeer::GodotDCO::GodotDCO(WebRTCLibPeer *parent) {
+ this->parent = parent;
+}
+
+void WebRTCLibPeer::GodotDCO::OnMessage(const webrtc::DataBuffer &buffer) {
+ const uint8_t *data = buffer.data.data<uint8_t>();
+ uint8_t *memory_controlled_buffer = new uint8_t[buffer.data.size()];
+
+ std::copy(data, data + buffer.data.size(), memory_controlled_buffer);
+ parent->queue_packet(memory_controlled_buffer, buffer.data.size());
+};
+
+void WebRTCLibPeer::GodotDCO::OnStateChange(){};
+
+void WebRTCLibPeer::GodotDCO::OnBufferedAmountChange(uint64_t previous_amount){};
diff --git a/src/GodotPeerConnectionObserver.cpp b/src/GodotPeerConnectionObserver.cpp
new file mode 100644
index 0000000..298cfcf
--- /dev/null
+++ b/src/GodotPeerConnectionObserver.cpp
@@ -0,0 +1,46 @@
+#include "WebRTCLibPeer.hpp"
+
+using namespace godot_webrtc;
+
+WebRTCLibPeer::GodotPCO::GodotPCO(WebRTCLibPeer *parent) {
+ this->parent = parent;
+}
+
+void WebRTCLibPeer::GodotPCO::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {
+}
+
+void WebRTCLibPeer::GodotPCO::OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
+}
+
+void WebRTCLibPeer::GodotPCO::OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
+}
+
+void WebRTCLibPeer::GodotPCO::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
+}
+
+void WebRTCLibPeer::GodotPCO::OnRenegotiationNeeded() {
+}
+
+void WebRTCLibPeer::GodotPCO::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) {
+}
+
+void WebRTCLibPeer::GodotPCO::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) {
+}
+
+void WebRTCLibPeer::GodotPCO::OnIceCandidate(const webrtc::IceCandidateInterface *candidate) {
+ // Serialize the candidate and send it to the remote peer:
+
+ godot::Dictionary candidateSDP;
+
+ godot::String candidateSdpMidName = candidate->sdp_mid().c_str();
+ int candidateSdpMlineIndexName = candidate->sdp_mline_index();
+ std::string sdp;
+ candidate->ToString(&sdp);
+ godot::String candidateSdpName = sdp.c_str();
+
+ parent->queue_signal("new_ice_candidate",
+ 3,
+ candidateSdpMidName,
+ candidateSdpMlineIndexName,
+ candidateSdpName);
+}
diff --git a/src/GodotSetSessionDescriptionObserver.cpp b/src/GodotSetSessionDescriptionObserver.cpp
new file mode 100644
index 0000000..52be2af
--- /dev/null
+++ b/src/GodotSetSessionDescriptionObserver.cpp
@@ -0,0 +1,11 @@
+#include "WebRTCLibPeer.hpp"
+
+using namespace godot_webrtc;
+
+WebRTCLibPeer::GodotSSDO::GodotSSDO(WebRTCLibPeer *parent) {
+ this->parent = parent;
+}
+
+void WebRTCLibPeer::GodotSSDO::OnSuccess(){};
+
+void WebRTCLibPeer::GodotSSDO::OnFailure(const std::string &error){};
diff --git a/src/WebRTCLibPeer.cpp b/src/WebRTCLibPeer.cpp
new file mode 100644
index 0000000..c94cfcd
--- /dev/null
+++ b/src/WebRTCLibPeer.cpp
@@ -0,0 +1,202 @@
+#include "WebRTCLibPeer.hpp"
+
+using namespace godot_webrtc;
+
+void WebRTCLibPeer::set_write_mode(godot_int mode) {
+}
+
+godot_int WebRTCLibPeer::get_write_mode() const {
+ return 0;
+}
+
+bool WebRTCLibPeer::was_string_packet() const {
+ return false;
+}
+
+godot_int WebRTCLibPeer::get_connection_state() const {
+ return 0;
+}
+
+godot_error WebRTCLibPeer::create_offer() {
+ peer_connection->CreateOffer(
+ ptr_csdo, // CreateSessionDescriptionObserver* observer,
+ nullptr // webrtc::PeerConnectionInterface::RTCOfferAnswerOptions() // const MediaConstraintsInterface* constraints
+ );
+ return GODOT_OK;
+}
+
+godot_error WebRTCLibPeer::set_remote_description(const char *type, const char *sdp) {
+ godot_error err = set_description(type, sdp, false); //false meaning !isLocal because it is remote
+ peer_connection->CreateAnswer(ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
+ return err;
+}
+
+godot_error WebRTCLibPeer::set_local_description(const char *type, const char *sdp) {
+ return set_description(type, sdp, true); // isLocal == true
+}
+
+godot_error WebRTCLibPeer::add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) {
+ webrtc::SdpParseError *error = nullptr;
+ webrtc::IceCandidateInterface *candidate = webrtc::CreateIceCandidate(
+ sdpMidName,
+ sdpMlineIndexName,
+ sdpName,
+ error);
+
+ // @TODO do something if there's an error (if error, or if !candidate)
+ if (error || !candidate)
+ std::cout << "ERROR with creating ICE candidate (" << error << ")\n";
+
+ if (!peer_connection->AddIceCandidate(candidate))
+ ERR_PRINT("Error with adding ICE candidate");
+ return GODOT_OK;
+}
+
+godot_error WebRTCLibPeer::poll() {
+ std::function<void()> signal;
+ while (!signal_queue.empty()) {
+ mutex_signal_queue->lock();
+ signal = signal_queue.front();
+ signal_queue.pop();
+ mutex_signal_queue->unlock();
+
+ signal();
+ }
+ return GODOT_OK;
+}
+
+godot_error WebRTCLibPeer::get_packet(const uint8_t **r_buffer, int *r_len) {
+ if (packet_queue_size == 0)
+ return GODOT_ERR_UNAVAILABLE;
+ mutex_packet_queue->lock();
+ uint8_t *current_packet = packet_queue.front();
+ *r_buffer = current_packet;
+ *r_len = packet_sizes_queue.front();
+
+ packet_queue.pop();
+ packet_sizes_queue.pop();
+ mutex_packet_queue->unlock();
+
+ --packet_queue_size;
+ return GODOT_OK;
+}
+
+godot_error WebRTCLibPeer::put_packet(const uint8_t *p_buffer, int p_len) {
+ webrtc::DataBuffer webrtc_buffer(rtc::CopyOnWriteBuffer(p_buffer, p_len), true);
+ data_channel->Send(webrtc_buffer);
+ return GODOT_OK; // @TODO properly return any Error we may get.
+}
+
+godot_int WebRTCLibPeer::get_available_packet_count() const {
+ return packet_queue_size;
+}
+
+godot_int WebRTCLibPeer::get_max_packet_size() const {
+ return 1200;
+}
+
+void WebRTCLibPeer::_register_methods() {
+}
+
+void WebRTCLibPeer::_init() {
+ register_interface(&interface);
+
+ // initialize variables:
+ mutex_signal_queue = new std::mutex;
+ mutex_packet_queue = new std::mutex;
+ packet_queue_size = 0;
+
+ // 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
+ );
+ if (pc_factory.get() == nullptr) { // PeerConnectionFactory couldn't be created. Fail the method call.
+ ERR_PRINT("PeerConnectionFactory could not be created");
+ // return GODOT_FAILED;
+ }
+
+ // create PeerConnection configuration and add the ice servers:
+ webrtc::PeerConnectionInterface::RTCConfiguration configuration;
+ //webrtc::PeerConnectionInterface::IceServer ice_server;
+
+ //ice_server.uri = "stun:stun.l.google.com:19302"; // @FIXME allow user to input ice servers
+ //configuration.servers.push_back(ice_server);
+
+ // create a PeerConnection object:
+ peer_connection = pc_factory->CreatePeerConnection(configuration, nullptr, nullptr, &pco);
+ if (peer_connection.get() == nullptr) { // PeerConnection couldn't be created. Fail the method call.
+ ERR_PRINT("PeerConnection could not be created");
+ // return GODOT_FAILED;
+ }
+
+ // create a DataChannel
+ webrtc::DataChannelInit data_channel_config;
+ data_channel_config.negotiated = true; // True if the channel has been externally negotiated
+ data_channel_config.id = 0;
+
+ data_channel = peer_connection->CreateDataChannel("channel", &data_channel_config);
+ // @TODO (NONESSENTIAL) create data_channel check. fail function call if data_channel isn't created
+ data_channel->RegisterObserver(&dco);
+}
+
+WebRTCLibPeer::WebRTCLibPeer() :
+ dco(this),
+ pco(this),
+ ptr_csdo(new rtc::RefCountedObject<GodotCSDO>(this)),
+ ptr_ssdo(new rtc::RefCountedObject<GodotSSDO>(this)) {
+}
+
+WebRTCLibPeer::~WebRTCLibPeer() {
+ if (_owner) {
+ register_interface(NULL);
+ }
+ delete mutex_signal_queue;
+ delete mutex_packet_queue;
+}
+
+void WebRTCLibPeer::queue_signal(godot::String p_name, int p_argc, const godot::Variant &p_arg1, const godot::Variant &p_arg2, const godot::Variant &p_arg3) {
+ mutex_signal_queue->lock();
+ signal_queue.push(
+ [this, p_name, p_argc, p_arg1, p_arg2, p_arg3] {
+ if (p_argc == 2)
+ emit_signal(p_name, p_arg1, p_arg2);
+ else
+ emit_signal(p_name, p_arg1, p_arg2, p_arg3);
+ });
+ mutex_signal_queue->unlock();
+}
+
+void WebRTCLibPeer::queue_packet(uint8_t *buffer, int buffer_size) {
+ mutex_packet_queue->lock();
+ packet_queue.push(buffer);
+ packet_sizes_queue.push(buffer_size);
+ ++packet_queue_size;
+ mutex_packet_queue->unlock();
+}
+
+godot_error WebRTCLibPeer::set_description(const char *type, const char *sdp, bool isLocal) {
+ // webrtc::SdpType type = (isOffer) ? webrtc::SdpType::kOffer : webrtc::SdpType::kAnswer;
+ godot::String string_sdp = sdp;
+
+ webrtc::SdpType sdptype = (godot::String(type) == godot::String("offer")) ? webrtc::SdpType::kOffer : webrtc::SdpType::kAnswer;
+ std::unique_ptr<webrtc::SessionDescriptionInterface> desc =
+ webrtc::CreateSessionDescription(sdptype, sdp);
+
+ if (isLocal) {
+ peer_connection->SetLocalDescription(
+ ptr_ssdo, // @TODO (NONESSENTIAL, OPTIONAL) replace this with DummySetSessionDescriptionObserver::Create()
+ desc.release());
+ } else {
+ peer_connection->SetRemoteDescription(
+ ptr_ssdo, // @TODO (NONESSENTIAL, OPTIONAL) replace this with DummySetSessionDescriptionObserver::Create()
+ desc.release());
+ }
+ return GODOT_OK;
+}
diff --git a/src/WebRTCLibPeer.hpp b/src/WebRTCLibPeer.hpp
new file mode 100644
index 0000000..437e80a
--- /dev/null
+++ b/src/WebRTCLibPeer.hpp
@@ -0,0 +1,116 @@
+#ifndef WEBRTC_PEER_H
+#define WEBRTC_PEER_H
+
+#include "api/peerconnectioninterface.h" // interface for all things needed from WebRTC
+#include "media/base/mediaengine.h" // needed for CreateModularPeerConnectionFactory
+#include <functional> // std::function
+#include <mutex> // mutex @TODO replace std::mutex with Godot mutex
+
+#include "net/WebRTCPeerNative.hpp"
+#include <Godot.hpp>
+
+namespace godot_webrtc {
+
+class WebRTCLibPeer : public WebRTCPeerNative {
+ GODOT_CLASS(WebRTCLibPeer, WebRTCPeerNative);
+
+public:
+ static void _register_methods();
+
+ void _init();
+
+ void set_write_mode(godot_int mode);
+ godot_int get_write_mode() const;
+ bool was_string_packet() const;
+ godot_int get_connection_state() const;
+
+ godot_error create_offer();
+ godot_error set_remote_description(const char *type, const char *sdp);
+ godot_error set_local_description(const char *type, const char *sdp);
+ godot_error add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName);
+ godot_error poll();
+
+ /* WebRTCPeer */
+ virtual godot_error get_packet(const uint8_t **r_buffer, int *r_len);
+ virtual godot_error put_packet(const uint8_t *p_buffer, int p_len);
+ virtual godot_int get_available_packet_count() const;
+ virtual godot_int get_max_packet_size() const;
+
+ WebRTCLibPeer();
+ ~WebRTCLibPeer();
+
+ /* helper functions */
+
+ void queue_signal(godot::String p_name, int p_argc, const godot::Variant &p_arg1 = godot::Variant(), const godot::Variant &p_arg2 = godot::Variant(), const godot::Variant &p_arg3 = godot::Variant());
+ // void queue_signal(godot::StringName p_name, Variant_ARG_LIST);
+ void queue_packet(uint8_t *, int);
+ godot_error set_description(const char *type, const char *sdp, bool isLocal);
+
+ /** DataChannelObserver callback functions **/
+ class GodotDCO : public webrtc::DataChannelObserver {
+ public:
+ WebRTCLibPeer *parent;
+
+ GodotDCO(WebRTCLibPeer *parent);
+ void OnMessage(const webrtc::DataBuffer &buffer) override;
+ void OnStateChange() override; // UNUSED
+ void OnBufferedAmountChange(uint64_t previous_amount) override; // UNUSED
+ };
+
+ /** PeerConnectionObserver callback functions **/
+ class GodotPCO : public webrtc::PeerConnectionObserver {
+ public:
+ WebRTCLibPeer *parent;
+
+ GodotPCO(WebRTCLibPeer *parent);
+ void OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) override;
+ void OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
+ void OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
+ void OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) override;
+ void OnRenegotiationNeeded() override;
+ void OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) override;
+ void OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) override;
+ void OnIceCandidate(const webrtc::IceCandidateInterface *candidate) override;
+ };
+
+ /** CreateSessionDescriptionObserver callback functions **/
+ class GodotCSDO : public webrtc::CreateSessionDescriptionObserver {
+ public:
+ WebRTCLibPeer *parent;
+
+ GodotCSDO(WebRTCLibPeer *parent);
+ void OnSuccess(webrtc::SessionDescriptionInterface *desc) override;
+ void OnFailure(const std::string &error) override;
+ };
+
+ /** SetSessionDescriptionObserver callback functions **/
+ class GodotSSDO : public webrtc::SetSessionDescriptionObserver {
+ public:
+ WebRTCLibPeer *parent;
+
+ GodotSSDO(WebRTCLibPeer *parent);
+ void OnSuccess() override;
+ void OnFailure(const std::string &error) override;
+ };
+
+ GodotDCO dco;
+ GodotPCO pco;
+ rtc::scoped_refptr<GodotSSDO> ptr_ssdo;
+ rtc::scoped_refptr<GodotCSDO> ptr_csdo;
+
+ std::mutex *mutex_signal_queue;
+ std::mutex *mutex_packet_queue;
+ int packet_queue_size;
+ std::queue<uint8_t *> packet_queue;
+ std::queue<int> packet_sizes_queue;
+ 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;
+ rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel;
+};
+
+} // namespace godot_webrtc
+
+#endif // WEBRTC_PEER_H
diff --git a/src/WebRTCPeer.cpp b/src/WebRTCPeer.cpp
deleted file mode 100644
index f7572ad..0000000
--- a/src/WebRTCPeer.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-#include "WebRTCPeer.hpp"
-
-using namespace godot_webrtc;
-
-void WebRTCPeer::set_write_mode(godot_int mode) {
-
-}
-
-godot_int WebRTCPeer::get_write_mode() const {
- return 0;
-}
-
-bool WebRTCPeer::was_string_packet() const {
- return false;
-}
-
-godot_int WebRTCPeer::get_connection_state() const {
- return 0;
-}
-
-godot_error WebRTCPeer::create_offer() {
- return GODOT_FAILED;
-}
-
-godot_error WebRTCPeer::set_remote_description(const char *type, const char *sdp) {
- return GODOT_FAILED;
-}
-
-godot_error WebRTCPeer::set_local_description(const char *type, const char *sdp) {
- return GODOT_FAILED;
-}
-
-godot_error WebRTCPeer::add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) {
- return GODOT_FAILED;
-}
-
-godot_error WebRTCPeer::poll() {
- return GODOT_FAILED;
-}
-
-godot_error WebRTCPeer::get_packet(const uint8_t **r_buffer, int &r_len) {
- printf("Get packet");
- r_len = 0;
- return GODOT_OK;
-}
-
-godot_error WebRTCPeer::put_packet(const uint8_t *p_buffer, int p_len) {
- printf("Put packet");
- return GODOT_OK;
-}
-
-godot_int WebRTCPeer::get_available_packet_count() const {
- printf("Get packet count");
- return 2;
-}
-
-godot_int WebRTCPeer::get_max_packet_size() const {
- printf("Get max packet size");
- return 1024;
-}
-
-void WebRTCPeer::_register_methods() { }
-
-void WebRTCPeer::_init() {
- printf("Binding PacketPeer interface");
- register_interface(&interface);
-}
-
-WebRTCPeer::WebRTCPeer() {
-}
-
-WebRTCPeer::~WebRTCPeer() {
- if (_owner) {
- printf("Unbinding PacketPeer interface");
- register_interface(NULL);
- }
-}
diff --git a/src/WebRTCPeer.hpp b/src/WebRTCPeer.hpp
deleted file mode 100644
index 72560bc..0000000
--- a/src/WebRTCPeer.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#ifndef WEBRTC_PEER_H
-#define WEBRTC_PEER_H
-
-#include <Godot.hpp>
-
-#include "net/WebRTCPeerNative.hpp"
-
-namespace godot_webrtc {
-
-class WebRTCPeer : public WebRTCPeerNative {
- GODOT_CLASS(WebRTCPeer, WebRTCPeerNative);
-
-public:
- static void _register_methods();
-
- void _init();
-
- void set_write_mode(godot_int mode);
- godot_int get_write_mode() const;
- bool was_string_packet() const;
- godot_int get_connection_state() const;
-
- godot_error create_offer();
- godot_error set_remote_description(const char *type, const char *sdp);
- godot_error set_local_description(const char *type, const char *sdp);
- godot_error add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName);
- godot_error poll();
-
- /* WebRTCPeer */
- virtual godot_error get_packet(const uint8_t **r_buffer, int &r_len);
- virtual godot_error put_packet(const uint8_t *p_buffer, int p_len);
- virtual godot_int get_available_packet_count() const;
- virtual godot_int get_max_packet_size() const;
-
- WebRTCPeer();
- ~WebRTCPeer();
-};
-
-}
-
-#endif // WEBRTC_PEER_H
diff --git a/src/init.cpp b/src/init.cpp
index 60aaf45..ec6998b 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1,6 +1,6 @@
-#include <gdnative_api_struct.gen.h>
+#include "WebRTCLibPeer.hpp"
#include "net/WebRTCPeerNative.hpp"
-#include "WebRTCPeer.hpp"
+#include <gdnative_api_struct.gen.h>
/* Godot export stuff */
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
@@ -21,5 +21,5 @@ extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_opt
extern "C" void GDN_EXPORT godot_nativescript_init(void *handle) {
godot::Godot::nativescript_init(handle);
- godot::register_class<godot_webrtc::WebRTCPeer>();
+ godot::register_class<godot_webrtc::WebRTCLibPeer>();
}
diff --git a/src/net/WebRTCPeerNative.cpp b/src/net/WebRTCPeerNative.cpp
index be9040c..449cca2 100644
--- a/src/net/WebRTCPeerNative.cpp
+++ b/src/net/WebRTCPeerNative.cpp
@@ -7,16 +7,14 @@ void WebRTCPeerNative::register_interface(const godot_net_webrtc_peer *p_interfa
_net_api->godot_net_bind_webrtc_peer(_owner, p_interface);
}
-void WebRTCPeerNative::_register_methods() { }
+void WebRTCPeerNative::_register_methods() {}
void WebRTCPeerNative::_init() {
- printf("Binding PacketPeer interface");
register_interface(&interface);
}
WebRTCPeerNative::~WebRTCPeerNative() {
if (_owner) {
- printf("Unbinding PacketPeer interface");
register_interface(NULL);
}
}
@@ -26,54 +24,54 @@ WebRTCPeerNative::~WebRTCPeerNative() {
* In this case it forwards calls to our C++ class, but could be plain C,
* and you could use void *user for any kind of state struct pointer you have.
*/
-godot_error get_packet_wp(void *user, const uint8_t **r_buffer, int &r_len) {
- return ((WebRTCPeerNative *) user)->get_packet(r_buffer, r_len);
+godot_error get_packet_wp(void *user, const uint8_t **r_buffer, int *r_len) {
+ return ((WebRTCPeerNative *)user)->get_packet(r_buffer, r_len);
}
godot_error put_packet_wp(void *user, const uint8_t *p_buffer, int p_len) {
- return ((WebRTCPeerNative *) user)->put_packet(p_buffer, p_len);
+ return ((WebRTCPeerNative *)user)->put_packet(p_buffer, p_len);
}
godot_int get_available_packet_count_wp(const void *user) {
- return ((WebRTCPeerNative *) user)->get_available_packet_count();
+ return ((WebRTCPeerNative *)user)->get_available_packet_count();
}
godot_int get_max_packet_size_wp(const void *user) {
- return ((WebRTCPeerNative *) user)->get_max_packet_size();
+ return ((WebRTCPeerNative *)user)->get_max_packet_size();
}
void set_write_mode_wp(void *user, godot_int write_mode) {
- ((WebRTCPeerNative *) user)->set_write_mode(write_mode);
+ ((WebRTCPeerNative *)user)->set_write_mode(write_mode);
}
godot_int get_write_mode_wp(const void *user) {
- return ((WebRTCPeerNative *) user)->get_write_mode();
+ return ((WebRTCPeerNative *)user)->get_write_mode();
}
bool was_string_packet_wp(const void *user) {
- return ((WebRTCPeerNative *) user)->was_string_packet();
+ return ((WebRTCPeerNative *)user)->was_string_packet();
}
godot_int get_connection_state_wp(const void *user) {
- return ((WebRTCPeerNative *) user)->get_connection_state();
+ return ((WebRTCPeerNative *)user)->get_connection_state();
}
godot_error create_offer_wp(void *user) {
- return ((WebRTCPeerNative *) user)->create_offer();
+ return ((WebRTCPeerNative *)user)->create_offer();
}
godot_error set_remote_description_wp(void *user, const char *type, const char *sdp) {
- return ((WebRTCPeerNative *) user)->set_remote_description(type, sdp);
+ return ((WebRTCPeerNative *)user)->set_remote_description(type, sdp);
}
godot_error set_local_description_wp(void *user, const char *type, const char *sdp) {
- return ((WebRTCPeerNative *) user)->set_local_description(type, sdp);
+ return ((WebRTCPeerNative *)user)->set_local_description(type, sdp);
}
godot_error add_ice_candidate_wp(void *user, const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) {
- return ((WebRTCPeerNative *) user)->add_ice_candidate(sdpMidName, sdpMlineIndexName, sdpName);
+ return ((WebRTCPeerNative *)user)->add_ice_candidate(sdpMidName, sdpMlineIndexName, sdpName);
}
godot_error poll_wp(void *user) {
- return ((WebRTCPeerNative *) user)->poll();
+ return ((WebRTCPeerNative *)user)->poll();
}
diff --git a/src/net/WebRTCPeerNative.hpp b/src/net/WebRTCPeerNative.hpp
index fe2a8a7..90e08b3 100644
--- a/src/net/WebRTCPeerNative.hpp
+++ b/src/net/WebRTCPeerNative.hpp
@@ -8,7 +8,7 @@
#include <net/godot_net.h>
/* Forward declare interface functions */
-godot_error get_packet_wp(void *, const uint8_t **, int &);
+godot_error get_packet_wp(void *, const uint8_t **, int *);
godot_error put_packet_wp(void *, const uint8_t *, int);
godot_int get_available_packet_count_wp(const void *);
godot_int get_max_packet_size_wp(const void *);
@@ -29,7 +29,7 @@ class WebRTCPeerNative : public godot::WebRTCPeerGDNative {
protected:
godot_net_webrtc_peer interface = {
- {3, 1},
+ { 3, 1 },
this,
&get_packet_wp,
@@ -63,13 +63,13 @@ public:
virtual godot_int get_connection_state() const = 0;
virtual godot_error create_offer() = 0;
- virtual godot_error set_remote_description(const char * type, const char * sdp) = 0;
- virtual godot_error set_local_description(const char * type, const char * sdp) = 0;
+ virtual godot_error set_remote_description(const char *type, const char *sdp) = 0;
+ virtual godot_error set_local_description(const char *type, const char *sdp) = 0;
virtual godot_error add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) = 0;
virtual godot_error poll() = 0;
/* PacketPeer */
- virtual godot_error get_packet(const uint8_t **r_buffer, int &r_len) = 0;
+ virtual godot_error get_packet(const uint8_t **r_buffer, int *r_len) = 0;
virtual godot_error put_packet(const uint8_t *p_buffer, int p_len) = 0;
virtual godot_int get_available_packet_count() const = 0;
virtual godot_int get_max_packet_size() const = 0;