【网络通信 -- WebRTC】项目实战记录 -- mediasoup android 适配 webrtc m94
【1】下载并配置 depot_tools
下载 depot_tools
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
编辑 ~/.bashrc 将 depot_tools 添加到路径中
vim ~/.bashrc
export PATH=$PATH:/(path to depot_tools)/depot_tools
source ~/.bashrc
检查 depot_tools 是否安装配置成功
which gn
which gclient
【2】获取 WebRTC 源码
获取 Android WebRTC 代码
fetch --nohooks webrtc_android
若其中发生中断则执行如下命令继续
gclient sync
切换到 m94 分支并同步
cd src
git checkout -b m94 branch-heads/4606
cd ..
gclient sync --nohooks
gclient runhooks
下载安装相关依赖
cd src
./build/install-build-deps.sh
./build/install-build-deps-android.sh
【3】编译 WebRTC
编译 AAR
编译 libwebrtc.a 和 libwebrtc.jar
默认不会编译 webrtc 模块,在 /tools_webrtc/android/build_aar.py 文件中加入 ':webrtc',如下
TARGETS = [
':webrtc',
'sdk/android:libwebrtc',
'sdk/android:libjingle_peerconnection_so',
]
--------------------------------------------------
开启 h264
修改 tools_webrtc/libs/generate_licenses.py 如下,添加 LICENSE
'g722': ['modules/third_party/g722/LICENSE'],
'fft4g': ['common_audio/third_party/fft4g/LICENSE'],
'spl_sqrt_floor': ['common_audio/third_party/spl_sqrt_floor/LICENSE'],
+ 'openh264':['third_party/openh264/src/LICENSE'],
+ 'ffmpeg':['third_party/ffmpeg/LICENSE.md'],
# TODO(bugs.webrtc.org/1110): Remove this hack. This is not a lib.
--------------------------------------------------
执行编译命令
./tools_webrtc/android/build_aar.py --extra-gn-args 'is_debug=false is_component_build=false is_clang=true rtc_include_tests=false rtc_use_h264=true rtc_enable_protobuf=false use_rtti=true use_custom_libcxx=false' --build-dir ./out/release-build/m94/
--------------------------------------------------
编译结果输出路径
out/release-build/m94/armeabi-v7a/obj/libwebrtc.a
out/release-build/m94/armeabi-v7a/lib.java/sdk/android/libwebrtc.jar
【4】保存 Webrtc Android 相关头文件与库
#!/bin/bash
cd ./src
mkdir -p ../m94/
mkdir -p ../m94/include/third_party/
cp -r api/ ../m94/include/
cp -r audio/ ../m94/include/
cp -r base/ ../m94/include/
cp -r build_overrides/ ../m94/include/
cp -r call/ ../m94/include/
cp -r common_audio/ ../m94/include/
cp -r common_video/ ../m94/include/
cp -r logging/ ../m94/include/
cp -r media/ ../m94/include/
cp -r modules/ ../m94/include/
cp -r p2p/ ../m94/include/
cp -r pc/ ../m94/include/
cp -r rtc_base/ ../m94/include/
cp -r rtc_tools/ ../m94/include/
cp -r sdk/ ../m94/include/
cp -r stats/ ../m94/include/
cp -r style-guide/ ../m94/include/
cp -r system_wrappers/ ../m94/include/
cp -r test/ ../m94/include/
cp -r third_party/abseil-cpp/ ../m94/include/third_party/
cp -r tools_webrtc/ ../m94/include/
cp -r video/ ../m94/include/
cp .clang-format ../m94/include/
cp .git-blame-ignore-revs ../m94/include/
cp .gitignore ../m94/include/
cp .vpython ../m94/include/
cp abseil-in-webrtc.md ../m94/include/
cp AUTHORS ../m94/include/
cp BUILD.gn ../m94/include/
cp codereview.settings ../m94/include/
cp CODE_OF_CONDUCT.md ../m94/include/
cp common_types.h ../m94/include/
cp DEPS ../m94/include/
cp ENG_REVIEW_OWNERS ../m94/include/
cp LICENSE ../m94/include/
cp license_template.txt ../m94/include/
cp native-api.md ../m94/include/
cp OWNERS ../m94/include/
cp PATENTS ../m94/include/
cp PRESUBMIT.py ../m94/include/
cp presubmit_test.py ../m94/include/
cp presubmit_test_mocks.py ../m94/include/
cp pylintrc ../m94/include/
cp README.chromium ../m94/include/
cp README.md ../m94/include/
cp style-guide.md ../m94/include/
cp WATCHLISTS ../m94/include/
cp webrtc.gni ../m94/include/
cp whitespace.txt ../m94/include/
mkdir -p ../m94/lib/arm64-v8a/obj/
mkdir -p ../m94/lib/arm64-v8a/lib.java/sdk/android/
cp out/release-build/m94/arm64-v8a/obj/libwebrtc.a ../m94/lib/arm64-v8a/obj/
cp -r out/release-build/m94/arm64-v8a/lib.java/sdk/android/ ../m94/lib/arm64-v8a/lib.java/sdk/android/
mkdir -p ../m94/lib/armeabi-v7a/obj/
mkdir -p ../m94/lib/armeabi-v7a/lib.java/sdk/android/
cp out/release-build/m94/armeabi-v7a/obj/libwebrtc.a ../m94/lib/armeabi-v7a/obj/
cp -r out/release-build/m94/armeabi-v7a/lib.java/sdk/android/ ../m94/lib/armeabi-v7a/lib.java/sdk/android/
mkdir -p ../m94/lib/x86/obj/
mkdir -p ../m94/lib/x86/lib.java/sdk/android/
cp out/release-build/m94/x86/obj/libwebrtc.a ../m94/lib/x86/obj/
cp -r out/release-build/m94/x86/lib.java/sdk/android/ ../m94/lib/x86/lib.java/sdk/android/
mkdir -p ../m94/lib/x86_64/obj/
mkdir -p ../m94/lib/x86_64/lib.java/sdk/android/
cp out/release-build/m94/x86_64/obj/libwebrtc.a ../m94/lib/x86_64/obj/
cp -r out/release-build/m94/x86_64/lib.java/sdk/android/ ../m94/lib/x86_64/lib.java/sdk/android/
cp libwebrtc.aar ../m94/lib/
【5】适配 MediaSoup Android Client Lib
下载 mediasoup-client-android
git clone https://github.com/haiyangwu/mediasoup-client-android.git
将编译好的 webrtc m94 android 库的头文件与库文件拷贝到项目对应的 deps/webrtc 目录下
下载 mediasoup-demo-android
git clone https://github.com/haiyangwu/mediasoup-demo-android.git
settings.gradle 中配置 mediasoup-client-android 项目路径
build.gradle(:app) 中引用 mediasoup-client-android
即可编译 mediaoup-android APK
参考致谢
本博客为博主的学习实践总结,并参考了众多博主的博文,在此表示感谢,博主若有不足之处,请批评指正。