Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Add support to compile RTP/RTCP module as a WebAssembly library #566

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Open WebRTC Toolkit Native SDK

## About this branch
This branch is working on enabling WebAssembly build. Some WebRTC modules could be used for WebTransport and WebCodecs based streaming.

## Introduction
The Open WebRTC Toolkit(OWT) client SDK for native Windows/Linux/Android/iOS applications is built upon the W3C WebRTC standard to accelerate the development
of real time communication applications on these platforms. It supports peer to peer communication, and conference mode communication working with
Expand Down
6 changes: 5 additions & 1 deletion scripts/prepare_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
LIBSRTP_PATH = os.path.join(THIRD_PARTY_PATH, 'libsrtp')
FFMPEG_PATH = os.path.join(THIRD_PARTY_PATH, 'ffmpeg')
LIBVPX_PATH = os.path.join(THIRD_PARTY_PATH, 'libvpx')
LIBJPEG_TURBO_PATH = os.path.join(THIRD_PARTY_PATH, 'libjpeg_turbo')
NASM_PATH = os.path.join(THIRD_PARTY_PATH, 'nasm')
LIBVPX_SOURCE_PATH = os.path.join(LIBVPX_PATH, 'source/libvpx')
WEBRTC_OVERRIDES_PATH = os.path.join(THIRD_PARTY_PATH, 'webrtc_overrides')
BUILD_PATH = os.path.join(HOME_PATH, 'build')
Expand All @@ -45,7 +47,9 @@
('0014-Fix-missing-ffmpeg-configure-item-for-msvc-build.patch', FFMPEG_PATH),
('0015-Remove-custom-d8-dependency.patch', BUILD_PATH),
('0016-Remove-deprecated-create_srcjar-property.patch', THIRD_PARTY_PATH),
('0017-Build-libvpx-with-RTC-rate-control-impl-included.patch', THIRD_PARTY_PATH)
('0017-Build-libvpx-with-RTC-rate-control-impl-included.patch', THIRD_PARTY_PATH),
('0018-Support-wasm-build.patch', LIBJPEG_TURBO_PATH),
('0019-Support-wasm-build.patch', NASM_PATH)
]

def _patch(ignoreFailures=False):
Expand Down
96 changes: 60 additions & 36 deletions talk/owt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
# SPDX-License-Identifier: Apache-2.0

import("//build_overrides/webrtc.gni")
import("//talk/owt/sdk/wasm/gn/wasm.gni")
import("//testing/test.gni")

# Introduced for using libvpx config files. We only enable libvpx rate
# controller for VP9 on Windows.
if (is_win) {

if (current_cpu == "x86") {
cpu_arch_full = "ia32"
} else if (current_cpu == "x64") {
cpu_arch_full = "x64"
} else if (current_cpu == "arm") {
if (arm_use_neon) {
cpu_arch_full = "arm-neon"
} else {
cpu_arch_full = "arm"
}
}
if (current_cpu == "x86") {
cpu_arch_full = "ia32"
} else if (current_cpu == "x64") {
cpu_arch_full = "x64"
} else if (current_cpu == "arm") {
if (arm_use_neon) {
cpu_arch_full = "arm-neon"
} else {
cpu_arch_full = "arm"
}
}
}

