Compare commits

...

34 Commits
0.3 ... 3.2

Author SHA1 Message Date
Fabio Alessandrelli
eeabf0a844 Merge pull request #38 from Faless/refactor/signals
Refactor signals and obeserver, fixes answer creation.
2021-07-09 16:24:35 +02:00
Fabio Alessandrelli
04fbae6ce3 Properly wait success callback before creating answers. 2021-07-09 03:46:25 +02:00
Fabio Alessandrelli
ce3f086ec4 Move observers implementations into PeerConnection. 2021-07-09 03:45:45 +02:00
Fabio Alessandrelli
00ac03c8e7 Use a class instead of lambdas for signals. 2021-07-09 00:53:15 +02:00
Fabio Alessandrelli
fa5296a4e4 Merge pull request #37 from Faless/ci/auto
[CI] Use organization's repository for automated builds.
2021-07-08 23:56:42 +02:00
Fabio Alessandrelli
189c353264 [CI] Use organization's repository for automated builds.
Update README.md to reflect new build sources.
2021-07-08 23:04:16 +02:00
Fabio Alessandrelli
e44c42fde8 Merge pull request #36 from Faless/ci/single
Setup CI for Android, iOS, Linux, macOS, Windows.
2021-07-06 16:27:59 +02:00
Fabio Alessandrelli
524fdde8f2 Setup CI for Android, iOS, Linux, macOS, Windows.
Includes all supported architectures:

* Android:
  - arm (neon)
  - arm64
  - x86
  - x64

* iOS:
  - arm
  - arm64
  - x64 (simulator)

* Linux
  - x86
  - x64

* macOS
  - x64

* windows
  - x86
  - x64

Use a single matrix for builds, then an extra step will package for
release.

Artefacts are generated for each platform/arch combination, along for
the 2 zip containing the full `webrtc` and `webrtc_debug` plugin.
2021-07-06 15:57:55 +02:00
Fabio Alessandrelli
673a4c1a1c Merge pull request #34 from Faless/build/optimization_flags
Fix osx, android optimization flags.
2021-07-05 03:17:27 +02:00
Fabio Alessandrelli
cf98eb2e7a Fix osx, android optimization flags.
Will need to be also fixed in upstream godot-cpp.
2021-07-02 21:58:44 +02:00
Fabio Alessandrelli
7b92ab2a7b Add missing iOS armv7 entry. 2021-07-02 18:11:35 +02:00
Fabio Alessandrelli
e120cc7ed6 Merge pull request #33 from Faless/bump/webrtc_4472
Bump webrtc to branch-heads/4472. Fixes signalling.
2021-07-02 15:50:08 +02:00
Fabio Alessandrelli
da20ebf397 Unified signalling thread. 2021-07-02 15:12:41 +02:00
Fabio Alessandrelli
3711ad23f6 Bump webrtc to branch-heads/4472. 2021-07-02 15:12:41 +02:00
Fabio Alessandrelli
001be78500 Merge pull request #32 from Faless/release/3.2_fix
Fix API breakage after godot cpp 3.2 bump.
2021-07-02 00:39:52 +02:00
Fabio Alessandrelli
416ea27305 Fix API breakage after godot cpp 3.2 bump. 2021-07-02 00:36:41 +02:00
Fabio Alessandrelli
65bb4cb9ae Merge pull request #31 from Faless/release/3.2
Update godot-cpp to tip of 3.2 branch.
2021-07-02 00:29:11 +02:00
Fabio Alessandrelli
3014c3099f Update godot-cpp to tip of 3.2 branch. 2021-07-02 00:26:10 +02:00
Fabio Alessandrelli
c1c7ae5081 Merge pull request #30 from Faless/scons/mac_ios
Add mac and ios platforms. Fix GDNLibrary.
2021-07-02 00:13:48 +02:00
Fabio Alessandrelli
9e287f7cee Add mac and ios platforms. Fix GDNLibrary. 2021-07-01 23:58:01 +02:00
Fabio Alessandrelli
a374cf4510 Merge pull request #24 from rondao/add_android_build_support
Add build support for Android
2021-07-01 07:34:03 +02:00
Fabio Alessandrelli
9ee98ff0e9 Merge pull request #28 from Faless/fix/python3
Fix gdns generation with python3.
2021-05-05 16:42:21 +02:00
Fabio Alessandrelli
f26a1d8e83 Fix gdns generation with python3.
Python2 has reached end-of-life.
2021-05-05 16:40:22 +02:00
Rafael Rondao
7a62fe467b Add build support for Android
To build for Android, use platform=android.
ANDROID_NDK_ROOT env variable needs to be defined.

