Ubuntu系统安装webrtc

前言:随着音视频的发展,webrtc成为PC端和移动端的标准,因此学习webrtc技术,必须先学会如何在Linux系统安装webrtc。

简介:WebRTC (Web Real-Time Communications) 是一项实时通讯技术,它允许网络应用或者站点,在不借助中间媒介的情况下,建立浏览器之间点对点(Peer-to-Peer)的连接,实现视频流和(或)音频流或者其他任意数据的传输。WebRTC 包含的这些标准使用户在无需安装任何插件或者第三方的软件的情况下,创建点对点(Peer-to-Peer)的数据分享和电话会议成为可能。

系统环境安装要求

1. Linux系统要求

一台运行Linux的64位英特尔机器,内存至少为8GB。强烈建议超过16GB。
至少100GB的可用磁盘空间。
您必须已经安装了Git和Python。

2. 由于国内下载webrtc需要翻墙,因此购买国外的阿里云服务器下载

阿里云服务器配置阿里云服务器配置

3.使用管理员账户登录系统,安装git

Git是一个分布式版本控制程序,您可以在开发软件时使用它监视代码的变化(版本)。 Git提供了恢复到前一阶段,多个工作流程,邻居分支以及其他许多功能的功能。 这使Git成为最好的版本控制系统之一,这也是许多软件开发人员使用Git的原因。

步骤1.首先,通过运行以下命令确保您的系统和apt包列表完全更新

apt-get update -y
apt-get upgrade -y

步骤2.安装git

apt install git

4.使用管理员账户登录系统,安装python3

步骤1.下载安装包

wget https://www.python.org/ftp/python/3.9.8/Python-3.9.8.tgz

步骤2.解压

tar zxvf Python-3.9.8.tgz -C /usr/local
cd /usr/local/Python-3.9.8

步骤3.配置

./configure prefix=/usr/local/python3 --enable-optimizations

步骤4.编译安装

make && make install

步骤5.配置环境

# 删除之前的python3
whereis python
#(有风险)* rm -rf 所有python3的版本(除去/usr/local/python3) 
# 删除之前软连接
rm -rf /usr/bin/python
rm -rf /usr/bin/pip
# 添加新的链接
cp /usr/local/python3/lib/libpython3.9.a /usr/lib
echo "/usr/lib" > /etc/ld.so.conf.d/python3.9.conf
ldconfig
ln -s /usr/local/python3/bin/python3 /usr/bin/python
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip
# 添加环境变量
vi /etc/profile
#
# 添加 export PATH=$PATH:/usr/local/python3/bin
#
source /etc/profile

安装Depot Tools

depot_tools是Google的构建工具,所有Google系的项目构建都离不开depot_tools。

步骤1.获取depot_tools

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

步骤2.配置环境变量

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

下载webrtc源码

步骤1.获取webrtc源码

mkdir webrtc
cd webrtc
fetch --nohooks webrtc
gclient sync

步骤2.切换分支

默认下载的是最新的源码,如果想要切换到指定分支,可以使用以下命令:

#进入webrtc源码目录
cd webrtc/src
# 查看可用版本分支
git branch -r | grep m
# 切换到m79分支
git checkout branch-heads/m79
#查看当前分支
git branch
#同步代码
gclient sync

步骤3.安装编译依赖

Ubuntu需要执行以下脚本,安装依赖库。这个脚本安装的大多数库都是不需要的,因为我们现在在build/linux中使用Debian sysroot映像进行构建,但是仍然有一些工具需要安装在install-build- dps .sh中

Linux版本:

./build/install-build-deps.sh

Android版本:

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

