Compile WebRTC under Mac (Mac and iOS versions)

preface

With the influence of COVID-19, the demand for audio and video has explode in the past two years. In the field of audio and video, WebRTC can be said to be an inseparable treasure house, including the whole process of audio and video acquisition, encoding and decoding, transmission and rendering. This article mainly records the whole process of compiling WebRTC Mac and iOS versions on Mac platform.

Set agent

For well-known reasons, agent tools are needed to download the source code of WebRTC.

export http_porxy="http://127.0.0.1:21087"
export https_porxy="http://127.0.0.1:21087"

Installation tool depot_tools

git clone get depot_tools

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

Depot_ Configure the path of tools into the environment variable

export PATH=$PWD/depot_tools:$PATH

Download webrtc source code

mkdir webrtc
cd webrtc
fetch --nohooks webrtc_ios
gclient sync

The latest source code is downloaded by default. If you want to switch to the specified branch, you can use the following command:

# View available version branches
git branch -r
# Switch to m79 branch
git checkout branch-heads/m79
gclient sync
# Or forcibly switch to the specified commit (b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b is the last commit id submitted by m79)
gclient sync -r b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b --force

You can get information about all release versions of webrtc here

compile

Mac version:

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

After successful compilation,.

iOS version:

# Compile version without certificate
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

# Get certificate name
security find-identity -v -p codesigning

# Compile version with certificate
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="The string of numbers obtained by the above command" proprietary_codecs=false rtc_use_h264=false rtc_include_tests=false' --ide=xcode
ninja -C out/ios-release-sign

After the compilation is successful, all will be generated under src\out\xxxx \ Xcworkspace file. Open to build and debug webrtc projects. APPRTCMobile is an example demo provided by Google, which can be packaged and run on a real machine. Webrtc is also generated in src\out\xxxx \ Framework library file, which can be referenced in external projects to use its audio and video capabilities.

WebRTC. The framework library file can also be generated separately by ninja command or python script.

# Generate webrtc. Net separately through ninja command Framework library file
ninja -C out/ios-release-sign framework_objc

# Through build_ ios_ libs. Generate webrtc. Py script Framework library file
python tools_webrtc/ios/build_ios_libs.py --bitcode

Through python script (the earlier version of webrtc, the latest version of xcframework) the generated library files are in the src/out_ios_lib directory. There will be five folders in this directory, among which WebRTC.framework is a dynamic library supporting arm, arm64, x64 and x86. In addition, the dynamic libraries supporting these four architectures are in the folders of arm_libs, arm64_libs, x64_libs and x86_libs respectively. You can To view the supported schemas through the lipo -info or file command.

Apple's new XC framework library type is to support its unified multi platform and multi architecture. webrtc earlier build_ios_libs.py does not support generating xcframework. Therefore, you can convert the framework to xcframework through the following script.

#!/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"

other

  • You may encounter a compilation error -- fatal error: 'libavutil / avconfig h' file not found. Solution: in src/third_party/ffmpeg/libavutil / create avconfig H document, which reads as follows:

    /* 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 encountered in compiling the version with certificate - Error: no mobile provisioning profile found for "com.google.AppRTCMobile". Solution: open all Xcworkspace project, modify the Signing in the project to your own, and recompile the project.
  • There is an unresolved issue with the version I compiled——
    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. Only RTC can be set first_ use_ h264 = false, h264 is not used.

Keywords: iOS webrtc macOS

Added by awpti on Tue, 04 Jan 2022 13:51:51 +0200