By default, it builds for armv7 with Api 18.
To build for arm64v8 (or x86, x86_64), use android_arch=arm64v8.
64 bits requires at least Api level 21.

If needed, you can change it with android_api_level=XX.

Signed-off-by: Rafael Rondao <rafael.rondao@gmail.com>
2020-11-07 23:01:34 -03:00
Fabio Alessandrelli
74f2c78db5 Merge pull request #18 from MarkSort/support-server-platform
set library paths for Server platform
2020-08-02 12:07:13 +02:00
Mark Achée
db6d416eba set library paths for Server platform 2020-06-20 12:22:29 -05:00
Fabio Alessandrelli
5f9e74f2fb Merge pull request #11 from Faless/fix/close_crash
Fix crash when closing an invalid peerconnection.
2020-01-13 18:18:20 +01:00
Fabio Alessandrelli
bd8e139ccc Fix crash when closing an invalid peerconnection. 2020-01-03 19:50:48 +01:00
Fabio Alessandrelli
61e45cb083 Merge pull request #10 from Faless/refactor/better-scons
Better build script, readme
2020-01-03 19:43:01 +01:00
Fabio Alessandrelli
6983019cab Initial README 2020-01-03 19:41:21 +01:00
Fabio Alessandrelli
54cbe83c56 Simplify webrtc lib folder structure 2020-01-03 19:41:21 +01:00
Fabio Alessandrelli
20f8f89c2c Use submodule for godot-cpp 2020-01-03 19:41:21 +01:00
Fabio Alessandrelli
4b22741255 Build script also create gdnlib 2020-01-03 19:41:07 +01:00
Fabio Alessandrelli
5769d8b2de Merge observers 2020-01-03 19:35:20 +01:00
22 changed files with 687 additions and 181 deletions

View File

@@ -0,0 +1,51 @@
name: 'Get WebRTC Library'
description: 'Get pre-build statically linked WebRTC library from Faless/webrtc-builds'
inputs:
repo:
description: 'Base repository'
required: true
default: "godotengine/webrtc-actions"
release:
description: 'Release tag'
required: true
default: '4472-33644-92ba70c'
webrtc-base-name:
description: 'The WebRTC version'
required: true
default: "webrtc-33644-92ba70c"
out-dir:
description: 'Directory where to extract the library'
required: true
default: "webrtc"
platform:
description: 'Platform to download'
required: true
archs:
description: 'Space separated list of architecture to fetch'
required: true
runs:
using: "composite"
steps:
- shell: bash
env:
RTC_BASE_URL: https://github.com/${{ inputs.repo }}/releases/download/${{ inputs.release }}/${{ inputs.webrtc-base-name }}
run: |
cd ${{ inputs.out-dir }}
libplat=${{ inputs.platform }}
if [ "${{ inputs.platform }}" = "windows" ]; then
libplat=win
elif [ "${{ inputs.platform }}" = "osx" ]; then
libplat=mac
fi
for arch in ${{ inputs.archs }}
do
echo "Downloading ${{ env.RTC_BASE_URL }}-${{ inputs.platform }}-${arch}.tar.gz"
curl -L ${{ env.RTC_BASE_URL }}-${libplat}-${arch}.tar.gz -o ${arch}.tar.gz
tar -xzf ${arch}.tar.gz
done
mv lib ${{ inputs.platform }}
ls -l
ls -l *

180
.github/workflows/build_release.yml vendored Normal file
View File

