Google 官方的 WebRTC 源码 并不托管在 GitHub 上,而是使用 Chromium 的代码管理工具(depot_tools
)。以下是完整的源码下载、编译和学习指南:
1. 获取 WebRTC 源码
(1) 安装 depot_tools
(必须)
WebRTC 使用 Chromium 的构建系统,需先安装 depot_tools
:
# Linux/macOS
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH="$PATH:/path/to/depot_tools"
# Windows (PowerShell)
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$env:PATH += ";$pwd\depot_tools"
(2) 下载 WebRTC 源码
mkdir webrtc-checkout
cd webrtc-checkout
fetch --nohooks webrtc # 初始化仓库
gclient sync # 同步依赖(耗时较长,约10-30分钟)
- 源码大小:~20GB(包含所有依赖)
- 默认分支:
main
(最新开发版),如需稳定版可切换:git checkout branch-heads/stable # 切换到稳定分支
2. 编译 WebRTC
(1) 生成编译配置
# Linux/macOS
gn gen out/Default --args='is_debug=false target_os="linux" target_cpu="x64"'
# Windows
gn gen out/Default --args='is_debug=false target_os="win" target_cpu="x64"'
is_debug=false
:编译 Release 版(调试可设为true
)target_os
:支持linux
、mac
、win
、android
、ios
target_cpu
:x64
、arm64
等
(2) 开始编译
ninja -C out/Default peerconnection_serverless
- 编译目标示例:
peerconnection_serverless
:最小化的 PeerConnection 示例webrtc
:完整库(libwebrtc.a
或webrtc.