### mediasoup編譯及注意事項
Mediasoup c++ demo編譯總體流程為 webrtc -> mediasoup-demo -> Mediasoup-broadcaster-demo
整體流程參考文檔: http://www.reibang.com/p/00cc45ea4620
Webrtc
地址:https://webrtc.googlesource.com/src.git
參考文檔: https://mediasoup.org/documentation/v3/libmediasoupclient/installation/
$ mkdir -p /data/webrtc
$ cd /data/webrtc
# 檢出depot_tools工具
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
# 獲取webrtc源碼,同時會拉取依賴
$ fetch --nohooks webrtc
$ cd src
# 切換到m94分支
$ git checkout -b m94 refs/remotes/branch-heads/4606
# 獲取m94分支最近一次的提交記錄時間點(diǎn)
$ COMMIT_DATE=$(git log -n 1 --pretty=format:%ci)
# 更改depot_tools工具到和webrtc分支m94比較靠近的時間點(diǎn)
$ cd ../depot_tools
# Check out depot_tools revision from the same time:
$ git checkout $(git rev-list -n 1 --before="$COMMIT_DATE" main)
# 不更新depot_tools版本
$ export DEPOT_TOOLS_UPDATE=0
# 切換到webrtc編譯目錄
$ cd ../src
# 這里主要是runhook,視網(wǎng)絡(luò)情況耗時可能比較長
$ gclient sync
# 編譯參數(shù)設(shè)定, 輸出在out/m94目錄
$ gn gen out/m94 --args='is_debug=false is_component_build=false is_clang=false rtc_include_tests=false rtc_use_h264=true use_rtti=true use_custom_libcxx=false treat_warnings_as_errors=false use_ozone=true'
# 開始編譯
$ ninja -C out/m94
關(guān)于頭文件提热唇簟:
native-api的說明: https://webrtc.googlesource.com/src/+/HEAD/native-api.md
注意:需要在gclient sync同步完成后執(zhí)行腳本, 因為有些依賴不在webrtc倉庫中胎撤,而在第三方依賴中晓殊。
創(chuàng)建一個空目錄, 將下面腳本復(fù)制并執(zhí)行哩照, 注意可能需要修改webrtc_path為實際的webrtc的目錄
#!/bin/bash
#
webrtc_path="/data/webrtc/src"
cp -a ${webrtc_path}/api .
find api -type f? -name "*.cc" -delete
find api -type f? -name "*.gn" -delete
base_dir_lists=(
"common_audio/include"
"media/base"
"media/engine"
"modules/audio_coding/include"
"modules/audio_device/include"
"modules/audio_processing/include"
"modules/congestion_controller/include"
"modules/include"
"modules/rtp_rtcp/include"
"modules/rtp_rtcp/source"
"modules/utility/include"
"modules/video_coding/codecs/h264/include"
"modules/video_coding/codecs/vp8/include"
"modules/video_coding/codecs/vp9/include"
"modules/video_coding/include"
"pc"
"rtc_base"
"system_wrappers/include"
)
for i in ${base_dir_lists[@]}
do
? mkdir -p ${i}
? cp -f ${webrtc_path}/${i}/*.h ${i}/
done
for r in $(seq 10)
do
? echo "round ========= ${r} =========="
? for i in $(grep -r '^#include' |awk '{print $2}' |grep -v '<' |tr -d '"' |grep -v '^api/' |grep -v '^\.\.' |sort |uniq)
? do
? ? #echo "file: ${i}, dir:$(dirname ${i}), name: $(basename ${i})"
? ? if [[ -e ${i} || $(dirname ${i}) == '.' ]]; then
? ? ? continue
? ? fi
? ? echo ${i}
? ? for j in $(find ${webrtc_path} -name "$(basename ${i})")
? ? do
? ? ? if echo ${j} |grep -q "${i}"; then
? ? ? ? mkdir -p $(dirname ${i})
? ? ? ? cp ${j} $(dirname ${i})/
? ? ? fi
? ? done
? done
done
可選操作步驟(和上面編譯操作互斥挺物, 只需要選一個執(zhí)行):
不使用fetch命令下載源碼, 通過手動下載并設(shè)定指定分支飘弧, 然后通過gclient sync進(jìn)行依賴同步
mkdir -p /data/webrtc
cd /data/webrtc
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
git clone https://webrtc.googlesource.com/src.git
export PATH=/data/webrtc/depot_tools:$PATH
gclient config --name src --unmanaged? https://webrtc.googlesource.com/src.git
cd /data/webrtc/src
git fetch origin +refs/branch-heads/*:refs/remotes/branch-heads/*
git checkout -b m94 refs/remotes/branch-heads/4606
COMMIT_DATE=$(git log -n 1 --pretty=format:%ci)
cd /data/webrtc/depot_tools
git checkout $(git rev-list -n 1 --before="$COMMIT_DATE" main)
export DEPOT_TOOLS_UPDATE=0
cd /data/webrtc/src
gclient sync --no-history
gn gen out/m94 --args='is_debug=false is_component_build=false is_clang=false rtc_include_tests=false rtc_use_h264=true use_rtti=true use_custom_libcxx=false treat_warnings_as_errors=false use_ozone=true'
ninja -C out/m94
libmediasoupclient (可選)
下面步驟的Mediasoup-broadcaster-demo自帶編譯了libmediasoupclient依賴, 所以這項不是必須砚著, 僅用作檢驗Webrtc編譯是否正常
$ cd /data/webrtc
$ git clone https://github.com/versatica/libmediasoupclient.git
# 具體是否切換分支視情況而定次伶, 一般情況就是v3, 不需要切換
$ cd libmediasoupclient
$ cmake . -Bbuild -DLIBWEBRTC_INCLUDE_PATH:PATH=/data/webrtc/src -DLIBWEBRTC_BINARY_PATH:PATH=/data/webrtc/src/out/m94/obj
$ make -C build/
mediasoup-demo
mediasoup-demo是基于nodejs的, 依賴nodejs 版本 >= v16.0.0稽穆。
下一步操作的Mediasoup-broadcaster-demo需要依賴這里的服務(wù)端冠王;
同時mediasoup-demo的客戶端打開web瀏覽器頁面可以提供一個roomid給下一步mediasoup-broadcaster-demo使用
具體流程可以參考官方github文檔: https://github.com/versatica/mediasoup-demo
$ cd /data/webrtc
$ git clone https://github.com/versatica/mediasoup-demo.git
$ cd mediasoup-demo
$ git checkout v3
# 服務(wù)端編譯:
$ cd /data/webrtc/mediasoup-demo/server
$ npm --registry=https://registry.npmmirror.com install
# 客戶端編譯:
$ cd /data/webrtc/mediasoup-demo/app
# For node 16
$ npm --registry=https://registry.npmmirror.com install
# For node 18, use legacy peer dependencies
$ npm --registry=https://registry.npmmirror.com install --legacy-peer-deps?
# 服務(wù)端本地運(yùn)行:
$ cd /data/webrtc/mediasoup-demo/server
$ cp config.example.js config.js
# 運(yùn)行服務(wù)端需要提供一個證書密鑰對:fullchain.pem 和 privkey.pem
# 運(yùn)行前需要確保webRtcServerOptions和webRtcTransportOptions地址正確,否則可能出現(xiàn)無畫面情況
$ npm start
# 客戶端本地運(yùn)行(新開一個窗口):
$ cd /data/webrtc/mediasoup-demo/app
$ npm start