Skip to content

Commit

Permalink
feat: Upgrade libwebrtc M115 (#960)
Browse files Browse the repository at this point in the history
* upgrade libwebrtc version M115

* fix build error

* fix

* fix

* fix

* fix

* add description about patches
  • Loading branch information
karasusan authored Aug 31, 2023
1 parent bdd6793 commit 3b74776
Show file tree
Hide file tree
Showing 26 changed files with 247 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .yamato/package.metafile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ upm:
registry_url: https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
package_version: stable
webrtc_version:
name: M112
name: M115

editors:
- version: 2020.3
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_libwebrtc_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fi

export COMMAND_DIR=$(cd $(dirname $0); pwd)
export PATH="$(pwd)/depot_tools:$PATH"
export WEBRTC_VERSION=5615
export WEBRTC_VERSION=5790
export OUTPUT_DIR="$(pwd)/out"
export ARTIFACTS_DIR="$(pwd)/artifacts"
export PYTHON3_BIN="$(pwd)/depot_tools/python-bin/python3"
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_libwebrtc_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fi

export COMMAND_DIR=$(cd $(dirname $0); pwd)
export PATH="$(pwd)/depot_tools:$PATH"
export WEBRTC_VERSION=5615
export WEBRTC_VERSION=5790
export OUTPUT_DIR="$(pwd)/out"
export ARTIFACTS_DIR="$(pwd)/artifacts"
export PYTHON3_BIN="$(pwd)/depot_tools/python-bin/python3"
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_libwebrtc_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fi

export COMMAND_DIR=$(cd $(dirname $0); pwd)
export PATH="$(pwd)/depot_tools:$PATH"
export WEBRTC_VERSION=5615
export WEBRTC_VERSION=5790
export OUTPUT_DIR="$(pwd)/out"
export ARTIFACTS_DIR="$(pwd)/artifacts"
export PYTHON3_BIN="$(pwd)/depot_tools/python-bin/python3"
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_libwebrtc_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fi

export COMMAND_DIR=$(cd $(dirname $0); pwd)
export PATH="$(pwd)/depot_tools:$PATH"
export WEBRTC_VERSION=5615
export WEBRTC_VERSION=5790
export OUTPUT_DIR="$(pwd)/out"
export ARTIFACTS_DIR="$(pwd)/artifacts"
export PYTHON3_BIN="$(pwd)/depot_tools/python-bin/python3"
Expand Down
5 changes: 4 additions & 1 deletion BuildScripts~/build_libwebrtc_win.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if not exist depot_tools (

set COMMAND_DIR=%~dp0
set PATH=%cd%\depot_tools;%PATH%
set WEBRTC_VERSION=5615
set WEBRTC_VERSION=5790
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
set GYP_GENERATORS=ninja,msvs-ninja
set GYP_MSVS_VERSION=2022
Expand All @@ -33,6 +33,9 @@ patch -N "src\modules\desktop_capture\win\full_screen_win_application_handler.cc
rem fix abseil
patch -N "src\third_party\abseil-cpp/absl/base/config.h" < "%COMMAND_DIR%\patches\fix_abseil.patch"

rem fix task_queue_base
patch -N "src\api\task_queue\task_queue_base.h" < "%COMMAND_DIR%\patches\fix_task_queue_base.patch"

mkdir "%ARTIFACTS_DIR%\lib"

setlocal enabledelayedexpansion
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_plugin_android.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-android.zip
export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-android.zip
export SOLUTION_DIR=$(pwd)/Plugin~
export PLUGIN_DIR=$(pwd)/Runtime/Plugins/Android

Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_plugin_ios.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-ios.zip
export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-ios.zip
export SOLUTION_DIR=$(pwd)/Plugin~
export WEBRTC_FRAMEWORK_DIR=$(pwd)/Runtime/Plugins/iOS
export WEBRTC_ARCHIVE_DIR=build/webrtc.xcarchive
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_plugin_linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-linux.zip
export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-linux.zip
export SOLUTION_DIR=$(pwd)/Plugin~
export OUTPUT_FILEPATH=$(pwd)/Runtime/Plugins/x86_64/libwebrtc.so
export LIBCXX_BUILD_DIR=$(pwd)/llvm-project/build
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_plugin_mac.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-mac.zip
export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-mac.zip
export SOLUTION_DIR=$(pwd)/Plugin~
export DYLIB_FILE=$(pwd)/Runtime/Plugins/macOS/libwebrtc.dylib

Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_plugin_win.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off

set LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-win.zip
set LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-win.zip
set SOLUTION_DIR=%cd%\Plugin~

echo Download LibWebRTC
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_testrunner_android.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-android.zip
export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-android.zip
export SOLUTION_DIR=$(pwd)/Plugin~
export ARCH_ABI=arm64-v8a

Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_testrunner_linux.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-linux.zip
export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-linux.zip
export SOLUTION_DIR=$(pwd)/Plugin~

source ~/.profile
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_testrunner_mac.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-mac.zip
export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-mac.zip
export SOLUTION_DIR=$(pwd)/Plugin~

# Install cmake
Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/build_testrunner_win.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@echo off

set LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-win.zip
set LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-win.zip
set SOLUTION_DIR=%cd%\Plugin~

echo -------------------
Expand Down
31 changes: 31 additions & 0 deletions BuildScripts~/patches/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Patch

## Workaround for the linker error of jsoncpp and InternalVideoEncoderFactory

The Unity package depends on modules `jsoncpp` and `InternalVideoEncoderFactory`. However, they are not contained in libwebrtc library by default. This patch file rewrites `BUILD.gn` file to add dependencies of the library for resolving the linker error which there are no symbols about these modules.

### Patch files

- add_jsoncpp.patch

### Example

```
# `src` is a root directory of libwebrtc.
patch -N "src/BUILD.gn" < "$COMMAND_DIR/patches/add_jsoncpp.patch"
```

## Workaround for the compile error about designated initializer which is supported since c++20

The C++ version of the compiler which build native plugins is **c++17** but not **c++20**. The libwebrtc library is built with **c++20**, and the header file contains the c++20 language feature [**designated initializer list**](https://en.cppreference.com/w/cpp/language/aggregate_initialization). That's why the compiler puts errors about the header file without this patch.

### Patch files

- fix_task_queue_base.patch

### Example

```
# `src` is a root directory of libwebrtc.
patch -N "src/api/task_queue/task_queue_base.h" < "$COMMAND_DIR/patches/fix_task_queue_base.patch"
```

## Workaround for gn error for building Android libwebrtc

Expand Down
14 changes: 9 additions & 5 deletions BuildScripts~/patches/add_jsoncpp.patch
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
--- BUILD.gn 2019-10-26 18:36:07.387629080 +0900
+++ BUILD.gn.edited 2019-10-26 18:36:38.013480481 +0900
@@ -397,6 +397,7 @@ if (!build_with_chromium) {
"rtc_base",
diff --git a/BUILD.gn b/BUILD.gn
index d847605cdd..e4ae568f8f 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -518,6 +518,9 @@ if (!build_with_chromium) {
"pc:rtc_pc",
"sdk",
"video",
+ "//third_party/jsoncpp",
+ "api/video_codecs:builtin_video_decoder_factory",
+ "api/video_codecs:builtin_video_encoder_factory",
]

# Include audio and video codecs by default.
if (rtc_include_builtin_audio_codecs) {
22 changes: 22 additions & 0 deletions BuildScripts~/patches/fix_task_queue_base.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/api/task_queue/task_queue_base.h b/api/task_queue/task_queue_base.h
index da7a00d438..b68c415a5c 100644
--- a/api/task_queue/task_queue_base.h
+++ b/api/task_queue/task_queue_base.h
@@ -95,7 +95,7 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueueBase {
TimeDelta delay,
const Location& location = Location::Current()) {
PostDelayedTaskImpl(std::move(task), delay,
- PostDelayedTaskTraits{.high_precision = false},
+ PostDelayedTaskTraits{false},
location);
}

@@ -120,7 +120,7 @@ class RTC_LOCKABLE RTC_EXPORT TaskQueueBase {
TimeDelta delay,
const Location& location = Location::Current()) {
PostDelayedTaskImpl(std::move(task), delay,
- PostDelayedTaskTraits{.high_precision = true},
+ PostDelayedTaskTraits{true},
location);
}

2 changes: 1 addition & 1 deletion BuildScripts~/test_plugin_android.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-android.zip
export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-android.zip
export SOLUTION_DIR=$(pwd)/Plugin~
export ARCH_ABI=arm64-v8a

Expand Down
2 changes: 1 addition & 1 deletion BuildScripts~/test_plugin_ios.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -eu

export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M112/webrtc-ios.zip
export LIBWEBRTC_DOWNLOAD_URL=https://github.com/Unity-Technologies/com.unity.webrtc/releases/download/M115/webrtc-ios.zip
export SOLUTION_DIR=$(pwd)/Plugin~

# Install cmake
Expand Down
2 changes: 1 addition & 1 deletion Plugin~/WebRTCPlugin/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ namespace webrtc
rtc::scoped_refptr<VideoTrackInterface>
Context::CreateVideoTrack(const std::string& label, VideoTrackSourceInterface* source)
{
return m_peerConnectionFactory->CreateVideoTrack(label, source);
return m_peerConnectionFactory->CreateVideoTrack(rtc::scoped_refptr<VideoTrackSourceInterface>(source), label);
}

void Context::StopMediaStreamTrack(webrtc::MediaStreamTrackInterface* track)
Expand Down
2 changes: 1 addition & 1 deletion Plugin~/WebRTCPlugin/WebRTCPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1537,7 +1537,7 @@ extern "C"
RTCVideoFrameMetadata* data =
static_cast<RTCVideoFrameMetadata*>(CoTaskMemAlloc(sizeof(RTCVideoFrameMetadata)));

auto metadata = frame->GetMetadata();
auto metadata = frame->Metadata();

data->frameId = metadata.GetFrameId();
data->width = metadata.GetWidth();
Expand Down
1 change: 1 addition & 0 deletions Plugin~/WebRTCPluginTest/FrameGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace webrtc
void ChangeResolution(size_t width, size_t height) override;
FrameGeneratorInterface::Resolution GetResolution() const override;
VideoFrameData NextFrame() override;
absl::optional<int> fps() const override { return absl::nullopt; }

private:
IGraphicsDevice* device_;
Expand Down
16 changes: 7 additions & 9 deletions Plugin~/WebRTCPluginTest/VideoFrameSchedulerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,25 @@ namespace webrtc

void Delete() override { }

void PostTask(absl::AnyInvocable<void() &&> task) override
void PostTaskImpl(
absl::AnyInvocable<void() &&> task, const PostTaskTraits& traits, const Location& location) override
{
last_task_ = std::move(task);
last_precision_ = absl::nullopt;
last_delay_ = TimeDelta::Zero();
}

void PostDelayedTask(absl::AnyInvocable<void() &&> task, TimeDelta delay) override
void PostDelayedTaskImpl(
absl::AnyInvocable<void() &&> task,
TimeDelta delay,
const PostDelayedTaskTraits& traits,
const Location& location) override
{
last_task_ = std::move(task);
last_precision_ = TaskQueueBase::DelayPrecision::kLow;
last_delay_ = delay;
}

void PostDelayedHighPrecisionTask(absl::AnyInvocable<void() &&> task, TimeDelta delay) override
{
last_task_ = std::move(task);
last_precision_ = TaskQueueBase::DelayPrecision::kHigh;
last_delay_ = delay;
}

bool AdvanceTimeAndRunLastTask()
{
EXPECT_TRUE(last_task_);
Expand Down
Loading

0 comments on commit 3b74776

Please sign in to comment.