@@ -0,0 +1,180 @@
name: 🔧 Build -> Package 📦
on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
name: 🔧 Build
strategy:
matrix:
include:
# Android
- platform: android
arch: 'x86'
sconsflags: 'android_arch=x86'
os: 'ubuntu-20.04'
- platform: android
arch: 'x64'
sconsflags: 'android_arch=x86_64'
os: 'ubuntu-20.04'
- platform: android
arch: 'arm'
sconsflags: 'android_arch=armv7'
os: 'ubuntu-20.04'
- platform: android
arch: 'arm64'
sconsflags: 'android_arch=arm64v8'
os: 'ubuntu-20.04'
# iOS
- platform: ios
arch: 'x64'
sconsflags: 'ios_arch=x86_64 ios_simulator=true'
os: 'macos-latest'
- platform: ios
arch: 'arm'
sconsflags: 'ios_arch=armv7'
os: 'macos-latest'
- platform: ios
arch: 'arm64'
sconsflags: 'ios_arch=arm64'
os: 'macos-latest'
# Linux
- platform: linux
arch: 'x86'
sconsflags: 'bits=32'
os: 'ubuntu-20.04'
- platform: linux
arch: 'x64'
sconsflags: 'bits=64'
os: 'ubuntu-20.04'
# macOS
- platform: osx
arch: 'x64'
sconsflags: 'bits=64'
os: 'macos-latest'
# Windows
- platform: windows
arch: 'x86'
sconsflags: 'bits=32'
os: 'windows-latest'
msvc_arch: amd64_x86
- platform: windows
arch: 'x64'
sconsflags: 'bits=64'
os: 'windows-latest'
msvc_arch: amd64
env:
SCONSFLAGS: ${{ matrix.sconsflags }} platform=${{ matrix.platform }} --jobs=2
NDK_VERSION: 22b
ANDROID_NDK_ROOT: ${{github.workspace}}/android-ndk-r22b
MSVC_VARS: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat'
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- name: Cache NDK
id: cache-ndk
if: ${{ matrix.platform == 'android' }}
uses: actions/cache@v2
with:
path: ${{ env.ANDROID_NDK_ROOT }}
key: ndk-${{ env.NDK_VERSION }}
- name: Download NDK
if: ${{ matrix.platform == 'android' && steps.cache-ndk.outputs.cache-hit != 'true' }}
id: setup-ndk
run: |
cd ${{ github.workspace }}
curl -L https://dl.google.com/android/repository/android-ndk-r${{ env.NDK_VERSION }}-linux-x86_64.zip -o ndk.zip
unzip ndk.zip
ls
- name: Setup MSVC build environment for ${{ matrix.msvc_arch }}
if: ${{ matrix.platform == 'windows' }}
run: "'${{ env.MSVC_VARS }}' ${{ matrix.msvc_arch }}"
- name: Install Linux build dependencies
if: ${{ matrix.platform == 'linux' }}
run: |
sudo apt-get install build-essential gcc-multilib wget g++-multilib
- name: Set up Python 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x'
architecture: 'x64'
- name: Configuring Python packages
run: |
python -c "import sys; print(sys.version)"
python -m pip install scons
python --version
scons --version
- name: Get WebRTC package for ${{ matrix.platform }} - ${{ matrix.arch }}
uses: ./.github/actions/webrtc-download
with:
platform: ${{ matrix.platform }}
archs: ${{ matrix.arch }}
- name: Compilation ${{ matrix.platform }} - ${{ matrix.arch }} - godot-cpp
run: |
scons -C godot-cpp target=debug generate_bindings=yes
scons -C godot-cpp target=release
- name: Compilation ${{ matrix.platform }} - ${{ matrix.arch }} - webrtc-native
run: |
scons target=debug
scons target=release
- uses: actions/upload-artifact@v2
with:
name: ${{ github.job }}-${{ matrix.platform }}-${{ matrix.arch }}
path: bin/*
package:
name: 📦 Package
needs: build
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
path: artifacts
- name: Package artifacts for release
run: |
mkdir release
cd release
for name in webrtc webrtc_debug
do
mkdir -p ${name}/lib/
find ../artifacts -wholename "*/${name}/lib/*" | xargs cp -t ${name}/lib/
find ../artifacts -wholename "*/${name}/${name}.tres" | head -n 1 | xargs cp -t ${name}/
done
zip -r godot-webrtc-native-release.zip webrtc
zip -r godot-webrtc-native-debug.zip webrtc_debug
ls -R
- uses: actions/upload-artifact@v2
with:
name: godot-webrtc-native-debug.zip
path: release/godot-webrtc-native-debug.zip
- uses: actions/upload-artifact@v2
with:
name: godot-webrtc-native-release.zip
path: release/godot-webrtc-native-release.zip

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "godot-cpp"]
path = godot-cpp
url = https://github.com/GodotNativeTools/godot-cpp

