Compiling WebRTC under Linux (Linux and Android versions)

preface

With the influence of COVID-19, the demand for audio and video has explode in the past two years. In the field of audio and video, WebRTC can be said to be an inseparable treasure house, including the whole process of audio and video acquisition, encoding and decoding, transmission and rendering. This paper mainly records the whole process of compiling WebRTC Linux and Android versions on Linux platform.

First of all, the official recommended Linux system for compilation is Ubuntu, because WebRTC is mainly developed under Ubuntu.

Set agent

For well-known reasons, agent tools are needed to download the source code of WebRTC.

export http_porxy="http://127.0.0.1:7777"
export https_porxy="http://127.0.0.1:7777"

Installation tool depot_tools

git clone get depot_tools

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

Depot_ Configure the path of tools into the environment variable

echo "export PATH=$PWD/depot_tools:$PATH" > ~/.bashrc
source ~/.bashrc

Download webrtc source code

From here on, the commands of Linux and Android versions are different.

Linux version:

mkdir webrtc
cd webrtc
fetch --nohooks webrtc
gclient sync

Android version:

mkdir webrtc
cd webrtc
fetch --nohooks webrtc_android
gclient sync

The latest source code is downloaded by default. If you want to switch to the specified branch, you can use the following command:

# View available version branches
git branch -r
# Switch to m79 branch
git checkout branch-heads/m79
gclient sync
# Or forcibly switch to the specified commit (b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b is the last commit id submitted by m79)
gclient sync -r b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b --force

You can get information about all release versions of webrtc here

Install compile dependencies

After obtaining the webrtc source code, you need to execute several scripts to install the compilation dependency.

Linux version:

cd src
./build/install-build-deps.sh

Android version:

cd src
./build/install-build-deps.sh
./build/install-build-deps-android.sh
source build/android/envsetup.sh

compile

Linux version:

By default, if Linux compiles based on ninja, its compiler uses clang, and its dependent stdc standard library is its/ buildtools/third_party/libc + + is built-in, so if you want to build libwebrtc based on clang A for development, the upper layer still needs to use clang as the compiler and link to the libc + + standard library inside webrtc, otherwise various errors will occur: undefined reference to symbol, Cannot be resolved.

# Compiled x64 version of clang
gn gen out/Release-clang --args='target_os="linux" target_cpu="x64" is_debug=false is_component_build=false rtc_include_tests=false rtc_build_examples=false'
ninja -C out/Release-clang
# gcc compiled x64
gn gen out/Release-gcc --args='target_os="linux" target_cpu="x64" is_debug=false is_component_build=false use_sysroot=false is_clang=false use_lld=false treat_warnings_as_errors=false rtc_include_tests=false rtc_build_examples=false use_custom_libcxx=false use_rtti=true'
ninja -C out/Release-gcc
# gcc compiles arm64 (the compiler needs to be installed first)
build/linux/sysroot_scripts/install-sysroot.py --arch=arm64
gn gen out/Release-arm64 --args='target_os="linux" target_cpu="arm64" is_debug=false is_component_build=false use_sysroot=false is_clang=false use_lld=false treat_warnings_as_errors=false rtc_include_tests=false rtc_build_examples=false use_custom_libcxx=false use_rtti=true'
ninja -C out/Release-arm64

After successful compilation, generate a static library libwebrtc. In the out/xxx//obj folder a.

Android version:

# Compile arm-v7
gn gen out/Release-arm-v7a --args='target_os="android" target_cpu="arm" is_debug=false rtc_include_tests=false rtc_build_examples=false'
ninja -C out/Release-arm-v7a
# Compile arm-v8 version
gn gen out/Release-arm-v8a --args='target_os="android" target_cpu="arm64" is_debug=false rtc_include_tests=false rtc_build_examples=false'
ninja -C out/Release-arm-v8a

After the compilation is successful, click out/xxx / lib Generate jar package in Java / SDK / Android -- libwebrtc Jar, generate the static library used by Android - libjingle in out/xxx_ peerconnection_ so. so.

The aar package can also be compiled directly in Android:

./tools_webrtc/android/build_aar.py --build-dir out --arch "armeabi-v7a" "arm64-v8a"

After the compilation is successful, libwebrtc.exe is generated in the / src directory AAR, including so of armeabi-v7a and arm64-v8a architectures.

Extract all header files in the webrtc project

find . -maxdepth 1 -name "*.h" -exec cp --parents '{}' /home/xxx/workspace/webrtc/include ';' && find api audio base call common_audio common_video logging media modules p2p pc rtc_base rtc_tools sdk stats system_wrappers third_party video -name "*.h" -exec cp --parents '{}' /home/xxx/workspace/webrtc/include ';'

Keywords: Linux Android webrtc

Added by wiegs on Sat, 11 Dec 2021 11:53:51 +0200