summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2018-08-14 04:41:15 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-03-08 15:11:34 +0100
commitf2799fdbb296fa764384ba085fcb46e19248b09a (patch)
tree8ab05706e0c067d30b31679b5cfbd95a2fa49f2c
parent34fd1f8caa847d75ff7d5c6e3b8619b494608629 (diff)
downloadfork-godot-webrtc-native-f2799fdbb296fa764384ba085fcb46e19248b09a.tar.gz
fork-godot-webrtc-native-f2799fdbb296fa764384ba085fcb46e19248b09a.tar.bz2
fork-godot-webrtc-native-f2799fdbb296fa764384ba085fcb46e19248b09a.zip
Fix name collision, scons file, final touches
-rw-r--r--SConstruct4
-rw-r--r--src/GodotCreateSessionDescriptionObserver.cpp8
-rw-r--r--src/GodotDataChannelObserver.cpp10
-rw-r--r--src/GodotPeerConnectionObserver.cpp20
-rw-r--r--src/GodotSetSessionDescriptionObserver.cpp8
-rw-r--r--src/WebRTCLibPeer.cpp (renamed from src/WebRTCPeer.cpp)48
-rw-r--r--src/WebRTCLibPeer.hpp (renamed from src/WebRTCPeer.hpp)31
-rw-r--r--src/init.cpp4
-rw-r--r--src/net/WebRTCPeerNative.cpp2
-rw-r--r--src/net/WebRTCPeerNative.hpp4
10 files changed, 67 insertions, 72 deletions
diff --git a/SConstruct b/SConstruct
index ba8e193..54a06ca 100644
--- a/SConstruct
+++ b/SConstruct
@@ -111,12 +111,12 @@ elif target_platform == "windows":
# Mostly VisualStudio
if env["CC"] == "cl":
env.Append(CCFLAGS=["/DWEBRTC_WIN", "/DWIN32_LEAN_AND_MEAN", "/DNOMINMAX", "/DRTC_UNUSED=", "/DNO_RETURN="])
- env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in ["secur32", lib_name]])
+ 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=["-DWINVER=0x0603", "-D_WIN32_WINNT=0x0603", "-DWEBRTC_WIN", "-DWIN32_LEAN_AND_MEAN", "-DNOMINMAX", "-DRTC_UNUSED=", "-DNO_RETURN="])
- env.Append(LIBS=["secur32", lib_name])
+ 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
index 1f4b661..77d1308 100644
--- a/src/GodotCreateSessionDescriptionObserver.cpp
+++ b/src/GodotCreateSessionDescriptionObserver.cpp
@@ -1,16 +1,16 @@
-#include "WebRTCPeer.hpp"
+#include "WebRTCLibPeer.hpp"
using namespace godot_webrtc;
-WebRTCPeer::GodotCSDO::GodotCSDO(WebRTCPeer *parent) {
+WebRTCLibPeer::GodotCSDO::GodotCSDO(WebRTCLibPeer *parent) {
this->parent = parent;
}
-void WebRTCPeer::GodotCSDO::OnSuccess(webrtc::SessionDescriptionInterface *desc) {
+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 WebRTCPeer::GodotCSDO::OnFailure(const std::string &error){};
+void WebRTCLibPeer::GodotCSDO::OnFailure(const std::string &error){};
diff --git a/src/GodotDataChannelObserver.cpp b/src/GodotDataChannelObserver.cpp
index 081c868..7a6cf96 100644
--- a/src/GodotDataChannelObserver.cpp
+++ b/src/GodotDataChannelObserver.cpp
@@ -1,12 +1,12 @@
-#include "WebRTCPeer.hpp"
+#include "WebRTCLibPeer.hpp"
using namespace godot_webrtc;
-WebRTCPeer::GodotDCO::GodotDCO(WebRTCPeer *parent) {
+WebRTCLibPeer::GodotDCO::GodotDCO(WebRTCLibPeer *parent) {
this->parent = parent;
}
-void WebRTCPeer::GodotDCO::OnMessage(const webrtc::DataBuffer &buffer) {
+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()];
@@ -14,6 +14,6 @@ void WebRTCPeer::GodotDCO::OnMessage(const webrtc::DataBuffer &buffer) {
parent->queue_packet(memory_controlled_buffer, buffer.data.size());
};
-void WebRTCPeer::GodotDCO::OnStateChange(){};
+void WebRTCLibPeer::GodotDCO::OnStateChange(){};
-void WebRTCPeer::GodotDCO::OnBufferedAmountChange(uint64_t previous_amount){};
+void WebRTCLibPeer::GodotDCO::OnBufferedAmountChange(uint64_t previous_amount){};
diff --git a/src/GodotPeerConnectionObserver.cpp b/src/GodotPeerConnectionObserver.cpp
index 572b6d7..298cfcf 100644
--- a/src/GodotPeerConnectionObserver.cpp
+++ b/src/GodotPeerConnectionObserver.cpp
@@ -1,33 +1,33 @@
-#include "WebRTCPeer.hpp"
+#include "WebRTCLibPeer.hpp"
using namespace godot_webrtc;
-WebRTCPeer::GodotPCO::GodotPCO(WebRTCPeer *parent) {
+WebRTCLibPeer::GodotPCO::GodotPCO(WebRTCLibPeer *parent) {
this->parent = parent;
}
-void WebRTCPeer::GodotPCO::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {
+void WebRTCLibPeer::GodotPCO::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {
}
-void WebRTCPeer::GodotPCO::OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
+void WebRTCLibPeer::GodotPCO::OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
}
-void WebRTCPeer::GodotPCO::OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
+void WebRTCLibPeer::GodotPCO::OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
}
-void WebRTCPeer::GodotPCO::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
+void WebRTCLibPeer::GodotPCO::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
}
-void WebRTCPeer::GodotPCO::OnRenegotiationNeeded() {
+void WebRTCLibPeer::GodotPCO::OnRenegotiationNeeded() {
}
-void WebRTCPeer::GodotPCO::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) {
+void WebRTCLibPeer::GodotPCO::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) {
}
-void WebRTCPeer::GodotPCO::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) {
+void WebRTCLibPeer::GodotPCO::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) {
}
-void WebRTCPeer::GodotPCO::OnIceCandidate(const webrtc::IceCandidateInterface *candidate) {
+void WebRTCLibPeer::GodotPCO::OnIceCandidate(const webrtc::IceCandidateInterface *candidate) {
// Serialize the candidate and send it to the remote peer:
godot::Dictionary candidateSDP;
diff --git a/src/GodotSetSessionDescriptionObserver.cpp b/src/GodotSetSessionDescriptionObserver.cpp
index 93b9b8d..52be2af 100644
--- a/src/GodotSetSessionDescriptionObserver.cpp
+++ b/src/GodotSetSessionDescriptionObserver.cpp
@@ -1,11 +1,11 @@
-#include "WebRTCPeer.hpp"
+#include "WebRTCLibPeer.hpp"
using namespace godot_webrtc;
-WebRTCPeer::GodotSSDO::GodotSSDO(WebRTCPeer *parent) {
+WebRTCLibPeer::GodotSSDO::GodotSSDO(WebRTCLibPeer *parent) {
this->parent = parent;
}
-void WebRTCPeer::GodotSSDO::OnSuccess(){};
+void WebRTCLibPeer::GodotSSDO::OnSuccess(){};
-void WebRTCPeer::GodotSSDO::OnFailure(const std::string &error){};
+void WebRTCLibPeer::GodotSSDO::OnFailure(const std::string &error){};
diff --git a/src/WebRTCPeer.cpp b/src/WebRTCLibPeer.cpp
index 00455c0..c94cfcd 100644
--- a/src/WebRTCPeer.cpp
+++ b/src/WebRTCLibPeer.cpp
@@ -1,23 +1,23 @@
-#include "WebRTCPeer.hpp"
+#include "WebRTCLibPeer.hpp"
using namespace godot_webrtc;
-void WebRTCPeer::set_write_mode(godot_int mode) {
+void WebRTCLibPeer::set_write_mode(godot_int mode) {
}
-godot_int WebRTCPeer::get_write_mode() const {
+godot_int WebRTCLibPeer::get_write_mode() const {
return 0;
}
-bool WebRTCPeer::was_string_packet() const {
+bool WebRTCLibPeer::was_string_packet() const {
return false;
}
-godot_int WebRTCPeer::get_connection_state() const {
+godot_int WebRTCLibPeer::get_connection_state() const {
return 0;
}
-godot_error WebRTCPeer::create_offer() {
+godot_error WebRTCLibPeer::create_offer() {
peer_connection->CreateOffer(
ptr_csdo, // CreateSessionDescriptionObserver* observer,
nullptr // webrtc::PeerConnectionInterface::RTCOfferAnswerOptions() // const MediaConstraintsInterface* constraints
@@ -25,17 +25,17 @@ godot_error WebRTCPeer::create_offer() {
return GODOT_OK;
}
-godot_error WebRTCPeer::set_remote_description(const char *type, const char *sdp) {
+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 WebRTCPeer::set_local_description(const char *type, const char *sdp) {
+godot_error WebRTCLibPeer::set_local_description(const char *type, const char *sdp) {
return set_description(type, sdp, true); // isLocal == true
}
-godot_error WebRTCPeer::add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) {
+godot_error WebRTCLibPeer::add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) {
webrtc::SdpParseError *error = nullptr;
webrtc::IceCandidateInterface *candidate = webrtc::CreateIceCandidate(
sdpMidName,
@@ -52,7 +52,7 @@ godot_error WebRTCPeer::add_ice_candidate(const char *sdpMidName, int sdpMlineIn
return GODOT_OK;
}
-godot_error WebRTCPeer::poll() {
+godot_error WebRTCLibPeer::poll() {
std::function<void()> signal;
while (!signal_queue.empty()) {
mutex_signal_queue->lock();
@@ -65,13 +65,13 @@ godot_error WebRTCPeer::poll() {
return GODOT_OK;
}
-godot_error WebRTCPeer::get_packet(const uint8_t **r_buffer, int &r_len) {
+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();
+ *r_len = packet_sizes_queue.front();
packet_queue.pop();
packet_sizes_queue.pop();
@@ -81,24 +81,24 @@ godot_error WebRTCPeer::get_packet(const uint8_t **r_buffer, int &r_len) {
return GODOT_OK;
}
-godot_error WebRTCPeer::put_packet(const uint8_t *p_buffer, int p_len) {
+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 WebRTCPeer::get_available_packet_count() const {
+godot_int WebRTCLibPeer::get_available_packet_count() const {
return packet_queue_size;
}
-godot_int WebRTCPeer::get_max_packet_size() const {
+godot_int WebRTCLibPeer::get_max_packet_size() const {
return 1200;
}
-void WebRTCPeer::_register_methods() {
+void WebRTCLibPeer::_register_methods() {
}
-void WebRTCPeer::_init() {
+void WebRTCLibPeer::_init() {
register_interface(&interface);
// initialize variables:
@@ -118,7 +118,7 @@ void WebRTCPeer::_init() {
nullptr // std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory
);
if (pc_factory.get() == nullptr) { // PeerConnectionFactory couldn't be created. Fail the method call.
- godot_print_error("PeerConnectionFactory could not be created", "_init", "WebRTCPeer.cpp", 80);
+ ERR_PRINT("PeerConnectionFactory could not be created");
// return GODOT_FAILED;
}
@@ -132,7 +132,7 @@ void WebRTCPeer::_init() {
// 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.
- godot_print_error("PeerConnection could not be created", "_init", "WebRTCPeer.cpp", 101);
+ ERR_PRINT("PeerConnection could not be created");
// return GODOT_FAILED;
}
@@ -146,14 +146,14 @@ void WebRTCPeer::_init() {
data_channel->RegisterObserver(&dco);
}
-WebRTCPeer::WebRTCPeer() :
+WebRTCLibPeer::WebRTCLibPeer() :
dco(this),
pco(this),
ptr_csdo(new rtc::RefCountedObject<GodotCSDO>(this)),
ptr_ssdo(new rtc::RefCountedObject<GodotSSDO>(this)) {
}
-WebRTCPeer::~WebRTCPeer() {
+WebRTCLibPeer::~WebRTCLibPeer() {
if (_owner) {
register_interface(NULL);
}
@@ -161,7 +161,7 @@ WebRTCPeer::~WebRTCPeer() {
delete mutex_packet_queue;
}
-void WebRTCPeer::queue_signal(godot::String p_name, int p_argc, const godot::Variant &p_arg1, const godot::Variant &p_arg2, const godot::Variant &p_arg3) {
+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] {
@@ -173,7 +173,7 @@ void WebRTCPeer::queue_signal(godot::String p_name, int p_argc, const godot::Var
mutex_signal_queue->unlock();
}
-void WebRTCPeer::queue_packet(uint8_t *buffer, int buffer_size) {
+void WebRTCLibPeer::queue_packet(uint8_t *buffer, int buffer_size) {
mutex_packet_queue->lock();
packet_queue.push(buffer);
packet_sizes_queue.push(buffer_size);
@@ -181,7 +181,7 @@ void WebRTCPeer::queue_packet(uint8_t *buffer, int buffer_size) {
mutex_packet_queue->unlock();
}
-godot_error WebRTCPeer::set_description(const char *type, const char *sdp, bool isLocal) {
+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;
diff --git a/src/WebRTCPeer.hpp b/src/WebRTCLibPeer.hpp
index 45a90ec..437e80a 100644
--- a/src/WebRTCPeer.hpp
+++ b/src/WebRTCLibPeer.hpp
@@ -3,11 +3,6 @@
#include "api/peerconnectioninterface.h" // interface for all things needed from WebRTC
#include "media/base/mediaengine.h" // needed for CreateModularPeerConnectionFactory
-#ifdef interface
-#pragma message("\n 'interface' is defined \n")
-#undef interface
-#endif // interface
-
#include <functional> // std::function
#include <mutex> // mutex @TODO replace std::mutex with Godot mutex
@@ -16,8 +11,8 @@
namespace godot_webrtc {
-class WebRTCPeer : public WebRTCPeerNative {
- GODOT_CLASS(WebRTCPeer, WebRTCPeerNative);
+class WebRTCLibPeer : public WebRTCPeerNative {
+ GODOT_CLASS(WebRTCLibPeer, WebRTCPeerNative);
public:
static void _register_methods();
@@ -36,13 +31,13 @@ public:
godot_error poll();
/* WebRTCPeer */
- virtual godot_error get_packet(const uint8_t **r_buffer, int &r_len);
+ 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();
+ WebRTCLibPeer();
+ ~WebRTCLibPeer();
/* helper functions */
@@ -54,9 +49,9 @@ public:
/** DataChannelObserver callback functions **/
class GodotDCO : public webrtc::DataChannelObserver {
public:
- WebRTCPeer *parent;
+ WebRTCLibPeer *parent;
- GodotDCO(WebRTCPeer *parent);
+ GodotDCO(WebRTCLibPeer *parent);
void OnMessage(const webrtc::DataBuffer &buffer) override;
void OnStateChange() override; // UNUSED
void OnBufferedAmountChange(uint64_t previous_amount) override; // UNUSED
@@ -65,9 +60,9 @@ public:
/** PeerConnectionObserver callback functions **/
class GodotPCO : public webrtc::PeerConnectionObserver {
public:
- WebRTCPeer *parent;
+ WebRTCLibPeer *parent;
- GodotPCO(WebRTCPeer *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;
@@ -81,9 +76,9 @@ public:
/** CreateSessionDescriptionObserver callback functions **/
class GodotCSDO : public webrtc::CreateSessionDescriptionObserver {
public:
- WebRTCPeer *parent;
+ WebRTCLibPeer *parent;
- GodotCSDO(WebRTCPeer *parent);
+ GodotCSDO(WebRTCLibPeer *parent);
void OnSuccess(webrtc::SessionDescriptionInterface *desc) override;
void OnFailure(const std::string &error) override;
};
@@ -91,9 +86,9 @@ public:
/** SetSessionDescriptionObserver callback functions **/
class GodotSSDO : public webrtc::SetSessionDescriptionObserver {
public:
- WebRTCPeer *parent;
+ WebRTCLibPeer *parent;
- GodotSSDO(WebRTCPeer *parent);
+ GodotSSDO(WebRTCLibPeer *parent);
void OnSuccess() override;
void OnFailure(const std::string &error) override;
};
diff --git a/src/init.cpp b/src/init.cpp
index e8e1d0c..ec6998b 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1,4 +1,4 @@
-#include "WebRTCPeer.hpp"
+#include "WebRTCLibPeer.hpp"
#include "net/WebRTCPeerNative.hpp"
#include <gdnative_api_struct.gen.h>
@@ -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 d2abcaa..449cca2 100644
--- a/src/net/WebRTCPeerNative.cpp
+++ b/src/net/WebRTCPeerNative.cpp
@@ -24,7 +24,7 @@ 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) {
+godot_error get_packet_wp(void *user, const uint8_t **r_buffer, int *r_len) {
return ((WebRTCPeerNative *)user)->get_packet(r_buffer, r_len);
}
diff --git a/src/net/WebRTCPeerNative.hpp b/src/net/WebRTCPeerNative.hpp
index e82f295..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 *);
@@ -69,7 +69,7 @@ public:
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;