View File

@@ -0,0 +1,71 @@
# 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/godotengine/godot-cpp) and [godot-headers](https://github.com/godotengine/godot-headers) dependencies.
```
$ git clone --recurse-submodules https://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 https://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
Building WebRTC is quite a complex task, involves huge downloads and long build times, and produces multiple output libraries that needs to bundled together.
To make things easier, a set of [GitHub Actions](https://docs.github.com/en/actions) are used to generate the library for this plugin, [available in this repository](https://github.com/godotengine/webrtc-actions).
Alternatively, [**download the latest pre-compiled libraries**](https://github.com/godotengine/webrtc-actions/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 `tres` will be placed in `bin/webrtc/` or `bin/webrtc_debug/` according to the desired target. You simply need to copy that folder to the root folder of your project.

View File

@@ -1,6 +1,14 @@
#!python
import os, sys, platform, json
import os, sys, platform, json, subprocess
if sys.version_info < (3,):
def decode_utf8(x):
return x
else:
import codecs
def decode_utf8(x):
return codecs.utf_8_decode(x)[0]
def add_sources(sources, dirpath, extension):
@@ -9,42 +17,89 @@ 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(decode_utf8(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)
opts.Add(BoolVariable('use_llvm', 'Use the LLVM compiler', False))
opts.Add(EnumVariable('target', "Compilation target", 'debug', ('debug', 'release')))
opts.Add(EnumVariable(
'android_arch',
'Target Android architecture',
'armv7',
['armv7','arm64v8', 'x86', 'x86_64']
))
opts.Add(
'android_api_level',
'Target Android API level',
'18' if ARGUMENTS.get("android_arch", 'armv7') in ['armv7', 'x86'] else '21'
)
opts.Add(
'ANDROID_NDK_ROOT',
'Path to your Android NDK installation. By default, uses ANDROID_NDK_ROOT from your defined environment variables.',
os.environ.get("ANDROID_NDK_ROOT", None)
)
opts.Add(EnumVariable(
'ios_arch',
'Target iOS architecture',
'arm64',
['armv7', 'arm64', 'x86_64']
))
opts.Add(BoolVariable(
'ios_simulator',
'Target iOS Simulator',
False
))
opts.Add(
'IPHONEPATH',
'Path to iPhone toolchain',
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain',
)
# Update environment (parse options)
opts.Update(env)
target = env['target']
if target_platform == 'android':
target_arch = env['android_arch']
elif target_platform == 'ios':
target_arch = env['ios_arch']
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
@@ -60,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' ])
@@ -68,20 +123,13 @@ if target_platform == 'linux':
elif target_arch == '64':
env.Append(CCFLAGS = [ '-m64' ])
env.Append(LINKFLAGS = [ '-m64' ])
# i386 does not like static libstdc++
env.Append(LINKFLAGS=['-static-libgcc', '-static-libstdc++'])
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' ])
@@ -93,7 +141,12 @@ elif target_platform == 'windows':
elif target_arch == '64':
env['CXX']='x86_64-w64-mingw32-g++'
env.Append(CCFLAGS = [ '-g', '-O3', '-std=c++14', '-Wwrite-strings' ])
if env['target'] == 'debug':
env.Append(CCFLAGS=['-Og', '-g'])
elif env['target'] == 'release':
env.Append(CCFLAGS=['-O3'])
env.Append(CCFLAGS = [ '-std=c++14', '-Wwrite-strings' ])
env.Append(LINKFLAGS = [ '--static', '-Wl,--no-undefined', '-static-libgcc', '-static-libstdc++' ])
elif target_platform == 'osx':
@@ -102,11 +155,109 @@ 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(CCFLAGS = [ '-std=c++14', '-arch', 'x86_64' ])
env.Append(LINKFLAGS = [ '-arch', 'x86_64', '-framework', 'Cocoa', '-Wl,-undefined,dynamic_lookup' ])
if env['target'] == 'debug':
env.Append(CCFLAGS=['-Og', '-g'])
elif env['target'] == 'release':
env.Append(CCFLAGS=['-O3'])
elif target_platform == 'ios':
if env['ios_simulator']:
sdk_name = 'iphonesimulator'
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
env['LIBSUFFIX'] = ".simulator" + env['LIBSUFFIX']
else:
sdk_name = 'iphoneos'
env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])
try:
sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
except (subprocess.CalledProcessError, OSError):
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
compiler_path = env['IPHONEPATH'] + '/usr/bin/'
env['ENV']['PATH'] = env['IPHONEPATH'] + "/Developer/usr/bin/:" + env['ENV']['PATH']
env['CC'] = compiler_path + 'clang'
env['CXX'] = compiler_path + 'clang++'
env['AR'] = compiler_path + 'ar'
env['RANLIB'] = compiler_path + 'ranlib'
env.Append(CCFLAGS=['-std=c++14', '-arch', env['ios_arch'], '-isysroot', sdk_path])
env.Append(LINKFLAGS=[
'-arch',
env['ios_arch'],
'-Wl,-undefined,dynamic_lookup',
'-isysroot', sdk_path,
'-F' + sdk_path
])
if env['target'] == 'debug':
env.Append(CCFLAGS=['-Og', '-g'])
elif env['target'] == 'release':
env.Append(CCFLAGS=['-O3'])
elif target_platform == 'android':
# Verify NDK root
if not 'ANDROID_NDK_ROOT' in env:
raise ValueError("To build for Android, ANDROID_NDK_ROOT must be defined. Please set ANDROID_NDK_ROOT to the root folder of your Android NDK installation.")
# Validate API level
api_level = int(env['android_api_level'])
if target_arch in ['arm64v8', 'x86_64'] and api_level < 21:
print("WARN: 64-bit Android architectures require an API level of at least 21; setting android_api_level=21")
env['android_api_level'] = '21'
api_level = 21
# Setup toolchain
toolchain = env['ANDROID_NDK_ROOT'] + "/toolchains/llvm/prebuilt/"
if host_platform == "Windows":
toolchain += "windows"
import platform as pltfm
if pltfm.machine().endswith("64"):
toolchain += "-x86_64"
elif host_platform == "Linux":
toolchain += "linux-x86_64"
elif host_platform == "Darwin":
toolchain += "darwin-x86_64"
# Get architecture info
arch_info_table = {
"armv7" : {
"march":"armv7-a", "target":"armv7a-linux-androideabi", "tool_path":"arm-linux-androideabi", "compiler_path":"armv7a-linux-androideabi",
"ccflags" : ['-mfpu=neon']
},
"arm64v8" : {
"march":"armv8-a", "target":"aarch64-linux-android", "tool_path":"aarch64-linux-android", "compiler_path":"aarch64-linux-android",
"ccflags" : []
},
"x86" : {
"march":"i686", "target":"i686-linux-android", "tool_path":"i686-linux-android", "compiler_path":"i686-linux-android",
"ccflags" : ['-mstackrealign']
},
"x86_64" : {"march":"x86-64", "target":"x86_64-linux-android", "tool_path":"x86_64-linux-android", "compiler_path":"x86_64-linux-android",
"ccflags" : []
}
}
arch_info = arch_info_table[target_arch]
# Setup tools
env['CC'] = toolchain + "/bin/clang"
env['CXX'] = toolchain + "/bin/clang++"
env.Append(CCFLAGS=['--target=' + arch_info['target'] + env['android_api_level'], '-march=' + arch_info['march'], '-fPIC'])
env.Append(CCFLAGS=arch_info['ccflags'])
env.Append(LINKFLAGS=['--target=' + arch_info['target'] + env['android_api_level'], '-march=' + arch_info['march']])
if env['target'] == 'debug':
env.Append(CCFLAGS=['-Og', '-g'])
elif env['target'] == 'release':
env.Append(CCFLAGS=['-O3'])
else:
print("No valid target platform selected.")
sys.exit(1)
@@ -114,28 +265,31 @@ 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%s' % (lib_prefix, target_platform, target, target_arch, ".simulator" if env["ios_simulator"] else "")])
# 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'
elif target_arch == '32':
lib_path += '/x86'
lib_path += {'32': '/x86',
'64': '/x64',
'armv7': '/arm',
'arm64v8': '/arm64',
'arm64': '/arm64',
'x86': '/x86',
'x86_64': '/x64'}[target_arch]
if target == 'debug':
lib_path += '/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])
env.Append(LIBS=[lib_name, "atomic"])
env.Append(LIBPATH=[lib_path])
#env.Append(CCFLAGS=["-std=c++11"])
env.Append(CCFLAGS=["-DWEBRTC_POSIX", "-DWEBRTC_LINUX"])
@@ -156,6 +310,26 @@ elif target_platform == "windows":
elif target_platform == "osx":
env.Append(LIBS=[lib_name])
env.Append(LIBPATH=[lib_path])
env.Append(CCFLAGS=["-DWEBRTC_POSIX", "-DWEBRTC_MAC"])
env.Append(CCFLAGS=["-DRTC_UNUSED=''", "-DNO_RETURN=''"])
elif target_platform == 'ios':
env.Append(LIBS=[lib_name])
env.Append(LIBPATH=[lib_path])
env.Append(CCFLAGS=["-DWEBRTC_POSIX", "-DWEBRTC_MAC", "-DWEBRTC_IOS"])
env.Append(CCFLAGS=["-DRTC_UNUSED=''", "-DNO_RETURN=''"])
elif target_platform == "android":
env.Append(LIBS=['log'])
env.Append(LIBS=[lib_name])
env.Append(LIBPATH=[lib_path])
env.Append(CCFLAGS=["-DWEBRTC_POSIX", "-DWEBRTC_LINUX", "-DWEBRTC_ANDROID"])
env.Append(CCFLAGS=["-DRTC_UNUSED=''", "-DNO_RETURN=''"])
if target_arch == 'arm64v8':
env.Append(CCFLAGS=["-DWEBRTC_ARCH_ARM64", "-DWEBRTC_HAS_NEON"])
elif target_arch == 'armv7':
env.Append(CCFLAGS=["-DWEBRTC_ARCH_ARM", "-DWEBRTC_ARCH_ARM_V7", "-DWEBRTC_HAS_NEON"])
# Our includes and sources
env.Append(CPPPATH=['src/'])
@@ -168,5 +342,13 @@ 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) + env["SHLIBSUFFIX"]
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 + '.tres')], ['misc/gdnlib.tres']))

1
godot-cpp Submodule

Submodule godot-cpp added at 77d41fa179

View File

@@ -1,2 +0,0 @@
*
!.gitignore

View File

@@ -1,2 +0,0 @@
*
!.gitignore

View File

@@ -1,2 +0,0 @@
*
!.gitignore

View File

@@ -1 +0,0 @@
include/

View File

@@ -1,2 +0,0 @@
*
!.gitignore

View File

@@ -1,2 +0,0 @@
*
!.gitignore

28
misc/gdnlib.tres Normal file
View File

@@ -0,0 +1,28 @@
[gd_resource type="GDNativeLibrary" format=2]
[resource]
singleton = true
reloadable = false
entry/OSX.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.osx.{TARGET}.64.dylib"
entry/OSX.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.osx.{TARGET}.arm64.dylib"
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"
entry/Server.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.64.so"
entry/Server.32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.32.so"
entry/Android.armeabi-v7a = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.armv7.so"
entry/Android.arm64-v8a = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.arm64v8.so"
entry/Android.x64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.x86_64.so"
entry/Android.x86 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.x86.so"
entry/iOS.armv7 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.armv7.dylib"
entry/iOS.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.arm64.dylib"
entry/iOS.x86_64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.x86_64.dylib"
dependency/Windows.64 = [ ]
dependency/Windows.32 = [ ]
dependency/X11.64 = [ ]
dependency/X11.32 = [ ]
dependency/Server.64 = [ ]
dependency/Server.32 = [ ]
dependency/Android.armeabi-v7a = [ ]
dependency/Android.arm64-v8a = [ ]

View File

@@ -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){};

View File

@@ -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);
}

View File

@@ -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){};

View File

@@ -1,5 +1,8 @@
#include "WebRTCLibDataChannel.hpp"
#include "GDNativeLibrary.hpp"
#include "NativeScript.hpp"
using namespace godot_webrtc;
// Channel observer
@@ -26,12 +29,12 @@ WebRTCLibDataChannel *WebRTCLibDataChannel::new_data_channel(rtc::scoped_refptr<
godot::WebRTCDataChannelGDNative *out = godot::WebRTCDataChannelGDNative::_new();
// Set our implementation as it's script
godot::NativeScript *script = godot::NativeScript::_new();
script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib));
script->set_library(godot::detail::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib));
script->set_class_name("WebRTCLibDataChannel");
out->set_script(script);
// Bind the data channel to the ScriptInstance userdata (our script)
WebRTCLibDataChannel *tmp = godot::as<WebRTCLibDataChannel>(out);
WebRTCLibDataChannel *tmp = out->cast_to<WebRTCLibDataChannel>(out);
tmp->bind_channel(p_channel);
return tmp;

View File

@@ -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"

View File

@@ -5,6 +5,48 @@
using namespace godot_webrtc;
std::unique_ptr<rtc::Thread> WebRTCLibPeerConnection::signaling_thread = nullptr;
// PeerConnectionObserver
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);
}
// SetSessionDescriptionObserver
void WebRTCLibPeerConnection::GodotSSDO::OnSuccess() {
if (make_offer) {
make_offer = false;
parent->peer_connection->CreateAnswer(parent->ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
}
}
// CreateSessionDescriptionObserver
void WebRTCLibPeerConnection::GodotCSDO::OnSuccess(webrtc::SessionDescriptionInterface *desc) {
// serialize this offer and send it to the remote peer:
std::string sdp;
desc->ToString(&sdp);
parent->queue_signal("session_description_created", 2, desc->type().c_str(), sdp.c_str());
}
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 +99,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 +161,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;
}
@@ -127,8 +169,10 @@ godot_error WebRTCLibPeerConnection::create_offer() {
godot_error WebRTCLibPeerConnection::set_remote_description(const char *type, const char *sdp) {
ERR_FAIL_COND_V(peer_connection.get() == nullptr, GODOT_ERR_UNCONFIGURED);
std::unique_ptr<webrtc::SessionDescriptionInterface> desc = _MAKE_DESC(type, sdp);
if (desc->GetType() == webrtc::SdpType::kOffer) {
ptr_ssdo->make_offer = true;
}
peer_connection->SetRemoteDescription(ptr_ssdo, desc.release());
peer_connection->CreateAnswer(ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
return GODOT_OK;
}
@@ -159,20 +203,21 @@ godot_error WebRTCLibPeerConnection::add_ice_candidate(const char *sdpMidName, i
godot_error WebRTCLibPeerConnection::poll() {
ERR_FAIL_COND_V(peer_connection.get() == nullptr, GODOT_ERR_UNCONFIGURED);
std::function<void()> signal;
while (!signal_queue.empty()) {
mutex_signal_queue->lock();
signal = signal_queue.front();
Signal signal = signal_queue.front();
signal_queue.pop();
mutex_signal_queue->unlock();
signal();
signal.emit(this);
}
return GODOT_OK;
}
void WebRTCLibPeerConnection::close() {
peer_connection->Close();
if (peer_connection.get() != nullptr) {
peer_connection->Close();
}
peer_connection = nullptr;
while(!signal_queue.empty()) {
signal_queue.pop();
}
@@ -188,16 +233,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;
@@ -231,15 +271,7 @@ WebRTCLibPeerConnection::~WebRTCLibPeerConnection() {
void WebRTCLibPeerConnection::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 == 1) {
emit_signal(p_name, p_arg1);
} else if (p_argc == 2) {
emit_signal(p_name, p_arg1, p_arg2);
} else {
emit_signal(p_name, p_arg1, p_arg2, p_arg3);
}
});
const godot::Variant argv[3] = { p_arg1, p_arg2, p_arg3 };
signal_queue.push(Signal(p_name, p_argc, argv));
mutex_signal_queue->unlock();
}

View File

@@ -3,10 +3,9 @@
#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 <functional> // std::function
#include <mutex> // mutex @TODO replace std::mutex with Godot mutex
#include "api/peer_connection_interface.h" // interface for all things needed from WebRTC
#include "media/base/media_engine.h" // needed for CreateModularPeerConnectionFactory
#include <mutex>
#include "net/WebRTCPeerConnectionNative.hpp"
@@ -18,8 +17,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();
@@ -38,9 +40,8 @@ public:
~WebRTCLibPeerConnection();
/* helper functions */
private:
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);
/** PeerConnectionObserver callback functions **/
@@ -48,45 +49,83 @@ public:
public:
WebRTCLibPeerConnection *parent;
GodotPCO(WebRTCLibPeerConnection *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;
GodotPCO(WebRTCLibPeerConnection *p_parent) {
parent = p_parent;
}
void OnIceCandidate(const webrtc::IceCandidateInterface *candidate) override;
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 {}
};
/** CreateSessionDescriptionObserver callback functions **/
class GodotCSDO : public webrtc::CreateSessionDescriptionObserver {
public:
WebRTCLibPeerConnection *parent;
WebRTCLibPeerConnection *parent = nullptr;
GodotCSDO(WebRTCLibPeerConnection *parent);
GodotCSDO(WebRTCLibPeerConnection *p_parent) {
parent = p_parent;
}
void OnSuccess(webrtc::SessionDescriptionInterface *desc) override;
void OnFailure(const std::string &error) override;
void OnFailure(webrtc::RTCError error) override {
ERR_PRINT(godot::String(error.message()));
}
};
/** SetSessionDescriptionObserver callback functions **/
class GodotSSDO : public webrtc::SetSessionDescriptionObserver {
public:
WebRTCLibPeerConnection *parent;
WebRTCLibPeerConnection *parent = nullptr;
bool make_offer = false;
GodotSSDO(WebRTCLibPeerConnection *parent);
GodotSSDO(WebRTCLibPeerConnection *p_parent) {
parent = p_parent;
}
void OnSuccess() override;
void OnFailure(const std::string &error) override;
void OnFailure(webrtc::RTCError error) override {
make_offer = false;
ERR_PRINT(godot::String(error.message()));
}
};
class Signal {
godot::String method;
godot::Variant argv[3];
int argc = 0;
public:
Signal(godot::String p_method, int p_argc, const godot::Variant *p_argv) {
method = p_method;
argc = p_argc;
for (int i = 0; i < argc; i++) {
argv[i] = p_argv[i];
}
}
void emit(godot::Object *p_object) {
if (argc == 0) {
p_object->emit_signal(method);
} else if (argc == 1) {
p_object->emit_signal(method, argv[0]);
} else if (argc == 2) {
p_object->emit_signal(method, argv[0], argv[1]);
} else if (argc == 3) {
p_object->emit_signal(method, argv[0], argv[1], argv[2]);
}
}
};
GodotPCO pco;
rtc::scoped_refptr<GodotSSDO> ptr_ssdo;
rtc::scoped_refptr<GodotCSDO> ptr_csdo;
std::mutex *mutex_signal_queue;
std::queue<std::function<void()> > signal_queue;
std::mutex *mutex_signal_queue = nullptr;
std::queue<Signal> signal_queue;
rtc::Thread *signaling_thread;
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory;
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection;
};

View File

@@ -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);
}