mirror of
https://github.com/godotengine/webrtc-native.git
synced 2026-01-07 10:10:05 +03:00
Merge pull request #10 from Faless/refactor/better-scons
Better build script, readme
This commit is contained in:
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
[submodule "godot-cpp"]
|
||||
path = godot-cpp
|
||||
url = https://github.com/GodotNativeTools/godot-cpp
|
||||
66
README.md
66
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.
|
||||
|
||||
65
SConstruct
65
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']))
|
||||
|
||||
1
godot-cpp
Submodule
1
godot-cpp
Submodule
Submodule godot-cpp added at 7cbb846417
2
lib/godot-cpp/release/x64/.gitignore
vendored
2
lib/godot-cpp/release/x64/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
lib/godot-cpp/release/x86/.gitignore
vendored
2
lib/godot-cpp/release/x86/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
lib/webrtc/lib/linux/.gitignore
vendored
2
lib/webrtc/lib/linux/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
2
lib/webrtc/lib/windows/.gitignore
vendored
2
lib/webrtc/lib/windows/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
13
misc/gdnlib.tres
Normal file
13
misc/gdnlib.tres
Normal file
@@ -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 = [ ]
|
||||
@@ -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){};
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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){};
|
||||
53
src/WebRTCLibObservers.cpp
Normal file
53
src/WebRTCLibObservers.cpp
Normal file
@@ -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) {}
|
||||
Reference in New Issue
Block a user