summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2020-01-03 19:43:01 +0100
committerGitHub <noreply@github.com>2020-01-03 19:43:01 +0100
commit61e45cb083a2879bed238f3052f7c12bd230da16 (patch)
tree8a8f727a8d79342f2bd5df79bc58fc32b964b821
parent423454086e21d40a545f9e46d6e35c1b3c557d77 (diff)
parent6983019cab6acc39d3e4157f7e03aafadb2291df (diff)
downloadfork-godot-webrtc-native-61e45cb083a2879bed238f3052f7c12bd230da16.tar.gz
fork-godot-webrtc-native-61e45cb083a2879bed238f3052f7c12bd230da16.tar.bz2
fork-godot-webrtc-native-61e45cb083a2879bed238f3052f7c12bd230da16.zip
Merge pull request #10 from Faless/refactor/better-scons
Better build script, readme
-rw-r--r--.gitmodules3
-rw-r--r--README.md66
-rw-r--r--SConstruct65
m---------godot-cpp0
-rw-r--r--lib/godot-cpp/release/x64/.gitignore2
-rw-r--r--lib/godot-cpp/release/x86/.gitignore2
-rw-r--r--lib/webrtc/lib/linux/.gitignore2
-rw-r--r--lib/webrtc/lib/windows/.gitignore2
-rw-r--r--misc/gdnlib.tres13
-rw-r--r--src/GodotCreateSessionDescriptionObserver.cpp16
-rw-r--r--src/GodotPeerConnectionObserver.cpp48
-rw-r--r--src/GodotSetSessionDescriptionObserver.cpp11
-rw-r--r--src/WebRTCLibObservers.cpp53
-rw-r--r--webrtc/.gitignore (renamed from lib/webrtc/.gitignore)0
-rw-r--r--webrtc/linux/.gitignore (renamed from lib/godot-cpp/debug/x64/.gitignore)0
-rw-r--r--webrtc/windows/.gitignore (renamed from lib/godot-cpp/debug/x86/.gitignore)0
16 files changed, 170 insertions, 113 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..64fc4d4
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "godot-cpp"]
+ path = godot-cpp
+ url = https://github.com/GodotNativeTools/godot-cpp
diff --git a/README.md b/README.md
index e69de29..5f6e8ab 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1,66 @@
+# GDNative WebRTC plugin for Godot
+
+## Getting Started
+
+| **Download latest binary version** | [**GitHub**](https://github.com/godotengine/webrtc-native/releases) |
+| --- | --- |
+
+### Compiling
+
+Clone this repository with the following command to checkout both [godot-cpp](https://github.com/GodotNativeTools/godot-cpp) and [godot_headers](https://github.com/GodotNativeTools/godot_headers) dependencies.
+
+```
+$ git clone --recurse-submodules git@github.com:godotengine/webrtc-native.git
+```
+
+Note that if you wish to use a specific branch, add the -b option to the clone command:
+```
+$ git clone --recurse-submodules -b 3.2 git@github.com:godotengine/webrtc-native.git
+```
+
+If you already checked out the branch use the following commands to update the dependencies:
+
+```
+$ git submodule update --init --recursive
+```
+
+Right now our directory structure should look like this:
+```
+webrtc-native/
+├─bin/
+├─godot-cpp/
+| └─godot_headers/
+├─src/
+└─webrtc/
+```
+
+### Compiling the cpp bindings library
+First, we need to compile our cpp bindings library:
+```
+$ cd godot-cpp
+$ scons platform=<your platform> generate_bindings=yes
+$ cd ..
+```
+
+> Replace `<your platform>` with either `windows`, `linux` or `osx`.
+
+> Include `use_llvm=yes` for using clang++
+
+> Include `target=runtime` to build a runtime build (windows only at the moment)
+
+> Include `target=release` or `target=debug` for release or debug build.
+
+> The resulting library will be created in `godot-cpp/bin/`, take note of its name as it will be different depending on platform.
+
+### Building WebRTC
+
+Use [this script](https://github.com/Faless/webrtc-builds) to build and package the WebRTCLibrary (`branch-heads/68`), or [**download latest pre-compiled binaries**](https://github.com/Faless/webrtc-builds/releases)
+Extract content of `include` into `webrtc/include` and content of `bin` into `webrtc/<your platform>`
+
+### Compiling the plugin.
+
+```
+$ scons platform=<your platform> target=<your target>
+```
+
+The generated library and associated `gdns` will be placed in `bin/webrtc/` or `bin/webrtc_debug/` according to the desired target. You simply need to copy that folder into your project.
diff --git a/SConstruct b/SConstruct
index cc5807d..6819640 100644
--- a/SConstruct
+++ b/SConstruct
@@ -9,14 +9,26 @@ def add_sources(sources, dirpath, extension):
sources.append(dirpath + '/' + f)
-def get_arch_dir(name):
- if name == '32':
- return 'x86'
- elif name == '64':
- return 'x64'
- return name
+def gen_gdnative_lib(target, source, env):
+ for t in target:
+ with open(t.srcnode().path, 'w') as w:
+ w.write(source[0].get_contents().replace('{GDNATIVE_PATH}', os.path.splitext(t.name)[0]).replace('{TARGET}', env['target']))
+
env = Environment()
+
+target_arch = ARGUMENTS.get('b', ARGUMENTS.get('bits', '64'))
+target_platform = ARGUMENTS.get('p', ARGUMENTS.get('platform', 'linux'))
+if target_platform == 'windows':
+ # This makes sure to keep the session environment variables on windows,
+ # that way you can run scons in a vs 2017 prompt and it will find all the required tools
+ if (target_arch == '64'):
+ env = Environment(ENV = os.environ, TARGET_ARCH='amd64')
+ else:
+ env = Environment(ENV = os.environ, TARGET_ARCH='x86')
+
+env.Append(BUILDERS={'GDNativeLibBuilder': Builder(action=gen_gdnative_lib)})
+
customs = ['custom.py']
opts = Variables(customs, ARGUMENTS)
@@ -29,22 +41,18 @@ opts.Update(env)
target = env['target']
host_platform = platform.system()
-target_platform = ARGUMENTS.get('p', ARGUMENTS.get('platform', 'linux'))
-target_arch = ARGUMENTS.get('a', ARGUMENTS.get('arch', '64'))
# Local dependency paths, adapt them to your setup
-godot_headers = ARGUMENTS.get('headers', '../godot_headers')
-godot_cpp_headers = ARGUMENTS.get('godot_cpp_headers', '../godot-cpp/include')
-godot_cpp_lib_dir = ARGUMENTS.get('godot_cpp_lib_dir', 'lib/godot-cpp')
-result_path = 'bin'
-result_name = 'webrtc_native'
+godot_headers = ARGUMENTS.get('headers', 'godot-cpp/godot_headers')
+godot_cpp_headers = ARGUMENTS.get('godot_cpp_headers', 'godot-cpp/include')
+godot_cpp_lib_dir = ARGUMENTS.get('godot_cpp_lib_dir', 'godot-cpp/bin')
+result_path = os.path.join('bin', 'webrtc' if env['target'] == 'release' else 'webrtc_debug', 'lib')
+lib_prefix = ""
# Convenience check to enforce the use_llvm overrides when CXX is clang(++)
if 'CXX' in env and 'clang' in os.path.basename(env['CXX']):
env['use_llvm'] = True
if target_platform == 'linux':
- result_name += '.linux.' + target + '.' + target_arch
-
env['CXX']='g++'
# LLVM
@@ -70,18 +78,9 @@ if target_platform == 'linux':
env.Append(LINKFLAGS = [ '-m64' ])
elif target_platform == 'windows':
- # This makes sure to keep the session environment variables on windows,
- # that way you can run scons in a vs 2017 prompt and it will find all the required tools
- if (target_arch == '64'):
- env = Environment(ENV = os.environ, TARGET_ARCH='amd64')
- else:
- env = Environment(ENV = os.environ, TARGET_ARCH='x86')
-
- result_name += '.windows.' + target + '.' + target_arch
-
if host_platform == 'Windows':
- #result_name += '.lib'
+ lib_prefix = "lib"
env.Append(LINKFLAGS = [ '/WX' ])
if target == 'debug':
env.Append(CCFLAGS = ['/EHsc', '/D_DEBUG', '/MDd' ])
@@ -102,7 +101,6 @@ elif target_platform == 'osx':
# Only 64-bits is supported for OS X
target_arch = '64'
- result_name += '.osx.' + target + '.' + target_arch
env.Append(CCFLAGS = [ '-g','-O3', '-std=c++14', '-arch', 'x86_64' ])
env.Append(LINKFLAGS = [ '-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup' ])
@@ -114,13 +112,13 @@ else:
# Godot CPP bindings
env.Append(CPPPATH=[godot_headers])
env.Append(CPPPATH=[godot_cpp_headers, godot_cpp_headers + '/core', godot_cpp_headers + '/gen'])
-env.Append(LIBPATH=[godot_cpp_lib_dir + '/' + target + '/' + get_arch_dir(target_arch)])
-env.Append(LIBS=['godot-cpp'])
+env.Append(LIBPATH=[godot_cpp_lib_dir])
+env.Append(LIBS=['%sgodot-cpp.%s.%s.%s' % (lib_prefix, target_platform, target, target_arch)])
# WebRTC stuff
-webrtc_dir = "lib/webrtc"
+webrtc_dir = "webrtc"
lib_name = 'libwebrtc_full'
-lib_path = webrtc_dir + '/lib/' + target_platform
+lib_path = os.path.join(webrtc_dir, target_platform)
if target_arch == '64':
lib_path += '/x64'
@@ -168,5 +166,12 @@ suffix = '.%s.%s' % (target, target_arch)
env["SHOBJSUFFIX"] = suffix + env["SHOBJSUFFIX"]
# Make the shared library
+result_name = 'webrtc_native.%s.%s.%s' % (target_platform, target, target_arch)
library = env.SharedLibrary(target=os.path.join(result_path, result_name), source=sources)
Default(library)
+
+# GDNativeLibrary
+gdnlib = 'webrtc'
+if target != 'release':
+ gdnlib += '_debug'
+Default(env.GDNativeLibBuilder([os.path.join('bin', gdnlib, gdnlib + '.gdns')], ['misc/gdnlib.tres']))
diff --git a/godot-cpp b/godot-cpp
new file mode 160000
+Subproject 7cbb846417acf0154a786bcaee8a5b1d7b40df5
diff --git a/lib/godot-cpp/release/x64/.gitignore b/lib/godot-cpp/release/x64/.gitignore
deleted file mode 100644
index d6b7ef3..0000000
--- a/lib/godot-cpp/release/x64/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*
-!.gitignore
diff --git a/lib/godot-cpp/release/x86/.gitignore b/lib/godot-cpp/release/x86/.gitignore
deleted file mode 100644
index d6b7ef3..0000000
--- a/lib/godot-cpp/release/x86/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*
-!.gitignore
diff --git a/lib/webrtc/lib/linux/.gitignore b/lib/webrtc/lib/linux/.gitignore
deleted file mode 100644
index d6b7ef3..0000000
--- a/lib/webrtc/lib/linux/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*
-!.gitignore
diff --git a/lib/webrtc/lib/windows/.gitignore b/lib/webrtc/lib/windows/.gitignore
deleted file mode 100644
index d6b7ef3..0000000
--- a/lib/webrtc/lib/windows/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-*
-!.gitignore
diff --git a/misc/gdnlib.tres b/misc/gdnlib.tres
new file mode 100644
index 0000000..6c44cc7
--- /dev/null
+++ b/misc/gdnlib.tres
@@ -0,0 +1,13 @@
+[gd_resource type="GDNativeLibrary" format=2]
+
+[resource]
+singleton = true
+reloadable = false
+entry/Windows.64 = "res://{GDNATIVE_PATH}/lib/webrtc_native.windows.{TARGET}.64.dll"
+entry/Windows.32 = "res://{GDNATIVE_PATH}/lib/webrtc_native.windows.{TARGET}.32.dll"
+entry/X11.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.64.so"
+entry/X11.32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.32.so"
+dependency/Windows.64 = [ ]
+dependency/Windows.32 = [ ]
+dependency/X11.64 = [ ]
+dependency/X11.32 = [ ]
diff --git a/src/GodotCreateSessionDescriptionObserver.cpp b/src/GodotCreateSessionDescriptionObserver.cpp
deleted file mode 100644
index f9d110c..0000000
--- a/src/GodotCreateSessionDescriptionObserver.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "WebRTCLibPeerConnection.hpp"
-
-using namespace godot_webrtc;
-
-WebRTCLibPeerConnection::GodotCSDO::GodotCSDO(WebRTCLibPeerConnection *parent) {
- this->parent = parent;
-}
-
-void WebRTCLibPeerConnection::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("session_description_created", 2, desc->type().c_str(), sdp.c_str());
-};
-
-void WebRTCLibPeerConnection::GodotCSDO::OnFailure(const std::string &error){};
diff --git a/src/GodotPeerConnectionObserver.cpp b/src/GodotPeerConnectionObserver.cpp
deleted file mode 100644
index c3f8f39..0000000
--- a/src/GodotPeerConnectionObserver.cpp
+++ /dev/null
@@ -1,48 +0,0 @@
-#include "WebRTCLibPeerConnection.hpp"
-#include "WebRTCLibDataChannel.hpp"
-
-using namespace godot_webrtc;
-
-WebRTCLibPeerConnection::GodotPCO::GodotPCO(WebRTCLibPeerConnection *parent) {
- this->parent = parent;
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
- parent->queue_signal("data_channel_received", 1, WebRTCLibDataChannel::new_data_channel(data_channel));
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnRenegotiationNeeded() {
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) {
-}
-
-void WebRTCLibPeerConnection::GodotPCO::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) {
-}
-
-void WebRTCLibPeerConnection::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("ice_candidate_created",
- 3,
- candidateSdpMidName,
- candidateSdpMlineIndexName,
- candidateSdpName);
-}
diff --git a/src/GodotSetSessionDescriptionObserver.cpp b/src/GodotSetSessionDescriptionObserver.cpp
deleted file mode 100644
index 96d466c..0000000
--- a/src/GodotSetSessionDescriptionObserver.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "WebRTCLibPeerConnection.hpp"
-
-using namespace godot_webrtc;
-
-WebRTCLibPeerConnection::GodotSSDO::GodotSSDO(WebRTCLibPeerConnection *parent) {
- this->parent = parent;
-}
-
-void WebRTCLibPeerConnection::GodotSSDO::OnSuccess(){};
-
-void WebRTCLibPeerConnection::GodotSSDO::OnFailure(const std::string &error){};
diff --git a/src/WebRTCLibObservers.cpp b/src/WebRTCLibObservers.cpp
new file mode 100644
index 0000000..4564195
--- /dev/null
+++ b/src/WebRTCLibObservers.cpp
@@ -0,0 +1,53 @@
+#include "WebRTCLibDataChannel.hpp"
+#include "WebRTCLibPeerConnection.hpp"
+
+using namespace godot_webrtc;
+
+// CreateSessionObseerver
+WebRTCLibPeerConnection::GodotCSDO::GodotCSDO(WebRTCLibPeerConnection *parent) {
+ this->parent = parent;
+}
+
+void WebRTCLibPeerConnection::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("session_description_created", 2, desc->type().c_str(), sdp.c_str());
+};
+
+void WebRTCLibPeerConnection::GodotCSDO::OnFailure(const std::string &error){};
+
+// SetSessionObseerver
+WebRTCLibPeerConnection::GodotSSDO::GodotSSDO(WebRTCLibPeerConnection *parent) {
+ this->parent = parent;
+}
+
+void WebRTCLibPeerConnection::GodotSSDO::OnSuccess(){};
+void WebRTCLibPeerConnection::GodotSSDO::OnFailure(const std::string &error){};
+
+// PeerConnectionObserver
+WebRTCLibPeerConnection::GodotPCO::GodotPCO(WebRTCLibPeerConnection *parent) {
+ this->parent = parent;
+}
+
+void WebRTCLibPeerConnection::GodotPCO::OnDataChannel(rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) {
+ parent->queue_signal("data_channel_received", 1, WebRTCLibDataChannel::new_data_channel(data_channel));
+}
+
+void WebRTCLibPeerConnection::GodotPCO::OnIceCandidate(const webrtc::IceCandidateInterface *candidate) {
+ 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("ice_candidate_created", 3, candidateSdpMidName, candidateSdpMlineIndexName, candidateSdpName);
+}
+
+void WebRTCLibPeerConnection::GodotPCO::OnSignalingChange(webrtc::PeerConnectionInterface::SignalingState new_state) {}
+void WebRTCLibPeerConnection::GodotPCO::OnAddStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {}
+void WebRTCLibPeerConnection::GodotPCO::OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) {}
+void WebRTCLibPeerConnection::GodotPCO::OnRenegotiationNeeded() {}
+void WebRTCLibPeerConnection::GodotPCO::OnIceConnectionChange(webrtc::PeerConnectionInterface::IceConnectionState new_state) {}
+void WebRTCLibPeerConnection::GodotPCO::OnIceGatheringChange(webrtc::PeerConnectionInterface::IceGatheringState new_state) {}
diff --git a/lib/webrtc/.gitignore b/webrtc/.gitignore
index 08f514e..08f514e 100644
--- a/lib/webrtc/.gitignore
+++ b/webrtc/.gitignore
diff --git a/lib/godot-cpp/debug/x64/.gitignore b/webrtc/linux/.gitignore
index d6b7ef3..d6b7ef3 100644
--- a/lib/godot-cpp/debug/x64/.gitignore
+++ b/webrtc/linux/.gitignore
diff --git a/lib/godot-cpp/debug/x86/.gitignore b/webrtc/windows/.gitignore
index d6b7ef3..d6b7ef3 100644
--- a/lib/godot-cpp/debug/x86/.gitignore
+++ b/webrtc/windows/.gitignore