WebRTC源码下载及编译(Ubuntu20.04)

一、环境准备

1.1 win10主机+虚拟机(Ubuntu20.04,建议硬盘可用空间40G以上)

bash 复制代码
$ cat /etc/issue
Ubuntu 20.04.5 LTS

1.2 网络配置(虚拟机借助主机的VPN来访问外网)

  1. 主机开启VPN网络
  2. 虚拟机网络配置为NAT模式
  3. 在主机上执行ipconfig查看vnet8的IP,查看vpn软件使用的端口
  4. 在ubuntu系统中配置网络代理,代理的IP和端口为步骤3中的IP和端口
  5. 主机开启vpn后,在虚拟机中浏览器中输入www.google.com可以打开即表示可以访问外网
  6. git 配置代理的IP和端口(步骤4中的IP和端口)
bash 复制代码
rtc@ubuntu:~$ cat ~/.gitconfig
[http]
	proxy = IP:PORT
[https]
	proxy = IP:PORT

二、下载流程

2.1 安装depot_tools工具,WebRTC使用depot工具管理和下载源码

  • 下载工具
bash 复制代码
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
  • 添加depot_tools到系统的环境变量PATH
    方法1: 在终端直接设置环境变量
    export PATH=$PATH:/path/to/depot_tools
    方法2:添加到~/.bashrc文件结尾,重新打开终端即可
bash 复制代码
 export PATH=$PATH:/path/to/depot_tools
  • 增加权限
bash 复制代码
 chmod 777 depot_tools -R
  • 验证测试
    终端输入fetch命令,如果提示找不到,则说明depot工具没有配置成功
bash 复制代码
$ fetch
usage: fetch.py [-h] [-n] [--nohooks] [--nohistory] [--force] [-p PROTOCOL_OVERRIDE] config ...
fetch.py: error: the following arguments are required: config, props

2.2 新建存储WebRTC源码的目录

bash 复制代码
   mkdir webrtc-checkout
   cd webrtc-checkout

2.3 使用fetch命令下载源码

fetch --nohooks webrtc

2.4 执行第3步后,如果报网络等异常断开情况时,需要用gclient sync继续下载

bash 复制代码
gclient sync

2.5 建立编译依赖

bash 复制代码
   cd src
   ./build/install-build-deps.sh

2.6 使用gn生成编译配置

bash 复制代码
gn gen out/Default

2.7 使用ninja编译代码

bash 复制代码
 ninja -C out/Default

编译完成会在out/Default目录下生成很多文件(包括各种库等)

三 问题及解决方法:

3.1 下载过程中出现以下问题

bash 复制代码
0:00:00] Started.
----------------------------------------
Traceback (most recent call last):
  File "/home/rtc/Project/office/depot_tools/metrics.py", line 302, in print_notice_and_exit
    yield
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 4638, in <module>
    sys.exit(main(sys.argv[1:]))
             ^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 4624, in main
    return dispatcher.execute(OptionParser(), argv)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/subcommand.py", line 254, in execute
    return command(parser, args[1:])
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 3977, in CMDsync
    ret = client.RunOnDeps('update', args)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 2436, in RunOnDeps
    work_queue.flush(revision_overrides,
  File "/home/rtc/Project/office/depot_tools/gclient_utils.py", line 1026, in flush
    reraise(e[0], e[1], e[2])
  File "/home/rtc/Project/office/depot_tools/gclient_utils.py", line 53, in reraise
    raise value
  File "/home/rtc/Project/office/depot_tools/gclient_utils.py", line 1105, in run
    self.item.run(*self.args, **self.kwargs)
  File "/home/rtc/Project/office/depot_tools/gclient.py", line 1251, in run
    self._got_revision = self._used_scm.RunCommand(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient_scm.py", line 137, in RunCommand
    return getattr(self, command)(options, args, file_list)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient_scm.py", line 664, in wrapper
    return_val = f(*args)
                 ^^^^^^^^
  File "/home/rtc/Project/office/depot_tools/gclient_scm.py", line 866, in update
    strp_current_url = current_url[:-4] if current_url.endswith(
                                           ^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'endswith'
  • 问题原因:git版本过低
  • 解决方法:升级git版本

升级前:

bash 复制代码
git --version
git version 2.25.1

升级后:

bash 复制代码
$ git --version
git version 2.46.1

升级流程:

  • 方法一: 直接安装更新
bash 复制代码
sudo apt-get install git
  • 方法二: 如果没更新,需要添加源
bash 复制代码
sudo add-apt-repository ppa:git-core/ppa

sudo apt update

sudo apt-get install git

四 其它说明

  1. 国外源码下载需要VPN支持,稳定、速度快的VPN能更快的下载代码
  2. 源码大小24G左右,下载前需要确认硬盘可用空间大小和VPN流量限制问题
bash 复制代码
rtc@ubuntu:~/Project/office/webrtc-checkout$ du -sh src
  24G	src
  1. 出现下载异常中断时,查明原因并解决后,可以通过gclient sync继续下载
  2. 声网提供的国内镜像下载源,在没有VPN时,可以尝试下面链接中的方法
bash 复制代码
https://webrtc.org.cn/mirror/
相关推荐
通信小小昕16 小时前
Ubuntu 26.04 中文输入法安装
linux·运维·ubuntu
CedarQR18 小时前
万字长文:从零在 RK3588 上部署 PaddleSpeech 中文 TTS 全流程(FastSpeech2 + HiFiGAN)
开发语言·c++·嵌入式硬件·ubuntu·json
雷工笔记21 小时前
Ubuntu迁移记录
笔记·ubuntu
一叶龙洲1 天前
ubuntu26.04 xfce美化成mac
服务器·ubuntu·macos
一叶龙洲1 天前
wslg打开Ubuntu24.04默认打开图形界面
linux·服务器·数据库·ubuntu
敖行客 Allthinker2 天前
Parallels Ubuntu虚拟机项目如何让手机访问?完整解决方案
linux·运维·ubuntu
keyipatience2 天前
线程栈与TLS和线程互斥
java·linux·服务器·开发语言·ubuntu
观山岳五楼2 天前
Ubuntu 24 怎么使用Ubuntu 20 的镜像源
linux·运维·ubuntu
辰痕~2 天前
物理机装Linux操作系统(Ubuntu为例)
linux·ubuntu
Byron Loong2 天前
【Git】如何检查 Ubuntu 系统上 gitLab 是否开启
git·ubuntu·gitlab