如果提示:
libcairo2-dev : Depends: libx11-dev but it is not going to be installed
Depends: libxrender-dev (>= 0.6) but it is not going to be installed
Depends: libxext-dev but it is not going to be installed
libglu1-mesa-dev : Depends: libgl1-mesa-dev but it is not going to be installed or
libgl-dev
libgtk-3-dev : Depends: libgdk-pixbuf2.0-dev (>= 2.30.0) but it is not going to be installed
Depends: libpango1.0-dev (>= 1.40.5) but it is not going to be installed
Depends: libx11-dev but it is not going to be installed
Depends: libxext-dev but it is not going to be installed
Depends: libxinerama-dev but it is not going to be installed
Depends: libxi-dev but it is not going to be installed
Depends: libxrandr-dev but it is not going to be installed
Depends: libxcursor-dev but it is not going to be installed
Depends: libxfixes-dev but it is not going to be installed
Depends: libxcomposite-dev but it is not going to be installed
Depends: libxdamage-dev but it is not going to be installed
Depends: libegl1-mesa-dev but it is not going to be installed
libpango1.0-0:i386 : Depends: libpangocairo-1.0-0:i386 (= 1.40.14-1ubuntu0.1) but it is not going to be installed
Depends: libpangox-1.0-0:i386 (>= 0.0.2-2~) but it is not going to be installed
Depends: libpangoxft-1.0-0:i386 (= 1.40.14-1ubuntu0.1) but it is not going to be installed
libxcomposite1:i386 : Depends: libx11-6:i386 (>= 2:1.4.99.1) but it is not going to be installed
libxcursor1:i386 : Depends: libx11-6:i386 (>= 2:1.4.99.1) but it is not going to be installed
Depends: libxfixes3:i386 but it is not going to be installed
Depends: libxrender1:i386 but it is not going to be installed
libxdamage1:i386 : Depends: libx11-6:i386 (>= 2:1.4.99.1) but it is not going to be installed
libxi6:i386 : Depends: libx11-6:i386 (>= 2:1.6.0) but it is not going to be installed
Depends: libxext6:i386 but it is not going to be installed
libxrandr2:i386 : Depends: libx11-6:i386 (>= 2:1.6.0) but it is not going to be installed
Depends: libxext6:i386 but it is not going to be installed
Depends: libxrender1:i386 but it is not going to be installed
libxss-dev : Depends: libx11-dev but it is not going to be installed
Depends: libxext-dev but it is not going to be installed
libxss1:i386 : Depends: libx11-6:i386 (>= 2:1.4.99.1) but it is not going to be installed
Depends: libxext6:i386 but it is not going to be installed
libxt-dev : Depends: libx11-dev but it is not going to be installed
libxtst-dev : Depends: libx11-dev but it is not going to be installed
Depends: libxext-dev but it is not going to be installed
Depends: libxi-dev but it is not going to be installed
libxtst6:i386 : Depends: libx11-6:i386 (>= 2:1.6.0) but it is not going to be installed
Depends: libxext6:i386 but it is not going to be installed
You will have to install the above packages yourself.

apt-get install -y libx11-dev

如果提示:
The following packages have unmet dependencies:
libx11-dev : Depends: libx11-6 (= 2:1.6.4-3ubuntu0.4) but 2:1.6.4-3ubuntu0.5 is to be installed
Recommends: libx11-doc but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

#apt-get purge 会同时清除软件包和软件的配置文件
apt-get purge libx11-6
apt-get install -y libx11-dev

步骤4.编译

默认情况下,Linux 下基于 ninja 编译的话,其编译器使用的是 clang,且其依赖的 stdc 标准库为其 ./buildtools/third_party/libc++ 内置的,所以如果外部想要基于 clang 编译的 libwebrtc.a 进行开发的话,上层依然需要使用 clang 做为编译器,且链接 webrtc 内部的 libc++ 标准库,否则将会产生各种 error: undefined reference to symbol …,无法解决。

Linux版本

# clang编译x64版
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编译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编译arm64版(需要先安装编译工具)
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

编译成功后,在out/xxx//obj文件夹下生成静态库——libwebrtc.a。

Android版本:

# 编译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
# 编译arm-v8版
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

编译成功后,在out/xxx/lib.java/sdk/android中生成jar包——libwebrtc.jar,在out/xxx中生成Android使用的静态库——libjingle_peerconnection_so.so。

Android中也可以直接编译aar包:

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

编译成功后,在/src目录下生成——libwebrtc.aar ,包含了 armeabi-v7a、arm64-v8a 两种架构的so。

步骤5.提取webrtc项目中的所有头文件

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 ';'

文章引用与参考

【1】https://blog.csdn.net/webrtc_video/article/details/115007232
【2】https://blog.csdn.net/qq_39196431/article/details/123797279
【3】https://blog.csdn.net/zhongjianboy/article/details/123448421
【4】https://blog.csdn.net/caesar1228/article/details/121876614

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值