if (is_android) {
Expand Down Expand Up @@ -181,10 +181,10 @@ static_library("owt_sdk_base") {
sources += [
"sdk/base/win/base_allocator.cc",
"sdk/base/win/base_allocator.h",
"sdk/base/win/d3d_allocator.cc",
"sdk/base/win/d3d_allocator.h",
"sdk/base/win/d3d11_allocator.cc",
"sdk/base/win/d3d11_allocator.h",
"sdk/base/win/d3d_allocator.cc",
"sdk/base/win/d3d_allocator.h",
"sdk/base/win/d3dnativeframe.h",
"sdk/base/win/mediacapabilities.cc",
"sdk/base/win/mediacapabilities.h",
Expand All @@ -200,9 +200,9 @@ static_library("owt_sdk_base") {
"sdk/base/win/msdkvideoencoderfactory.h",
"sdk/base/win/sysmem_allocator.cc",
"sdk/base/win/sysmem_allocator.h",
"sdk/base/win/vpedefs.h",
"sdk/base/win/vp9ratecontrol.cc",
"sdk/base/win/vp9ratecontrol.h",
"sdk/base/win/vpedefs.h",
]
public_deps += [ "//third_party/libvpx" ]
include_dirs += [
Expand All @@ -224,7 +224,7 @@ static_library("owt_sdk_base") {
} else {
defines += [ "OWT_USE_H265" ]
}

if (owt_use_quic) {
defines += [ "OWT_ENABLE_QUIC" ]
if (owt_quic_header_root != "") {
Expand All @@ -242,39 +242,38 @@ static_library("owt_sdk_base") {
sources += [
"sdk/base/desktopcapturer.cc",
"sdk/base/desktopcapturer.h",
"sdk/base/win/videorendererwin.cc",
"sdk/base/win/videorendererwin.h",
"sdk/base/win/videorendererd3d11.cc",
"sdk/base/win/videorendererd3d11.h",
"sdk/base/win/d3d11_manager.h",
"sdk/base/win/device_info_mf.h",
"sdk/base/win/device_info_mf.cc",
"sdk/base/win/video_capture_mf.h",
"sdk/base/win/device_info_mf.h",
"sdk/base/win/video_capture_mf.cc",
"sdk/base/win/video_capture_mf.h",
"sdk/base/win/videorendererd3d11.cc",
"sdk/base/win/videorendererd3d11.h",
"sdk/base/win/videorendererwin.cc",
"sdk/base/win/videorendererwin.h",
]
public_deps += [ "//third_party/webrtc/modules/audio_device:audio_device_module_from_input_and_output" ]

}
if (is_linux) {
if (owt_msdk_header_root != "") {
include_dirs += [ owt_msdk_header_root ]
defines += [ "OWT_USE_MSDK" ]
sources += [
"sdk/base/linux/displayutils.cc",
"sdk/base/linux/displayutils.h",
"sdk/base/linux/base_allocator.cc",
"sdk/base/linux/base_allocator.h",
"sdk/base/linux/vaapi_allocator.cc",
"sdk/base/linux/vaapi_allocator.h",
"sdk/base/linux/msdkvideosession.cc",
"sdk/base/linux/msdkvideosession.h",
"sdk/base/linux/msdkvideodecoderfactory.cc",
"sdk/base/linux/msdkvideodecoderfactory.h",
"sdk/base/linux/displayutils.cc",
"sdk/base/linux/displayutils.h",
"sdk/base/linux/msdkvideodecoder.cc",
"sdk/base/linux/msdkvideodecoder.h",
"sdk/base/linux/xwindownativeframe.h",
"sdk/base/linux/msdkvideodecoderfactory.cc",
"sdk/base/linux/msdkvideodecoderfactory.h",
"sdk/base/linux/msdkvideosession.cc",
"sdk/base/linux/msdkvideosession.h",
"sdk/base/linux/vaapi_allocator.cc",
"sdk/base/linux/vaapi_allocator.h",
"sdk/base/linux/videorenderlinux.cc",
"sdk/base/linux/videorenderlinux.h",
"sdk/base/linux/xwindownativeframe.h",
]
}
}
Expand All @@ -286,15 +285,15 @@ static_library("owt_sdk_base") {
"sdk/base/customizedvideodecoderproxy.h",
]
}
if ((is_win || is_linux)) {
if (is_win || is_linux) {
sources += [
"sdk/base/customizedaudiocapturer.cc",
"sdk/base/customizedaudiocapturer.h",
"sdk/base/customizedaudiodevicemodule.cc",
"sdk/base/customizedaudiodevicemodule.h",
]
}
if (is_clang) {
if (is_clang && !is_wasm) {
configs -= [ "//build/config/clang:find_bad_constructs" ]
}
if (is_win && is_clang) {
Expand Down Expand Up @@ -328,10 +327,35 @@ static_library("owt_sdk_p2p") {
"sdk/p2p/p2psignalingsenderimpl.cc",
"sdk/p2p/p2psignalingsenderimpl.h",
]
if (is_clang) {
if (is_clang && !is_wasm) {
configs -= [ "//build/config/clang:find_bad_constructs" ]
}
}

if (is_wasm) {
wasm_lib("owt_wasm") {
name = "owt"
deps = [
"//third_party/boringssl",
"//third_party/webrtc/call",
"//third_party/webrtc/modules/rtp_rtcp:rtp_rtcp",
"//third_party/webrtc/rtc_base:rtc_json",
"//third_party/webrtc/rtc_base:rtc_task_queue_stdlib",
"//third_party/webrtc/api/rtc_event_log:rtc_event_log_factory",
]
sources = [
"sdk/wasm/binding.h",
"sdk/wasm/main.cc",
"sdk/wasm/media_session.cc",
"sdk/wasm/media_session.h",
"sdk/wasm/rtp_video_receiver.cc",
"sdk/wasm/rtp_video_receiver.h",
"sdk/wasm/web_transport_session.cc",
"sdk/wasm/web_transport_session.h",
]
}
}

static_library("owt_sdk_conf") {
deps = [
":owt_sdk_base",
Expand All @@ -356,7 +380,7 @@ static_library("owt_sdk_conf") {
"sdk/include/cpp/owt/conference/remotemixedstream.h",
"sdk/include/cpp/owt/conference/user.h",
]
if (is_clang) {
if (is_clang && !is_wasm) {
configs -= [ "//build/config/clang:find_bad_constructs" ]
}

Expand Down
27 changes: 27 additions & 0 deletions talk/owt/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) <2021> Intel Corporation
#
# SPDX-License-Identifier: Apache-2.0

FROM ubuntu:20.04
SHELL ["/bin/bash", "-c"]
RUN apt-get update && apt-get install -y git curl wget python python3
RUN mkdir workspace
WORKDIR /workspace
RUN git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
ENV PATH="$PATH:/workspace/depot_tools"
RUN mkdir owt
WORKDIR /workspace/owt
RUN echo $'solutions = [\n\
{\n\
"name" : "src",\n\
"url" : "https://github.com/open-webrtc-toolkit/owt-client-native.git",\n\
"deps_file" : "DEPS",\n\
"managed" : False,\n\
"custom_deps" : {\n\
},\n\
"custom_vars": {},\n\
},\n\
]' > .gclient
RUN git config --global user.name owt-bot
RUN git config --global user.email [email protected]
RUN gclient sync
39 changes: 39 additions & 0 deletions talk/owt/gn/toolchain/.emscripten
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright (C) 2021 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This is the init script that is passed to `emcc --em-config=.emscripten`
# (Wasm toolchain). It sets vars to locate the various emsdk / llvm dirs.

import os
import sys
from platform import system

# We cannot use __file__ here.
this_file = os.getenv('EM_CONFIG')
if this_file is None:
sys.stderr.write('Could not find EM_CONFIG in .emscripten\n')
sys.exit(1)

root_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_file)))
buildools_os = 'mac' if system().lower() == 'darwin' else 'linux64'
node_path = os.path.join(root_dir, 'buildtools', buildools_os, 'nodejs')
emsdk_path = os.path.join(root_dir, 'buildtools', buildools_os, 'emsdk')

# Exported vars.
NODE_JS = os.path.join(node_path, 'bin', 'node')
LLVM_ROOT = os.path.join(emsdk_path, 'bin')
BINARYEN_ROOT = emsdk_path
EMSCRIPTEN_ROOT = os.path.join(emsdk_path, 'emscripten')
COMPILER_ENGINE = NODE_JS
JS_ENGINES = [NODE_JS]
25 changes: 25 additions & 0 deletions talk/owt/patches/0018-Support-wasm-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From e4850e5a4ae4eb73f7a3625b332241d7cd941c3a Mon Sep 17 00:00:00 2001
From: Jianjun Zhu <[email protected]>
Date: Thu, 9 Jun 2022 18:38:00 +0800
Subject: [PATCH] Support wasm build.

---
BUILD.gn | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/BUILD.gn b/BUILD.gn
index f9c483e..e18123d 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -277,7 +277,7 @@ static_library("libjpeg") {

# MemorySanitizer doesn't support assembly code, so keep it disabled in
# MSan builds for now.
- if (is_msan) {
+ if (is_msan || is_wasm) {
sources += [ "jsimd_none.c" ]
} else {
public_deps += [ ":simd" ]
--
2.36.1

25 changes: 25 additions & 0 deletions talk/owt/patches/0019-Support-wasm-build.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From d723c37c9a9be8796036602df510fe1c16e68e92 Mon Sep 17 00:00:00 2001
From: Jianjun Zhu <[email protected]>
Date: Thu, 9 Jun 2022 18:50:34 +0800
Subject: [PATCH] Support wasm build.

---
nasm_assemble.gni | 2 ++
1 file changed, 2 insertions(+)

diff --git a/nasm_assemble.gni b/nasm_assemble.gni
index 902a6320..d2724feb 100644
--- a/nasm_assemble.gni
+++ b/nasm_assemble.gni
@@ -67,6 +67,8 @@ if (is_mac || is_ios) {
} else if (current_cpu == "x64") {
_nasm_flags = [ "-fwin64" ]
}
+} else {
+ _nasm_flags = []
}

if (is_win) {
--
2.36.1

32 changes: 32 additions & 0 deletions talk/owt/sdk/wasm/binding.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (C) <2021> Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0

#ifndef OWT_WASM_BINDING_H_
#define OWT_WASM_BINDING_H_

#include "talk/owt/sdk/wasm/media_session.h"
#include "talk/owt/sdk/wasm/rtp_video_receiver.h"

namespace owt {
namespace wasm {

EMSCRIPTEN_BINDINGS(Owt) {
emscripten::class_<MediaSession>("MediaSession")
.smart_ptr<std::shared_ptr<MediaSession>>("MediaSession")
.function("createRtpVideoReceiver", &MediaSession::CreateRtpVideoReceiver)
.function("setRtcpCallback", &MediaSession::SetRtcpCallback)
.class_function("get", &MediaSession::Get,
emscripten::allow_raw_pointers());
emscripten::class_<RtpVideoReceiver>("RtpVideoReceiver")
.smart_ptr<std::shared_ptr<RtpVideoReceiver>>("RtpVideoReceiver")
.function("onRtpPacket", &RtpVideoReceiver::OnRtpPacket,
emscripten::allow_raw_pointers())
.function("setCompleteFrameCallback",
&RtpVideoReceiver::SetCompleteFrameCallback);
}

} // namespace wasm
} // namespace owt

#endif
Loading