关于webrtc:Mac下编译WebRTCMac和iOS版本

12次阅读

共计 3278 个字符,预计需要花费 9 分钟才能阅读完成。

前言

随着新冠疫情的影响,这两年音视频的需要呈爆发式增长。在音视频畛域中,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 webrtc
cd webrtc
fetch --nohooks webrtc_ios
gclient sync

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

# 查看可用版本分支
git branch -r
# 切换到 m79 分支
git checkout branch-heads/m79
gclient 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=xcode
ninja -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=xcode
ninja -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=xcode
ninja -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/bash

mkdir iphoneos iphonesimulator

cp -R WebRTC.framework  iphoneos
cp -R WebRTC.framework  iphonesimulator

lipo -remove i386 -remove x86_64 iphoneos/WebRTC.framework/WebRTC -o iphoneos/WebRTC.framework/WebRTC
lipo -remove armv7 -remove arm64 iphonesimulator/WebRTC.framework/WebRTC -o iphonesimulator/WebRTC.framework/WebRTC

xcodebuild -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。
正文完
 0