WebRTC Compilation Guide

For the latest content and errata, please refer to the online book "WebRTC Study Guide" written by the author .

In the previous articles, the author introduced some background knowledge of WebRTC connection establishment, but not all. We had to build a WebRTC client to better understand the details of the connection. Since the author is an Android developer, this article will   be compiled to Android  according to the official document . For the compilation method of iOS, please refer to this link .

build environment

Compiling to Android  must use the Linux development environment; for Windows, you can use  the WSL  environment. The author uses macOS. Although it is a Unix-like system like Linux, it cannot be directly compiled to Android. But it doesn't matter, we can   easily build a Linux development environment with the help of vagrant .

First of all, we need to download and install  VirtualBox ; then execute  brew install vagrant the installation of vagrant, and restart the terminal after the installation is complete to make it take effect. Then execute the following command:

# 创建并切换到 ~/vagrant 目录
$ mkdir ~/vagrant && cd "$_"
# 初始化虚拟机(目前系统为 Ubuntu 18.04 LTS 64-bit)
$ vagrant init hashicorp/bionic64
# 启动这个虚拟机
$ vagrant up
# 通过 ssh 连接到这个虚拟机
$ vagrant ssh

All subsequent operations will be performed in the vagrant virtual machine. If you want to exit the virtual machine, just type logout.

Get the source code

First, we need to  clone depot_tools  locally. We all know that WebRTC is part of the Chromium project, and depot_tools is a collection of git workflow enhancement tools designed to organize and manage the huge code base of Chromium. Just execute the following command:

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

Then add the following command to  ~/.bashrc , and enter to  source ~/.bashrc reload bash. Among them,  /path/to/ you need to replace it with the path of depot_tools:

export PATH=/path/to/depot_tools:$PATH

Then execute the following command, the whole process takes about 40 minutes, please be patient

# 创建并切换到 ~/webrtc(也可以是自定义路径)
$ mkdir ~/webrtc && cd "$_"
# 拉取并同步 WebRTC 的最新代码
$ fetch --nohooks webrtc_android
$ gclient sync

The downloaded code contains the normal WebRTC branch and the Android branch. The Android branch contains the SDK and NDK (about 8GB), while all code is about 16GB. This code can be used for both Android development and normal Linux development. Because WebRTC uses  Ninja  as its build system, you only need to generate different compilation configurations under different paths (of course, this is another topic).

I believe you have performed all the above processes. At this point you should be in the master branch of WebRTC, but we generally don't use master directly, but should switch to the latest release version. All release information can be obtained here . As of this writing, the latest release is m85 (branch-heads/4183)

# 下载的代码位于 ~/webrtc/src
$ cd ~/webrtc/src
# 创建一个新的分支 m85(注意一定要 sync)
$ git checkout -b m85 branch-heads/4183
$ gclient sync

All subsequent operations will  ~/webrtc/src be performed in the directory (refer to the following steps to update to the latest code:

# 切换到 master 分支
$ git checkout master
$ git pull origin master
$ gclient sync
# 切换回你自己的分支(有冲突的话自己解决)
$ git checkout my-branch
$ git merge master

Compile the source code

Execute the following command to install and compile the dependencies required for compiling WebRTC. It takes about 60 minutes, please be patient

# 安装编译 WebRTC 所需的依赖
$ ./build/install-build-deps.sh
$ ./build/install-build-deps-android.sh
# -h 可以查看有哪些编译参数
$ ./tools_webrtc/android/build_aar.py -h
# 直接执行脚本,使用默认参数进行编译
$ ./tools_webrtc/android/build_aar.py

As shown in the figure, the compiled result libwebrtc.aar is located  ~/webrtc/src in the directory by default, including .so of four architectures: armeabi-v7a, arm64-v8a, x86 and x86_64 (you can use -h to see how to compile only the package of the specified architecture).

Demo

Execute  cp libwebrtc.aar /vagrant and copy libwebrtc.aar to  /vagrant the directory, which is the shared file directory between the vagrant virtual machine and the host. For this article, the directory corresponding to the host machine (macOS) is  ~/vagrantthe directory where we set up the environment at the beginning.

WebRTC officially provides a demo called AppRTC, but the process of importing it into Android Studio is very cumbersome and has complicated dependencies. Here the author provides a sorted version of  mthli/YaaRTC , readers can replace it  app/libs/libwebrtc.aar with their own compiled aar for testing.

Readers can visit https://appr.tc on the browser side  , and then enter the same room number in YaaRTC to join it. As long as the two-way video is successful, it means that we compiled libwebrtc.aar is no problem

Original WebRTC Compilation Guide-Knowledge 

 

★The business card at the end of the article can receive audio and video development learning materials for free, including (FFmpeg, webRTC, rtmp, hls, rtsp, ffplay, srs) and audio and video learning roadmaps, etc.

see below!

 

Guess you like

Origin blog.csdn.net/yinshipin007/article/details/132380179