mirror of
https://github.com/godotengine/webrtc-native.git
synced 2026-01-01 05:48:15 +03:00
Compare commits
177 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3ca94ae0e | ||
|
|
40e5c0c733 | ||
|
|
b45d3a3f46 | ||
|
|
41648bbf60 | ||
|
|
a77bf9bdb0 | ||
|
|
b1ee39e6c4 | ||
|
|
29fc1bb84d | ||
|
|
4567fb22c1 | ||
|
|
13a934298a | ||
|
|
68338ed576 | ||
|
|
f149f97815 | ||
|
|
cf038b2788 | ||
|
|
1992779387 | ||
|
|
25bb44730e | ||
|
|
79bae8e0d5 | ||
|
|
355fdd9051 | ||
|
|
49de259a08 | ||
|
|
9afa5c3a48 | ||
|
|
93e11a7343 | ||
|
|
ba46b25c00 | ||
|
|
31fd88dbf5 | ||
|
|
ea8b37fe29 | ||
|
|
cb1ef2e59c | ||
|
|
038bac82d6 | ||
|
|
effada6b45 | ||
|
|
26bc56f934 | ||
|
|
44ee53715d | ||
|
|
0b89ed885d | ||
|
|
bf8f6e4581 | ||
|
|
1443d02c8d | ||
|
|
431df320c4 | ||
|
|
762f7cc5d2 | ||
|
|
66a9c6bab3 | ||
|
|
e391109df2 | ||
|
|
762365d20a | ||
|
|
34ef1043ee | ||
|
|
7141bc487e | ||
|
|
9520b23a4c | ||
|
|
cdb4673f48 | ||
|
|
5b4221462b | ||
|
|
86d080b328 | ||
|
|
1831677f63 | ||
|
|
fa28efa51d | ||
|
|
6e33e43f36 | ||
|
|
81239d820d | ||
|
|
b0efc17d3b | ||
|
|
ec0ededcde | ||
|
|
308db19120 | ||
|
|
724910c734 | ||
|
|
7a4e27e5f0 | ||
|
|
d768508435 | ||
|
|
fb2c9c3687 | ||
|
|
cf23e5e740 | ||
|
|
668d0250a7 | ||
|
|
121ed5664d | ||
|
|
67a378a667 | ||
|
|
023c42d3b3 | ||
|
|
6d96092f88 | ||
|
|
77969f68d9 | ||
|
|
a9d8ea2a1c | ||
|
|
6e2262b6c3 | ||
|
|
cb2be8723a | ||
|
|
d278661d76 | ||
|
|
552d696e0a | ||
|
|
6f4d8f5238 | ||
|
|
8040565b0e | ||
|
|
38c83f667d | ||
|
|
1de32aa9ea | ||
|
|
ed3771ced0 | ||
|
|
ac3bdb3613 | ||
|
|
931a7551f5 | ||
|
|
0771084b54 | ||
|
|
ae0dd0626a | ||
|
|
0be6b671e5 | ||
|
|
d96b43b7ee | ||
|
|
ec8cd5c0e4 | ||
|
|
b03099f7b4 | ||
|
|
85efdfd6ce | ||
|
|
32ae1d1195 | ||
|
|
54c8586235 | ||
|
|
f19011f2fb | ||
|
|
86c27ec7ef | ||
|
|
f2ee596bd9 | ||
|
|
61299ca4b7 | ||
|
|
df643250f5 | ||
|
|
45549e020f | ||
|
|
ee40730c20 | ||
|
|
8f7cb77f34 | ||
|
|
eb65d88cd4 | ||
|
|
e8de07dbb1 | ||
|
|
e34000653b | ||
|
|
826a736176 | ||
|
|
b7098e7496 | ||
|
|
6de604ffee | ||
|
|
f0af5f9982 | ||
|
|
fbe4e06b9f | ||
|
|
9a9fc0953b | ||
|
|
c6b6f7e18c | ||
|
|
00f952bcf1 | ||
|
|
d7032f7b85 | ||
|
|
c9a1efc7a0 | ||
|
|
5bc4b79435 | ||
|
|
b7b76dddab | ||
|
|
0b1c55ed83 | ||
|
|
093ac7d489 | ||
|
|
84e9d6dd37 | ||
|
|
a49a2b03e1 | ||
|
|
656d3a9964 | ||
|
|
2bc2a5d162 | ||
|
|
7176344056 | ||
|
|
7d260b1b32 | ||
|
|
0c10a7f3e3 | ||
|
|
40962dbe19 | ||
|
|
bdd9d50745 | ||
|
|
5348407de9 | ||
|
|
5002991511 | ||
|
|
0fc992e0d5 | ||
|
|
fbadff454c | ||
|
|
61a6d25c47 | ||
|
|
dfaad6f5ba | ||
|
|
35bdd5efa7 | ||
|
|
90aaa0b82e | ||
|
|
16f311844b | ||
|
|
dfb34df36e | ||
|
|
9715e73ae4 | ||
|
|
2e9a25bb39 | ||
|
|
6067addd96 | ||
|
|
a3fbd33464 | ||
|
|
d697901f81 | ||
|
|
3eb7d0aa3b | ||
|
|
ecec40f59e | ||
|
|
37a289addf | ||
|
|
1436024f59 | ||
|
|
690b31e7dd | ||
|
|
9b0a5d8b46 | ||
|
|
1769730ef0 | ||
|
|
04898f2714 | ||
|
|
d7fc6cde3b | ||
|
|
1009e8bb1c | ||
|
|
5fd359f674 | ||
|
|
822e0532c2 | ||
|
|
d8cbd14a28 | ||
|
|
6e52fce986 | ||
|
|
a93af67d75 | ||
|
|
22ee6435a1 | ||
|
|
b5d8a72ef8 | ||
|
|
2ad1bf1716 | ||
|
|
e683c79938 | ||
|
|
426ca6cc8e | ||
|
|
9b53ef3325 | ||
|
|
e41d2903ad | ||
|
|
f315912d85 | ||
|
|
62ab2e59f8 | ||
|
|
a2fc27f646 | ||
|
|
b2654cc2bd | ||
|
|
e19b370126 | ||
|
|
8c18112f5d | ||
|
|
c37cc530e7 | ||
|
|
13ab33af36 | ||
|
|
3bdf6cdc13 | ||
|
|
072ba5c1d0 | ||
|
|
7cb6d6c846 | ||
|
|
c0b31562f5 | ||
|
|
69f92fa26c | ||
|
|
d06e536d12 | ||
|
|
68a892d9f3 | ||
|
|
72b337e32c | ||
|
|
eeabf0a844 | ||
|
|
04fbae6ce3 | ||
|
|
ce3f086ec4 | ||
|
|
00ac03c8e7 | ||
|
|
fa5296a4e4 | ||
|
|
189c353264 | ||
|
|
e44c42fde8 | ||
|
|
524fdde8f2 | ||
|
|
673a4c1a1c | ||
|
|
cf98eb2e7a |
199
.clang-format
Normal file
199
.clang-format
Normal file
@@ -0,0 +1,199 @@
|
||||
# Commented out parameters are those with the same value as base LLVM style.
|
||||
# We can uncomment them if we want to change their value, or enforce the
|
||||
# chosen value in case the base style changes (last sync: Clang 14.0).
|
||||
---
|
||||
### General config, applies to all languages ###
|
||||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: DontAlign
|
||||
# AlignArrayOfStructures: None
|
||||
# AlignConsecutiveMacros: None
|
||||
# AlignConsecutiveAssignments: None
|
||||
# AlignConsecutiveBitFields: None
|
||||
# AlignConsecutiveDeclarations: None
|
||||
# AlignEscapedNewlines: Right
|
||||
AlignOperands: DontAlign
|
||||
AlignTrailingComments: false
|
||||
# AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
# AllowShortEnumsOnASingleLine: true
|
||||
# AllowShortBlocksOnASingleLine: Never
|
||||
# AllowShortCaseLabelsOnASingleLine: false
|
||||
# AllowShortFunctionsOnASingleLine: All
|
||||
# AllowShortLambdasOnASingleLine: All
|
||||
# AllowShortIfStatementsOnASingleLine: Never
|
||||
# AllowShortLoopsOnASingleLine: false
|
||||
# AlwaysBreakAfterDefinitionReturnType: None
|
||||
# AlwaysBreakAfterReturnType: None
|
||||
# AlwaysBreakBeforeMultilineStrings: false
|
||||
# AlwaysBreakTemplateDeclarations: MultiLine
|
||||
# AttributeMacros:
|
||||
# - __capability
|
||||
# BinPackArguments: true
|
||||
# BinPackParameters: true
|
||||
# BraceWrapping:
|
||||
# AfterCaseLabel: false
|
||||
# AfterClass: false
|
||||
# AfterControlStatement: Never
|
||||
# AfterEnum: false
|
||||
# AfterFunction: false
|
||||
# AfterNamespace: false
|
||||
# AfterObjCDeclaration: false
|
||||
# AfterStruct: false
|
||||
# AfterUnion: false
|
||||
# AfterExternBlock: false
|
||||
# BeforeCatch: false
|
||||
# BeforeElse: false
|
||||
# BeforeLambdaBody: false
|
||||
# BeforeWhile: false
|
||||
# IndentBraces: false
|
||||
# SplitEmptyFunction: true
|
||||
# SplitEmptyRecord: true
|
||||
# SplitEmptyNamespace: true
|
||||
# BreakBeforeBinaryOperators: None
|
||||
# BreakBeforeConceptDeclarations: true
|
||||
# BreakBeforeBraces: Attach
|
||||
# BreakBeforeInheritanceComma: false
|
||||
# BreakInheritanceList: BeforeColon
|
||||
# BreakBeforeTernaryOperators: true
|
||||
# BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: AfterColon
|
||||
# BreakStringLiterals: true
|
||||
ColumnLimit: 0
|
||||
# CommentPragmas: '^ IWYU pragma:'
|
||||
# QualifierAlignment: Leave
|
||||
# CompactNamespaces: false
|
||||
ConstructorInitializerIndentWidth: 8
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: false
|
||||
# DeriveLineEnding: true
|
||||
# DerivePointerAlignment: false
|
||||
# DisableFormat: false
|
||||
# EmptyLineAfterAccessModifier: Never
|
||||
# EmptyLineBeforeAccessModifier: LogicalBlock
|
||||
# ExperimentalAutoDetectBinPacking: false
|
||||
# PackConstructorInitializers: BinPack
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||
# AllowAllConstructorInitializersOnNextLine: true
|
||||
# FixNamespaceComments: true
|
||||
# ForEachMacros:
|
||||
# - foreach
|
||||
# - Q_FOREACH
|
||||
# - BOOST_FOREACH
|
||||
# IfMacros:
|
||||
# - KJ_IF_MAYBE
|
||||
# IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '".*"'
|
||||
Priority: 1
|
||||
- Regex: '^<.*\.h>'
|
||||
Priority: 2
|
||||
- Regex: '^<.*'
|
||||
Priority: 3
|
||||
# IncludeIsMainRegex: '(Test)?$'
|
||||
# IncludeIsMainSourceRegex: ''
|
||||
# IndentAccessModifiers: false
|
||||
IndentCaseLabels: true
|
||||
# IndentCaseBlocks: false
|
||||
# IndentGotoLabels: true
|
||||
# IndentPPDirectives: None
|
||||
# IndentExternBlock: AfterExternBlock
|
||||
# IndentRequires: false
|
||||
IndentWidth: 4
|
||||
# IndentWrappedFunctionNames: false
|
||||
# InsertTrailingCommas: None
|
||||
# JavaScriptQuotes: Leave
|
||||
# JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
# LambdaBodyIndentation: Signature
|
||||
# MacroBlockBegin: ''
|
||||
# MacroBlockEnd: ''
|
||||
# MaxEmptyLinesToKeep: 1
|
||||
# NamespaceIndentation: None
|
||||
# PenaltyBreakAssignment: 2
|
||||
# PenaltyBreakBeforeFirstCallParameter: 19
|
||||
# PenaltyBreakComment: 300
|
||||
# PenaltyBreakFirstLessLess: 120
|
||||
# PenaltyBreakOpenParenthesis: 0
|
||||
# PenaltyBreakString: 1000
|
||||
# PenaltyBreakTemplateDeclaration: 10
|
||||
# PenaltyExcessCharacter: 1000000
|
||||
# PenaltyReturnTypeOnItsOwnLine: 60
|
||||
# PenaltyIndentedWhitespace: 0
|
||||
# PointerAlignment: Right
|
||||
# PPIndentWidth: -1
|
||||
# ReferenceAlignment: Pointer
|
||||
# ReflowComments: true
|
||||
# RemoveBracesLLVM: false
|
||||
# SeparateDefinitionBlocks: Leave
|
||||
# ShortNamespaceLines: 1
|
||||
# SortIncludes: CaseSensitive
|
||||
# SortJavaStaticImport: Before
|
||||
# SortUsingDeclarations: true
|
||||
# SpaceAfterCStyleCast: false
|
||||
# SpaceAfterLogicalNot: false
|
||||
# SpaceAfterTemplateKeyword: true
|
||||
# SpaceBeforeAssignmentOperators: true
|
||||
# SpaceBeforeCaseColon: false
|
||||
# SpaceBeforeCpp11BracedList: false
|
||||
# SpaceBeforeCtorInitializerColon: true
|
||||
# SpaceBeforeInheritanceColon: true
|
||||
# SpaceBeforeParens: ControlStatements
|
||||
# SpaceBeforeParensOptions:
|
||||
# AfterControlStatements: true
|
||||
# AfterForeachMacros: true
|
||||
# AfterFunctionDefinitionName: false
|
||||
# AfterFunctionDeclarationName: false
|
||||
# AfterIfMacros: true
|
||||
# AfterOverloadedOperator: false
|
||||
# BeforeNonEmptyParentheses: false
|
||||
# SpaceAroundPointerQualifiers: Default
|
||||
# SpaceBeforeRangeBasedForLoopColon: true
|
||||
# SpaceInEmptyBlock: false
|
||||
# SpaceInEmptyParentheses: false
|
||||
# SpacesBeforeTrailingComments: 1
|
||||
# SpacesInAngles: Never
|
||||
# SpacesInConditionalStatement: false
|
||||
# SpacesInContainerLiterals: true
|
||||
# SpacesInCStyleCastParentheses: false
|
||||
## Godot TODO: We'll want to use a min of 1, but we need to see how to fix
|
||||
## our comment capitalization at the same time.
|
||||
SpacesInLineCommentPrefix:
|
||||
Minimum: 0
|
||||
Maximum: -1
|
||||
# SpacesInParentheses: false
|
||||
# SpacesInSquareBrackets: false
|
||||
# SpaceBeforeSquareBrackets: false
|
||||
# BitFieldColonSpacing: Both
|
||||
# StatementAttributeLikeMacros:
|
||||
# - Q_EMIT
|
||||
# StatementMacros:
|
||||
# - Q_UNUSED
|
||||
# - QT_REQUIRE_VERSION
|
||||
TabWidth: 4
|
||||
# UseCRLF: false
|
||||
UseTab: Always
|
||||
# WhitespaceSensitiveMacros:
|
||||
# - STRINGIZE
|
||||
# - PP_STRINGIZE
|
||||
# - BOOST_PP_STRINGIZE
|
||||
# - NS_SWIFT_NAME
|
||||
# - CF_SWIFT_NAME
|
||||
---
|
||||
### C++ specific config ###
|
||||
Language: Cpp
|
||||
Standard: c++17
|
||||
---
|
||||
### ObjC specific config ###
|
||||
Language: ObjC
|
||||
# ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 4
|
||||
# ObjCBreakBeforeNestedBlockParam: true
|
||||
# ObjCSpaceAfterProperty: false
|
||||
# ObjCSpaceBeforeProtocolList: true
|
||||
---
|
||||
### Java specific config ###
|
||||
Language: Java
|
||||
# BreakAfterJavaFieldAnnotations: false
|
||||
JavaImportGroups: ['org.godotengine', 'android', 'androidx', 'com.android', 'com.google', 'java', 'javax']
|
||||
...
|
||||
64
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
64
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
name: Bug report
|
||||
description: Report a bug in the WebRTC native plugin.
|
||||
body:
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
- Write a descriptive issue title above.
|
||||
- Search [open](https://github.com/godotengine/webrtc-native/issues) and [closed](https://github.com/godotengine/webrtc-native/issues?q=is%3Aissue+is%3Aclosed) issues to ensure it has not already been reported.
|
||||
- Verify that you are using a [supported Godot version](https://docs.godotengine.org/en/stable/about/release_policy.html).
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Godot version
|
||||
description: >
|
||||
Specify the Git commit hash if using a development or non-official build.
|
||||
If you use a custom build, please test if your issue is reproducible in official builds too.
|
||||
placeholder: 3.3.stable, 4.0.dev (3041becc6)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: Plugin version
|
||||
description: >
|
||||
Specify the Git commit hash if using a development or non-official build.
|
||||
If you use a custom build, please test if your issue is reproducible in official builds too.
|
||||
placeholder: 0.3, 0.5, 0.6.dev (072ba5c)
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: input
|
||||
attributes:
|
||||
label: System information
|
||||
description: |
|
||||
Specify the OS version, and when relevant hardware information.
|
||||
placeholder: Android 10, Fairphone 3+.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Issue description
|
||||
description: |
|
||||
Describe your issue briefly. What doesn't work, and how do you expect it to work instead?
|
||||
You can include images or videos with drag and drop, and format code blocks or logs with <code>```</code> tags.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Steps to reproduce
|
||||
description: |
|
||||
List of steps or sample code that reproduces the issue. Having reproducible issues is a prerequisite for contributors to be able to solve them.
|
||||
If you include a minimal reproduction project below, you can detail how to use it here.
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Minimal reproduction project
|
||||
description: |
|
||||
A small Godot project which reproduces the issue. Highly recommended to speed up troubleshooting.
|
||||
Drag and drop a ZIP archive to upload it.
|
||||
6
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
6
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
blank_issues_enabled: false
|
||||
|
||||
contact_links:
|
||||
- name: Godot proposals
|
||||
url: https://github.com/godotengine/godot-proposals
|
||||
about: Please submit feature proposals about the WebRTC exposed API on the Godot proposals repository, not here.
|
||||
22
.github/actions/godot-cache/action.yml
vendored
Normal file
22
.github/actions/godot-cache/action.yml
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
name: Setup Godot build cache
|
||||
description: Setup Godot build cache.
|
||||
inputs:
|
||||
cache-name:
|
||||
description: The cache base name (job name by default).
|
||||
default: "${{github.job}}"
|
||||
scons-cache:
|
||||
description: The scons cache path.
|
||||
default: "${{github.workspace}}/.scons-cache/"
|
||||
runs:
|
||||
using: "composite"
|
||||
steps:
|
||||
# Upload cache on completion and check it out now
|
||||
- name: Load .scons_cache directory
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{inputs.scons-cache}}
|
||||
key: ${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}
|
||||
restore-keys: |
|
||||
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}
|
||||
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}
|
||||
${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}
|
||||
281
.github/workflows/build_release.yml
vendored
Normal file
281
.github/workflows/build_release.yml
vendored
Normal file
@@ -0,0 +1,281 @@
|
||||
name: 🔧 Build -> Package 📦
|
||||
on: [push, pull_request]
|
||||
|
||||
env:
|
||||
# Only used for the cache key. Increment version to force clean build.
|
||||
GODOT_BASE_BRANCH: master
|
||||
# Hardcoding this seem to be the only way
|
||||
ANDROID_NDK_ROOT: /usr/local/lib/android/sdk/ndk/23.2.8568313/
|
||||
|
||||
jobs:
|
||||
static-checks:
|
||||
name: 📊 Static Checks (clang-format, black format, file format)
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
# Add clang repository (so we have clang-format-14)
|
||||
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||
sudo apt-add-repository "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main"
|
||||
sudo apt-get update
|
||||
# Install required deps
|
||||
sudo apt-get install -qq dos2unix moreutils recode clang-format-14
|
||||
sudo update-alternatives --remove-all clang-format
|
||||
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-14 100
|
||||
sudo pip3 install black==22.3.0 pygments
|
||||
|
||||
- name: File formatting checks (file_format.sh)
|
||||
run: |
|
||||
bash ./misc/scripts/file_format.sh
|
||||
|
||||
- name: Style checks via clang-format (clang_format.sh)
|
||||
run: |
|
||||
bash ./misc/scripts/clang_format.sh
|
||||
|
||||
- name: Python style checks via black (black_format.sh)
|
||||
run: |
|
||||
bash ./misc/scripts/black_format.sh
|
||||
|
||||
build:
|
||||
runs-on: ${{ matrix.os }}
|
||||
name: 🔧 Build
|
||||
needs: static-checks
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
# Android
|
||||
- platform: android
|
||||
arch: 'x86_64'
|
||||
gdnative_flags: 'android_arch=x86_64'
|
||||
sconsflags: ''
|
||||
os: 'ubuntu-22.04'
|
||||
cache-name: android-x86_64
|
||||
- platform: android
|
||||
arch: 'arm64'
|
||||
gdnative_flags: 'android_arch=arm64v8'
|
||||
sconsflags: ''
|
||||
os: 'ubuntu-22.04'
|
||||
cache-name: android-arm64
|
||||
|
||||
# iOS
|
||||
- platform: ios
|
||||
arch: 'x86_64'
|
||||
gdnative_flags: 'ios_arch=x86_64'
|
||||
sconsflags: 'ios_simulator=true'
|
||||
os: 'macos-latest'
|
||||
cache-name: ios-x86_64-simulator
|
||||
- platform: ios
|
||||
arch: 'arm64'
|
||||
gdnative_flags: 'ios_arch=arm64'
|
||||
sconsflags: ''
|
||||
os: 'macos-latest'
|
||||
cache-name: ios-arm64
|
||||
|
||||
# Linux
|
||||
- platform: linux
|
||||
arch: 'x86_32'
|
||||
buildroot: 'i686-godot-linux-gnu_sdk-buildroot'
|
||||
gdnative_flags: 'bits=32'
|
||||
sconsflags: ''
|
||||
os: 'ubuntu-22.04'
|
||||
cache-name: linux-x86_32
|
||||
- platform: linux
|
||||
arch: 'x86_64'
|
||||
buildroot: 'x86_64-godot-linux-gnu_sdk-buildroot'
|
||||
gdnative_flags: 'bits=64'
|
||||
sconsflags: ''
|
||||
os: 'ubuntu-22.04'
|
||||
cache-name: linux-x86_64
|
||||
- platform: linux
|
||||
arch: 'arm32'
|
||||
buildroot: 'arm-godot-linux-gnueabihf_sdk-buildroot'
|
||||
gdnative_flags: 'bits=32'
|
||||
sconsflags: ''
|
||||
os: 'ubuntu-22.04'
|
||||
cache-name: linux-arm32
|
||||
- platform: linux
|
||||
arch: 'arm64'
|
||||
buildroot: 'aarch64-godot-linux-gnu_sdk-buildroot'
|
||||
gdnative_flags: 'bits=64'
|
||||
sconsflags: ''
|
||||
os: 'ubuntu-22.04'
|
||||
cache-name: linux-arm64
|
||||
|
||||
# macOS
|
||||
- platform: macos
|
||||
arch: 'universal'
|
||||
gdnative_flags: 'macos_arch=universal bits=64'
|
||||
sconsflags: ''
|
||||
os: 'macos-latest'
|
||||
cache-name: macos-universal
|
||||
|
||||
# Windows
|
||||
- platform: windows
|
||||
arch: 'x86_32'
|
||||
gdnative_flags: 'bits=32'
|
||||
sconsflags: 'use_mingw=yes'
|
||||
os: 'ubuntu-22.04'
|
||||
msvc_arch: amd64_x86
|
||||
cache-name: win-x86_32
|
||||
- platform: windows
|
||||
arch: 'x86_64'
|
||||
gdnative_flags: 'bits=64'
|
||||
sconsflags: 'use_mingw=yes'
|
||||
os: 'ubuntu-22.04'
|
||||
msvc_arch: amd64
|
||||
cache-name: win-x86_64
|
||||
|
||||
env:
|
||||
SCONS_CACHE: ${{ github.workspace }}/.scons-cache/
|
||||
SCONSFLAGS: ${{ matrix.sconsflags }} platform=${{ matrix.platform }} arch=${{ matrix.arch }} build_profile=build_profile.json --jobs=2
|
||||
|
||||
defaults:
|
||||
run:
|
||||
shell: bash
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- name: Setup Godot build cache
|
||||
uses: ./.github/actions/godot-cache
|
||||
with:
|
||||
cache-name: ${{ matrix.cache-name }}
|
||||
continue-on-error: true
|
||||
|
||||
- name: Install Windows build dependencies
|
||||
if: ${{ matrix.platform == 'windows' }}
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install build-essential mingw-w64
|
||||
sudo update-alternatives --set i686-w64-mingw32-gcc /usr/bin/i686-w64-mingw32-gcc-posix
|
||||
sudo update-alternatives --set i686-w64-mingw32-g++ /usr/bin/i686-w64-mingw32-g++-posix
|
||||
sudo update-alternatives --set x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-posix
|
||||
sudo update-alternatives --set x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-posix
|
||||
dpkg -l | grep ii | grep mingw
|
||||
update-alternatives --get-selections | grep mingw
|
||||
|
||||
- name: Install Linux build dependencies
|
||||
if: ${{ matrix.platform == 'linux' }}
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install build-essential gcc-multilib g++-multilib wget
|
||||
|
||||
- name: Setup Linux buildroot toolchain cache
|
||||
if: ${{ matrix.platform == 'linux' }}
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: |
|
||||
${{ matrix.buildroot }}.tar.bz2
|
||||
key: linux-${{ matrix.buildroot }}-buildroot
|
||||
|
||||
- name: Set up Python 3.x
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.x'
|
||||
architecture: 'x64'
|
||||
|
||||
- name: Configuring Python packages
|
||||
run: |
|
||||
python -c "import sys; print(sys.version)"
|
||||
python -m pip install scons
|
||||
|
||||
- name: Setup Linux toolchains
|
||||
if: ${{ matrix.platform == 'linux' }}
|
||||
run: |
|
||||
if [ ! -f ${{ matrix.buildroot }}.tar.bz2 ]; then
|
||||
wget https://github.com/godotengine/buildroot/releases/download/godot-2023.08.x-4/${{ matrix.buildroot }}.tar.bz2
|
||||
fi
|
||||
tar -xjf ${{ matrix.buildroot }}.tar.bz2
|
||||
${{ matrix.buildroot }}/relocate-sdk.sh
|
||||
rm ${{ matrix.buildroot }}/bin/cmake
|
||||
echo "$GITHUB_WORKSPACE/${{ matrix.buildroot }}/bin" >> $GITHUB_PATH
|
||||
echo "PKG_CONFIG=$GITHUB_WORKSPACE/${{ matrix.buildroot }}/share/pkgconfig/" >> $GITHUB_ENV
|
||||
patch -p1 < misc/patches/scons_path.diff
|
||||
patch -p1 < misc/patches/gdnantive_arm_warnings.diff
|
||||
|
||||
- name: Setup Android dependencies
|
||||
if: ${{ matrix.platform == 'android' }}
|
||||
uses: nttld/setup-ndk@v1
|
||||
with:
|
||||
ndk-version: r23c
|
||||
link-to-sdk: true
|
||||
|
||||
- name: Patch godot-cpp to support build profile.
|
||||
run: |
|
||||
patch -p1 < misc/patches/build_profile.diff
|
||||
patch -p1 < misc/patches/build_profile_3.x.diff
|
||||
|
||||
- name: Print tools versions
|
||||
run: |
|
||||
python --version
|
||||
scons --version
|
||||
cmake --version
|
||||
|
||||
- name: Compile Extension (4.1+) - template_debug - ${{ matrix.platform }} - ${{ matrix.arch }}
|
||||
run: |
|
||||
scons target=template_debug godot_version=4
|
||||
|
||||
- name: Compile Extension (4.1+) - template_release - ${{ matrix.platform }} - ${{ matrix.arch }}
|
||||
run: |
|
||||
scons target=template_release godot_version=4
|
||||
|
||||
- name: Compile GDNative (3.5+) - release ${{ matrix.platform }} - ${{ matrix.arch }}
|
||||
run: |
|
||||
scons target=release generate_bindings=yes ${{ matrix.gdnative_flags }} godot_version=3
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ github.job }}-${{ matrix.platform }}-${{ matrix.arch }}
|
||||
path: |
|
||||
bin/
|
||||
!bin/thirdparty/
|
||||
|
||||
package:
|
||||
name: 📦 Package
|
||||
needs: build
|
||||
runs-on: "ubuntu-latest"
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: recursive
|
||||
|
||||
- uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: artifacts
|
||||
|
||||
- name: Bundle licenses.
|
||||
run: |
|
||||
cp LICENSE artifacts/LICENSE.webrtc-native
|
||||
cp thirdparty/libdatachannel/LICENSE artifacts/LICENSE.libdatachannel
|
||||
cp thirdparty/mbedtls/LICENSE artifacts/LICENSE.mbedtls
|
||||
cp thirdparty/libdatachannel/deps/libjuice/LICENSE artifacts/LICENSE.libjuice
|
||||
cp thirdparty/libdatachannel/deps/usrsctp/LICENSE.md artifacts/LICENSE.usrsctp
|
||||
cp thirdparty/libdatachannel/deps/libsrtp/LICENSE artifacts/LICENSE.libsrtp
|
||||
cp thirdparty/libdatachannel/deps/plog/LICENSE artifacts/LICENSE.plog
|
||||
|
||||
- name: Package artifacts for release
|
||||
env:
|
||||
DESTINATION: "release"
|
||||
run: |
|
||||
mkdir release
|
||||
|
||||
VERSION="extension" TYPE="webrtc" ./misc/scripts/package_release.sh
|
||||
VERSION="gdnative" TYPE="webrtc" ./misc/scripts/package_release.sh
|
||||
|
||||
ls -R release
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: godot-webrtc-extension
|
||||
path: release/*-extension-*.zip
|
||||
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: godot-webrtc-gdnative
|
||||
path: release/*-gdnative-*.zip
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -5,3 +5,5 @@ bin/*
|
||||
.sconsign.dblite
|
||||
*.obj
|
||||
*.swp
|
||||
__pycache__/*
|
||||
*.pyc
|
||||
|
||||
11
.gitmodules
vendored
11
.gitmodules
vendored
@@ -1,3 +1,12 @@
|
||||
[submodule "godot-cpp"]
|
||||
path = godot-cpp
|
||||
url = https://github.com/GodotNativeTools/godot-cpp
|
||||
url = https://github.com/godotengine/godot-cpp.git
|
||||
[submodule "godot-cpp-3.x"]
|
||||
path = godot-cpp-3.x
|
||||
url = https://github.com/godotengine/godot-cpp.git
|
||||
[submodule "libdatachannel"]
|
||||
path = thirdparty/libdatachannel
|
||||
url = https://github.com/paullouisageneau/libdatachannel.git
|
||||
[submodule "mbedtls"]
|
||||
path = thirdparty/mbedtls
|
||||
url = https://github.com/Mbed-TLS/mbedtls.git
|
||||
|
||||
72
README.md
72
README.md
@@ -7,15 +7,10 @@
|
||||
|
||||
### 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.
|
||||
Clone this repository with the following command to checkout all the dependencies: [godot-cpp](https://github.com/godotengine/godot-cpp), [mbedTLS](https://github.com/Mbed-TLS/mbedtls) and [libdatachannel](https://github.com/paullouisageneau/libdatachannel) (and sub-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
|
||||
$ git clone --recurse-submodules https://github.com/godotengine/webrtc-native.git
|
||||
```
|
||||
|
||||
If you already checked out the branch use the following commands to update the dependencies:
|
||||
@@ -24,43 +19,36 @@ If you already checked out the branch use the following commands to update the d
|
||||
$ 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 extension.
|
||||
|
||||
### 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.
|
||||
To build the GDExtension version of the plugin (Godot 4.1+) run the following command from the `webrtc-native` folder:
|
||||
|
||||
```
|
||||
$ scons platform=<your platform> target=<your target>
|
||||
$ scons platform=<your platform>
|
||||
```
|
||||
|
||||
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.
|
||||
This will build all the required dependencies into a single shared library.
|
||||
|
||||
To build the "legacy" GDExtension version of the plugin (Godot 4.0) run the following command instead:
|
||||
|
||||
```
|
||||
$ scons platform=<your platform> godot_version=4.0
|
||||
```
|
||||
|
||||
To build the GDNative version of the plugin (Godot 3.x) run the following command instead:
|
||||
|
||||
```
|
||||
$ scons platform=<your platform> godot_version=3
|
||||
```
|
||||
|
||||
> Replace `<your platform>` with either `windows`, `linux`, `osx`, `android`, or `ios`.
|
||||
|
||||
> Include `target=release` or `target=debug` for release or debug build (default is `debug`).
|
||||
|
||||
The resulting library and associated `tres` or `gdextension` will be created in `bin/[extension|gdnative]/webrtc[_debug]` depending on the `target` and `godot_version`.
|
||||
|
||||
You simply need to copy that folder to the root folder of your project. Note that you will have to build the library for all the desired export platforms.
|
||||
|
||||
### License
|
||||
|
||||
The `webrtc-native` plugin is licensed under the MIT license (see [LICENSE](https://github.com/godotengine/webrtc-native/blob/master/LICENSE)), while `libdatachannel` and its dependencies are licensed under other permissive open source licences. Please see [`thirdparty/README.md`](thirdparty/README.md) for more informations.
|
||||
|
||||
509
SConstruct
509
SConstruct
@@ -1,344 +1,255 @@
|
||||
#!python
|
||||
|
||||
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]
|
||||
import SCons
|
||||
|
||||
|
||||
def add_sources(sources, dirpath, extension):
|
||||
for f in os.listdir(dirpath):
|
||||
if f.endswith('.' + extension):
|
||||
sources.append(dirpath + '/' + f)
|
||||
for f in os.listdir(dirpath):
|
||||
if f.endswith("." + extension):
|
||||
sources.append(dirpath + "/" + f)
|
||||
|
||||
|
||||
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']))
|
||||
def replace_flags(flags, replaces):
|
||||
for k, v in replaces.items():
|
||||
if k not in flags:
|
||||
continue
|
||||
if v is None:
|
||||
flags.remove(k)
|
||||
else:
|
||||
flags[flags.index(k)] = v
|
||||
|
||||
|
||||
def validate_godotcpp_dir(key, val, env):
|
||||
normalized = val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
|
||||
if not os.path.isdir(normalized):
|
||||
raise UserError("GDExtension directory ('%s') does not exist: %s" % (key, val))
|
||||
|
||||
|
||||
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 = Variables(["customs.py"], ARGUMENTS)
|
||||
opts.Add(EnumVariable("godot_version", "The Godot target version", "4", ["3", "4"], {"4.1+": "4", "4.1": "4"}))
|
||||
opts.Add(
|
||||
'android_api_level',
|
||||
'Target Android API level',
|
||||
'18' if ARGUMENTS.get("android_arch", 'armv7') in ['armv7', 'x86'] else '21'
|
||||
PathVariable(
|
||||
"godot_cpp",
|
||||
"Path to the directory containing Godot CPP folder",
|
||||
None,
|
||||
validate_godotcpp_dir,
|
||||
)
|
||||
)
|
||||
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']
|
||||
# Minimum target platform versions.
|
||||
if "ios_min_version" not in ARGUMENTS:
|
||||
ARGUMENTS["ios_min_version"] = "12.0"
|
||||
if "macos_deployment_target" not in ARGUMENTS:
|
||||
ARGUMENTS["macos_deployment_target"] = "11.0"
|
||||
if "android_api_level" not in ARGUMENTS:
|
||||
ARGUMENTS["android_api_level"] = "28"
|
||||
|
||||
if target_platform == 'android':
|
||||
target_arch = env['android_arch']
|
||||
elif target_platform == 'ios':
|
||||
target_arch = env['ios_arch']
|
||||
# Recent godot-cpp versions disables exceptions by default, but libdatachannel requires them.
|
||||
ARGUMENTS["disable_exceptions"] = "no"
|
||||
|
||||
host_platform = platform.system()
|
||||
# Local dependency paths, adapt them to your setup
|
||||
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 = ""
|
||||
if env["godot_version"] == "3":
|
||||
if "platform" in ARGUMENTS and ARGUMENTS["platform"] == "macos":
|
||||
ARGUMENTS["platform"] = "osx" # compatibility with old osx name
|
||||
|
||||
# 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
|
||||
sconstruct = env.get("godot_cpp", "godot-cpp-3.x") + "/SConstruct"
|
||||
cpp_env = SConscript(sconstruct)
|
||||
|
||||
if target_platform == 'linux':
|
||||
env['CXX']='g++'
|
||||
# Patch base env
|
||||
replace_flags(
|
||||
cpp_env["CCFLAGS"],
|
||||
{
|
||||
"-mios-simulator-version-min=10.0": "-mios-simulator-version-min=12.0",
|
||||
"-miphoneos-version-min=10.0": "-miphoneos-version-min=12.0",
|
||||
"/std:c++14": "/std:c++17",
|
||||
"-std=c++14": "-std=c++17",
|
||||
},
|
||||
)
|
||||
|
||||
# LLVM
|
||||
if env['use_llvm']:
|
||||
if ('clang++' not in os.path.basename(env['CXX'])):
|
||||
env['CC'] = 'clang'
|
||||
env["CXX"] = "clang++"
|
||||
env["LINK"] = "clang++"
|
||||
env = cpp_env.Clone()
|
||||
|
||||
if (env["target"] == "debug"):
|
||||
env.Prepend(CCFLAGS=['-g3'])
|
||||
env.Append(LINKFLAGS=['-rdynamic'])
|
||||
else:
|
||||
env.Prepend(CCFLAGS=['-O3'])
|
||||
if env["target"] == "debug":
|
||||
env.Append(CPPDEFINES=["DEBUG_ENABLED"])
|
||||
|
||||
env.Append(CCFLAGS=['-fPIC', '-std=c++14'])
|
||||
if env["platform"] == "windows" and env["use_mingw"]:
|
||||
env.Append(LINKFLAGS=["-static-libgcc"])
|
||||
|
||||
if target_arch == '32':
|
||||
env.Append(CCFLAGS = [ '-m32' ])
|
||||
env.Append(LINKFLAGS = [ '-m32' ])
|
||||
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++'])
|
||||
if env["platform"] == "osx":
|
||||
env["platform"] = "macos" # compatibility with old osx name
|
||||
ARGUMENTS["platform"] = "macos"
|
||||
env["CC"] = "clang" # CC is not set in 3.x and can result in it being "gcc".
|
||||
|
||||
elif target_platform == 'windows':
|
||||
if host_platform == 'Windows':
|
||||
if env["platform"] == "ios":
|
||||
env["ios_min_version"] = "12.0"
|
||||
|
||||
lib_prefix = "lib"
|
||||
env.Append(LINKFLAGS = [ '/WX' ])
|
||||
if target == 'debug':
|
||||
env.Append(CCFLAGS = ['/EHsc', '/D_DEBUG', '/MDd' ])
|
||||
else:
|
||||
env.Append(CCFLAGS = ['/O2', '/EHsc', '/DNDEBUG', '/MD' ])
|
||||
else:
|
||||
if target_arch == '32':
|
||||
env['CXX']='i686-w64-mingw32-g++'
|
||||
elif target_arch == '64':
|
||||
env['CXX']='x86_64-w64-mingw32-g++'
|
||||
# Normalize suffix
|
||||
if env["platform"] in ["windows", "linux"]:
|
||||
env["arch"] = ARGUMENTS.get("arch", "x86_32" if env["bits"] == "32" else "x86_64")
|
||||
env["arch_suffix"] = env["arch"]
|
||||
elif env["platform"] == "macos":
|
||||
env["arch"] = env["macos_arch"]
|
||||
env["arch_suffix"] = env["arch"]
|
||||
elif env["platform"] == "ios":
|
||||
env["arch"] = "arm32" if env["ios_arch"] == "armv7" else env["ios_arch"]
|
||||
env["arch_suffix"] = env["ios_arch"] + (".simulator" if env["ios_simulator"] else "")
|
||||
elif env["platform"] == "android":
|
||||
env["arch"] = {
|
||||
"armv7": "arm32",
|
||||
"arm64v8": "arm64",
|
||||
"x86": "x86_32",
|
||||
"x86_64": "x86_64",
|
||||
}[env["android_arch"]]
|
||||
env["arch_suffix"] = env["arch"]
|
||||
|
||||
env.Append(CCFLAGS = [ '-g', '-O3', '-std=c++14', '-Wwrite-strings' ])
|
||||
env.Append(LINKFLAGS = [ '--static', '-Wl,--no-undefined', '-static-libgcc', '-static-libstdc++' ])
|
||||
|
||||
elif target_platform == 'osx':
|
||||
if env['use_llvm']:
|
||||
env['CXX'] = 'clang++'
|
||||
|
||||
# Only 64-bits is supported for OS X
|
||||
target_arch = '64'
|
||||
|
||||
env.Append(CCFLAGS = [ '-g','-O3', '-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']])
|
||||
target_compat = "template_" + env["target"]
|
||||
env["suffix"] = ".{}.{}.{}".format(env["platform"], target_compat, env["arch_suffix"])
|
||||
env["debug_symbols"] = False
|
||||
|
||||
# Some windows specific hacks.
|
||||
if env["platform"] == "windows":
|
||||
if sys.platform not in ["win32", "msys"]:
|
||||
# Set missing CC for MinGW from upstream build module.
|
||||
if env["bits"] == "64":
|
||||
env["CC"] = "x86_64-w64-mingw32-gcc"
|
||||
elif env["bits"] == "32":
|
||||
env["CC"] = "i686-w64-mingw32-gcc"
|
||||
elif not env["use_mingw"]:
|
||||
# Mark as MSVC build (would have failed to build the library otherwise).
|
||||
env["is_msvc"] = True
|
||||
# Some linux specific hacks to allow cross-compiling for non-x86 machines.
|
||||
if env["platform"] == "linux" and env["arch"] not in ("x86_32", "x86_64"):
|
||||
for flags in (env["CCFLAGS"], env["LINKFLAGS"], cpp_env["CCFLAGS"], cpp_env["LINKFLAGS"]):
|
||||
replace_flags(flags, {"-m32": None, "-m64": None})
|
||||
else:
|
||||
print("No valid target platform selected.")
|
||||
sys.exit(1)
|
||||
sconstruct = env.get("godot_cpp", "godot-cpp") + "/SConstruct"
|
||||
cpp_env = SConscript(sconstruct)
|
||||
env = cpp_env.Clone()
|
||||
|
||||
# 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])
|
||||
env.Append(LIBS=['%sgodot-cpp.%s.%s.%s%s' % (lib_prefix, target_platform, target, target_arch, ".simulator" if env["ios_simulator"] else "")])
|
||||
if cpp_env.get("is_msvc", False):
|
||||
# Make sure we don't build with static cpp on MSVC (default in recent godot-cpp versions).
|
||||
replace_flags(env["CCFLAGS"], {"/MT": "/MD"})
|
||||
replace_flags(cpp_env["CCFLAGS"], {"/MT": "/MD"})
|
||||
|
||||
# WebRTC stuff
|
||||
webrtc_dir = "webrtc"
|
||||
lib_name = 'libwebrtc_full'
|
||||
lib_path = os.path.join(webrtc_dir, target_platform)
|
||||
|
||||
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", webrtc_dir + "/include/third_party/abseil-cpp"])
|
||||
|
||||
if target_platform == "linux":
|
||||
env.Append(LIBS=[lib_name, "atomic"])
|
||||
env.Append(LIBPATH=[lib_path])
|
||||
#env.Append(CCFLAGS=["-std=c++11"])
|
||||
env.Append(CCFLAGS=["-DWEBRTC_POSIX", "-DWEBRTC_LINUX"])
|
||||
env.Append(CCFLAGS=["-DRTC_UNUSED=''", "-DNO_RETURN=''"])
|
||||
|
||||
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", "advapi32", "winmm", lib_name]])
|
||||
env.Append(LIBPATH=[lib_path])
|
||||
# Mostly "gcc"
|
||||
if env["platform"] == "ios":
|
||||
if env["ios_simulator"]:
|
||||
env.AppendUnique(LINKFLAGS=["-mios-simulator-version-min=" + ARGUMENTS["ios_min_version"]])
|
||||
else:
|
||||
env.Append(CCFLAGS=["-DWINVER=0x0603", "-D_WIN32_WINNT=0x0603", "-DWEBRTC_WIN", "-DWIN32_LEAN_AND_MEAN", "-DNOMINMAX", "-DRTC_UNUSED=", "-DNO_RETURN="])
|
||||
env.Append(LINKFLAGS=[p + env["LIBSUFFIX"] for p in ["secur32", "advapi32", "winmm", lib_name]])
|
||||
env.Append(LIBPATH=[lib_path])
|
||||
env.AppendUnique(LINKFLAGS=["-miphoneos-version-min=" + ARGUMENTS["ios_min_version"]])
|
||||
|
||||
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=''"])
|
||||
# Should probably go to upstream godot-cpp.
|
||||
# We let SCons build its default ENV as it includes OS-specific things which we don't
|
||||
# want to have to pull in manually.
|
||||
# Then we prepend PATH to make it take precedence, while preserving SCons' own entries.
|
||||
env.PrependENVPath("PATH", os.getenv("PATH"))
|
||||
env.PrependENVPath("PKG_CONFIG_PATH", os.getenv("PKG_CONFIG_PATH"))
|
||||
if "TERM" in os.environ: # Used for colored output.
|
||||
env["ENV"]["TERM"] = os.environ["TERM"]
|
||||
|
||||
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=''"])
|
||||
# Patch mingw SHLIBSUFFIX.
|
||||
if env["platform"] == "windows" and env["use_mingw"]:
|
||||
env["SHLIBSUFFIX"] = ".dll"
|
||||
|
||||
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=''"])
|
||||
# Patch OSXCross config.
|
||||
if env["platform"] == "macos" and os.environ.get("OSXCROSS_ROOT", ""):
|
||||
env["SHLIBSUFFIX"] = ".dylib"
|
||||
if env["macos_deployment_target"] != "default":
|
||||
env["ENV"]["MACOSX_DEPLOYMENT_TARGET"] = env["macos_deployment_target"]
|
||||
|
||||
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"])
|
||||
opts.Update(env)
|
||||
|
||||
target = env["target"]
|
||||
if env["godot_version"] == "3":
|
||||
result_path = os.path.join("bin", "gdnative", "webrtc" if env["target"] == "release" else "webrtc_debug")
|
||||
else:
|
||||
result_path = os.path.join("bin", "extension", "webrtc")
|
||||
|
||||
# Our includes and sources
|
||||
env.Append(CPPPATH=['src/'])
|
||||
env.Append(CPPPATH=["src/"])
|
||||
env.Append(CPPDEFINES=["RTC_STATIC"])
|
||||
sources = []
|
||||
add_sources(sources, 'src/', 'cpp')
|
||||
add_sources(sources, 'src/net/', 'cpp')
|
||||
sources.append(
|
||||
[
|
||||
"src/WebRTCLibDataChannel.cpp",
|
||||
"src/WebRTCLibPeerConnection.cpp",
|
||||
]
|
||||
)
|
||||
if env["godot_version"] == "3":
|
||||
env.Append(CPPDEFINES=["GDNATIVE_WEBRTC"])
|
||||
sources.append("src/init_gdnative.cpp")
|
||||
add_sources(sources, "src/net/", "cpp")
|
||||
else:
|
||||
sources.append("src/init_gdextension.cpp")
|
||||
|
||||
# Suffix
|
||||
suffix = '.%s.%s' % (target, target_arch)
|
||||
env["SHOBJSUFFIX"] = suffix + env["SHOBJSUFFIX"]
|
||||
# Add our build tools
|
||||
for tool in ["cmake", "mbedtls", "rtc"]:
|
||||
env.Tool(tool, toolpath=["tools"])
|
||||
|
||||
# Make sure Substfile is also loaded
|
||||
env.Tool("textfile")
|
||||
|
||||
mbedtls = env.BuildMbedTLS()
|
||||
|
||||
rtc = env.BuildLibDataChannel(mbedtls)
|
||||
|
||||
# Forces building our sources after OpenSSL and libdatachannel.
|
||||
# This is because OpenSSL headers are generated by their build system and SCons doesn't know about them.
|
||||
# Note: This might not be necessary in this specific case since our sources doesn't include OpenSSL headers directly,
|
||||
# but it's better to be safe in case of indirect inclusions by one of our other dependencies.
|
||||
env.Depends(sources, rtc + mbedtls)
|
||||
|
||||
# We want to statically link against libstdc++ on Linux to maximize compatibility, but we must restrict the exported
|
||||
# symbols using a GCC version script, or we might end up overriding symbols from other libraries.
|
||||
# Using "-fvisibility=hidden" will not work, since libstdc++ explicitly exports its symbols.
|
||||
symbols_file = None
|
||||
if env["platform"] == "linux" or (
|
||||
env["platform"] == "windows" and env.get("use_mingw", False) and not env.get("use_llvm", False)
|
||||
):
|
||||
if env["godot_version"] == "3":
|
||||
symbols_file = env.File("misc/gcc/symbols-gdnative.map")
|
||||
else:
|
||||
symbols_file = env.File("misc/gcc/symbols-extension.map")
|
||||
env.Append(
|
||||
LINKFLAGS=[
|
||||
"-Wl,--no-undefined,--version-script=" + symbols_file.abspath,
|
||||
"-static-libgcc",
|
||||
"-static-libstdc++",
|
||||
]
|
||||
)
|
||||
env.Depends(sources, symbols_file)
|
||||
|
||||
# Make the shared library
|
||||
result_name = 'webrtc_native.%s.%s.%s' % (target_platform, target, target_arch) + env["SHLIBSUFFIX"]
|
||||
result_name = "libwebrtc_native{}{}".format(env["suffix"], env["SHLIBSUFFIX"])
|
||||
if env["godot_version"] != "3" and env["platform"] == "macos":
|
||||
framework_path = os.path.join(
|
||||
result_path, "lib", "libwebrtc_native.macos.{}.{}.framework".format(env["target"], env["arch"])
|
||||
)
|
||||
library_file = env.SharedLibrary(target=os.path.join(framework_path, result_name), source=sources)
|
||||
plist_file = env.Substfile(
|
||||
os.path.join(framework_path, "Resources", "Info.plist"),
|
||||
"misc/dist/macos/Info.plist",
|
||||
SUBST_DICT={"{LIBRARY_NAME}": result_name, "{DISPLAY_NAME}": "libwebrtc_native" + env["suffix"]},
|
||||
)
|
||||
library = [library_file, plist_file]
|
||||
else:
|
||||
library = env.SharedLibrary(target=os.path.join(result_path, "lib", result_name), source=sources)
|
||||
|
||||
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']))
|
||||
if env["godot_version"] == "3":
|
||||
gdnlib = "webrtc" if target != "debug" else "webrtc_debug"
|
||||
ext = ".tres"
|
||||
extfile = env.Substfile(
|
||||
os.path.join(result_path, gdnlib + ext),
|
||||
"misc/webrtc" + ext,
|
||||
SUBST_DICT={
|
||||
"{GDNATIVE_PATH}": gdnlib,
|
||||
"{TARGET}": "template_" + env["target"],
|
||||
},
|
||||
)
|
||||
else:
|
||||
extfile = env.InstallAs(os.path.join(result_path, "webrtc.gdextension"), "misc/webrtc.gdextension")
|
||||
|
||||
Default(extfile)
|
||||
|
||||
11
build_profile.json
Normal file
11
build_profile.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"enabled_classes": [
|
||||
"WebRTCDataChannelExtension",
|
||||
"WebRTCPeerConnectionExtension",
|
||||
"WebRTCDataChannelGDNative",
|
||||
"WebRTCPeerConnectionGDNative",
|
||||
"NativeScript",
|
||||
"GDNativeLibrary",
|
||||
"Window"
|
||||
]
|
||||
}
|
||||
Submodule godot-cpp updated: 77d41fa179...631cd5fe37
1
godot-cpp-3.x
Submodule
1
godot-cpp-3.x
Submodule
Submodule godot-cpp-3.x added at 7c09b5484d
28
misc/dist/macos/Info.plist
vendored
Normal file
28
misc/dist/macos/Info.plist
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>{LIBRARY_NAME}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.godotengine.webrtc-native</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>{DISPLAY_NAME}</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>webrtc_native</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.0</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>MacOSX</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0.0</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
<string>11.0</string>
|
||||
</dict>
|
||||
</plist>
|
||||
6
misc/gcc/symbols-extension.map
Normal file
6
misc/gcc/symbols-extension.map
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
global:
|
||||
webrtc_extension_init;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
9
misc/gcc/symbols-gdnative.map
Normal file
9
misc/gcc/symbols-gdnative.map
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
global:
|
||||
godot_gdnative_singleton;
|
||||
godot_gdnative_init;
|
||||
godot_gdnative_terminate;
|
||||
godot_nativescript_init;
|
||||
local:
|
||||
*;
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
[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 = [ ]
|
||||
297
misc/patches/build_profile.diff
Normal file
297
misc/patches/build_profile.diff
Normal file
@@ -0,0 +1,297 @@
|
||||
diff --git a/godot-cpp/binding_generator.py b/godot-cpp/binding_generator.py
|
||||
index 18db9fd..e0c8caf 100644
|
||||
--- a/godot-cpp/binding_generator.py
|
||||
+++ b/godot-cpp/binding_generator.py
|
||||
@@ -72,9 +72,13 @@ def generate_wrappers(target):
|
||||
|
||||
def get_file_list(api_filepath, output_dir, headers=False, sources=False):
|
||||
api = {}
|
||||
- files = []
|
||||
with open(api_filepath, encoding="utf-8") as api_file:
|
||||
api = json.load(api_file)
|
||||
+ return _get_file_list(api, output_dir, headers, sources)
|
||||
+
|
||||
+
|
||||
+def _get_file_list(api, output_dir, headers=False, sources=False):
|
||||
+ files = []
|
||||
|
||||
core_gen_folder = Path(output_dir) / "gen" / "include" / "godot_cpp" / "core"
|
||||
include_gen_folder = Path(output_dir) / "gen" / "include" / "godot_cpp"
|
||||
@@ -158,13 +162,15 @@ def scons_generate_bindings(target, source, env):
|
||||
return None
|
||||
|
||||
|
||||
-def generate_bindings(api_filepath, use_template_get_node, bits="64", precision="single", output_dir="."):
|
||||
- api = None
|
||||
-
|
||||
- target_dir = Path(output_dir) / "gen"
|
||||
-
|
||||
+def _generate_bindings(api_filepath, use_template_get_node, bits="64", precision="single", output_dir="."):
|
||||
+ api = {}
|
||||
with open(api_filepath, encoding="utf-8") as api_file:
|
||||
api = json.load(api_file)
|
||||
+ _generate_bindings(api, use_template_get_node, bits, precision, output_dir)
|
||||
+
|
||||
+
|
||||
+def _generate_bindings(api, use_template_get_node, bits="64", precision="single", output_dir="."):
|
||||
+ target_dir = Path(output_dir) / "gen"
|
||||
|
||||
shutil.rmtree(target_dir, ignore_errors=True)
|
||||
target_dir.mkdir(parents=True)
|
||||
diff --git a/godot-cpp/build_profile.py b/godot-cpp/build_profile.py
|
||||
new file mode 100644
|
||||
index 0000000..b4d19de
|
||||
--- /dev/null
|
||||
+++ b/godot-cpp/build_profile.py
|
||||
@@ -0,0 +1,183 @@
|
||||
+import json
|
||||
+import sys
|
||||
+
|
||||
+
|
||||
+def parse_build_profile(profile_filepath, api):
|
||||
+ if profile_filepath == "":
|
||||
+ return {}
|
||||
+
|
||||
+ with open(profile_filepath, encoding="utf-8") as profile_file:
|
||||
+ profile = json.load(profile_file)
|
||||
+
|
||||
+ api_dict = {}
|
||||
+ parents = {}
|
||||
+ children = {}
|
||||
+ for engine_class in api["classes"]:
|
||||
+ api_dict[engine_class["name"]] = engine_class
|
||||
+ parent = engine_class.get("inherits", "")
|
||||
+ child = engine_class["name"]
|
||||
+ parents[child] = parent
|
||||
+ if parent == "":
|
||||
+ continue
|
||||
+ children[parent] = children.get(parent, [])
|
||||
+ children[parent].append(child)
|
||||
+
|
||||
+ included = []
|
||||
+ front = list(profile.get("enabled_classes", []))
|
||||
+ if front:
|
||||
+ # These must always be included
|
||||
+ front.append("WorkerThreadPool")
|
||||
+ front.append("ClassDB")
|
||||
+ front.append("ClassDBSingleton")
|
||||
+ # In src/classes/low_level.cpp
|
||||
+ front.append("FileAccess")
|
||||
+ front.append("Image")
|
||||
+ front.append("XMLParser")
|
||||
+ # In include/godot_cpp/templates/thread_work_pool.hpp
|
||||
+ front.append("Semaphore")
|
||||
+ while front:
|
||||
+ cls = front.pop()
|
||||
+ if cls in included:
|
||||
+ continue
|
||||
+ included.append(cls)
|
||||
+ parent = parents.get(cls, "")
|
||||
+ if parent:
|
||||
+ front.append(parent)
|
||||
+
|
||||
+ excluded = []
|
||||
+ front = list(profile.get("disabled_classes", []))
|
||||
+ while front:
|
||||
+ cls = front.pop()
|
||||
+ if cls in excluded:
|
||||
+ continue
|
||||
+ excluded.append(cls)
|
||||
+ front += children.get(cls, [])
|
||||
+
|
||||
+ if included and excluded:
|
||||
+ print(
|
||||
+ "WARNING: Cannot specify both 'enabled_classes' and 'disabled_classes' in build profile. 'disabled_classes' will be ignored."
|
||||
+ )
|
||||
+
|
||||
+ return {
|
||||
+ "enabled_classes": included,
|
||||
+ "disabled_classes": excluded,
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+def generate_trimmed_api(source_api_filepath, profile_filepath):
|
||||
+ with open(source_api_filepath, encoding="utf-8") as api_file:
|
||||
+ api = json.load(api_file)
|
||||
+
|
||||
+ if profile_filepath == "":
|
||||
+ return api
|
||||
+
|
||||
+ build_profile = parse_build_profile(profile_filepath, api)
|
||||
+
|
||||
+ engine_classes = {}
|
||||
+ for class_api in api["classes"]:
|
||||
+ engine_classes[class_api["name"]] = class_api["is_refcounted"]
|
||||
+ for native_struct in api["native_structures"]:
|
||||
+ if native_struct["name"] == "ObjectID":
|
||||
+ continue
|
||||
+ engine_classes[native_struct["name"]] = False
|
||||
+
|
||||
+ classes = []
|
||||
+ for class_api in api["classes"]:
|
||||
+ if not is_class_included(class_api["name"], build_profile):
|
||||
+ continue
|
||||
+ if "methods" in class_api:
|
||||
+ methods = []
|
||||
+ for method in class_api["methods"]:
|
||||
+ if not is_method_included(method, build_profile, engine_classes):
|
||||
+ continue
|
||||
+ methods.append(method)
|
||||
+ class_api["methods"] = methods
|
||||
+ classes.append(class_api)
|
||||
+ api["classes"] = classes
|
||||
+
|
||||
+ return api
|
||||
+
|
||||
+
|
||||
+def is_class_included(class_name, build_profile):
|
||||
+ """
|
||||
+ Check if an engine class should be included.
|
||||
+ This removes classes according to a build profile of enabled or disabled classes.
|
||||
+ """
|
||||
+ included = build_profile.get("enabled_classes", [])
|
||||
+ excluded = build_profile.get("disabled_classes", [])
|
||||
+ if included:
|
||||
+ return class_name in included
|
||||
+ if excluded:
|
||||
+ return class_name not in excluded
|
||||
+ return True
|
||||
+
|
||||
+
|
||||
+def is_method_included(method, build_profile, engine_classes):
|
||||
+ """
|
||||
+ Check if an engine class method should be included.
|
||||
+ This removes methods according to a build profile of enabled or disabled classes.
|
||||
+ """
|
||||
+ included = build_profile.get("enabled_classes", [])
|
||||
+ excluded = build_profile.get("disabled_classes", [])
|
||||
+ ref_cls = set()
|
||||
+ rtype = get_base_type(method.get("return_value", {}).get("type", ""))
|
||||
+ args = [get_base_type(a["type"]) for a in method.get("arguments", [])]
|
||||
+ if rtype in engine_classes:
|
||||
+ ref_cls.add(rtype)
|
||||
+ elif is_enum(rtype) and get_enum_class(rtype) in engine_classes:
|
||||
+ ref_cls.add(get_enum_class(rtype))
|
||||
+ for arg in args:
|
||||
+ if arg in engine_classes:
|
||||
+ ref_cls.add(arg)
|
||||
+ elif is_enum(arg) and get_enum_class(arg) in engine_classes:
|
||||
+ ref_cls.add(get_enum_class(arg))
|
||||
+ for acls in ref_cls:
|
||||
+ if len(included) > 0 and acls not in included:
|
||||
+ return False
|
||||
+ elif len(excluded) > 0 and acls in excluded:
|
||||
+ return False
|
||||
+ return True
|
||||
+
|
||||
+
|
||||
+def is_enum(type_name):
|
||||
+ return type_name.startswith("enum::") or type_name.startswith("bitfield::")
|
||||
+
|
||||
+
|
||||
+def get_enum_class(enum_name: str):
|
||||
+ if "." in enum_name:
|
||||
+ if is_bitfield(enum_name):
|
||||
+ return enum_name.replace("bitfield::", "").split(".")[0]
|
||||
+ else:
|
||||
+ return enum_name.replace("enum::", "").split(".")[0]
|
||||
+ else:
|
||||
+ return "GlobalConstants"
|
||||
+
|
||||
+
|
||||
+def get_base_type(type_name):
|
||||
+ if type_name.startswith("const "):
|
||||
+ type_name = type_name[6:]
|
||||
+ if type_name.endswith("*"):
|
||||
+ type_name = type_name[:-1]
|
||||
+ if type_name.startswith("typedarray::"):
|
||||
+ type_name = type_name.replace("typedarray::", "")
|
||||
+ return type_name
|
||||
+
|
||||
+
|
||||
+def is_bitfield(type_name):
|
||||
+ return type_name.startswith("bitfield::")
|
||||
+
|
||||
+
|
||||
+if __name__ == "__main__":
|
||||
+ if len(sys.argv) < 3 or len(sys.argv) > 4:
|
||||
+ print("Usage: %s BUILD_PROFILE INPUT_JSON [OUTPUT_JSON]" % (sys.argv[0]))
|
||||
+ sys.exit(1)
|
||||
+ profile = sys.argv[1]
|
||||
+ infile = sys.argv[2]
|
||||
+ outfile = sys.argv[3] if len(sys.argv) > 3 else ""
|
||||
+ api = generate_trimmed_api(infile, profile)
|
||||
+
|
||||
+ if outfile:
|
||||
+ with open(outfile, "w", encoding="utf-8") as f:
|
||||
+ json.dump(api, f)
|
||||
+ else:
|
||||
+ json.dump(api, sys.stdout)
|
||||
diff --git a/godot-cpp/tools/godotcpp.py b/godot-cpp/tools/godotcpp.py
|
||||
index efe632a..993aa81 100644
|
||||
--- a/godot-cpp/tools/godotcpp.py
|
||||
+++ b/godot-cpp/tools/godotcpp.py
|
||||
@@ -5,7 +5,8 @@ from SCons.Tool import Tool
|
||||
from SCons.Builder import Builder
|
||||
from SCons.Errors import UserError
|
||||
|
||||
-from binding_generator import scons_generate_bindings, scons_emit_files
|
||||
+from binding_generator import _generate_bindings, _get_file_list, get_file_list
|
||||
+from build_profile import generate_trimmed_api
|
||||
|
||||
|
||||
def add_sources(sources, dir, extension):
|
||||
@@ -14,6 +15,37 @@ def add_sources(sources, dir, extension):
|
||||
sources.append(dir + "/" + f)
|
||||
|
||||
|
||||
+def scons_emit_files(target, source, env):
|
||||
+ profile_filepath = env.get("build_profile", "")
|
||||
+ if profile_filepath:
|
||||
+ profile_filepath = normalize_path(profile_filepath, env)
|
||||
+
|
||||
+ # Always clean all files
|
||||
+ env.Clean(target, [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True)])
|
||||
+
|
||||
+ api = generate_trimmed_api(str(source[0]), profile_filepath)
|
||||
+ files = [env.File(f) for f in _get_file_list(api, target[0].abspath, True, True)]
|
||||
+ env["godot_cpp_gen_dir"] = target[0].abspath
|
||||
+ return files, source
|
||||
+
|
||||
+
|
||||
+def scons_generate_bindings(target, source, env):
|
||||
+ profile_filepath = env.get("build_profile", "")
|
||||
+ if profile_filepath:
|
||||
+ profile_filepath = normalize_path(profile_filepath, env)
|
||||
+
|
||||
+ api = generate_trimmed_api(str(source[0]), profile_filepath)
|
||||
+
|
||||
+ _generate_bindings(
|
||||
+ api,
|
||||
+ env["generate_template_get_node"],
|
||||
+ "32" if "32" in env["arch"] else "64",
|
||||
+ env["precision"],
|
||||
+ env["godot_cpp_gen_dir"],
|
||||
+ )
|
||||
+ return None
|
||||
+
|
||||
+
|
||||
def normalize_path(val, env):
|
||||
return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
|
||||
|
||||
@@ -175,6 +207,15 @@ def options(opts, env):
|
||||
)
|
||||
)
|
||||
|
||||
+ opts.Add(
|
||||
+ PathVariable(
|
||||
+ "build_profile",
|
||||
+ "Path to a file containing a feature build profile",
|
||||
+ default=env.get("build_profile", None),
|
||||
+ validator=validate_file,
|
||||
+ )
|
||||
+ )
|
||||
+
|
||||
opts.Add(
|
||||
BoolVariable(
|
||||
"disable_exceptions",
|
||||
286
misc/patches/build_profile_3.x.diff
Normal file
286
misc/patches/build_profile_3.x.diff
Normal file
@@ -0,0 +1,286 @@
|
||||
diff --git a/godot-cpp-3.x/SConstruct b/godot-cpp-3.x/SConstruct
|
||||
index f653d54..483f190 100644
|
||||
--- a/godot-cpp-3.x/SConstruct
|
||||
+++ b/godot-cpp-3.x/SConstruct
|
||||
@@ -3,7 +3,42 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
-from binding_generator import scons_generate_bindings, scons_emit_files
|
||||
+from binding_generator import _generate_bindings, _get_file_list, get_file_list
|
||||
+from build_profile import generate_trimmed_api
|
||||
+
|
||||
+
|
||||
+def normalize_path(val):
|
||||
+ return val if os.path.isabs(val) else os.path.join(env.Dir("#").abspath, val)
|
||||
+
|
||||
+
|
||||
+def scons_emit_files(target, source, env):
|
||||
+ profile_filepath = env.get("build_profile", "")
|
||||
+ if profile_filepath:
|
||||
+ profile_filepath = normalize_path(profile_filepath)
|
||||
+
|
||||
+ # Always clean all files
|
||||
+ env.Clean(target, [env.File(f) for f in get_file_list(str(source[0]), target[0].abspath, True, True)])
|
||||
+
|
||||
+ api = generate_trimmed_api(str(source[0]), profile_filepath)
|
||||
+ files = [env.File(f) for f in _get_file_list(api, target[0].abspath, True, True)]
|
||||
+ env["godot_cpp_gen_dir"] = target[0].abspath
|
||||
+ return files, source
|
||||
+
|
||||
+
|
||||
+def scons_generate_bindings(target, source, env):
|
||||
+ profile_filepath = env.get("build_profile", "")
|
||||
+ if profile_filepath:
|
||||
+ profile_filepath = normalize_path(profile_filepath)
|
||||
+
|
||||
+ api = generate_trimmed_api(str(source[0]), profile_filepath)
|
||||
+
|
||||
+ _generate_bindings(
|
||||
+ api,
|
||||
+ env["generate_template_get_node"],
|
||||
+ env["godot_cpp_gen_dir"],
|
||||
+ )
|
||||
+ return None
|
||||
+
|
||||
|
||||
if sys.version_info < (3,):
|
||||
|
||||
@@ -170,6 +205,14 @@ opts.Add(
|
||||
True,
|
||||
)
|
||||
)
|
||||
+opts.Add(
|
||||
+ PathVariable(
|
||||
+ "build_profile",
|
||||
+ "Path to a file containing a feature build profile",
|
||||
+ default=env.get("build_profile", None),
|
||||
+ validator=lambda key, val, env: os.path.isfile(normalize_path(val)),
|
||||
+ )
|
||||
+)
|
||||
|
||||
opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True))
|
||||
|
||||
diff --git a/godot-cpp-3.x/binding_generator.py b/godot-cpp-3.x/binding_generator.py
|
||||
index da4bb61..1348a51 100644
|
||||
--- a/godot-cpp-3.x/binding_generator.py
|
||||
+++ b/godot-cpp-3.x/binding_generator.py
|
||||
@@ -16,10 +16,16 @@ classes = []
|
||||
|
||||
|
||||
def get_file_list(api_filepath, output_dir, headers=False, sources=False):
|
||||
- global classes
|
||||
- files = []
|
||||
+ api = {}
|
||||
with open(api_filepath) as api_file:
|
||||
classes = json.load(api_file)
|
||||
+ return _get_file_list(classes, output_dir, headers, sources)
|
||||
+
|
||||
+
|
||||
+def _get_file_list(api, output_dir, headers=False, sources=False):
|
||||
+ global classes
|
||||
+ classes = api
|
||||
+ files = []
|
||||
include_gen_folder = Path(output_dir) / "include" / "gen"
|
||||
source_gen_folder = Path(output_dir) / "src" / "gen"
|
||||
for _class in classes:
|
||||
@@ -58,9 +64,15 @@ def scons_generate_bindings(target, source, env):
|
||||
|
||||
|
||||
def generate_bindings(api_filepath, use_template_get_node, output_dir="."):
|
||||
- global classes
|
||||
+ classes = {}
|
||||
with open(api_filepath) as api_file:
|
||||
classes = json.load(api_file)
|
||||
+ _generate_bindings(classes, use_template_get_node, output_dir)
|
||||
+
|
||||
+
|
||||
+def _generate_bindings(api, use_template_get_node, output_dir="."):
|
||||
+ global classes
|
||||
+ classes = api
|
||||
|
||||
icalls = set()
|
||||
include_gen_folder = Path(output_dir) / "include" / "gen"
|
||||
diff --git a/godot-cpp-3.x/build_profile.py b/godot-cpp-3.x/build_profile.py
|
||||
new file mode 100644
|
||||
index 0000000..5518f64
|
||||
--- /dev/null
|
||||
+++ b/godot-cpp-3.x/build_profile.py
|
||||
@@ -0,0 +1,177 @@
|
||||
+import json
|
||||
+import sys
|
||||
+
|
||||
+
|
||||
+def parse_build_profile(profile_filepath, api):
|
||||
+ if profile_filepath == "":
|
||||
+ return {}
|
||||
+
|
||||
+ with open(profile_filepath, encoding="utf-8") as profile_file:
|
||||
+ profile = json.load(profile_file)
|
||||
+
|
||||
+ api_dict = {}
|
||||
+ parents = {}
|
||||
+ children = {}
|
||||
+ for engine_class in api:
|
||||
+ api_dict[engine_class["name"]] = engine_class
|
||||
+ parent = engine_class.get("base_class", "")
|
||||
+ child = engine_class["name"]
|
||||
+ parents[child] = parent
|
||||
+ if parent == "":
|
||||
+ continue
|
||||
+ children[parent] = children.get(parent, [])
|
||||
+ children[parent].append(child)
|
||||
+
|
||||
+ included = []
|
||||
+ front = list(profile.get("enabled_classes", []))
|
||||
+ if front:
|
||||
+ # These must always be included
|
||||
+ front.append("WorkerThreadPool")
|
||||
+ front.append("ClassDB")
|
||||
+ front.append("ClassDBSingleton")
|
||||
+ # In src/classes/low_level.cpp
|
||||
+ front.append("FileAccess")
|
||||
+ front.append("Image")
|
||||
+ front.append("XMLParser")
|
||||
+ # In include/godot_cpp/templates/thread_work_pool.hpp
|
||||
+ front.append("Semaphore")
|
||||
+ while front:
|
||||
+ cls = front.pop()
|
||||
+ if cls in included:
|
||||
+ continue
|
||||
+ included.append(cls)
|
||||
+ parent = parents.get(cls, "")
|
||||
+ if parent:
|
||||
+ front.append(parent)
|
||||
+
|
||||
+ excluded = []
|
||||
+ front = list(profile.get("disabled_classes", []))
|
||||
+ while front:
|
||||
+ cls = front.pop()
|
||||
+ if cls in excluded:
|
||||
+ continue
|
||||
+ excluded.append(cls)
|
||||
+ front += children.get(cls, [])
|
||||
+
|
||||
+ if included and excluded:
|
||||
+ print(
|
||||
+ "WARNING: Cannot specify both 'enabled_classes' and 'disabled_classes' in build profile. 'disabled_classes' will be ignored."
|
||||
+ )
|
||||
+
|
||||
+ return {
|
||||
+ "enabled_classes": included,
|
||||
+ "disabled_classes": excluded,
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+def generate_trimmed_api(source_api_filepath, profile_filepath):
|
||||
+ with open(source_api_filepath, encoding="utf-8") as api_file:
|
||||
+ api = json.load(api_file)
|
||||
+
|
||||
+ if profile_filepath == "":
|
||||
+ return api
|
||||
+
|
||||
+ build_profile = parse_build_profile(profile_filepath, api)
|
||||
+
|
||||
+ engine_classes = {}
|
||||
+ for class_api in api:
|
||||
+ engine_classes[class_api["name"]] = class_api["is_reference"]
|
||||
+
|
||||
+ classes = []
|
||||
+ for class_api in api:
|
||||
+ if not is_class_included(class_api["name"], build_profile):
|
||||
+ continue
|
||||
+ if "methods" in class_api:
|
||||
+ methods = []
|
||||
+ for method in class_api["methods"]:
|
||||
+ if not is_method_included(method, build_profile, engine_classes):
|
||||
+ continue
|
||||
+ methods.append(method)
|
||||
+ class_api["methods"] = methods
|
||||
+ classes.append(class_api)
|
||||
+ return classes
|
||||
+
|
||||
+
|
||||
+def is_class_included(class_name, build_profile):
|
||||
+ """
|
||||
+ Check if an engine class should be included.
|
||||
+ This removes classes according to a build profile of enabled or disabled classes.
|
||||
+ """
|
||||
+ included = build_profile.get("enabled_classes", [])
|
||||
+ excluded = build_profile.get("disabled_classes", [])
|
||||
+ if included:
|
||||
+ return class_name in included
|
||||
+ if excluded:
|
||||
+ return class_name not in excluded
|
||||
+ return True
|
||||
+
|
||||
+
|
||||
+def is_method_included(method, build_profile, engine_classes):
|
||||
+ """
|
||||
+ Check if an engine class method should be included.
|
||||
+ This removes methods according to a build profile of enabled or disabled classes.
|
||||
+ """
|
||||
+ included = build_profile.get("enabled_classes", [])
|
||||
+ excluded = build_profile.get("disabled_classes", [])
|
||||
+ ref_cls = set()
|
||||
+ rtype = get_base_type(method.get("return_type", ""))
|
||||
+ args = [get_base_type(a["type"]) for a in method.get("arguments", [])]
|
||||
+ if rtype in engine_classes:
|
||||
+ ref_cls.add(rtype)
|
||||
+ elif is_enum(rtype) and get_enum_class(rtype) in engine_classes:
|
||||
+ ref_cls.add(get_enum_class(rtype))
|
||||
+ for arg in args:
|
||||
+ if arg in engine_classes:
|
||||
+ ref_cls.add(arg)
|
||||
+ elif is_enum(arg) and get_enum_class(arg) in engine_classes:
|
||||
+ ref_cls.add(get_enum_class(arg))
|
||||
+ for acls in ref_cls:
|
||||
+ if len(included) > 0 and acls not in included:
|
||||
+ return False
|
||||
+ elif len(excluded) > 0 and acls in excluded:
|
||||
+ return False
|
||||
+ return True
|
||||
+
|
||||
+
|
||||
+def is_enum(type_name):
|
||||
+ return type_name.startswith("enum::") or type_name.startswith("bitfield::")
|
||||
+
|
||||
+
|
||||
+def get_enum_class(enum_name: str):
|
||||
+ if "." in enum_name:
|
||||
+ if is_bitfield(enum_name):
|
||||
+ return enum_name.replace("bitfield::", "").split(".")[0]
|
||||
+ else:
|
||||
+ return enum_name.replace("enum::", "").split(".")[0]
|
||||
+ else:
|
||||
+ return "GlobalConstants"
|
||||
+
|
||||
+
|
||||
+def get_base_type(type_name):
|
||||
+ if type_name.startswith("const "):
|
||||
+ type_name = type_name[6:]
|
||||
+ if type_name.endswith("*"):
|
||||
+ type_name = type_name[:-1]
|
||||
+ if type_name.startswith("typedarray::"):
|
||||
+ type_name = type_name.replace("typedarray::", "")
|
||||
+ return type_name
|
||||
+
|
||||
+
|
||||
+def is_bitfield(type_name):
|
||||
+ return type_name.startswith("bitfield::")
|
||||
+
|
||||
+
|
||||
+if __name__ == "__main__":
|
||||
+ if len(sys.argv) < 3 or len(sys.argv) > 4:
|
||||
+ print("Usage: %s BUILD_PROFILE INPUT_JSON [OUTPUT_JSON]" % (sys.argv[0]))
|
||||
+ sys.exit(1)
|
||||
+ profile = sys.argv[1]
|
||||
+ infile = sys.argv[2]
|
||||
+ outfile = sys.argv[3] if len(sys.argv) > 3 else ""
|
||||
+ api = generate_trimmed_api(infile, profile)
|
||||
+
|
||||
+ if outfile:
|
||||
+ with open(outfile, "w", encoding="utf-8") as f:
|
||||
+ json.dump(api, f)
|
||||
+ else:
|
||||
+ json.dump(api, sys.stdout)
|
||||
34
misc/patches/gdnantive_arm_warnings.diff
Normal file
34
misc/patches/gdnantive_arm_warnings.diff
Normal file
@@ -0,0 +1,34 @@
|
||||
diff --git a/godot-cpp-3.x/godot-headers/gdnative/gdnative.h b/godot-cpp-3.x/godot-headers/gdnative/gdnative.h
|
||||
index c0573d21b5d7a..ec95c4c4ebfcc 100644
|
||||
--- a/godot-cpp-3.x/godot-headers/gdnative/gdnative.h
|
||||
+++ b/godot-cpp-3.x/godot-headers/gdnative/gdnative.h
|
||||
@@ -37,20 +37,24 @@ extern "C" {
|
||||
|
||||
#if defined(_WIN32) || defined(__ANDROID__)
|
||||
#define GDCALLINGCONV
|
||||
-#define GDAPI GDCALLINGCONV
|
||||
+
|
||||
#elif defined(__APPLE__)
|
||||
#include "TargetConditionals.h"
|
||||
#if TARGET_OS_IPHONE
|
||||
#define GDCALLINGCONV __attribute__((visibility("default")))
|
||||
-#define GDAPI GDCALLINGCONV
|
||||
#elif TARGET_OS_MAC
|
||||
#define GDCALLINGCONV __attribute__((sysv_abi))
|
||||
-#define GDAPI GDCALLINGCONV
|
||||
#endif
|
||||
-#else // !_WIN32 && !__APPLE__
|
||||
+
|
||||
+#else // Linux/BSD/Web
|
||||
+#if defined(__aarch64__) || defined(__arm__)
|
||||
+#define GDCALLINGCONV
|
||||
+#else
|
||||
#define GDCALLINGCONV __attribute__((sysv_abi))
|
||||
-#define GDAPI GDCALLINGCONV
|
||||
#endif
|
||||
+#endif
|
||||
+
|
||||
+#define GDAPI GDCALLINGCONV
|
||||
|
||||
// This is for libraries *using* the header, NOT GODOT EXPOSING STUFF!!
|
||||
#if !defined(GDN_EXPORT)
|
||||
15
misc/patches/scons_path.diff
Normal file
15
misc/patches/scons_path.diff
Normal file
@@ -0,0 +1,15 @@
|
||||
diff --git a/godot-cpp-3.x/SConstruct b/godot-cpp-3.x/SConstruct
|
||||
index f653d54..6f40377 100644
|
||||
--- a/godot-cpp-3.x/SConstruct
|
||||
+++ b/godot-cpp-3.x/SConstruct
|
||||
@@ -194,6 +194,9 @@ if host_platform == "windows" and env["platform"] != "android":
|
||||
|
||||
opts.Update(env)
|
||||
|
||||
+# Allows us to use Godot buildroot toolchain
|
||||
+env.PrependENVPath("PATH", os.getenv("PATH"))
|
||||
+
|
||||
# Require C++14
|
||||
if host_platform == "windows" and env["platform"] == "windows" and not env["use_mingw"]:
|
||||
# MSVC
|
||||
|
||||
26
misc/scripts/black_format.sh
Executable file
26
misc/scripts/black_format.sh
Executable file
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script runs black on all Python files in the repo.
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
# Apply black.
|
||||
echo -e "Formatting Python files..."
|
||||
PY_FILES=$(git ls-files -- '*SConstruct' '*SCsub' '*.py' ':!:.git/*' ':!:thirdparty/*')
|
||||
black -l 120 $PY_FILES
|
||||
|
||||
diff=$(git diff --color)
|
||||
|
||||
# If no diff has been generated all is OK, clean up, and exit.
|
||||
if [ -z "$diff" ] ; then
|
||||
printf "\e[1;32m*** Files in this commit comply with the black style rules.\e[0m\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# A diff has been created, notify the user, clean up, and exit.
|
||||
printf "\n\e[1;33m*** The following changes must be made to comply with the formatting rules:\e[0m\n\n"
|
||||
# Perl commands replace trailing spaces with `·` and tabs with `<TAB>`.
|
||||
printf "$diff\n" | perl -pe 's/(.*[^ ])( +)(\e\[m)$/my $spaces="·" x length($2); sprintf("$1$spaces$3")/ge' | perl -pe 's/(.*[^\t])(\t+)(\e\[m)$/my $tabs="<TAB>" x length($2); sprintf("$1$tabs$3")/ge'
|
||||
|
||||
printf "\n\e[1;91m*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\e[0m\n"
|
||||
exit 1
|
||||
53
misc/scripts/clang_format.sh
Executable file
53
misc/scripts/clang_format.sh
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script runs clang-format and fixes copyright headers on all relevant files in the repo.
|
||||
# This is the primary script responsible for fixing style violations.
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
# Loop through all code files tracked by Git.
|
||||
files=$(git ls-files -- '*.c' '*.h' '*.cpp' '*.hpp' '*.cc' '*.hh' '*.cxx' '*.m' '*.mm' '*.inc' '*.java' '*.glsl' \
|
||||
':!:.git/*' ':!:thirdparty/*' ':!:*/thirdparty/*' ':!:platform/android/java/lib/src/com/google/*' \
|
||||
':!:*-so_wrap.*' ':!:tests/python_build/*')
|
||||
else
|
||||
# $1 should be a file listing file paths to process. Used in CI.
|
||||
files=$(cat "$1" | grep -v "thirdparty/" | grep -E "\.(c|h|cpp|hpp|cc|hh|cxx|m|mm|inc|java|glsl)$" | grep -v "platform/android/java/lib/src/com/google/" | grep -v "\-so_wrap\." | grep -v "tests/python_build/")
|
||||
fi
|
||||
|
||||
if [ ! -z "$files" ]; then
|
||||
clang-format --Wno-error=unknown -i $files
|
||||
fi
|
||||
|
||||
# Fix copyright headers, but not all files get them.
|
||||
for f in $files; do
|
||||
if [[ "$f" == *"inc" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *"glsl" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/GLSurfaceView"* ]]; then
|
||||
continue
|
||||
elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/gl/EGLLogWrapper"* ]]; then
|
||||
continue
|
||||
elif [[ "$f" == "platform/android/java/lib/src/org/godotengine/godot/utils/ProcessPhoenix"* ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
python misc/scripts/copyright_headers.py "$f"
|
||||
done
|
||||
|
||||
diff=$(git diff --color)
|
||||
|
||||
# If no diff has been generated all is OK, clean up, and exit.
|
||||
if [ -z "$diff" ] ; then
|
||||
printf "\e[1;32m*** Files in this commit comply with the clang-format style rules.\e[0m\n"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# A diff has been created, notify the user, clean up, and exit.
|
||||
printf "\n\e[1;33m*** The following changes must be made to comply with the formatting rules:\e[0m\n\n"
|
||||
# Perl commands replace trailing spaces with `·` and tabs with `<TAB>`.
|
||||
printf "$diff\n" | perl -pe 's/(.*[^ ])( +)(\e\[m)$/my $spaces="·" x length($2); sprintf("$1$spaces$3")/ge' | perl -pe 's/(.*[^\t])(\t+)(\e\[m)$/my $tabs="<TAB>" x length($2); sprintf("$1$tabs$3")/ge'
|
||||
|
||||
printf "\n\e[1;91m*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\e[0m\n"
|
||||
exit 1
|
||||
95
misc/scripts/copyright_headers.py
Executable file
95
misc/scripts/copyright_headers.py
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import sys
|
||||
|
||||
header = """\
|
||||
/**************************************************************************/
|
||||
/* $filename */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
"""
|
||||
|
||||
fname = sys.argv[1]
|
||||
|
||||
# Handle replacing $filename with actual filename and keep alignment
|
||||
fsingle = fname.strip()
|
||||
if fsingle.find("/") != -1:
|
||||
fsingle = fsingle[fsingle.rfind("/") + 1 :]
|
||||
rep_fl = "$filename"
|
||||
rep_fi = fsingle
|
||||
len_fl = len(rep_fl)
|
||||
len_fi = len(rep_fi)
|
||||
# Pad with spaces to keep alignment
|
||||
if len_fi < len_fl:
|
||||
for x in range(len_fl - len_fi):
|
||||
rep_fi += " "
|
||||
elif len_fl < len_fi:
|
||||
for x in range(len_fi - len_fl):
|
||||
rep_fl += " "
|
||||
if header.find(rep_fl) != -1:
|
||||
text = header.replace(rep_fl, rep_fi)
|
||||
else:
|
||||
text = header.replace("$filename", fsingle)
|
||||
text += "\n"
|
||||
|
||||
# We now have the proper header, so we want to ignore the one in the original file
|
||||
# and potentially empty lines and badly formatted lines, while keeping comments that
|
||||
# come after the header, and then keep everything non-header unchanged.
|
||||
# To do so, we skip empty lines that may be at the top in a first pass.
|
||||
# In a second pass, we skip all consecutive comment lines starting with "/*",
|
||||
# then we can append the rest (step 2).
|
||||
|
||||
fileread = open(fname.strip(), "r")
|
||||
line = fileread.readline()
|
||||
header_done = False
|
||||
|
||||
while line.strip() == "": # Skip empty lines at the top
|
||||
line = fileread.readline()
|
||||
|
||||
if line.find("/**********") == -1: # Godot header starts this way
|
||||
# Maybe starting with a non-Godot comment, abort header magic
|
||||
header_done = True
|
||||
|
||||
while not header_done: # Handle header now
|
||||
if line.find("/*") != 0: # No more starting with a comment
|
||||
header_done = True
|
||||
if line.strip() != "":
|
||||
text += line
|
||||
line = fileread.readline()
|
||||
|
||||
while line != "": # Dump everything until EOF
|
||||
text += line
|
||||
line = fileread.readline()
|
||||
|
||||
fileread.close()
|
||||
|
||||
# Write
|
||||
filewrite = open(fname.strip(), "w")
|
||||
filewrite.write(text)
|
||||
filewrite.close()
|
||||
91
misc/scripts/file_format.sh
Executable file
91
misc/scripts/file_format.sh
Executable file
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This script ensures proper POSIX text file formatting and a few other things.
|
||||
# This is supplementary to clang_format.sh and black_format.sh, but should be
|
||||
# run before them.
|
||||
|
||||
# We need dos2unix and isutf8.
|
||||
if [ ! -x "$(command -v dos2unix)" -o ! -x "$(command -v isutf8)" ]; then
|
||||
printf "Install 'dos2unix' and 'isutf8' (moreutils package) to use this script.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
if [ $# -eq 0 ]; then
|
||||
# Loop through all code files tracked by Git.
|
||||
mapfile -d '' files < <(git grep -zIl '')
|
||||
else
|
||||
# $1 should be a file listing file paths to process. Used in CI.
|
||||
mapfile -d ' ' < <(cat "$1")
|
||||
fi
|
||||
|
||||
for f in "${files[@]}"; do
|
||||
# Exclude some types of files.
|
||||
if [[ "$f" == *"csproj" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *"sln" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *".bat" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *".out" ]]; then
|
||||
# GDScript integration testing files.
|
||||
continue
|
||||
elif [[ "$f" == *"patch" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *"pot" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *"po" ]]; then
|
||||
continue
|
||||
elif [[ "$f" == "thirdparty/"* ]]; then
|
||||
continue
|
||||
elif [[ "$f" == "misc/patches/"* ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *"/thirdparty/"* ]]; then
|
||||
continue
|
||||
elif [[ "$f" == "platform/android/java/lib/src/com/google"* ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *"-so_wrap."* ]]; then
|
||||
continue
|
||||
elif [[ "$f" == *".test.txt" ]]; then
|
||||
continue
|
||||
fi
|
||||
# Ensure that files are UTF-8 formatted.
|
||||
isutf8 "$f" >> utf8-validation.txt 2>&1
|
||||
# Ensure that files have LF line endings and do not contain a BOM.
|
||||
dos2unix "$f" 2> /dev/null
|
||||
# Remove trailing space characters and ensures that files end
|
||||
# with newline characters. -l option handles newlines conveniently.
|
||||
perl -i -ple 's/\s*$//g' "$f"
|
||||
done
|
||||
|
||||
diff=$(git diff --color)
|
||||
|
||||
if [ ! -s utf8-validation.txt ] && [ -z "$diff" ] ; then
|
||||
# If no UTF-8 violations were collected (the file is empty) and
|
||||
# no diff has been generated all is OK, clean up, and exit.
|
||||
printf "\e[1;32m*** Files in this commit comply with the file formatting rules.\e[0m\n"
|
||||
rm -f utf8-validation.txt
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -s utf8-validation.txt ]
|
||||
then
|
||||
# If the file has content and is not empty, violations
|
||||
# detected, notify the user, clean up, and exit.
|
||||
printf "\n\e[1;33m*** The following files contain invalid UTF-8 character sequences:\e[0m\n\n"
|
||||
cat utf8-validation.txt
|
||||
fi
|
||||
|
||||
rm -f utf8-validation.txt
|
||||
|
||||
if [ ! -z "$diff" ]
|
||||
then
|
||||
# A diff has been created, notify the user, clean up, and exit.
|
||||
printf "\n\e[1;33m*** The following changes must be made to comply with the formatting rules:\e[0m\n\n"
|
||||
# Perl commands replace trailing spaces with `·` and tabs with `<TAB>`.
|
||||
printf "$diff\n" | perl -pe 's/(.*[^ ])( +)(\e\[m)$/my $spaces="·" x length($2); sprintf("$1$spaces$3")/ge' | perl -pe 's/(.*[^\t])(\t+)(\e\[m)$/my $tabs="<TAB>" x length($2); sprintf("$1$tabs$3")/ge'
|
||||
fi
|
||||
|
||||
printf "\n\e[1;91m*** Please fix your commit(s) with 'git commit --amend' or 'git rebase -i <hash>'\e[0m\n"
|
||||
exit 1
|
||||
33
misc/scripts/package_release.sh
Executable file
33
misc/scripts/package_release.sh
Executable file
@@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
ARTIFACTS=${ARTIFACTS:-"artifacts"}
|
||||
DESTINATION=${DESTIONATION:-"release"}
|
||||
VERSION=${VERSION:-"extension"}
|
||||
TYPE=${TYPE:-"webrtc"}
|
||||
|
||||
mkdir -p ${DESTINATION}
|
||||
ls -R ${DESTINATION}
|
||||
ls -R ${ARTIFACTS}
|
||||
|
||||
DESTDIR="${DESTINATION}/${VERSION}/${TYPE}"
|
||||
|
||||
mkdir -p ${DESTDIR}/lib
|
||||
|
||||
find "${ARTIFACTS}" -maxdepth 5 -wholename "*/${VERSION}/${TYPE}/lib/*" | xargs cp -r -t "${DESTDIR}/lib/"
|
||||
find "${ARTIFACTS}" -wholename "*/LICENSE*" | xargs cp -t "${DESTDIR}/"
|
||||
|
||||
if [ $VERSION = "gdnative" ]; then
|
||||
find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/${TYPE}.tres" | head -n 1 | xargs cp -t "${DESTDIR}/"
|
||||
else
|
||||
find "${ARTIFACTS}" -wholename "*/${VERSION}/${TYPE}/${TYPE}.gdextension" | head -n 1 | xargs cp -t "${DESTDIR}/"
|
||||
fi
|
||||
|
||||
CURDIR=$(pwd)
|
||||
cd "${DESTINATION}/${VERSION}"
|
||||
zip -r ../godot-${VERSION}-${TYPE}.zip ${TYPE}
|
||||
cd "$CURDIR"
|
||||
|
||||
ls -R ${DESTINATION}
|
||||
30
misc/webrtc.gdextension
Normal file
30
misc/webrtc.gdextension
Normal file
@@ -0,0 +1,30 @@
|
||||
[configuration]
|
||||
|
||||
entry_symbol = "webrtc_extension_init"
|
||||
compatibility_minimum = 4.1
|
||||
|
||||
[libraries]
|
||||
|
||||
linux.debug.x86_64 = "lib/libwebrtc_native.linux.template_debug.x86_64.so"
|
||||
linux.debug.x86_32 = "lib/libwebrtc_native.linux.template_debug.x86_32.so"
|
||||
linux.debug.arm64 = "lib/libwebrtc_native.linux.template_debug.arm64.so"
|
||||
linux.debug.arm32 = "lib/libwebrtc_native.linux.template_debug.arm32.so"
|
||||
macos.debug = "lib/libwebrtc_native.macos.template_debug.universal.framework"
|
||||
windows.debug.x86_64 = "lib/libwebrtc_native.windows.template_debug.x86_64.dll"
|
||||
windows.debug.x86_32 = "lib/libwebrtc_native.windows.template_debug.x86_32.dll"
|
||||
android.debug.arm64 = "lib/libwebrtc_native.android.template_debug.arm64.so"
|
||||
android.debug.x86_64 = "lib/libwebrtc_native.android.template_debug.x86_64.so"
|
||||
ios.debug.arm64 = "lib/libwebrtc_native.ios.template_debug.arm64.dylib"
|
||||
ios.debug.x86_64 = "lib/libwebrtc_native.ios.template_debug.x86_64.simulator.dylib"
|
||||
|
||||
linux.release.x86_64 = "lib/libwebrtc_native.linux.template_release.x86_64.so"
|
||||
linux.release.x86_32 = "lib/libwebrtc_native.linux.template_release.x86_32.so"
|
||||
linux.release.arm64 = "lib/libwebrtc_native.linux.template_release.arm64.so"
|
||||
linux.release.arm32 = "lib/libwebrtc_native.linux.template_release.arm32.so"
|
||||
macos.release = "lib/libwebrtc_native.macos.template_release.universal.framework"
|
||||
windows.release.x86_64 = "lib/libwebrtc_native.windows.template_release.x86_64.dll"
|
||||
windows.release.x86_32 = "lib/libwebrtc_native.windows.template_release.x86_32.dll"
|
||||
android.release.arm64 = "lib/libwebrtc_native.android.template_release.arm64.so"
|
||||
android.release.x86_64 = "lib/libwebrtc_native.android.template_release.x86_64.so"
|
||||
ios.release.arm64 = "lib/libwebrtc_native.ios.template_release.arm64.dylib"
|
||||
ios.release.x86_64 = "lib/libwebrtc_native.ios.template_release.x86_64.simulator.dylib"
|
||||
21
misc/webrtc.tres
Normal file
21
misc/webrtc.tres
Normal file
@@ -0,0 +1,21 @@
|
||||
[gd_resource type="GDNativeLibrary" format=2]
|
||||
|
||||
[resource]
|
||||
singleton = true
|
||||
reloadable = false
|
||||
entry/OSX.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.macos.{TARGET}.universal.dylib"
|
||||
entry/Windows.64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.windows.{TARGET}.x86_64.dll"
|
||||
entry/Windows.32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.windows.{TARGET}.x86_32.dll"
|
||||
entry/X11.64.x86_64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_64.so"
|
||||
entry/X11.32.x86_32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_32.so"
|
||||
entry/X11.64.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.arm64.so"
|
||||
entry/X11.32.arm32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.arm32.so"
|
||||
entry/Server.64.x86_64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_64.so"
|
||||
entry/Server.32.x86_32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.x86_32.so"
|
||||
entry/Server.64.arm64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.arm64.so"
|
||||
entry/Server.32.arm32 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.linux.{TARGET}.arm32.so"
|
||||
entry/Android.arm64-v8a = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.arm64.so"
|
||||
entry/Android.x64 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.android.{TARGET}.x86_64.so"
|
||||
entry/iOS.armv7 = "res://{GDNATIVE_PATH}/lib/libwebrtc_native.ios.{TARGET}.armv32.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.simulator.dylib"
|
||||
@@ -1,133 +1,184 @@
|
||||
/**************************************************************************/
|
||||
/* WebRTCLibDataChannel.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "WebRTCLibDataChannel.hpp"
|
||||
|
||||
#ifdef GDNATIVE_WEBRTC
|
||||
#include "GDNativeLibrary.hpp"
|
||||
#include "NativeScript.hpp"
|
||||
#define ERR_UNAVAILABLE Error::ERR_UNAVAILABLE
|
||||
#define FAILED Error::FAILED
|
||||
#define ERR_INVALID_PARAMETER Error::ERR_INVALID_PARAMETER
|
||||
#define OK Error::OK
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
using namespace godot;
|
||||
using namespace godot_webrtc;
|
||||
|
||||
// Channel observer
|
||||
WebRTCLibDataChannel::ChannelObserver::ChannelObserver(WebRTCLibDataChannel *parent) {
|
||||
this->parent = parent;
|
||||
}
|
||||
|
||||
void WebRTCLibDataChannel::ChannelObserver::OnMessage(const webrtc::DataBuffer &buffer) {
|
||||
parent->queue_packet(buffer.data.data<uint8_t>(), buffer.data.size());
|
||||
}
|
||||
|
||||
void WebRTCLibDataChannel::ChannelObserver::OnStateChange() {
|
||||
}
|
||||
|
||||
void WebRTCLibDataChannel::ChannelObserver::OnBufferedAmountChange(uint64_t previous_amount) {
|
||||
}
|
||||
|
||||
// DataChannel
|
||||
WebRTCLibDataChannel *WebRTCLibDataChannel::new_data_channel(rtc::scoped_refptr<webrtc::DataChannelInterface> p_channel) {
|
||||
WebRTCLibDataChannel *WebRTCLibDataChannel::new_data_channel(std::shared_ptr<rtc::DataChannel> p_channel, bool p_negotiated) {
|
||||
// Invalid channel result in NULL return
|
||||
ERR_FAIL_COND_V(p_channel.get() == nullptr, NULL);
|
||||
ERR_FAIL_COND_V(!p_channel, nullptr);
|
||||
|
||||
#ifdef GDNATIVE_WEBRTC
|
||||
// Instance a WebRTCDataChannelGDNative object
|
||||
godot::WebRTCDataChannelGDNative *out = godot::WebRTCDataChannelGDNative::_new();
|
||||
// Set our implementation as it's script
|
||||
godot::NativeScript *script = godot::NativeScript::_new();
|
||||
script->set_library(godot::detail::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib));
|
||||
WebRTCDataChannelGDNative *native = WebRTCDataChannelGDNative::_new();
|
||||
// Set our implementation as its script
|
||||
NativeScript *script = NativeScript::_new();
|
||||
script->set_library(detail::get_wrapper<GDNativeLibrary>((godot_object *)gdnlib));
|
||||
script->set_class_name("WebRTCLibDataChannel");
|
||||
out->set_script(script);
|
||||
|
||||
// Bind the data channel to the ScriptInstance userdata (our script)
|
||||
WebRTCLibDataChannel *tmp = out->cast_to<WebRTCLibDataChannel>(out);
|
||||
tmp->bind_channel(p_channel);
|
||||
|
||||
return tmp;
|
||||
native->set_script(script);
|
||||
WebRTCLibDataChannel *out = native->cast_to<WebRTCLibDataChannel>(native);
|
||||
#else
|
||||
WebRTCLibDataChannel *out = memnew(WebRTCLibDataChannel);
|
||||
#endif
|
||||
// Bind the library data channel to our object.
|
||||
out->bind_channel(p_channel, p_negotiated);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
void WebRTCLibDataChannel::bind_channel(rtc::scoped_refptr<webrtc::DataChannelInterface> p_channel) {
|
||||
ERR_FAIL_COND(p_channel.get() == nullptr);
|
||||
void WebRTCLibDataChannel::bind_channel(std::shared_ptr<rtc::DataChannel> p_channel, bool p_negotiated) {
|
||||
ERR_FAIL_COND(!p_channel);
|
||||
|
||||
channel = p_channel;
|
||||
label = p_channel->label();
|
||||
protocol = p_channel->protocol();
|
||||
channel->RegisterObserver(&observer);
|
||||
negotiated = p_negotiated;
|
||||
|
||||
// Binding this should be fine as long as we call close when going out of scope.
|
||||
p_channel->onMessage([this](auto message) {
|
||||
if (std::holds_alternative<rtc::string>(message)) {
|
||||
rtc::string str = std::get<rtc::string>(message);
|
||||
queue_packet(reinterpret_cast<const uint8_t *>(str.c_str()), str.size(), true);
|
||||
} else if (std::holds_alternative<rtc::binary>(message)) {
|
||||
rtc::binary bin = std::get<rtc::binary>(message);
|
||||
queue_packet(reinterpret_cast<const uint8_t *>(&bin[0]), bin.size(), false);
|
||||
} else {
|
||||
ERR_PRINT("Message parsing bug. Unknown message type.");
|
||||
}
|
||||
});
|
||||
p_channel->onOpen([this]() {
|
||||
channel_state = STATE_OPEN;
|
||||
});
|
||||
p_channel->onClosed([this]() {
|
||||
channel_state = STATE_CLOSED;
|
||||
});
|
||||
p_channel->onError([](auto error) {
|
||||
ERR_PRINT("Channel Error: " + String(std::string(error).c_str()));
|
||||
});
|
||||
}
|
||||
|
||||
void WebRTCLibDataChannel::queue_packet(const uint8_t *data, uint32_t size) {
|
||||
void WebRTCLibDataChannel::queue_packet(const uint8_t *data, uint32_t size, bool p_is_string) {
|
||||
mutex->lock();
|
||||
|
||||
godot::PoolByteArray packet;
|
||||
std::vector<uint8_t> packet;
|
||||
packet.resize(size);
|
||||
{
|
||||
godot::PoolByteArray::Write w = packet.write();
|
||||
memcpy(w.ptr(), data, size);
|
||||
}
|
||||
packet_queue.push(packet);
|
||||
memcpy(&packet[0], data, size);
|
||||
packet_queue.push(QueuedPacket(packet, p_is_string));
|
||||
|
||||
mutex->unlock();
|
||||
}
|
||||
|
||||
void WebRTCLibDataChannel::set_write_mode(godot_int mode) {
|
||||
void WebRTCLibDataChannel::_set_write_mode(WriteMode p_mode) {
|
||||
ERR_FAIL_COND(p_mode != WRITE_MODE_TEXT && p_mode != WRITE_MODE_BINARY);
|
||||
write_mode = p_mode;
|
||||
}
|
||||
|
||||
godot_int WebRTCLibDataChannel::get_write_mode() const {
|
||||
return 0;
|
||||
WebRTCDataChannel::WriteMode WebRTCLibDataChannel::_get_write_mode() const {
|
||||
return write_mode;
|
||||
}
|
||||
|
||||
bool WebRTCLibDataChannel::was_string_packet() const {
|
||||
return false;
|
||||
bool WebRTCLibDataChannel::_was_string_packet() const {
|
||||
return current_packet.second;
|
||||
}
|
||||
|
||||
WebRTCLibDataChannel::ChannelState WebRTCLibDataChannel::get_ready_state() const {
|
||||
ERR_FAIL_COND_V(channel.get() == nullptr, STATE_CLOSED);
|
||||
return (ChannelState)channel->state();
|
||||
WebRTCDataChannel::ChannelState WebRTCLibDataChannel::_get_ready_state() const {
|
||||
ERR_FAIL_COND_V(!channel, STATE_CLOSED);
|
||||
return channel_state;
|
||||
}
|
||||
|
||||
const char *WebRTCLibDataChannel::get_label() const {
|
||||
ERR_FAIL_COND_V(channel.get() == nullptr, "");
|
||||
return label.c_str();
|
||||
String WebRTCLibDataChannel::_get_label() const {
|
||||
ERR_FAIL_COND_V(!channel, "");
|
||||
return channel->label().c_str();
|
||||
}
|
||||
|
||||
bool WebRTCLibDataChannel::is_ordered() const {
|
||||
ERR_FAIL_COND_V(channel.get() == nullptr, false);
|
||||
return channel->ordered();
|
||||
bool WebRTCLibDataChannel::_is_ordered() const {
|
||||
ERR_FAIL_COND_V(!channel, false);
|
||||
return channel->reliability().unordered == false;
|
||||
}
|
||||
|
||||
int WebRTCLibDataChannel::get_id() const {
|
||||
ERR_FAIL_COND_V(channel.get() == nullptr, -1);
|
||||
return channel->id();
|
||||
int32_t WebRTCLibDataChannel::_get_id() const {
|
||||
ERR_FAIL_COND_V(!channel, -1);
|
||||
return channel->id().value_or(-1);
|
||||
}
|
||||
|
||||
int WebRTCLibDataChannel::get_max_packet_life_time() const {
|
||||
ERR_FAIL_COND_V(channel.get() == nullptr, 0);
|
||||
return channel->maxRetransmitTime();
|
||||
int32_t WebRTCLibDataChannel::_get_max_packet_life_time() const {
|
||||
ERR_FAIL_COND_V(!channel, 0);
|
||||
return channel->reliability().maxPacketLifeTime.has_value() ? channel->reliability().maxPacketLifeTime.value().count() : -1;
|
||||
}
|
||||
|
||||
int WebRTCLibDataChannel::get_max_retransmits() const {
|
||||
ERR_FAIL_COND_V(channel.get() == nullptr, 0);
|
||||
return channel->maxRetransmits();
|
||||
int32_t WebRTCLibDataChannel::_get_max_retransmits() const {
|
||||
ERR_FAIL_COND_V(!channel, 0);
|
||||
return channel->reliability().maxRetransmits.value_or(-1);
|
||||
}
|
||||
|
||||
const char *WebRTCLibDataChannel::get_protocol() const {
|
||||
ERR_FAIL_COND_V(channel.get() == nullptr, "");
|
||||
return protocol.c_str();
|
||||
String WebRTCLibDataChannel::_get_protocol() const {
|
||||
ERR_FAIL_COND_V(!channel, "");
|
||||
return channel->protocol().c_str();
|
||||
}
|
||||
|
||||
bool WebRTCLibDataChannel::is_negotiated() const {
|
||||
ERR_FAIL_COND_V(channel.get() == nullptr, false);
|
||||
return channel->negotiated();
|
||||
bool WebRTCLibDataChannel::_is_negotiated() const {
|
||||
ERR_FAIL_COND_V(!channel, false);
|
||||
return negotiated;
|
||||
}
|
||||
|
||||
godot_error WebRTCLibDataChannel::poll() {
|
||||
return GODOT_OK;
|
||||
int32_t WebRTCLibDataChannel::_get_buffered_amount() const {
|
||||
ERR_FAIL_COND_V(!channel, 0);
|
||||
return channel->bufferedAmount();
|
||||
}
|
||||
|
||||
void WebRTCLibDataChannel::close() {
|
||||
if(channel.get() != nullptr) {
|
||||
channel->Close();
|
||||
channel->UnregisterObserver();
|
||||
Error WebRTCLibDataChannel::_poll() {
|
||||
return OK;
|
||||
}
|
||||
|
||||
void WebRTCLibDataChannel::_close() try {
|
||||
if (channel) {
|
||||
channel->close();
|
||||
}
|
||||
} catch (...) {
|
||||
}
|
||||
|
||||
godot_error WebRTCLibDataChannel::get_packet(const uint8_t **r_buffer, int *r_len) {
|
||||
ERR_FAIL_COND_V(packet_queue.empty(), GODOT_ERR_UNAVAILABLE);
|
||||
Error WebRTCLibDataChannel::_get_packet(const uint8_t **r_buffer, int32_t *r_len) {
|
||||
ERR_FAIL_COND_V(packet_queue.empty(), ERR_UNAVAILABLE);
|
||||
|
||||
mutex->lock();
|
||||
|
||||
@@ -135,46 +186,46 @@ godot_error WebRTCLibDataChannel::get_packet(const uint8_t **r_buffer, int *r_le
|
||||
current_packet = packet_queue.front();
|
||||
packet_queue.pop();
|
||||
// Set out buffer and size (buffer will be gone at next get_packet or close)
|
||||
*r_buffer = current_packet.read().ptr();
|
||||
*r_len = current_packet.size();
|
||||
*r_buffer = ¤t_packet.first[0];
|
||||
*r_len = current_packet.first.size();
|
||||
|
||||
mutex->unlock();
|
||||
|
||||
return GODOT_OK;
|
||||
return OK;
|
||||
}
|
||||
|
||||
godot_error WebRTCLibDataChannel::put_packet(const uint8_t *p_buffer, int p_len) {
|
||||
ERR_FAIL_COND_V(channel.get() == nullptr, GODOT_ERR_UNAVAILABLE);
|
||||
|
||||
webrtc::DataBuffer webrtc_buffer(rtc::CopyOnWriteBuffer(p_buffer, p_len), true);
|
||||
ERR_FAIL_COND_V(!channel->Send(webrtc_buffer), GODOT_FAILED);
|
||||
|
||||
return GODOT_OK;
|
||||
Error WebRTCLibDataChannel::_put_packet(const uint8_t *p_buffer, int32_t p_len) try {
|
||||
ERR_FAIL_COND_V(!channel, FAILED);
|
||||
ERR_FAIL_COND_V(channel->isClosed(), FAILED);
|
||||
if (write_mode == WRITE_MODE_TEXT) {
|
||||
std::string str(p_len, '\x00');
|
||||
std::strncpy(str.data(), (const char *)p_buffer, p_len);
|
||||
channel->send(str);
|
||||
} else if (write_mode == WRITE_MODE_BINARY) {
|
||||
channel->send(reinterpret_cast<const std::byte *>(p_buffer), p_len);
|
||||
} else {
|
||||
ERR_FAIL_V(ERR_INVALID_PARAMETER);
|
||||
}
|
||||
return OK;
|
||||
} catch (const std::exception &e) {
|
||||
ERR_PRINT(e.what());
|
||||
ERR_FAIL_V(FAILED);
|
||||
}
|
||||
|
||||
godot_int WebRTCLibDataChannel::get_available_packet_count() const {
|
||||
int32_t WebRTCLibDataChannel::_get_available_packet_count() const {
|
||||
return packet_queue.size();
|
||||
}
|
||||
|
||||
godot_int WebRTCLibDataChannel::get_max_packet_size() const {
|
||||
return 1200;
|
||||
int32_t WebRTCLibDataChannel::_get_max_packet_size() const {
|
||||
return 16384; // See RFC-8831 section 6.6: https://datatracker.ietf.org/doc/rfc8831/
|
||||
}
|
||||
|
||||
void WebRTCLibDataChannel::_register_methods() {
|
||||
}
|
||||
|
||||
void WebRTCLibDataChannel::_init() {
|
||||
register_interface(&interface);
|
||||
}
|
||||
|
||||
WebRTCLibDataChannel::WebRTCLibDataChannel() : observer(this) {
|
||||
WebRTCLibDataChannel::WebRTCLibDataChannel() {
|
||||
mutex = new std::mutex;
|
||||
}
|
||||
|
||||
WebRTCLibDataChannel::~WebRTCLibDataChannel() {
|
||||
close();
|
||||
if (_owner) {
|
||||
register_interface(NULL);
|
||||
}
|
||||
_close();
|
||||
channel = nullptr;
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
@@ -1,71 +1,109 @@
|
||||
/**************************************************************************/
|
||||
/* WebRTCLibDataChannel.hpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef WEBRTC_DATA_CHANNEL_H
|
||||
#define WEBRTC_DATA_CHANNEL_H
|
||||
|
||||
#ifdef GDNATIVE_WEBRTC
|
||||
#include <Godot.hpp> // Godot.hpp must go first, or windows builds breaks
|
||||
|
||||
#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"
|
||||
#define WebRTCDataChannelExtension WebRTCDataChannelNative
|
||||
#if !defined(GDCLASS)
|
||||
#define GDCLASS(arg1, arg2) GODOT_CLASS(arg1, arg2)
|
||||
#endif
|
||||
#else
|
||||
#include <godot_cpp/core/binder_common.hpp>
|
||||
|
||||
#include <godot_cpp/classes/global_constants_binds.hpp>
|
||||
#include <godot_cpp/classes/web_rtc_data_channel_extension.hpp>
|
||||
#endif
|
||||
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <utility>
|
||||
|
||||
#include "rtc/rtc.hpp"
|
||||
|
||||
namespace godot_webrtc {
|
||||
|
||||
class WebRTCLibDataChannel : public WebRTCDataChannelNative {
|
||||
GODOT_CLASS(WebRTCLibDataChannel, WebRTCDataChannelNative);
|
||||
class WebRTCLibDataChannel : public godot::WebRTCDataChannelExtension {
|
||||
GDCLASS(WebRTCLibDataChannel, WebRTCDataChannelExtension);
|
||||
|
||||
private:
|
||||
class ChannelObserver : public webrtc::DataChannelObserver {
|
||||
public:
|
||||
WebRTCLibDataChannel *parent;
|
||||
|
||||
ChannelObserver(WebRTCLibDataChannel *parent);
|
||||
void OnMessage(const webrtc::DataBuffer &buffer) override;
|
||||
void OnStateChange() override; // UNUSED
|
||||
void OnBufferedAmountChange(uint64_t previous_amount) override; // UNUSED
|
||||
};
|
||||
|
||||
ChannelObserver observer;
|
||||
rtc::scoped_refptr<webrtc::DataChannelInterface> channel;
|
||||
|
||||
using QueuedPacket = std::pair<std::vector<uint8_t>, bool>;
|
||||
std::mutex *mutex;
|
||||
std::queue<godot::PoolByteArray> packet_queue;
|
||||
godot::PoolByteArray current_packet;
|
||||
std::string label;
|
||||
std::string protocol;
|
||||
std::queue<QueuedPacket> packet_queue;
|
||||
QueuedPacket current_packet;
|
||||
std::shared_ptr<rtc::DataChannel> channel = nullptr;
|
||||
|
||||
WriteMode write_mode = WRITE_MODE_BINARY;
|
||||
ChannelState channel_state = STATE_CONNECTING;
|
||||
bool negotiated = false;
|
||||
|
||||
void queue_packet(const uint8_t *data, uint32_t size, bool p_is_string);
|
||||
void bind_channel(std::shared_ptr<rtc::DataChannel> p_channel, bool p_negotiated);
|
||||
|
||||
protected:
|
||||
static void _bind_methods() {}
|
||||
|
||||
godot::String _to_string() const {
|
||||
return "WebRTCLibDataChannel";
|
||||
}
|
||||
|
||||
public:
|
||||
static WebRTCLibDataChannel *new_data_channel(rtc::scoped_refptr<webrtc::DataChannelInterface> p_channel);
|
||||
static void _register_methods();
|
||||
|
||||
void _init();
|
||||
|
||||
void bind_channel(rtc::scoped_refptr<webrtc::DataChannelInterface> p_channel);
|
||||
void queue_packet(const uint8_t *data, uint32_t size);
|
||||
|
||||
/* WebRTCDataChannel */
|
||||
void set_write_mode(godot_int mode);
|
||||
godot_int get_write_mode() const;
|
||||
bool was_string_packet() const;
|
||||
|
||||
ChannelState get_ready_state() const;
|
||||
const char *get_label() const;
|
||||
bool is_ordered() const;
|
||||
int get_id() const;
|
||||
int get_max_packet_life_time() const;
|
||||
int get_max_retransmits() const;
|
||||
const char *get_protocol() const;
|
||||
bool is_negotiated() const;
|
||||
|
||||
godot_error poll();
|
||||
void close();
|
||||
static WebRTCLibDataChannel *new_data_channel(std::shared_ptr<rtc::DataChannel> p_channel, bool p_negotiated);
|
||||
|
||||
/* PacketPeer */
|
||||
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;
|
||||
virtual godot::Error _get_packet(const uint8_t **r_buffer, int32_t *r_len) override;
|
||||
virtual godot::Error _put_packet(const uint8_t *p_buffer, int32_t p_len) override;
|
||||
virtual int32_t _get_available_packet_count() const override;
|
||||
virtual int32_t _get_max_packet_size() const override;
|
||||
|
||||
/* WebRTCDataChannel */
|
||||
godot::Error _poll() override;
|
||||
void _close() override;
|
||||
|
||||
void _set_write_mode(WriteMode p_mode) override;
|
||||
WriteMode _get_write_mode() const override;
|
||||
bool _was_string_packet() const override;
|
||||
|
||||
ChannelState _get_ready_state() const override;
|
||||
godot::String _get_label() const override;
|
||||
bool _is_ordered() const override;
|
||||
int32_t _get_id() const override;
|
||||
int32_t _get_max_packet_life_time() const override;
|
||||
int32_t _get_max_retransmits() const override;
|
||||
godot::String _get_protocol() const override;
|
||||
bool _is_negotiated() const override;
|
||||
int32_t _get_buffered_amount() const override;
|
||||
|
||||
WebRTCLibDataChannel();
|
||||
~WebRTCLibDataChannel();
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
#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(webrtc::RTCError error){};
|
||||
|
||||
// SetSessionObseerver
|
||||
WebRTCLibPeerConnection::GodotSSDO::GodotSSDO(WebRTCLibPeerConnection *parent) {
|
||||
this->parent = parent;
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::GodotSSDO::OnSuccess(){};
|
||||
void WebRTCLibPeerConnection::GodotSSDO::OnFailure(webrtc::RTCError 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) {}
|
||||
@@ -1,258 +1,363 @@
|
||||
#include "WebRTCDataChannel.hpp"
|
||||
#include "WebRTCDataChannelGDNative.hpp"
|
||||
/**************************************************************************/
|
||||
/* WebRTCLibPeerConnection.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "WebRTCLibPeerConnection.hpp"
|
||||
#include "WebRTCLibDataChannel.hpp"
|
||||
|
||||
using namespace godot;
|
||||
using namespace godot_webrtc;
|
||||
|
||||
std::unique_ptr<rtc::Thread> WebRTCLibPeerConnection::signaling_thread = nullptr;
|
||||
#ifdef GDNATIVE_WEBRTC
|
||||
#define OK Error::OK
|
||||
#define FAILED Error::FAILED
|
||||
#define ERR_UNCONFIGURED Error::ERR_UNCONFIGURED
|
||||
#define ERR_INVALID_PARAMETER Error::ERR_INVALID_PARAMETER
|
||||
#define VERBOSE_PRINT(str) Godot::print(str)
|
||||
#else
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
#define VERBOSE_PRINT(str) UtilityFunctions::print_verbose(str)
|
||||
#endif
|
||||
void LogCallback(rtc::LogLevel level, std::string message) {
|
||||
switch (level) {
|
||||
case rtc::LogLevel::Fatal:
|
||||
case rtc::LogLevel::Error:
|
||||
ERR_PRINT(message.c_str());
|
||||
return;
|
||||
case rtc::LogLevel::Warning:
|
||||
WARN_PRINT(message.c_str());
|
||||
return;
|
||||
default:
|
||||
VERBOSE_PRINT(message.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::initialize_signaling() {
|
||||
if (signaling_thread.get() == nullptr) {
|
||||
signaling_thread = rtc::Thread::Create();
|
||||
}
|
||||
signaling_thread->Start();
|
||||
#ifdef DEBUG_ENABLED
|
||||
rtc::InitLogger(rtc::LogLevel::Debug, LogCallback);
|
||||
#else
|
||||
rtc::InitLogger(rtc::LogLevel::Warning, LogCallback);
|
||||
#endif
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::deinitialize_signaling() {
|
||||
if (signaling_thread.get() != nullptr) {
|
||||
signaling_thread->Stop();
|
||||
}
|
||||
rtc::Cleanup();
|
||||
}
|
||||
|
||||
godot_error _parse_ice_server(webrtc::PeerConnectionInterface::RTCConfiguration &r_config, godot::Dictionary p_server) {
|
||||
godot::Variant v;
|
||||
webrtc::PeerConnectionInterface::IceServer ice_server;
|
||||
godot::String url;
|
||||
|
||||
ERR_FAIL_COND_V(!p_server.has("urls"), GODOT_ERR_INVALID_PARAMETER);
|
||||
Error WebRTCLibPeerConnection::_parse_ice_server(rtc::Configuration &r_config, Dictionary p_server) {
|
||||
ERR_FAIL_COND_V(!p_server.has("urls"), ERR_INVALID_PARAMETER);
|
||||
|
||||
// Parse mandatory URL
|
||||
v = p_server["urls"];
|
||||
if (v.get_type() == godot::Variant::STRING) {
|
||||
url = v;
|
||||
ice_server.urls.push_back(url.utf8().get_data());
|
||||
} else if (v.get_type() == godot::Variant::ARRAY) {
|
||||
godot::Array names = v;
|
||||
for (int j = 0; j < names.size(); j++) {
|
||||
v = names[j];
|
||||
ERR_FAIL_COND_V(v.get_type() != godot::Variant::STRING, GODOT_ERR_INVALID_PARAMETER);
|
||||
url = v;
|
||||
ice_server.urls.push_back(url.utf8().get_data());
|
||||
}
|
||||
Array urls;
|
||||
Variant urls_var = p_server["urls"];
|
||||
if (urls_var.get_type() == Variant::STRING) {
|
||||
urls.push_back(urls_var);
|
||||
} else if (urls_var.get_type() == Variant::ARRAY) {
|
||||
urls = urls_var;
|
||||
} else {
|
||||
ERR_FAIL_V(GODOT_ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_V(ERR_INVALID_PARAMETER);
|
||||
}
|
||||
// Parse credentials (only meaningful for TURN, only support password)
|
||||
if (p_server.has("username") && (v = p_server["username"]) && v.get_type() == godot::Variant::STRING) {
|
||||
ice_server.username = (v.operator godot::String()).utf8().get_data();
|
||||
String username;
|
||||
String credential;
|
||||
if (p_server.has("username") && p_server["username"].get_type() == Variant::STRING) {
|
||||
username = p_server["username"];
|
||||
}
|
||||
if (p_server.has("credential") && (v = p_server["credential"]) && v.get_type() == godot::Variant::STRING) {
|
||||
ice_server.password = (v.operator godot::String()).utf8().get_data();
|
||||
if (p_server.has("credential") && p_server["credential"].get_type() == Variant::STRING) {
|
||||
credential = p_server["credential"];
|
||||
}
|
||||
|
||||
r_config.servers.push_back(ice_server);
|
||||
return GODOT_OK;
|
||||
for (int i = 0; i < urls.size(); i++) {
|
||||
rtc::IceServer srv(urls[i].operator String().utf8().get_data());
|
||||
srv.username = username.utf8().get_data();
|
||||
srv.password = credential.utf8().get_data();
|
||||
r_config.iceServers.push_back(srv);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
godot_error _parse_channel_config(webrtc::DataChannelInit &r_config, godot::Dictionary p_dict) {
|
||||
godot::Variant v;
|
||||
#define _SET_N(PROP, PNAME, TYPE) if (p_dict.has(#PROP)) { v = p_dict[#PROP]; if(v.get_type() == godot::Variant::TYPE) r_config.PNAME = v; }
|
||||
#define _SET(PROP, TYPE) _SET_N(PROP, PROP, TYPE)
|
||||
_SET(negotiated, BOOL);
|
||||
_SET(id, INT);
|
||||
_SET_N(maxPacketLifeTime, maxRetransmitTime, INT);
|
||||
_SET(maxRetransmits, INT);
|
||||
_SET(ordered, BOOL);
|
||||
#undef _SET
|
||||
if (p_dict.has("protocol") && (v = p_dict["protocol"]) && v.get_type() == godot::Variant::STRING) {
|
||||
r_config.protocol = v.operator godot::String().utf8().get_data();
|
||||
Error WebRTCLibPeerConnection::_parse_channel_config(rtc::DataChannelInit &r_config, const Dictionary &p_dict) {
|
||||
Variant nil;
|
||||
Variant v;
|
||||
if (p_dict.has("negotiated")) {
|
||||
r_config.negotiated = p_dict["negotiated"].operator bool();
|
||||
}
|
||||
|
||||
// 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 && r_config.maxRetransmitTime, GODOT_ERR_INVALID_PARAMETER);
|
||||
return GODOT_OK;
|
||||
if (p_dict.has("id")) {
|
||||
r_config.id = uint16_t(p_dict["id"].operator int32_t());
|
||||
}
|
||||
// If negotiated it must have an ID, and ID only makes sense when negotiated.
|
||||
ERR_FAIL_COND_V(r_config.negotiated != r_config.id.has_value(), ERR_INVALID_PARAMETER);
|
||||
// Channels cannot be both time-constrained and retry-constrained.
|
||||
ERR_FAIL_COND_V(p_dict.has("maxPacketLifeTime") && p_dict.has("maxRetransmits"), ERR_INVALID_PARAMETER);
|
||||
if (p_dict.has("maxPacketLifeTime")) {
|
||||
r_config.reliability.maxPacketLifeTime = std::chrono::milliseconds(p_dict["maxPacketLifeTime"].operator int32_t());
|
||||
} else if (p_dict.has("maxRetransmits")) {
|
||||
r_config.reliability.maxRetransmits = p_dict["maxRetransmits"].operator int32_t();
|
||||
}
|
||||
if (p_dict.has("ordered") && p_dict["ordered"].operator bool() == false) {
|
||||
r_config.reliability.unordered = true;
|
||||
}
|
||||
if (p_dict.has("protocol")) {
|
||||
r_config.protocol = p_dict["protocol"].operator String().utf8().get_data();
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
WebRTCLibPeerConnection::ConnectionState WebRTCLibPeerConnection::get_connection_state() const {
|
||||
ERR_FAIL_COND_V(peer_connection.get() == nullptr, STATE_CLOSED);
|
||||
WebRTCPeerConnection::ConnectionState WebRTCLibPeerConnection::_get_connection_state() const {
|
||||
ERR_FAIL_COND_V(peer_connection == nullptr, STATE_CLOSED);
|
||||
|
||||
webrtc::PeerConnectionInterface::IceConnectionState state = peer_connection->ice_connection_state();
|
||||
switch(state) {
|
||||
case webrtc::PeerConnectionInterface::kIceConnectionNew:
|
||||
rtc::PeerConnection::State state = peer_connection->state();
|
||||
switch (state) {
|
||||
case rtc::PeerConnection::State::New:
|
||||
return STATE_NEW;
|
||||
case webrtc::PeerConnectionInterface::kIceConnectionChecking:
|
||||
case rtc::PeerConnection::State::Connecting:
|
||||
return STATE_CONNECTING;
|
||||
case webrtc::PeerConnectionInterface::kIceConnectionConnected:
|
||||
case rtc::PeerConnection::State::Connected:
|
||||
return STATE_CONNECTED;
|
||||
case webrtc::PeerConnectionInterface::kIceConnectionCompleted:
|
||||
return STATE_CONNECTED;
|
||||
case webrtc::PeerConnectionInterface::kIceConnectionFailed:
|
||||
return STATE_FAILED;
|
||||
case webrtc::PeerConnectionInterface::kIceConnectionDisconnected:
|
||||
case rtc::PeerConnection::State::Disconnected:
|
||||
return STATE_DISCONNECTED;
|
||||
case webrtc::PeerConnectionInterface::kIceConnectionClosed:
|
||||
return STATE_CLOSED;
|
||||
case rtc::PeerConnection::State::Failed:
|
||||
return STATE_FAILED;
|
||||
default:
|
||||
return STATE_CLOSED;
|
||||
}
|
||||
}
|
||||
|
||||
godot_error WebRTCLibPeerConnection::initialize(const godot_dictionary *p_config) {
|
||||
webrtc::PeerConnectionInterface::RTCConfiguration config;
|
||||
godot::Dictionary d = *(godot::Dictionary *)p_config;
|
||||
godot::Variant v;
|
||||
if (d.has("iceServers") && (v = d["iceServers"]) && v.get_type() == godot::Variant::ARRAY) {
|
||||
godot::Array servers = v;
|
||||
WebRTCLibPeerConnection::GatheringState WebRTCLibPeerConnection::_get_gathering_state() const {
|
||||
ERR_FAIL_COND_V(peer_connection == nullptr, GATHERING_STATE_NEW);
|
||||
|
||||
rtc::PeerConnection::GatheringState state = peer_connection->gatheringState();
|
||||
switch (state) {
|
||||
case rtc::PeerConnection::GatheringState::New:
|
||||
return GATHERING_STATE_NEW;
|
||||
case rtc::PeerConnection::GatheringState::InProgress:
|
||||
return GATHERING_STATE_GATHERING;
|
||||
case rtc::PeerConnection::GatheringState::Complete:
|
||||
return GATHERING_STATE_COMPLETE;
|
||||
default:
|
||||
return GATHERING_STATE_NEW;
|
||||
}
|
||||
}
|
||||
|
||||
WebRTCLibPeerConnection::SignalingState WebRTCLibPeerConnection::_get_signaling_state() const {
|
||||
ERR_FAIL_COND_V(peer_connection == nullptr, SIGNALING_STATE_CLOSED);
|
||||
|
||||
rtc::PeerConnection::SignalingState state = peer_connection->signalingState();
|
||||
switch (state) {
|
||||
case rtc::PeerConnection::SignalingState::Stable:
|
||||
return SIGNALING_STATE_STABLE;
|
||||
case rtc::PeerConnection::SignalingState::HaveLocalOffer:
|
||||
return SIGNALING_STATE_HAVE_LOCAL_OFFER;
|
||||
case rtc::PeerConnection::SignalingState::HaveRemoteOffer:
|
||||
return SIGNALING_STATE_HAVE_REMOTE_OFFER;
|
||||
case rtc::PeerConnection::SignalingState::HaveLocalPranswer:
|
||||
return SIGNALING_STATE_HAVE_LOCAL_PRANSWER;
|
||||
case rtc::PeerConnection::SignalingState::HaveRemotePranswer:
|
||||
return SIGNALING_STATE_HAVE_REMOTE_PRANSWER;
|
||||
default:
|
||||
return SIGNALING_STATE_CLOSED;
|
||||
}
|
||||
}
|
||||
|
||||
Error WebRTCLibPeerConnection::_initialize(const Dictionary &p_config) {
|
||||
rtc::Configuration config = {};
|
||||
if (p_config.has("iceServers") && p_config["iceServers"].get_type() == Variant::ARRAY) {
|
||||
Array servers = p_config["iceServers"];
|
||||
for (int i = 0; i < servers.size(); i++) {
|
||||
v = servers[i];
|
||||
ERR_FAIL_COND_V(v.get_type() != godot::Variant::DICTIONARY, GODOT_ERR_INVALID_PARAMETER);
|
||||
godot_error err;
|
||||
godot::Dictionary server = v;
|
||||
err = _parse_ice_server(config, server);
|
||||
ERR_FAIL_COND_V(err != GODOT_OK, err);
|
||||
ERR_FAIL_COND_V(servers[i].get_type() != Variant::DICTIONARY, ERR_INVALID_PARAMETER);
|
||||
Dictionary server = servers[i];
|
||||
Error err = _parse_ice_server(config, server);
|
||||
ERR_FAIL_COND_V(err != OK, FAILED);
|
||||
}
|
||||
}
|
||||
return _create_pc(config);
|
||||
}
|
||||
|
||||
godot_object *WebRTCLibPeerConnection::create_data_channel(const char *p_channel, const godot_dictionary *p_channel_config) {
|
||||
ERR_FAIL_COND_V(peer_connection.get() == nullptr, NULL);
|
||||
#if defined(GDNATIVE_WEBRTC)
|
||||
Object *WebRTCLibPeerConnection::_create_data_channel(const String &p_channel, const Dictionary &p_channel_config) try {
|
||||
#else
|
||||
Ref<WebRTCDataChannel> WebRTCLibPeerConnection::_create_data_channel(const String &p_channel, const Dictionary &p_channel_config) try {
|
||||
#endif
|
||||
ERR_FAIL_COND_V(!peer_connection, nullptr);
|
||||
|
||||
// Read config from dictionary
|
||||
webrtc::DataChannelInit config;
|
||||
godot::Dictionary d = *(godot::Dictionary *)p_channel_config;
|
||||
godot_error err = _parse_channel_config(config, d);
|
||||
ERR_FAIL_COND_V(err != GODOT_OK, NULL);
|
||||
rtc::DataChannelInit config;
|
||||
|
||||
WebRTCLibDataChannel *wrapper = WebRTCLibDataChannel::new_data_channel(peer_connection->CreateDataChannel(p_channel, &config));
|
||||
ERR_FAIL_COND_V(wrapper == NULL, NULL);
|
||||
return wrapper->_owner;
|
||||
Error err = _parse_channel_config(config, p_channel_config);
|
||||
ERR_FAIL_COND_V(err != OK, nullptr);
|
||||
|
||||
std::shared_ptr<rtc::DataChannel> ch = peer_connection->createDataChannel(p_channel.utf8().get_data(), config);
|
||||
ERR_FAIL_COND_V(ch == nullptr, nullptr);
|
||||
|
||||
WebRTCLibDataChannel *wrapper = WebRTCLibDataChannel::new_data_channel(ch, ch->id().has_value());
|
||||
ERR_FAIL_COND_V(wrapper == nullptr, nullptr);
|
||||
return wrapper;
|
||||
} catch (const std::exception &e) {
|
||||
ERR_PRINT(e.what());
|
||||
ERR_FAIL_V(nullptr);
|
||||
}
|
||||
|
||||
godot_error WebRTCLibPeerConnection::create_offer() {
|
||||
ERR_FAIL_COND_V(peer_connection.get() == nullptr, GODOT_ERR_UNCONFIGURED);
|
||||
peer_connection->CreateOffer(ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
||||
return GODOT_OK;
|
||||
Error WebRTCLibPeerConnection::_create_offer() try {
|
||||
ERR_FAIL_COND_V(!peer_connection, ERR_UNCONFIGURED);
|
||||
ERR_FAIL_COND_V(_get_connection_state() != STATE_NEW, FAILED);
|
||||
peer_connection->setLocalDescription(rtc::Description::Type::Offer);
|
||||
return OK;
|
||||
} catch (const std::exception &e) {
|
||||
ERR_PRINT(e.what());
|
||||
ERR_FAIL_V(FAILED);
|
||||
}
|
||||
|
||||
#define _MAKE_DESC(TYPE, SDP) webrtc::CreateSessionDescription((godot::String(TYPE) == godot::String("offer") ? webrtc::SdpType::kOffer : webrtc::SdpType::kAnswer), SDP)
|
||||
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);
|
||||
peer_connection->SetRemoteDescription(ptr_ssdo, desc.release());
|
||||
peer_connection->CreateAnswer(ptr_csdo, webrtc::PeerConnectionInterface::RTCOfferAnswerOptions());
|
||||
return GODOT_OK;
|
||||
Error WebRTCLibPeerConnection::_set_remote_description(const String &p_type, const String &p_sdp) try {
|
||||
ERR_FAIL_COND_V(!peer_connection, ERR_UNCONFIGURED);
|
||||
std::string sdp(p_sdp.utf8().get_data());
|
||||
std::string type(p_type.utf8().get_data());
|
||||
rtc::Description desc(sdp, type);
|
||||
peer_connection->setRemoteDescription(desc);
|
||||
// Automatically create the answer.
|
||||
if (p_type == String("offer")) {
|
||||
peer_connection->setLocalDescription(rtc::Description::Type::Answer);
|
||||
}
|
||||
return OK;
|
||||
} catch (const std::exception &e) {
|
||||
ERR_PRINT(e.what());
|
||||
ERR_FAIL_V(FAILED);
|
||||
}
|
||||
|
||||
godot_error WebRTCLibPeerConnection::set_local_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);
|
||||
peer_connection->SetLocalDescription(ptr_ssdo, desc.release());
|
||||
return GODOT_OK;
|
||||
}
|
||||
#undef _MAKE_DESC
|
||||
|
||||
godot_error WebRTCLibPeerConnection::add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) {
|
||||
ERR_FAIL_COND_V(peer_connection.get() == nullptr, GODOT_ERR_UNCONFIGURED);
|
||||
|
||||
webrtc::SdpParseError *error = nullptr;
|
||||
webrtc::IceCandidateInterface *candidate = webrtc::CreateIceCandidate(
|
||||
sdpMidName,
|
||||
sdpMlineIndexName,
|
||||
sdpName,
|
||||
error);
|
||||
|
||||
ERR_FAIL_COND_V(error || !candidate, GODOT_ERR_INVALID_PARAMETER);
|
||||
ERR_FAIL_COND_V(!peer_connection->AddIceCandidate(candidate), GODOT_FAILED);
|
||||
|
||||
return GODOT_OK;
|
||||
Error WebRTCLibPeerConnection::_set_local_description(const String &p_type, const String &p_sdp) {
|
||||
ERR_FAIL_COND_V(!peer_connection, ERR_UNCONFIGURED);
|
||||
// XXX Library quirk. It doesn't seem possible to create offers/answers without setting the local description.
|
||||
// Ignore this call for now to avoid crash (it's already set automatically!).
|
||||
// peer_connection->setLocalDescription(p_type == String("offer") ? rtc::Description::Type::Offer : rtc::Description::Type::Answer);
|
||||
return OK;
|
||||
}
|
||||
|
||||
godot_error WebRTCLibPeerConnection::poll() {
|
||||
ERR_FAIL_COND_V(peer_connection.get() == nullptr, GODOT_ERR_UNCONFIGURED);
|
||||
#ifdef GDNATIVE_WEBRTC
|
||||
Error WebRTCLibPeerConnection::_add_ice_candidate(const String &sdpMidName, int64_t sdpMlineIndexName, const String &sdpName) try {
|
||||
#else
|
||||
Error WebRTCLibPeerConnection::_add_ice_candidate(const String &sdpMidName, int32_t sdpMlineIndexName, const String &sdpName) try {
|
||||
#endif
|
||||
ERR_FAIL_COND_V(!peer_connection, ERR_UNCONFIGURED);
|
||||
rtc::Candidate candidate(sdpName.utf8().get_data(), sdpMidName.utf8().get_data());
|
||||
peer_connection->addRemoteCandidate(candidate);
|
||||
return OK;
|
||||
} catch (const std::exception &e) {
|
||||
ERR_PRINT(e.what());
|
||||
ERR_FAIL_V(FAILED);
|
||||
}
|
||||
|
||||
Error WebRTCLibPeerConnection::_poll() {
|
||||
ERR_FAIL_COND_V(!peer_connection, 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;
|
||||
return OK;
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::close() {
|
||||
if (peer_connection.get() != nullptr) {
|
||||
peer_connection->Close();
|
||||
void WebRTCLibPeerConnection::_close() {
|
||||
if (peer_connection != nullptr) {
|
||||
try {
|
||||
peer_connection->close();
|
||||
} catch (...) {
|
||||
}
|
||||
}
|
||||
peer_connection = nullptr;
|
||||
while(!signal_queue.empty()) {
|
||||
|
||||
while (!signal_queue.empty()) {
|
||||
signal_queue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::_register_methods() {
|
||||
}
|
||||
|
||||
void WebRTCLibPeerConnection::_init() {
|
||||
#ifdef GDNATIVE_WEBRTC
|
||||
register_interface(&interface);
|
||||
|
||||
// initialize variables:
|
||||
#endif
|
||||
mutex_signal_queue = new std::mutex;
|
||||
|
||||
// create a PeerConnectionFactoryInterface:
|
||||
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;
|
||||
_create_pc(config);
|
||||
_initialize(Dictionary());
|
||||
}
|
||||
|
||||
godot_error WebRTCLibPeerConnection::_create_pc(webrtc::PeerConnectionInterface::RTCConfiguration &config) {
|
||||
ERR_FAIL_COND_V(pc_factory.get() == nullptr, GODOT_ERR_BUG);
|
||||
peer_connection = nullptr;
|
||||
peer_connection = pc_factory->CreatePeerConnection(config, nullptr, nullptr, &pco);
|
||||
if (peer_connection.get() == nullptr) { // PeerConnection couldn't be created. Fail the method call.
|
||||
ERR_PRINT("PeerConnection could not be created");
|
||||
return GODOT_FAILED;
|
||||
}
|
||||
return GODOT_OK;
|
||||
Error WebRTCLibPeerConnection::_create_pc(rtc::Configuration &r_config) try {
|
||||
// Prevents libdatachannel from automatically creating offers.
|
||||
r_config.disableAutoNegotiation = true;
|
||||
|
||||
peer_connection = std::make_shared<rtc::PeerConnection>(r_config);
|
||||
ERR_FAIL_COND_V(!peer_connection, FAILED);
|
||||
|
||||
// Binding this should be fine as long as we call close when going out of scope.
|
||||
peer_connection->onLocalDescription([this](rtc::Description description) {
|
||||
String type = description.type() == rtc::Description::Type::Offer ? "offer" : "answer";
|
||||
queue_signal("session_description_created", 2, type, String(std::string(description).c_str()));
|
||||
});
|
||||
peer_connection->onLocalCandidate([this](rtc::Candidate candidate) {
|
||||
queue_signal("ice_candidate_created", 3, String(candidate.mid().c_str()), 0, String(candidate.candidate().c_str()));
|
||||
});
|
||||
peer_connection->onDataChannel([this](std::shared_ptr<rtc::DataChannel> channel) {
|
||||
queue_signal("data_channel_received", 1, WebRTCLibDataChannel::new_data_channel(channel, false));
|
||||
});
|
||||
/*
|
||||
peer_connection->onStateChange([](rtc::PeerConnection::State state) {
|
||||
std::cout << "[State: " << state << "]" << std::endl;
|
||||
});
|
||||
|
||||
peer_connection->onGatheringStateChange([](rtc::PeerConnection::GatheringState state) {
|
||||
std::cout << "[Gathering State: " << state << "]" << std::endl;
|
||||
});
|
||||
*/
|
||||
return OK;
|
||||
} catch (const std::exception &e) {
|
||||
ERR_PRINT(e.what());
|
||||
ERR_FAIL_V(FAILED);
|
||||
}
|
||||
|
||||
WebRTCLibPeerConnection::WebRTCLibPeerConnection() :
|
||||
pco(this),
|
||||
ptr_csdo(new rtc::RefCountedObject<GodotCSDO>(this)),
|
||||
ptr_ssdo(new rtc::RefCountedObject<GodotSSDO>(this)) {
|
||||
WebRTCLibPeerConnection::WebRTCLibPeerConnection() {
|
||||
#ifndef GDNATIVE_WEBRTC
|
||||
_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
WebRTCLibPeerConnection::~WebRTCLibPeerConnection() {
|
||||
#ifdef GDNATIVE_WEBRTC
|
||||
if (_owner) {
|
||||
register_interface(NULL);
|
||||
register_interface(nullptr);
|
||||
}
|
||||
close();
|
||||
#endif
|
||||
_close();
|
||||
delete mutex_signal_queue;
|
||||
}
|
||||
|
||||
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) {
|
||||
void WebRTCLibPeerConnection::queue_signal(String p_name, int p_argc, const Variant &p_arg1, const Variant &p_arg2, const 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 Variant argv[3] = { p_arg1, p_arg2, p_arg3 };
|
||||
signal_queue.push(Signal(p_name, p_argc, argv));
|
||||
mutex_signal_queue->unlock();
|
||||
}
|
||||
|
||||
@@ -1,96 +1,139 @@
|
||||
/**************************************************************************/
|
||||
/* WebRTCLibPeerConnection.hpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef WEBRTC_PEER_H
|
||||
#define WEBRTC_PEER_H
|
||||
|
||||
#ifdef GDNATIVE_WEBRTC
|
||||
#include <Godot.hpp> // Godot.hpp must go first, or windows builds breaks
|
||||
|
||||
#include "api/peer_connection_interface.h" // interface for all things needed from WebRTC
|
||||
#include "media/base/media_engine.h" // needed for CreateModularPeerConnectionFactory
|
||||
#include <functional> // std::function
|
||||
#include <mutex> // mutex @TODO replace std::mutex with Godot mutex
|
||||
|
||||
#include "net/WebRTCPeerConnectionNative.hpp"
|
||||
#define WebRTCPeerConnectionExtension WebRTCPeerConnectionNative
|
||||
#if !defined(GDCLASS)
|
||||
#define GDCLASS(arg1, arg2) GODOT_CLASS(arg1, arg2)
|
||||
#endif
|
||||
#else
|
||||
#include <godot_cpp/core/binder_common.hpp>
|
||||
|
||||
#include <godot_cpp/classes/global_constants_binds.hpp>
|
||||
#include <godot_cpp/classes/web_rtc_peer_connection_extension.hpp>
|
||||
#endif
|
||||
|
||||
#include "rtc/rtc.hpp"
|
||||
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
namespace godot_webrtc {
|
||||
|
||||
class WebRTCLibPeerConnection : public WebRTCPeerConnectionNative {
|
||||
GODOT_CLASS(WebRTCLibPeerConnection, WebRTCPeerConnectionNative);
|
||||
class WebRTCLibPeerConnection : public godot::WebRTCPeerConnectionExtension {
|
||||
GDCLASS(WebRTCLibPeerConnection, WebRTCPeerConnectionExtension);
|
||||
|
||||
private:
|
||||
godot_error _create_pc(webrtc::PeerConnectionInterface::RTCConfiguration &config);
|
||||
std::shared_ptr<rtc::PeerConnection> peer_connection = nullptr;
|
||||
godot::Array candidates;
|
||||
|
||||
godot::Error _create_pc(rtc::Configuration &r_config);
|
||||
godot::Error _parse_ice_server(rtc::Configuration &r_config, godot::Dictionary p_server);
|
||||
godot::Error _parse_channel_config(rtc::DataChannelInit &r_config, const godot::Dictionary &p_dict);
|
||||
|
||||
protected:
|
||||
static void _bind_methods() {}
|
||||
|
||||
godot::String _to_string() const {
|
||||
return "WebRTCLibPeerConnection";
|
||||
}
|
||||
|
||||
static std::unique_ptr<rtc::Thread> signaling_thread;
|
||||
public:
|
||||
static void _register_methods();
|
||||
static void _register_methods() {}
|
||||
static void initialize_signaling();
|
||||
static void deinitialize_signaling();
|
||||
|
||||
void _init();
|
||||
|
||||
ConnectionState get_connection_state() const;
|
||||
ConnectionState _get_connection_state() const override;
|
||||
GatheringState _get_gathering_state() const override;
|
||||
SignalingState _get_signaling_state() const override;
|
||||
|
||||
godot_error initialize(const godot_dictionary *p_config);
|
||||
godot_object *create_data_channel(const char *p_channel, const godot_dictionary *p_channel_config);
|
||||
godot_error create_offer();
|
||||
godot_error set_remote_description(const char *type, const char *sdp);
|
||||
godot_error set_local_description(const char *type, const char *sdp);
|
||||
godot_error add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName);
|
||||
godot_error poll();
|
||||
void close();
|
||||
godot::Error _initialize(const godot::Dictionary &p_config) override;
|
||||
#if defined(GDNATIVE_WEBRTC)
|
||||
godot::Object *_create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) override;
|
||||
#else
|
||||
godot::Ref<godot::WebRTCDataChannel> _create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) override;
|
||||
#endif
|
||||
godot::Error _create_offer() override;
|
||||
godot::Error _set_remote_description(const godot::String &type, const godot::String &sdp) override;
|
||||
godot::Error _set_local_description(const godot::String &type, const godot::String &sdp) override;
|
||||
#ifdef GDNATIVE_WEBRTC
|
||||
godot::Error _add_ice_candidate(const godot::String &sdpMidName, int64_t sdpMlineIndexName, const godot::String &sdpName) override;
|
||||
#else
|
||||
godot::Error _add_ice_candidate(const godot::String &sdpMidName, int32_t sdpMlineIndexName, const godot::String &sdpName) override;
|
||||
#endif
|
||||
godot::Error _poll() override;
|
||||
void _close() override;
|
||||
|
||||
WebRTCLibPeerConnection();
|
||||
~WebRTCLibPeerConnection();
|
||||
|
||||
/* helper functions */
|
||||
private:
|
||||
class Signal {
|
||||
godot::String method;
|
||||
godot::Variant argv[3];
|
||||
int argc = 0;
|
||||
|
||||
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 **/
|
||||
class GodotPCO : public webrtc::PeerConnectionObserver {
|
||||
public:
|
||||
WebRTCLibPeerConnection *parent;
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
void OnIceCandidate(const webrtc::IceCandidateInterface *candidate) override;
|
||||
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]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** CreateSessionDescriptionObserver callback functions **/
|
||||
class GodotCSDO : public webrtc::CreateSessionDescriptionObserver {
|
||||
public:
|
||||
WebRTCLibPeerConnection *parent;
|
||||
|
||||
GodotCSDO(WebRTCLibPeerConnection *parent);
|
||||
void OnSuccess(webrtc::SessionDescriptionInterface *desc) override;
|
||||
void OnFailure(webrtc::RTCError error) override;
|
||||
};
|
||||
|
||||
/** SetSessionDescriptionObserver callback functions **/
|
||||
class GodotSSDO : public webrtc::SetSessionDescriptionObserver {
|
||||
public:
|
||||
WebRTCLibPeerConnection *parent;
|
||||
|
||||
GodotSSDO(WebRTCLibPeerConnection *parent);
|
||||
void OnSuccess() override;
|
||||
void OnFailure(webrtc::RTCError error) override;
|
||||
};
|
||||
|
||||
GodotPCO pco;
|
||||
rtc::scoped_refptr<GodotSSDO> ptr_ssdo;
|
||||
rtc::scoped_refptr<GodotCSDO> ptr_csdo;
|
||||
|
||||
std::mutex *mutex_signal_queue = nullptr;
|
||||
std::queue<std::function<void()> > signal_queue;
|
||||
std::queue<Signal> signal_queue;
|
||||
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory;
|
||||
rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection;
|
||||
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());
|
||||
};
|
||||
|
||||
} // namespace godot_webrtc
|
||||
|
||||
78
src/init_gdextension.cpp
Normal file
78
src/init_gdextension.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/**************************************************************************/
|
||||
/* init_gdextension.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include <gdextension_interface.h>
|
||||
|
||||
#include <godot_cpp/core/class_db.hpp>
|
||||
#include <godot_cpp/core/defs.hpp>
|
||||
#include <godot_cpp/godot.hpp>
|
||||
|
||||
#include "WebRTCLibDataChannel.hpp"
|
||||
#include "WebRTCLibPeerConnection.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
// See upstream godot-cpp GH-771.
|
||||
#undef GDN_EXPORT
|
||||
#define GDN_EXPORT __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
using namespace godot;
|
||||
using namespace godot_webrtc;
|
||||
|
||||
void register_webrtc_extension_types(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
|
||||
WebRTCLibPeerConnection::initialize_signaling();
|
||||
godot::ClassDB::register_class<WebRTCLibDataChannel>();
|
||||
godot::ClassDB::register_class<WebRTCLibPeerConnection>();
|
||||
WebRTCPeerConnection::set_default_extension("WebRTCLibPeerConnection");
|
||||
}
|
||||
|
||||
void unregister_webrtc_extension_types(ModuleInitializationLevel p_level) {
|
||||
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
|
||||
return;
|
||||
}
|
||||
|
||||
WebRTCLibPeerConnection::deinitialize_signaling();
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
GDExtensionBool GDE_EXPORT webrtc_extension_init(const GDExtensionInterfaceGetProcAddress p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
|
||||
GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
|
||||
|
||||
init_obj.register_initializer(register_webrtc_extension_types);
|
||||
init_obj.register_terminator(unregister_webrtc_extension_types);
|
||||
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
|
||||
|
||||
return init_obj.init();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,45 @@
|
||||
/**************************************************************************/
|
||||
/* init_gdnative.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "WebRTCLibDataChannel.hpp"
|
||||
#include "WebRTCLibPeerConnection.hpp"
|
||||
#include "net/WebRTCPeerConnectionNative.hpp"
|
||||
#include <gdnative_api_struct.gen.h>
|
||||
#include <net/godot_net.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
// See upstream godot GH-62173.
|
||||
#undef GDN_EXPORT
|
||||
#define GDN_EXPORT __declspec(dllexport)
|
||||
#endif
|
||||
|
||||
/* Singleton */
|
||||
static bool _singleton = false;
|
||||
static const godot_object *_singleton_lib = NULL;
|
||||
@@ -34,21 +70,21 @@ godot_error create_peer_connection_wp(godot_object *out) {
|
||||
_singleton_api->godot_string_destroy(&s);
|
||||
|
||||
// Bind script to Object
|
||||
const void *args3[] = { (void *)script };
|
||||
const void *args3[] = { (void *)script };
|
||||
_singleton_api->godot_method_bind_ptrcall(_set_script_mb, out, args3, nullptr);
|
||||
|
||||
return GODOT_OK;
|
||||
}
|
||||
|
||||
godot_net_webrtc_library library = {
|
||||
{3, 2},
|
||||
{ 3, 2 },
|
||||
&unregistered,
|
||||
&create_peer_connection_wp,
|
||||
NULL,
|
||||
};
|
||||
|
||||
extern "C" void GDN_EXPORT godot_gdnative_singleton() {
|
||||
if (WebRTCPeerConnectionNative::_net_api) {
|
||||
if (godot::WebRTCPeerConnectionNative::_net_api) {
|
||||
ERR_FAIL_COND(!godot::gdnlib);
|
||||
_singleton_lib = godot::gdnlib;
|
||||
ERR_FAIL_COND(!godot::api);
|
||||
@@ -62,7 +98,7 @@ extern "C" void GDN_EXPORT godot_gdnative_singleton() {
|
||||
_set_library_mb = godot::api->godot_method_bind_get_method("NativeScript", "set_library");
|
||||
ERR_FAIL_COND(!_set_library_mb);
|
||||
// If registration is successful _singleton will be set to true
|
||||
_singleton = WebRTCPeerConnectionNative::_net_api->godot_net_set_webrtc_library(&library) == GODOT_OK;
|
||||
_singleton = godot::WebRTCPeerConnectionNative::_net_api->godot_net_set_webrtc_library(&library) == GODOT_OK;
|
||||
if (!_singleton)
|
||||
ERR_PRINT("Failed initializing webrtc singleton library");
|
||||
}
|
||||
@@ -72,7 +108,6 @@ extern "C" void GDN_EXPORT godot_gdnative_singleton() {
|
||||
extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
|
||||
const godot_gdnative_core_api_struct *api = o->api_struct;
|
||||
for (int i = 0; i < api->num_extensions; i++) {
|
||||
|
||||
if (api->extensions[i]->type != GDNATIVE_EXT_NET)
|
||||
continue;
|
||||
|
||||
@@ -82,7 +117,7 @@ extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
|
||||
break;
|
||||
|
||||
if (net_api->next->version.major == 3 && net_api->next->version.minor == 2) {
|
||||
WebRTCPeerConnectionNative::_net_api = (const godot_gdnative_ext_net_3_2_api_struct *)net_api->next;
|
||||
godot::WebRTCPeerConnectionNative::_net_api = (const godot_gdnative_ext_net_3_2_api_struct *)net_api->next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +127,7 @@ extern "C" void GDN_EXPORT godot_gdnative_init(godot_gdnative_init_options *o) {
|
||||
|
||||
extern "C" void GDN_EXPORT godot_gdnative_terminate(godot_gdnative_terminate_options *o) {
|
||||
if (_singleton) { // If we are the active singleton, unregister
|
||||
WebRTCPeerConnectionNative::_net_api->godot_net_set_webrtc_library(NULL);
|
||||
godot::WebRTCPeerConnectionNative::_net_api->godot_net_set_webrtc_library(NULL);
|
||||
}
|
||||
godot_webrtc::WebRTCLibPeerConnection::deinitialize_signaling();
|
||||
godot::Godot::gdnative_terminate(o);
|
||||
@@ -1,6 +1,38 @@
|
||||
/**************************************************************************/
|
||||
/* WebRTCDataChannelNative.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "WebRTCDataChannelNative.hpp"
|
||||
#include "net/WebRTCPeerConnectionNative.hpp"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void WebRTCDataChannelNative::register_interface(const godot_net_webrtc_data_channel *p_interface) {
|
||||
ERR_FAIL_COND(!WebRTCPeerConnectionNative::_net_api);
|
||||
WebRTCPeerConnectionNative::_net_api->godot_net_bind_webrtc_data_channel(_owner, p_interface);
|
||||
@@ -24,69 +56,73 @@ WebRTCDataChannelNative::~WebRTCDataChannelNative() {
|
||||
* and you could use void *user for any kind of state struct pointer you have.
|
||||
*/
|
||||
godot_error get_packet_wdc(void *user, const uint8_t **r_buffer, int *r_len) {
|
||||
return ((WebRTCDataChannelNative *)user)->get_packet(r_buffer, r_len);
|
||||
return (godot_error)(((WebRTCDataChannelNative *)user)->_get_packet(r_buffer, r_len));
|
||||
}
|
||||
|
||||
godot_error put_packet_wdc(void *user, const uint8_t *p_buffer, int p_len) {
|
||||
return ((WebRTCDataChannelNative *)user)->put_packet(p_buffer, p_len);
|
||||
return (godot_error)(((WebRTCDataChannelNative *)user)->_put_packet(p_buffer, p_len));
|
||||
}
|
||||
|
||||
godot_int get_available_packet_count_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->get_available_packet_count();
|
||||
return ((WebRTCDataChannelNative *)user)->_get_available_packet_count();
|
||||
}
|
||||
|
||||
godot_int get_max_packet_size_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->get_max_packet_size();
|
||||
return ((WebRTCDataChannelNative *)user)->_get_max_packet_size();
|
||||
}
|
||||
|
||||
void set_write_mode_wdc(void *user, godot_int write_mode) {
|
||||
((WebRTCDataChannelNative *)user)->set_write_mode(write_mode);
|
||||
((WebRTCDataChannelNative *)user)->_set_write_mode((godot::WebRTCDataChannel::WriteMode)write_mode);
|
||||
}
|
||||
|
||||
godot_int get_write_mode_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->get_write_mode();
|
||||
return ((WebRTCDataChannelNative *)user)->_get_write_mode();
|
||||
}
|
||||
|
||||
bool was_string_packet_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->was_string_packet();
|
||||
return ((WebRTCDataChannelNative *)user)->_was_string_packet();
|
||||
}
|
||||
|
||||
godot_int get_ready_state_wdc(const void *user) {
|
||||
return (godot_int)(((WebRTCDataChannelNative *)user)->get_ready_state());
|
||||
return (godot_int)(((WebRTCDataChannelNative *)user)->_get_ready_state());
|
||||
}
|
||||
|
||||
const char *get_label_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->get_label();
|
||||
return ((WebRTCDataChannelNative *)user)->_get_label().utf8().get_data();
|
||||
}
|
||||
|
||||
bool is_ordered_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->is_ordered();
|
||||
return ((WebRTCDataChannelNative *)user)->_is_ordered();
|
||||
}
|
||||
|
||||
int get_id_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->get_id();
|
||||
return ((WebRTCDataChannelNative *)user)->_get_id();
|
||||
}
|
||||
|
||||
int get_max_packet_life_time_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->get_max_packet_life_time();
|
||||
return ((WebRTCDataChannelNative *)user)->_get_max_packet_life_time();
|
||||
}
|
||||
|
||||
int get_max_retransmits_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->get_max_retransmits();
|
||||
return ((WebRTCDataChannelNative *)user)->_get_max_retransmits();
|
||||
}
|
||||
|
||||
const char *get_protocol_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->get_protocol();
|
||||
return ((WebRTCDataChannelNative *)user)->_get_protocol().utf8().get_data();
|
||||
}
|
||||
|
||||
bool is_negotiated_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->is_negotiated();
|
||||
return ((WebRTCDataChannelNative *)user)->_is_negotiated();
|
||||
}
|
||||
|
||||
int get_buffered_amount_wdc(const void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->_get_buffered_amount();
|
||||
}
|
||||
|
||||
godot_error poll_wdc(void *user) {
|
||||
return ((WebRTCDataChannelNative *)user)->poll();
|
||||
return (godot_error)(((WebRTCDataChannelNative *)user)->_poll());
|
||||
}
|
||||
|
||||
void close_wdc(void *user) {
|
||||
((WebRTCDataChannelNative *)user)->close();
|
||||
((WebRTCDataChannelNative *)user)->_close();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,33 @@
|
||||
/**************************************************************************/
|
||||
/* WebRTCDataChannelNative.hpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef WEBRTC_DATA_CHANNEL_NATIVE
|
||||
#define WEBRTC_DATA_CHANNEL_NATIVE
|
||||
|
||||
@@ -24,13 +54,32 @@ int get_max_packet_life_time_wdc(const void *);
|
||||
int get_max_retransmits_wdc(const void *);
|
||||
const char *get_protocol_wdc(const void *);
|
||||
bool is_negotiated_wdc(const void *);
|
||||
int get_buffered_amount_wdc(const void *);
|
||||
godot_error poll_wdc(void *);
|
||||
void close_wdc(void *);
|
||||
|
||||
#if GODOT_NET_WEBRTC_API_MAJOR == 3 && GODOT_NET_WEBRTC_API_MINOR < 4
|
||||
extern "C" {
|
||||
/* Extensions to WebRTCDataChannel */
|
||||
typedef struct {
|
||||
int (*get_buffered_amount)(const void *);
|
||||
|
||||
void *next; /* For extension? */
|
||||
} godot_net_webrtc_data_channel_ext;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace godot {
|
||||
|
||||
class WebRTCDataChannelNative : public godot::WebRTCDataChannelGDNative {
|
||||
GODOT_CLASS(WebRTCDataChannelNative, godot::WebRTCDataChannelGDNative);
|
||||
|
||||
protected:
|
||||
godot_net_webrtc_data_channel_ext interface_ext = {
|
||||
&get_buffered_amount_wdc,
|
||||
NULL,
|
||||
};
|
||||
|
||||
godot_net_webrtc_data_channel interface = {
|
||||
{ 3, 1 },
|
||||
this,
|
||||
@@ -54,7 +103,7 @@ protected:
|
||||
|
||||
&poll_wdc,
|
||||
&close_wdc,
|
||||
NULL,
|
||||
&interface_ext,
|
||||
};
|
||||
|
||||
public:
|
||||
@@ -63,29 +112,32 @@ public:
|
||||
void _init();
|
||||
void register_interface(const godot_net_webrtc_data_channel *interface);
|
||||
|
||||
virtual void set_write_mode(godot_int mode) = 0;
|
||||
virtual godot_int get_write_mode() const = 0;
|
||||
virtual bool was_string_packet() const = 0;
|
||||
virtual void _set_write_mode(WriteMode mode) = 0;
|
||||
virtual WriteMode _get_write_mode() const = 0;
|
||||
virtual bool _was_string_packet() const = 0;
|
||||
|
||||
virtual ChannelState get_ready_state() const = 0;
|
||||
virtual const char *get_label() const = 0;
|
||||
virtual bool is_ordered() const = 0;
|
||||
virtual int get_id() const = 0;
|
||||
virtual int get_max_packet_life_time() const = 0;
|
||||
virtual int get_max_retransmits() const = 0;
|
||||
virtual const char *get_protocol() const = 0;
|
||||
virtual bool is_negotiated() const = 0;
|
||||
virtual ChannelState _get_ready_state() const = 0;
|
||||
virtual godot::String _get_label() const = 0;
|
||||
virtual bool _is_ordered() const = 0;
|
||||
virtual int32_t _get_id() const = 0;
|
||||
virtual int32_t _get_max_packet_life_time() const = 0;
|
||||
virtual int32_t _get_max_retransmits() const = 0;
|
||||
virtual godot::String _get_protocol() const = 0;
|
||||
virtual bool _is_negotiated() const = 0;
|
||||
virtual int32_t _get_buffered_amount() const = 0;
|
||||
|
||||
virtual godot_error poll() = 0;
|
||||
virtual void close() = 0;
|
||||
virtual godot::Error _poll() = 0;
|
||||
virtual void _close() = 0;
|
||||
|
||||
/* PacketPeer */
|
||||
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;
|
||||
virtual godot::Error _get_packet(const uint8_t **r_buffer, int32_t *r_len) = 0;
|
||||
virtual godot::Error _put_packet(const uint8_t *p_buffer, int32_t p_len) = 0;
|
||||
virtual int32_t _get_available_packet_count() const = 0;
|
||||
virtual int32_t _get_max_packet_size() const = 0;
|
||||
|
||||
~WebRTCDataChannelNative();
|
||||
};
|
||||
|
||||
}; // namespace godot
|
||||
|
||||
#endif // WEBRTC_DATA_CHANNEL_NATIVE
|
||||
|
||||
@@ -1,5 +1,37 @@
|
||||
/**************************************************************************/
|
||||
/* WebRTCPeerConnectionNative.cpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#include "WebRTCPeerConnectionNative.hpp"
|
||||
|
||||
using namespace godot;
|
||||
|
||||
const godot_gdnative_ext_net_3_2_api_struct *WebRTCPeerConnectionNative::_net_api = NULL;
|
||||
|
||||
void WebRTCPeerConnectionNative::register_interface(const godot_net_webrtc_peer_connection *p_interface) {
|
||||
@@ -25,19 +57,23 @@ WebRTCPeerConnectionNative::~WebRTCPeerConnectionNative() {
|
||||
* and you could use void *user for any kind of state struct pointer you have.
|
||||
*/
|
||||
godot_int get_connection_state_wp(const void *user) {
|
||||
return (godot_int)((WebRTCPeerConnectionNative *)user)->get_connection_state();
|
||||
return (godot_int)((WebRTCPeerConnectionNative *)user)->_get_connection_state();
|
||||
}
|
||||
|
||||
godot_error initialize_wp(void *user, const godot_dictionary *p_config) {
|
||||
return ((WebRTCPeerConnectionNative *)user)->initialize(p_config);
|
||||
return (godot_error)(((WebRTCPeerConnectionNative *)user)->_initialize(*(Dictionary *)p_config));
|
||||
}
|
||||
|
||||
godot_object *create_data_channel_wp(void *user, const char *p_channel, const godot_dictionary *p_channel_config) {
|
||||
return ((WebRTCPeerConnectionNative *)user)->create_data_channel(p_channel, p_channel_config);
|
||||
Object *ptr = ((WebRTCPeerConnectionNative *)user)->_create_data_channel(p_channel, *(Dictionary *)p_channel_config);
|
||||
if (ptr) {
|
||||
return ptr->_owner;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
godot_error create_offer_wp(void *user) {
|
||||
return ((WebRTCPeerConnectionNative *)user)->create_offer();
|
||||
return (godot_error)(((WebRTCPeerConnectionNative *)user)->_create_offer());
|
||||
}
|
||||
|
||||
godot_error create_answer_wp(void *user) {
|
||||
@@ -45,21 +81,21 @@ godot_error create_answer_wp(void *user) {
|
||||
}
|
||||
|
||||
godot_error set_remote_description_wp(void *user, const char *type, const char *sdp) {
|
||||
return ((WebRTCPeerConnectionNative *)user)->set_remote_description(type, sdp);
|
||||
return (godot_error)(((WebRTCPeerConnectionNative *)user)->_set_remote_description(type, sdp));
|
||||
}
|
||||
|
||||
godot_error set_local_description_wp(void *user, const char *type, const char *sdp) {
|
||||
return ((WebRTCPeerConnectionNative *)user)->set_local_description(type, sdp);
|
||||
return (godot_error)(((WebRTCPeerConnectionNative *)user)->_set_local_description(type, sdp));
|
||||
}
|
||||
|
||||
godot_error add_ice_candidate_wp(void *user, const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) {
|
||||
return ((WebRTCPeerConnectionNative *)user)->add_ice_candidate(sdpMidName, sdpMlineIndexName, sdpName);
|
||||
return (godot_error)(((WebRTCPeerConnectionNative *)user)->_add_ice_candidate(sdpMidName, sdpMlineIndexName, sdpName));
|
||||
}
|
||||
|
||||
godot_error poll_wp(void *user) {
|
||||
return ((WebRTCPeerConnectionNative *)user)->poll();
|
||||
return (godot_error)((WebRTCPeerConnectionNative *)user)->_poll();
|
||||
}
|
||||
|
||||
void close_wp(void *user) {
|
||||
((WebRTCPeerConnectionNative *)user)->close();
|
||||
((WebRTCPeerConnectionNative *)user)->_close();
|
||||
}
|
||||
|
||||
@@ -1,3 +1,33 @@
|
||||
/**************************************************************************/
|
||||
/* WebRTCPeerConnectionNative.hpp */
|
||||
/**************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/**************************************************************************/
|
||||
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
||||
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef WEBRTC_PEER_NATIVE
|
||||
#define WEBRTC_PEER_NATIVE
|
||||
|
||||
@@ -20,6 +50,8 @@ godot_error add_ice_candidate_wp(void *, const char *, int, const char *);
|
||||
godot_error poll_wp(void *);
|
||||
void close_wp(void *);
|
||||
|
||||
namespace godot {
|
||||
|
||||
class WebRTCPeerConnectionNative : public godot::WebRTCPeerConnectionGDNative {
|
||||
GODOT_CLASS(WebRTCPeerConnectionNative, godot::WebRTCPeerConnectionGDNative);
|
||||
|
||||
@@ -43,24 +75,43 @@ protected:
|
||||
};
|
||||
|
||||
public:
|
||||
enum GatheringState {
|
||||
GATHERING_STATE_NEW,
|
||||
GATHERING_STATE_GATHERING,
|
||||
GATHERING_STATE_COMPLETE,
|
||||
};
|
||||
|
||||
enum SignalingState {
|
||||
SIGNALING_STATE_STABLE,
|
||||
SIGNALING_STATE_HAVE_LOCAL_OFFER,
|
||||
SIGNALING_STATE_HAVE_REMOTE_OFFER,
|
||||
SIGNALING_STATE_HAVE_LOCAL_PRANSWER,
|
||||
SIGNALING_STATE_HAVE_REMOTE_PRANSWER,
|
||||
SIGNALING_STATE_CLOSED,
|
||||
};
|
||||
|
||||
static void _register_methods();
|
||||
static const godot_gdnative_ext_net_3_2_api_struct *_net_api;
|
||||
|
||||
void _init();
|
||||
void register_interface(const godot_net_webrtc_peer_connection *interface);
|
||||
|
||||
virtual ConnectionState get_connection_state() const = 0;
|
||||
virtual ConnectionState _get_connection_state() const = 0;
|
||||
virtual GatheringState _get_gathering_state() const = 0;
|
||||
virtual SignalingState _get_signaling_state() const = 0;
|
||||
|
||||
virtual godot_error initialize(const godot_dictionary *p_config) = 0;
|
||||
virtual godot_object *create_data_channel(const char *p_channel, const godot_dictionary *p_channel_config) = 0;
|
||||
virtual godot_error create_offer() = 0;
|
||||
virtual godot_error set_remote_description(const char *type, const char *sdp) = 0;
|
||||
virtual godot_error set_local_description(const char *type, const char *sdp) = 0;
|
||||
virtual godot_error add_ice_candidate(const char *sdpMidName, int sdpMlineIndexName, const char *sdpName) = 0;
|
||||
virtual godot_error poll() = 0;
|
||||
virtual void close() = 0;
|
||||
virtual godot::Error _initialize(const godot::Dictionary &p_config) = 0;
|
||||
virtual godot::Object *_create_data_channel(const godot::String &p_channel, const godot::Dictionary &p_channel_config) = 0;
|
||||
virtual godot::Error _create_offer() = 0;
|
||||
virtual godot::Error _set_remote_description(const godot::String &type, const godot::String &sdp) = 0;
|
||||
virtual godot::Error _set_local_description(const godot::String &type, const godot::String &sdp) = 0;
|
||||
virtual godot::Error _add_ice_candidate(const godot::String &sdpMidName, int64_t sdpMlineIndexName, const godot::String &sdpName) = 0;
|
||||
virtual godot::Error _poll() = 0;
|
||||
virtual void _close() = 0;
|
||||
|
||||
~WebRTCPeerConnectionNative();
|
||||
};
|
||||
|
||||
}; // namespace godot
|
||||
|
||||
#endif // WEBRTC_PEER_NATIVE
|
||||
|
||||
71
thirdparty/README.md
vendored
Normal file
71
thirdparty/README.md
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
# Third party libraries
|
||||
|
||||
Please keep categories (`##` level) listed alphabetically and matching their
|
||||
respective folder names. Use two empty lines to separate categories for
|
||||
readability.
|
||||
|
||||
|
||||
## libdatachannel
|
||||
|
||||
- Upstream: https://github.com/paullouisageneau/libdatachannel
|
||||
- Version: 0.22.6 (0d6adc021953d7263fd4503482ea7bde33553724, 2025)
|
||||
- License: MPL 2.0
|
||||
|
||||
Module location:
|
||||
|
||||
- thirdparty/libdatachannel
|
||||
|
||||
|
||||
# libjuice
|
||||
|
||||
- Upstream: https://github.com/paullouisageneau/libjuice
|
||||
- Version: 1.5.9 (8d1a99a0683a811876c03a73ff764a92774027ad, 2025)
|
||||
- License: MPL 2.0
|
||||
|
||||
Module location:
|
||||
|
||||
- thirdparty/libdatachannel/deps/libjuice
|
||||
|
||||
|
||||
## libsrtp
|
||||
|
||||
- Upstream: https://github.com/cisco/libsrtp
|
||||
- Version: 2.5.0 (a566a9cfcd619e8327784aa7cff4a1276dc1e895, 2023)
|
||||
- License: BSD-3-Clause
|
||||
|
||||
Module location:
|
||||
|
||||
- thirdparty/libdatachannel/deps/libsrtp
|
||||
|
||||
|
||||
## mbedTLS
|
||||
|
||||
- Upstream: https://github.com/Mbed-TLS/mbedtls.git
|
||||
- Version: 3.6.3 (22098d41c6620ce07cf8a0134d37302355e1e5ef, 2025)
|
||||
- License: Apache 2.0
|
||||
|
||||
Module location:
|
||||
|
||||
- thirdparty/mbedtls
|
||||
|
||||
|
||||
## plog
|
||||
|
||||
- Upstream: https://github.com/SergiusTheBest/plog
|
||||
- Version: 1.1.10 (e21baecd4753f14da64ede979c5a19302618b752, 2023)
|
||||
- License: MIT
|
||||
|
||||
Module location:
|
||||
|
||||
- thirdparty/libdatachannel/deps/plog
|
||||
|
||||
|
||||
## usrsctp
|
||||
|
||||
- Upstream: https://github.com/sctplab/usrsctp
|
||||
- Version: git (ebb18adac6501bad4501b1f6dccb67a1c85cc299, 2023)
|
||||
- License: BSD-3-Clause
|
||||
|
||||
Module location:
|
||||
|
||||
- thirdparty/libdatachannel/deps/usrsctp
|
||||
1
thirdparty/libdatachannel
vendored
Submodule
1
thirdparty/libdatachannel
vendored
Submodule
Submodule thirdparty/libdatachannel added at 0d6adc0219
1
thirdparty/mbedtls
vendored
Submodule
1
thirdparty/mbedtls
vendored
Submodule
Submodule thirdparty/mbedtls added at 22098d41c6
177
tools/cmake.py
Normal file
177
tools/cmake.py
Normal file
@@ -0,0 +1,177 @@
|
||||
import os
|
||||
import shlex
|
||||
import sys
|
||||
|
||||
import SCons.Action
|
||||
import SCons.Builder
|
||||
import SCons.Util
|
||||
|
||||
|
||||
# This must be kept in sync with the value in https://github.com/godotengine/godot/blob/master/platform/android/detect.py#L58.
|
||||
def get_ndk_version():
|
||||
return "23.2.8568313"
|
||||
|
||||
|
||||
def cmake_default_flags(env):
|
||||
if env.get("cmake_default_flags", ""):
|
||||
return shlex.split(env["cmake_default_flags"])
|
||||
|
||||
config = {}
|
||||
|
||||
if "CC" in env:
|
||||
config["CMAKE_C_COMPILER"] = env["CC"]
|
||||
if "CXX" in env:
|
||||
config["CMAKE_CXX_COMPILER"] = env["CXX"]
|
||||
|
||||
if env["platform"] == "android":
|
||||
api = env["android_api_level"]
|
||||
abi = {
|
||||
"arm64": "arm64-v8a",
|
||||
"arm32": "armeabi-v7a",
|
||||
"x86_32": "x86",
|
||||
"x86_64": "x86_64",
|
||||
}[env["arch"]]
|
||||
config["CMAKE_SYSTEM_NAME"] = "Android"
|
||||
config["CMAKE_SYSTEM_VERSION"] = api
|
||||
config["CMAKE_ANDROID_ARCH_ABI"] = abi
|
||||
config["ANDROID_ABI"] = abi
|
||||
ndk_root = os.environ.get("ANDROID_NDK_ROOT", env.get("ANDROID_HOME", "") + "/ndk/" + get_ndk_version())
|
||||
config["CMAKE_TOOLCHAIN_FILE"] = "%s/build/cmake/android.toolchain.cmake" % ndk_root
|
||||
config["CMAKE_ANDROID_STL_TYPE"] = "c++_static"
|
||||
|
||||
elif env["platform"] == "linux":
|
||||
linux_flags = {
|
||||
"x86_64": "-m64",
|
||||
"x86_32": "-m32",
|
||||
"arm32": "-march=armv7-a",
|
||||
"arm64": "-march=armv8-a",
|
||||
}.get(env["arch"], "")
|
||||
if linux_flags:
|
||||
config["CMAKE_C_FLAGS"] = linux_flags
|
||||
config["CMAKE_CXX_FLAGS"] = linux_flags
|
||||
|
||||
elif env["platform"] == "macos":
|
||||
if env["arch"] == "universal":
|
||||
config["CMAKE_OSX_ARCHITECTURES"] = '"x86_64;arm64"'
|
||||
else:
|
||||
config["CMAKE_OSX_ARCHITECTURES"] = env["arch"]
|
||||
if env.get("macos_deployment_target", "default") != "default":
|
||||
config["CMAKE_OSX_DEPLOYMENT_TARGET"] = env["macos_deployment_target"]
|
||||
if sys.platform != "darwin" and "OSXCROSS_ROOT" in os.environ:
|
||||
config["CMAKE_AR"] = env["AR"]
|
||||
config["CMAKE_RANLIB"] = env["RANLIB"]
|
||||
if env["arch"] == "universal":
|
||||
flags = "-arch x86_64 -arch arm64"
|
||||
else:
|
||||
flags = "-arch " + env["arch"]
|
||||
if env["macos_deployment_target"] != "default":
|
||||
flags += " -mmacosx-version-min=" + env["macos_deployment_target"]
|
||||
config["CMAKE_C_FLAGS"] = flags
|
||||
config["CMAKE_CXX_FLAGS"] = flags
|
||||
|
||||
elif env["platform"] == "ios":
|
||||
if env["arch"] == "universal":
|
||||
raise ValueError("iOS architecture not supported: %s" % env["arch"])
|
||||
config["CMAKE_SYSTEM_NAME"] = "iOS"
|
||||
config["CMAKE_OSX_ARCHITECTURES"] = env["arch"]
|
||||
if env.get("ios_min_version", "default") != "default":
|
||||
config["CMAKE_OSX_DEPLOYMENT_TARGET"] = env["ios_min_version"]
|
||||
if env["ios_simulator"]:
|
||||
config["CMAKE_OSX_SYSROOT"] = "iphonesimulator"
|
||||
|
||||
elif env["platform"] == "windows":
|
||||
config["CMAKE_SYSTEM_NAME"] = "Windows"
|
||||
if env.get("is_msvc", False):
|
||||
config["CMAKE_POLICY_DEFAULT_CMP0091"] = "NEW"
|
||||
if env.get("debug_crt", False):
|
||||
config["CMAKE_MSVC_RUNTIME_LIBRARY"] = "MultiThreadedDebugDLL"
|
||||
else:
|
||||
if env.get("use_static_cpp", False):
|
||||
config["CMAKE_MSVC_RUNTIME_LIBRARY"] = "MultiThreaded"
|
||||
else:
|
||||
config["CMAKE_MSVC_RUNTIME_LIBRARY"] = "MultiThreadedDLL"
|
||||
|
||||
return ["-D%s=%s" % it for it in config.items()]
|
||||
|
||||
|
||||
def cmake_emitter(target, source, env):
|
||||
return [str(target[0]) + "/CMakeCache.txt"] + target[1:], [str(source[0]) + "/CMakeLists.txt"] + source[1:]
|
||||
|
||||
|
||||
def cmake_generator(target, source, env, for_signature):
|
||||
# Strip the -j option for signature to avoid rebuilding when num_jobs changes.
|
||||
build = env["CMAKEBUILDCOM"].replace("-j$CMAKEBUILDJOBS", "") if for_signature else env["CMAKEBUILDCOM"]
|
||||
actions = [
|
||||
SCons.Action.Action("$CMAKECONFCOM", "$CMAKECONFCOMSTR"),
|
||||
SCons.Action.Action(build, "$CMAKEBUILDCOMSTR"),
|
||||
]
|
||||
if env["CMAKE_INSTALL"]:
|
||||
actions.append(
|
||||
SCons.Action.Action("$CMAKEINSTALLCOM", "$CMAKEINSTALLCOMSTR"),
|
||||
)
|
||||
return actions
|
||||
|
||||
|
||||
def cmake_build(
|
||||
env, target_dir, source_dir, cmake_outputs=[], cmake_targets=[], cmake_options=[], dependencies=[], install=False
|
||||
):
|
||||
cmake_env = env.Clone()
|
||||
target = env.Dir("{}/{}/{}".format(target_dir, env["platform"], env["arch"]))
|
||||
source = env.Dir(source_dir)
|
||||
builder_targets = [target] + [str(target) + "/" + f for f in cmake_outputs]
|
||||
builder_sources = [source] + dependencies
|
||||
default_flags = cmake_default_flags(env)
|
||||
|
||||
# Merge flags
|
||||
flags = []
|
||||
for df in default_flags:
|
||||
if not df.startswith("-D"):
|
||||
flags.append(df)
|
||||
else:
|
||||
f = df[2:].split("=")[0]
|
||||
if f in cmake_options:
|
||||
df += " " + cmake_options[f]
|
||||
cmake_options.pop(f)
|
||||
flags.append(df)
|
||||
for opt in cmake_options:
|
||||
flags.append("-D%s=%s" % (opt, cmake_options[opt]))
|
||||
|
||||
# Select generator
|
||||
if env["cmake_generator"]:
|
||||
flags.extend(["-G", env["cmake_generator"]])
|
||||
elif env["platform"] == "windows":
|
||||
if env.get("is_msvc", False):
|
||||
flags.extend(["-G", "NMake Makefiles"])
|
||||
elif sys.platform in ["win32", "msys", "cygwin"]:
|
||||
flags.extend(["-G", "Ninja"])
|
||||
else:
|
||||
flags.extend(["-G", "Unix Makefiles"])
|
||||
|
||||
cmake_env.Append(CMAKECONFFLAGS=flags)
|
||||
if len(cmake_targets) > 0:
|
||||
cmake_env.Append(CMAKEBUILDFLAGS=["-t"] + [t for t in cmake_targets])
|
||||
cmake_env["CMAKE_INSTALL"] = install
|
||||
return cmake_env.CMake(builder_targets, builder_sources)
|
||||
|
||||
|
||||
def options(opts):
|
||||
opts.Add("cmake_default_flags", "Default CMake platform flags override, will be autodetected if not specified.", "")
|
||||
opts.Add("cmake_generator", "CMake generator override, will be autodetected from platform if not specified.", "")
|
||||
opts.Add("cmake", "CMake binary to use", "cmake")
|
||||
|
||||
|
||||
def exists(env):
|
||||
return True
|
||||
|
||||
|
||||
def generate(env):
|
||||
env["CMAKE"] = env["cmake"]
|
||||
env["CMAKECONFFLAGS"] = SCons.Util.CLVar("")
|
||||
env["CMAKECONFCOM"] = "$CMAKE -B ${TARGET.dir} $CMAKECONFFLAGS ${SOURCE.dir}"
|
||||
env["CMAKEBUILDJOBS"] = "${__env__.GetOption('num_jobs')}"
|
||||
env["CMAKEBUILDFLAGS"] = SCons.Util.CLVar("")
|
||||
env["CMAKEINSTALLFLAGS"] = SCons.Util.CLVar("")
|
||||
env["CMAKEBUILDCOM"] = "$CMAKE --build ${TARGET.dir} $CMAKEBUILDFLAGS -j$CMAKEBUILDJOBS"
|
||||
env["CMAKEINSTALLCOM"] = "$CMAKE --install ${TARGET.dir} $CMAKEINSTALLFLAGS"
|
||||
env["BUILDERS"]["CMake"] = SCons.Builder.Builder(generator=cmake_generator, emitter=cmake_emitter)
|
||||
env.AddMethod(cmake_build, "CMakeBuild")
|
||||
69
tools/mbedtls.py
Normal file
69
tools/mbedtls.py
Normal file
@@ -0,0 +1,69 @@
|
||||
def build_library(env):
|
||||
mbedtls_bin = env.Dir("bin/thirdparty/mbedtls/{}/{}/install".format(env["platform"], env["arch"]))
|
||||
is_msvc = env.get("is_msvc", False)
|
||||
c_flags = "-DMBEDTLS_SSL_DTLS_SRTP"
|
||||
if env["platform"] == "linux":
|
||||
# This is needed on some arch when building with the godot buildroot toolchain
|
||||
c_flags += " -fPIC"
|
||||
elif env["platform"] == "windows" and not is_msvc:
|
||||
c_flags += " -D__USE_MINGW_ANSI_STDIO=0" # See https://github.com/Mbed-TLS/mbedtls/issues/10161
|
||||
|
||||
mbedtls_config = {
|
||||
"CMAKE_BUILD_TYPE": "RelWithDebInfo" if env["debug_symbols"] else "Release",
|
||||
"ENABLE_TESTING": 0,
|
||||
"ENABLE_PROGRAMS": 0,
|
||||
"CMAKE_INSTALL_PREFIX": env.Dir(mbedtls_bin).abspath,
|
||||
"CMAKE_INSTALL_LIBDIR": "lib",
|
||||
"CMAKE_C_FLAGS": c_flags,
|
||||
"MBEDTLS_FATAL_WARNINGS": 0,
|
||||
}
|
||||
lib_ext = ".lib" if is_msvc else ".a"
|
||||
lib_prefix = "" if is_msvc else "lib"
|
||||
mbedtls_libs = [
|
||||
"/install/lib/{}mbedtls{}".format(lib_prefix, lib_ext),
|
||||
"/install/lib/{}mbedx509{}".format(lib_prefix, lib_ext),
|
||||
"/install/lib/{}mbedcrypto{}".format(lib_prefix, lib_ext),
|
||||
]
|
||||
|
||||
mbedtls_cmake_config = [
|
||||
"/install/lib/cmake/MbedTLS/MbedTLSConfig.cmake",
|
||||
"/install/lib/cmake/MbedTLS/MbedTLSConfigVersion.cmake",
|
||||
"/install/lib/cmake/MbedTLS/MbedTLSTargets.cmake",
|
||||
]
|
||||
|
||||
# Build libdatachannel
|
||||
mbedtls = env.CMakeBuild(
|
||||
env.Dir("bin/thirdparty/mbedtls/"),
|
||||
env.Dir("thirdparty/mbedtls"),
|
||||
cmake_options=mbedtls_config,
|
||||
cmake_outputs=mbedtls_libs + mbedtls_cmake_config,
|
||||
install=True,
|
||||
)
|
||||
|
||||
# Configure env.
|
||||
if env["platform"] == "windows":
|
||||
env.PrependUnique(LIBS=["bcrypt", "ws2_32", "iphlpapi"])
|
||||
if env["platform"] == "linux":
|
||||
env.PrependUnique(LIBS=["pthread"])
|
||||
env.Prepend(LIBS=list(filter(lambda f: str(f).endswith(lib_ext), mbedtls)))
|
||||
env.Append(CPPPATH=[env.Dir("thirdparty/mbedtls/include")])
|
||||
|
||||
return mbedtls
|
||||
|
||||
|
||||
def exists(env):
|
||||
return "CMake" in env
|
||||
|
||||
|
||||
def generate(env):
|
||||
mbedtls_install_dir = "bin/thirdparty/mbedtls/{}/{}/install".format(env["platform"], env["arch"])
|
||||
lib_ext = ".lib" if env.get("is_msvc", False) else ".a"
|
||||
mbedtls = env.File(mbedtls_install_dir + "/lib/libmbedtls" + lib_ext)
|
||||
crypto = env.File(mbedtls_install_dir + "/lib/libmbedcrypto" + lib_ext)
|
||||
x509 = env.File(mbedtls_install_dir + "/lib/libmbedx509" + lib_ext)
|
||||
includes = env.Dir("thirdparty/mbedtls/include")
|
||||
env.AddMethod(build_library, "BuildMbedTLS")
|
||||
env["MBEDTLS_LIBRARY"] = mbedtls.abspath
|
||||
env["MBEDTLS_CRYPTO_LIBRARY"] = crypto.abspath
|
||||
env["MBEDTLS_X509_LIBRARY"] = x509.abspath
|
||||
env["MBEDTLS_INCLUDE"] = includes.abspath
|
||||
53
tools/rtc.py
Normal file
53
tools/rtc.py
Normal file
@@ -0,0 +1,53 @@
|
||||
def build_library(env, mbedtls):
|
||||
rtc_config = {
|
||||
"CMAKE_BUILD_TYPE": "RelWithDebInfo" if env["debug_symbols"] else "Release",
|
||||
"CMAKE_CXX_FLAGS": "-DMBEDTLS_SSL_DTLS_SRTP",
|
||||
"USE_NICE": 0,
|
||||
"NO_WEBSOCKET": 1,
|
||||
"NO_EXAMPLES": 1,
|
||||
"NO_TESTS": 1,
|
||||
"BUILD_WITH_WARNINGS": "0", # Disables werror in libsrtp.
|
||||
"USE_MBEDTLS": 1,
|
||||
"MbedTLS_LIBRARY": env["MBEDTLS_LIBRARY"],
|
||||
"MbedCrypto_LIBRARY": env["MBEDTLS_CRYPTO_LIBRARY"],
|
||||
"MbedX509_LIBRARY": env["MBEDTLS_X509_LIBRARY"],
|
||||
"MbedTLS_INCLUDE_DIR": env["MBEDTLS_INCLUDE"],
|
||||
}
|
||||
is_msvc = env.get("is_msvc", False)
|
||||
lib_ext = ".lib" if is_msvc else ".a"
|
||||
lib_prefix = "" if is_msvc else "lib"
|
||||
rtc_libs = [
|
||||
"{}datachannel-static{}".format(lib_prefix, lib_ext),
|
||||
"deps/libjuice/{}juice-static{}".format(lib_prefix, lib_ext),
|
||||
"deps/libsrtp/{}srtp2{}".format(lib_prefix, lib_ext),
|
||||
"deps/usrsctp/usrsctplib/{}usrsctp{}".format(lib_prefix, lib_ext),
|
||||
]
|
||||
|
||||
# Build libdatachannel
|
||||
rtc = env.CMakeBuild(
|
||||
env.Dir("bin/thirdparty/libdatachannel/"),
|
||||
env.Dir("thirdparty/libdatachannel"),
|
||||
cmake_options=rtc_config,
|
||||
cmake_outputs=rtc_libs,
|
||||
cmake_targets=["datachannel-static"],
|
||||
dependencies=mbedtls,
|
||||
)
|
||||
|
||||
# Configure env.
|
||||
if env["platform"] == "windows":
|
||||
env.PrependUnique(LIBS=["iphlpapi", "ws2_32", "bcrypt"])
|
||||
if env["platform"] == "linux":
|
||||
env.PrependUnique(LIBS=["pthread"])
|
||||
env.Prepend(LIBS=list(filter(lambda f: str(f).endswith(lib_ext), rtc)))
|
||||
env.Append(CPPPATH=[env.Dir("thirdparty/libdatachannel/include")])
|
||||
env.Append(CPPDEFINES=["RTC_STATIC"]) # For Windows MSVC
|
||||
|
||||
return rtc
|
||||
|
||||
|
||||
def exists(env):
|
||||
return "CMake" in env
|
||||
|
||||
|
||||
def generate(env):
|
||||
env.AddMethod(build_library, "BuildLibDataChannel")
|
||||
1
webrtc/.gitignore
vendored
1
webrtc/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
include/
|
||||
2
webrtc/windows/.gitignore
vendored
2
webrtc/windows/.gitignore
vendored
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
Reference in New Issue
Block a user