前言
随着新冠疫情的影响,这两年音视频的需要呈爆发式增长。在音视频畛域中,WebRTC能够说是一个绕不开宝库,包含了音视频采集、编解码、传输、渲染的全过程。本文次要记录下在Mac平台上编译WebRTC Mac和iOS版本的全过程。
设置代理
因为家喻户晓的起因,要下载WebRTC的源码是须要代理工具的。
export http_porxy="http://127.0.0.1:21087"export https_porxy="http://127.0.0.1:21087"
装置工具depot_tools
git clone获取depot_tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
将depot_tools的门路配置到环境变量中
export PATH=$PWD/depot_tools:$PATH
下载webrtc源码
mkdir webrtccd webrtcfetch --nohooks webrtc_iosgclient sync
默认下载的是最新的源码,如果想要切换到指定分支,能够应用以下命令:
# 查看可用版本分支git branch -r# 切换到m79分支git checkout branch-heads/m79gclient sync# 或者强制切换到指定commit(b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b是m79最初一次提交的commit id)gclient sync -r b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b --force
能够在从这里获取webrtc所有release版本的信息
编译
Mac版本:
gn gen out/mac-release --args='target_os="mac" target_cpu="x64" is_debug=false use_rtti=true is_component_build=false rtc_use_h264=false rtc_include_tests=false' --ide=xcodeninja -C out/mac-release
编译胜利后,。
iOS版本:
# 编译不带证书版本gn gen out/ios-release --args='target_os="ios" target_cpu="arm64" is_debug=false use_rtti=true is_component_build=false ios_enable_code_signing=false proprietary_codecs=false rtc_use_h264=false rtc_include_tests=false' --ide=xcodeninja -C out/ios-release# 获取证书名security find-identity -v -p codesigning# 编译带证书版本gn gen out/ios-release-sign --args='target_os="ios" target_cpu="arm64" is_debug=false use_rtti=true is_component_build=false ios_code_signing_identity="下面命令获取到的那串数字" proprietary_codecs=false rtc_use_h264=false rtc_include_tests=false' --ide=xcodeninja -C out/ios-release-sign
编译胜利后,会在src\out\xxxx\下生成all.xcworkspace文件。关上就能够构建、调试webrtc的我的项目。其中APPRTCMobile是谷歌提供的示例demo,可打包在真机上运行。在src\out\xxxx\也生成了WebRTC.framework库文件,在内部我的项目中援用该库文件就能够应用其音视频能力了。
WebRTC.framework库文件也能够通过ninja命令或者python脚本独自生成。
# 通过ninja命令独自生成WebRTC.framework库文件ninja -C out/ios-release-sign framework_objc# 通过build_ios_libs.py脚本生成WebRTC.framework库文件python tools_webrtc/ios/build_ios_libs.py --bitcode
通过python脚本(较早版本的webrtc,最新版本的生成xcframework)生成的库文件在 src/out_ios_lib目录下。该目录下会有5个文件夹,其中WebRTC.framework是反对arm、arm64、x64、x86这四种架构的动静库。另外,arm_libs、arm64_libs、x64_libs、x86_libs文件夹里别离是独自反对这四种架构的动静库。能够通过lipo -info或者file命令来查看其反对的架构。
苹果起初新出的xcframework的库类型,为反对其大一统的多平台多架构。webrtc较早版本的build_ios_libs.py是不反对生成xcframework,为此能够通过以下脚本将framework转换为为xcframework。
#!/bin/bashmkdir iphoneos iphonesimulatorcp -R WebRTC.framework iphoneoscp -R WebRTC.framework iphonesimulatorlipo -remove i386 -remove x86_64 iphoneos/WebRTC.framework/WebRTC -o iphoneos/WebRTC.framework/WebRTClipo -remove armv7 -remove arm64 iphonesimulator/WebRTC.framework/WebRTC -o iphonesimulator/WebRTC.framework/WebRTCxcodebuild -create-xcframework \-framework iphoneos/WebRTC.framework \-framework iphonesimulator/WebRTC.framework \-output "WebRTC.xcframework"
其余
可能碰到编译谬误——fatal error: 'libavutil/avconfig.h' file not found。解决方案:在src/third_party/ffmpeg/libavutil/创立avconfig.h文件,内容如下:
/* Generated by ffconf */\#ifndef AVUTIL_AVCONFIG_H\#define AVUTIL_AVCONFIG_H\#define AV_HAVE_BIGENDIAN 0\#define AV_HAVE_FAST_UNALIGNED 0\#endif /* AVUTIL_AVCONFIG_H */
- 编译带证书版本中碰到谬误——Error: no mobile provisioning profile found for "com.google.AppRTCMobile"。解决方案:关上all.xcworkspace工程,批改工程中的Signing为你本人的,从新编译工程即可。
- 我编译的版本存在一个未解决问题——
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool: file list file: obj/third_party/ffmpeg/libffmpeg_internal.a.rsp is empty。只能先设置rtc_use_h264=false,不应用h264。