Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 61a8175

Browse files
committed
Introduce .NET bindings
1 parent 42caedb commit 61a8175

File tree

198 files changed

+13573
-132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

198 files changed

+13573
-132
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@
4141
/base
4242
/build
4343
/buildtools
44+
/examples/unity/*
45+
!/examples/unity/Assets
46+
!/examples/unity/Packages
47+
!/examples/unity/ProjectSettings
4448
/ios
4549
/mojo
4650
/out
51+
/sdk/dotnet/unity/bin
52+
/sdk/dotnet/unity/obj
53+
/sdk/dotnet/webrtc/bin
54+
/sdk/dotnet/webrtc/obj
4755
/testing
4856
/third_party
4957
/tools

BUILD.gn

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ if (!build_with_chromium) {
8080
]
8181
}
8282
}
83+
if (rtc_enable_symbol_export && !is_android) {
84+
deps += [ ":jingle_peerconnection_so" ]
85+
}
8386
}
8487
}
8588

@@ -389,8 +392,8 @@ config("common_objc") {
389392
if (!build_with_chromium) {
390393
# Target to build all the WebRTC production code.
391394
rtc_static_library("webrtc") {
392-
# Only the root target should depend on this.
393-
visibility = [ "//:default" ]
395+
# Only the root target and "shared:webrtc" should depend on this.
396+
visibility = [ "//:default", "shared:webrtc" ]
394397

395398
sources = []
396399
complete_static_lib = true
@@ -669,6 +672,16 @@ if (rtc_include_tests) {
669672
}
670673
}
671674

675+
if (!is_android) {
676+
rtc_shared_library("jingle_peerconnection_so") {
677+
deps = [
678+
"sdk/c",
679+
"pc:libjingle_peerconnection",
680+
"rtc_base",
681+
]
682+
}
683+
}
684+
672685
# ---- Poisons ----
673686
#
674687
# Here is one empty dummy target for each poison type (needed because

README.pixiv.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
This is a fork of WebRTC made by [pixiv Inc](https://www.pixiv.co.jp/).
2+
3+
# Changes
4+
- `rtc_symbol_enable_export` is compatible with Windows build.
5+
- `tools_webrtc/libs/generate_licenses.py` is compatible with Windows build.
6+
- Partial C bindings are introduced at `sdk/c`
7+
- .NET bindings based on C bindings are introduced at `sdk/dotnet`
8+
- `sdk/dotnet/unity` is a Unity package. Build with MSBuild.
9+
- `example/unity` is an example to connect to
10+
[WebRTC SFU Sora](https://sora.shiguredo.jp/) on Unity.
11+
- Native APIs are availble for Android library.
12+
- `webrtc::VideoBuffer`, a simple `webrtc::VideoSinkInterface` which allows you
13+
to retrieve the last frame at an arbitrary time is introduced.
14+
15+
# .NET bindings
16+
17+
## Features
18+
19+
There are a few .NET binding libraries for WebRTC. Such examples include:
20+
21+
- [WebRTC for the Universal Windows Platform (webrtc-uwp)](https://webrtc-uwp.github.io/)
22+
- [MixedReality-WebRTC](https://github.com/microsoft/MixedReality-WebRTC), based on webrtc-uwp
23+
- [Unity Render Streaming](https://github.com/Unity-Technologies/UnityRenderStreaming)
24+
- The unity plugin located at `sdk/unityplugin`
25+
26+
The bindings provided by this fork has following *unique* features:
27+
28+
- Portable
29+
- .NET Standard 2.0
30+
- Satisfies additional requirements of [Mono's full AOT](https://www.mono-project.com/docs/advanced/aot/#full-aot)
31+
and [IL2CPP](https://docs.unity3d.com/Manual/IL2CPP.html).
32+
- No Unity or other runtime dependency.
33+
- No operating system requirements other than WebRTC requirements.
34+
- Up-to-date
35+
- [Unified Plan](https://webrtc.org/web-apis/chrome/unified-plan/)
36+
- Available as a Unity [package](https://docs.unity3d.com/Manual/Packages.html),
37+
whose format is an enhancement of traditional Unity asset packages.
38+
- Extensible
39+
- Its interface-based API design allows to create bindings for C++ code using
40+
native API.
41+
- As low-level as native API.
42+
- No assumption for inputs/outputs. Use [Unity's RenderTexture](https://docs.unity3d.com/Manual/class-RenderTexture.html)
43+
or whatever.
44+
- No assumption for signaling. You can use existing signaling server
45+
implementations such as [Sora](https://sora.shiguredo.jp/) and SaaS such
46+
as [ImageFlux Live Streaming](https://www.sakura.ad.jp/services/imageflux/livestreaming/).
47+
- This also means you need more code to integrate it to an application.
48+
- Provides comprehensive license file
49+
- Although it may sound ridiculous to say this as a *unique* feature, it is
50+
almost impossible to create one without
51+
`tools_webrtc/libs/generate_licenses.py`.
52+
53+
## Tested platforms
54+
55+
- Unity on Android
56+
- Unity on Linux/X11
57+
- Unity on Windows
58+
- Unity on iOS
59+
- Unity on macOS
60+
61+
## Why fork instead of implementing C/.NET bindings completely out-of-tree?
62+
63+
By forking and extending the build infrastructure for C/.NET bindings, the
64+
build system of those bindings are automatically aligned with the one of the
65+
library itself.
66+
67+
The build system of WebRTC also contributes to the portability because it is of
68+
course capable to build for any platforms WebRTC supports.
69+
70+
The changes made in existing code for the bindings are minimal, and it is
71+
expected to be easy to maintain them, comparing with possible tons of build
72+
scripts and their messes. (Note that it supports multiple platforms.)
73+
74+
## Using the bindings
75+
76+
The bindings are simple mappings for native APIs. See
77+
https://webrtc.org/native-code/native-apis/ for details of native APIs.
78+
79+
You may also refer to `examples/unity` for .NET/Unity specifics.
80+
81+
## Coding style
82+
83+
C# coding style is conforming to
84+
[.NET Core coding style](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md).
85+
86+
## Release build procedure
87+
88+
Currently unity package is built manually because of build system complications.
89+
The release build procedure is as follows:
90+
91+
1. Prepare a computer with Linux installed for Android, Linux, and Windows
92+
builds according to https://webrtc.org/native-code/development/.
93+
94+
2. Check out this code base at `src`.
95+
96+
3. Build `unity.msbuildproj` with:
97+
* `src/sdk/dotnet/unity` as the working directory,
98+
* `Android;LinuxX64;WinX64` as `Targets` property, and
99+
* `Release` as `Configuration` property
100+
101+
4. Prepare a computer with macOS installed for iOS and macOS builds according to
102+
https://webrtc.org/native-code/development/.
103+
104+
5. Check out this code base at `src`.
105+
106+
6. Build `src/sdk/dotnet/unity/unity.msbuildproj` the following properties:
107+
* `src/sdk/dotnet/unity` as the working directory,
108+
* `Ios;MacX64` as `Targets` property, and
109+
* `Release` as `Configuration` property
110+
111+
7. Copy `Editor` and `Editor.meta` in `src/sdk/dotnet/unity/bin/Release`
112+
produced by 6 to `src/sdk/dotnet/unity/bin/Release` produced by 3.
113+
114+
8. Copy the contents of `src/sdk/dotnet/unity/bin/Release/Runtime`
115+
produced by 6 to `src/sdk/dotnet/unity/bin/Release/Runtime` produced by 3.
116+
Do not overwrite exist files.
117+
118+
9. Add license notices included in `src/sdk/dotnet/unity/bin/Release/LICENSE.md`
119+
produced by 6 to one produced by 3 if they are missing.
120+
121+
9. Make a tarball containing `src/sdk/dotnet/unity/bin/Release/Runtime`
122+
produced by 3 as `package` directory.
123+
124+
10. Gzip the tarball produced by 9.
125+
126+
# Further enhancements
127+
128+
The following is something nice to have, but it is not currently planned to
129+
implement them:
130+
131+
- Automated tests
132+
- Examples for .NET Core, .NET Framework/Mono and Xamarin
133+
- Examples independent of Sora
134+
- NuGet package
135+
136+
# Additional copyright notice
137+
138+
`examples/unity/Assets/aint_we_got_fun_billy_jones1921.mp3` is a recording of
139+
_Ain't We Got Fun_, performed by Billy Jones. It is distributed by Digital
140+
History.
141+
Mintz, S., & McNeil, S. (2016). Digital History.
142+
http://www.digitalhistory.uh.edu/music/music.cfm
143+
144+
The copyrights of the recording has expired and it is in the public domain.

api/jsep.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
// Though in the future, we're planning to provide an SDP parsing API, with a
1818
// structure more friendly than cricket::SessionDescription.
1919

20+
#include "sdk/c/api/jsep.h"
21+
2022
#ifndef API_JSEP_H_
2123
#define API_JSEP_H_
2224

@@ -100,11 +102,15 @@ class IceCandidateCollection {
100102
// Corresponds to RTCSdpType in the WebRTC specification.
101103
// https://w3c.github.io/webrtc-pc/#dom-rtcsdptype
102104
enum class SdpType {
103-
kOffer, // Description must be treated as an SDP offer.
104-
kPrAnswer, // Description must be treated as an SDP answer, but not a final
105-
// answer.
106-
kAnswer // Description must be treated as an SDP final answer, and the offer-
107-
// answer exchange must be considered complete after receiving this.
105+
// Description must be treated as an SDP offer.
106+
kOffer = WEBRTC_SDP_TYPE_OFFER,
107+
108+
// Description must be treated as an SDP answer, but not a final answer.
109+
kPrAnswer = WEBRTC_SDP_TYPE_PR_ANSWER,
110+
111+
// Description must be treated as an SDP final answer, and the offer-
112+
// answer exchange must be considered complete after receiving this.
113+
kAnswer = WEBRTC_SDP_TYPE_ANSER
108114
};
109115

110116
// Returns the string form of the given SDP type. String forms are defined in

api/media_stream_interface.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// interfaces must be used only with PeerConnection. PeerConnectionManager
1515
// interface provides the factory methods to create MediaStream and MediaTracks.
1616

17+
#include "sdk/c/api/media_stream_interface.h"
18+
1719
#ifndef API_MEDIA_STREAM_INTERFACE_H_
1820
#define API_MEDIA_STREAM_INTERFACE_H_
1921

@@ -56,7 +58,12 @@ class NotifierInterface {
5658
class RTC_EXPORT MediaSourceInterface : public rtc::RefCountInterface,
5759
public NotifierInterface {
5860
public:
59-
enum SourceState { kInitializing, kLive, kEnded, kMuted };
61+
enum SourceState {
62+
kInitializing = WEBRTC_MEDIA_SOURCE_INTERFACE_SOURCE_STATE_INITIALIZING,
63+
kLive = WEBRTC_MEDIA_SOURCE_INTERFACE_SOURCE_STATE_LIVE,
64+
kEnded = WEBRTC_MEDIA_SOURCE_INTERFACE_SOURCE_STATE_ENDED,
65+
kMuted = WEBRTC_MEDIA_SOURCE_INTERFACE_SOURCE_STATE_MUTED
66+
};
6067

6168
virtual SourceState state() const = 0;
6269

0 commit comments

Comments
 (0)