Skip to content

Commit

Permalink
Introduce .NET bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
akihikodaki committed Sep 30, 2019
1 parent 42caedb commit 61a8175
Show file tree
Hide file tree
Showing 198 changed files with 13,573 additions and 132 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@
/base
/build
/buildtools
/examples/unity/*
!/examples/unity/Assets
!/examples/unity/Packages
!/examples/unity/ProjectSettings
/ios
/mojo
/out
/sdk/dotnet/unity/bin
/sdk/dotnet/unity/obj
/sdk/dotnet/webrtc/bin
/sdk/dotnet/webrtc/obj
/testing
/third_party
/tools
Expand Down
17 changes: 15 additions & 2 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ if (!build_with_chromium) {
]
}
}
if (rtc_enable_symbol_export && !is_android) {
deps += [ ":jingle_peerconnection_so" ]
}
}
}

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

sources = []
complete_static_lib = true
Expand Down Expand Up @@ -669,6 +672,16 @@ if (rtc_include_tests) {
}
}

if (!is_android) {
rtc_shared_library("jingle_peerconnection_so") {
deps = [
"sdk/c",
"pc:libjingle_peerconnection",
"rtc_base",
]
}
}

# ---- Poisons ----
#
# Here is one empty dummy target for each poison type (needed because
Expand Down
144 changes: 144 additions & 0 deletions README.pixiv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
This is a fork of WebRTC made by [pixiv Inc](https://www.pixiv.co.jp/).

# Changes
- `rtc_symbol_enable_export` is compatible with Windows build.
- `tools_webrtc/libs/generate_licenses.py` is compatible with Windows build.
- Partial C bindings are introduced at `sdk/c`
- .NET bindings based on C bindings are introduced at `sdk/dotnet`
- `sdk/dotnet/unity` is a Unity package. Build with MSBuild.
- `example/unity` is an example to connect to
[WebRTC SFU Sora](https://sora.shiguredo.jp/) on Unity.
- Native APIs are availble for Android library.
- `webrtc::VideoBuffer`, a simple `webrtc::VideoSinkInterface` which allows you
to retrieve the last frame at an arbitrary time is introduced.

# .NET bindings

## Features

There are a few .NET binding libraries for WebRTC. Such examples include:

- [WebRTC for the Universal Windows Platform (webrtc-uwp)](https://webrtc-uwp.github.io/)
- [MixedReality-WebRTC](https://github.com/microsoft/MixedReality-WebRTC), based on webrtc-uwp
- [Unity Render Streaming](https://github.com/Unity-Technologies/UnityRenderStreaming)
- The unity plugin located at `sdk/unityplugin`

The bindings provided by this fork has following *unique* features:

- Portable
- .NET Standard 2.0
- Satisfies additional requirements of [Mono's full AOT](https://www.mono-project.com/docs/advanced/aot/#full-aot)
and [IL2CPP](https://docs.unity3d.com/Manual/IL2CPP.html).
- No Unity or other runtime dependency.
- No operating system requirements other than WebRTC requirements.
- Up-to-date
- [Unified Plan](https://webrtc.org/web-apis/chrome/unified-plan/)
- Available as a Unity [package](https://docs.unity3d.com/Manual/Packages.html),
whose format is an enhancement of traditional Unity asset packages.
- Extensible
- Its interface-based API design allows to create bindings for C++ code using
native API.
- As low-level as native API.
- No assumption for inputs/outputs. Use [Unity's RenderTexture](https://docs.unity3d.com/Manual/class-RenderTexture.html)
or whatever.
- No assumption for signaling. You can use existing signaling server
implementations such as [Sora](https://sora.shiguredo.jp/) and SaaS such
as [ImageFlux Live Streaming](https://www.sakura.ad.jp/services/imageflux/livestreaming/).
- This also means you need more code to integrate it to an application.
- Provides comprehensive license file
- Although it may sound ridiculous to say this as a *unique* feature, it is
almost impossible to create one without
`tools_webrtc/libs/generate_licenses.py`.

## Tested platforms

- Unity on Android
- Unity on Linux/X11
- Unity on Windows
- Unity on iOS
- Unity on macOS

## Why fork instead of implementing C/.NET bindings completely out-of-tree?

By forking and extending the build infrastructure for C/.NET bindings, the
build system of those bindings are automatically aligned with the one of the
library itself.

The build system of WebRTC also contributes to the portability because it is of
course capable to build for any platforms WebRTC supports.

The changes made in existing code for the bindings are minimal, and it is
expected to be easy to maintain them, comparing with possible tons of build
scripts and their messes. (Note that it supports multiple platforms.)

## Using the bindings

The bindings are simple mappings for native APIs. See
https://webrtc.org/native-code/native-apis/ for details of native APIs.

You may also refer to `examples/unity` for .NET/Unity specifics.

## Coding style

C# coding style is conforming to
[.NET Core coding style](https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/coding-style.md).

## Release build procedure

Currently unity package is built manually because of build system complications.
The release build procedure is as follows:

1. Prepare a computer with Linux installed for Android, Linux, and Windows
builds according to https://webrtc.org/native-code/development/.

2. Check out this code base at `src`.

3. Build `unity.msbuildproj` with:
* `src/sdk/dotnet/unity` as the working directory,
* `Android;LinuxX64;WinX64` as `Targets` property, and
* `Release` as `Configuration` property

4. Prepare a computer with macOS installed for iOS and macOS builds according to
https://webrtc.org/native-code/development/.

5. Check out this code base at `src`.

6. Build `src/sdk/dotnet/unity/unity.msbuildproj` the following properties:
* `src/sdk/dotnet/unity` as the working directory,
* `Ios;MacX64` as `Targets` property, and
* `Release` as `Configuration` property

7. Copy `Editor` and `Editor.meta` in `src/sdk/dotnet/unity/bin/Release`
produced by 6 to `src/sdk/dotnet/unity/bin/Release` produced by 3.

8. Copy the contents of `src/sdk/dotnet/unity/bin/Release/Runtime`
produced by 6 to `src/sdk/dotnet/unity/bin/Release/Runtime` produced by 3.
Do not overwrite exist files.

9. Add license notices included in `src/sdk/dotnet/unity/bin/Release/LICENSE.md`
produced by 6 to one produced by 3 if they are missing.

9. Make a tarball containing `src/sdk/dotnet/unity/bin/Release/Runtime`
produced by 3 as `package` directory.

10. Gzip the tarball produced by 9.

# Further enhancements

The following is something nice to have, but it is not currently planned to
implement them:

- Automated tests
- Examples for .NET Core, .NET Framework/Mono and Xamarin
- Examples independent of Sora
- NuGet package

# Additional copyright notice

`examples/unity/Assets/aint_we_got_fun_billy_jones1921.mp3` is a recording of
_Ain't We Got Fun_, performed by Billy Jones. It is distributed by Digital
History.
Mintz, S., & McNeil, S. (2016). Digital History.
http://www.digitalhistory.uh.edu/music/music.cfm

The copyrights of the recording has expired and it is in the public domain.
16 changes: 11 additions & 5 deletions api/jsep.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// Though in the future, we're planning to provide an SDP parsing API, with a
// structure more friendly than cricket::SessionDescription.

#include "sdk/c/api/jsep.h"

#ifndef API_JSEP_H_
#define API_JSEP_H_

Expand Down Expand Up @@ -100,11 +102,15 @@ class IceCandidateCollection {
// Corresponds to RTCSdpType in the WebRTC specification.
// https://w3c.github.io/webrtc-pc/#dom-rtcsdptype
enum class SdpType {
kOffer, // Description must be treated as an SDP offer.
kPrAnswer, // Description must be treated as an SDP answer, but not a final
// answer.
kAnswer // Description must be treated as an SDP final answer, and the offer-
// answer exchange must be considered complete after receiving this.
// Description must be treated as an SDP offer.
kOffer = WEBRTC_SDP_TYPE_OFFER,

// Description must be treated as an SDP answer, but not a final answer.
kPrAnswer = WEBRTC_SDP_TYPE_PR_ANSWER,

// Description must be treated as an SDP final answer, and the offer-
// answer exchange must be considered complete after receiving this.
kAnswer = WEBRTC_SDP_TYPE_ANSER
};

// Returns the string form of the given SDP type. String forms are defined in
Expand Down
9 changes: 8 additions & 1 deletion api/media_stream_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// interfaces must be used only with PeerConnection. PeerConnectionManager
// interface provides the factory methods to create MediaStream and MediaTracks.

#include "sdk/c/api/media_stream_interface.h"

#ifndef API_MEDIA_STREAM_INTERFACE_H_
#define API_MEDIA_STREAM_INTERFACE_H_

Expand Down Expand Up @@ -56,7 +58,12 @@ class NotifierInterface {
class RTC_EXPORT MediaSourceInterface : public rtc::RefCountInterface,
public NotifierInterface {
public:
enum SourceState { kInitializing, kLive, kEnded, kMuted };
enum SourceState {
kInitializing = WEBRTC_MEDIA_SOURCE_INTERFACE_SOURCE_STATE_INITIALIZING,
kLive = WEBRTC_MEDIA_SOURCE_INTERFACE_SOURCE_STATE_LIVE,
kEnded = WEBRTC_MEDIA_SOURCE_INTERFACE_SOURCE_STATE_ENDED,
kMuted = WEBRTC_MEDIA_SOURCE_INTERFACE_SOURCE_STATE_MUTED
};

virtual SourceState state() const = 0;

Expand Down
Loading

0 comments on commit 61a8175

Please sign in to comment.