当前位置: 首页 > Linux

Linux下编译WebRTC(Linux和安卓版)

时间:2023-04-07 01:14:08 Linux

前言随着新冠疫情的影响,近两年音视频需求呈爆发式增长。在音视频领域,WebRTC可以说是一个绕不过去的宝库,包括音视频采集、编解码、传输、渲染的全过程。本文主要记录在Linux平台上编译WebRTCLinux和Android版本的全过程。首先需要说明的是,官方推荐编译的Linux系统是Ubuntu,因为WebRTC主要是在Ubuntu下开发的。设置代理由于众所周知的原因,下载WebRTC的源代码需要代理工具。exporthttp_proxy="http://127.0.0.1:7777"exporthttps_porxy="http://127.0.0.1:7777"安装工具depot_toolsgitclonegetdepot_toolsgitclonehttps://chromium.googlesource.com/chromium/tools/depot_tools.git配置depot_tools路径到环境变量echo"exportPATH=$PWD/depot_tools:$PATH">~/.bashrcsource~/.bashrc下载webrtc源码Linux和Android的命令从这里版本写的不同。Linuxversion:mkdirwebrtccdwebrtcfetch--nohookswebrtcgclientsyncAndroidversion:mkdirwebrtccdwebrtcfetch--nohookswebrtc_androidgclientsyncThelatestsourcecodeisdownloadedbydefault.Ifyouwanttoswitchtothespecifiedbranch,youcanusethefollowingcommand:#Viewavailableversionbranchesgitbranch-r#切换到m79分支gitcheckoutbranch-heads/m79gclientsync#或者强制切换到指定commit(b484ec0082948ae086c2ba4142b4d2bf8bc4dd4b是m79最后一次提交的commitid)gclientsync-rb484ec0082948ae086c2ba4142b4d2bf8bc4dd4b--force可以在从这里获取webrtc所有release版本的InformationinstallationandcompilationdependenciesAfterobtainingthewebrtcsourcecode,severalscriptsneedtobeexecutedtoinstallthecompilationdependencies.Linuxversion:cdsrc./build/install-build-deps.shAndroidversion:cdsrc./build/install-build-deps.sh./build/install-build-deps-android.shsourcebuild/android/envsetup.ShcompilestheLinuxversion:Bydefault,ifthecompilerisbasedonninjaunderLinux,thecompilerusesclang,andthestdcstandardlibraryitdependsonisbuiltin./buildtools/third_party/libc++,soifyouwanttouseclang-basedIfthecompiledlibwebrtc.aisdeveloped,theupperlayerstillneedstouseclangasthecompiler,andlinkthelibc++standardlibraryinsidewebrtc,otherwisevariouserrorswilloccur:undefinedreferencetosymbol...,whichcannotberesolved.#clang编译x64版gngenout/Release-clang--args='target_os="linux"target_cpu="x64"is_debug=falseis_component_build=falsertc_include_tests=falsertc_build_examples=false'ninja-Cout/Release-clang#gcc编译x64版gngenout/Release-gcc--args='target_os="linux"target_cpu="x64"is_debug=falseis_component_build=falseuse_sysroot=falseis_clang=falseuse_lld=falsetreat_warnings_as_errors=falsertc_include_tests=falsertc_build_examples=falseuse_custom_custom_custom_custom_custom=falseuse_rtti=true'ninja-Cout/Release-gcc#gcc编译arm64版(需要先安装编译工具)build/linux/sysroot_scripts/install-sysroot.py--arch=arm64gngenout/Release-arm64--args='target_os="linux"target_cpu="arm64"is_debug=falseis_component_build=falseuse_sysroot=falseis_clang=falseuse_lld=falsetreat_warnings_as_errors=falsertc_include_tests=falsertc_build_examples=falseuse_custom_libcxx=falseuse_rtti=true'ninja-Cout/Release-arm64编译成功后,在out/xxx//在obj文件夹下生成静态库-libwebrtc.aAndroid版本:#编译arm-v7版本gngenout/Release-arm-v7a--args='target_os="android"target_cpu="arm"is_debug=falsertc_include_tests=falsertc_build_examples=false'ninja-Cout/Release-arm-v7a#编译arm-v8版本gngenout/Release-arm-v8a--args='target_os="android"target_cpu="arm64"is_debug=falsertc_include_tests=falsertc_build_examples=false'ninja-Cout/Release-arm-v8a编译成功后,在out/xxx/lib.java/sdk/android中生成jar包-libwebrtc.jar,在out/xxx中生成Android以供使用的静态库-libjingle_peerconnection_so.so。Android也可以直接编译aar包:./tools_webrtc/android/build_aar.py--build-dirout--arch"armeabi-v7a""arm64-v8a"编译成功后会生成在/src目录下--libwebrtc.aar,包含armeabi-v7a和arm64-v8a两种架构。提取webrtc项目中的所有头文件find.-maxdepth1-name"*.h"-execcp--parents'{}'/home/xxx/workspace/webrtc/include';'&&查找api音频基础调用common_audiocommon_video记录媒体模块p2ppcrtc_basertc_toolssdkstatssystem_wrappersthird_partyvideo-name"*.h"-execcp--parents'{}'/home/xxx/workspace/webrtc/include';'