webrtc編譯


webrtc編譯

最近研究 libmediasoupclient,而 libmediasoupclient 又依賴 libwebrtc,所以首先就想着先在windows上編譯一個webrtc的庫,先是在網上找了一大堆,發現都不全面,導致各種問題,這里做個歸納總結。

由於 webrtc 是google的產物,而且很多東西都是自成一家,所以前提是需要FQ的。准備一個本地的代理,例如127.0.0.1:10080

windows

掛代理

代理需要掛在git和cmd下,后面通過git拉取depot_tools和webrtc都要借助git的代理,而掛在cmd下是為了在depot_tools下載好之后安裝一系列工具鏈時下載用。

git

通過git拉取代碼有http、https、ssh三種方式,對於這三種方式要分兩種方式掛代理。詳細可參考Git設置代理。本文后續使用的是https方式,所以只需要配置http和https即可。

  • http和https
    • git命令方式
      這里只針對后續可能使用的url地址使用代理,如果不帶特定的url的話,會作用於全局。
      git config --global http.https://*.googlesource.com.proxy http://127.0.0.1:10080
      git config --global https.https://*.googlesource.com.proxy http://127.0.0.1:10080
      git config --global http.https://*.appspot.com.proxy http://127.0.0.1:10080
      git config --global https.https://*.appspot.com.proxy http://127.0.0.1:10080
      
    • 修改git配置文件
      修改git的配置文件 .gitconfig
      [http "https://*.googlesource.com"]
          proxy = http://127.0.0.1:10080
      [https "https://*.googlesource.com"]
          proxy = http://127.0.0.1:10080
      [http "https://*.appspot.com"]
          proxy = http://127.0.0.1:10080
      [https "https://*.appspot.com"]
          proxy = http://127.0.0.1:10080
      
  • ssh
    修改 .ssh 文件夾下的 config 文件
    Host googlesource.com
    User git
    ProxyCommand connect -H 127.0.0.1:10080 %h %p
    
    如果是socks5代理的話,最后的選項 -H 改成 -S

cmd

在cmd中直接設置環境變量,這兩條命令只在當前窗口有效!

set http_proxy=127.0.0.1:10080
set https_proxy=127.0.0.1:10080

安裝depot_tools

按照webrtc源碼編譯要求的,編譯webrtc之前的准備工作需要安裝google自家的depot_tools工具鏈。這個工具鏈的安裝部署直接關系到后面是否能順利下載webrtc的源碼。

按照depot_tools安裝描述的過程,大致分為以下幾步:

  1. 獲取 depot_tools

    • 使用 git 工具直接從google源碼庫中拉取

      git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
      
    • 直接下載depot_tools包並解壓(解壓時要以防某些解壓工具不將壓縮包中的隱藏文件一並解壓!) https://storage.googleapis.com/chrome-infra/depot_tools.zip

  2. 設置環境變量
    將depot_tools文件夾所在路徑設置在系統環境變量 PATH 的最前面!

  3. 執行 gclient
    通過cmd運行gclient,注意在此之前設置了cmd的代理!這條命令執行完成后,depot_tools目錄下會多出很多東西,像python、git等工具都會被下載並安裝在depot_tools的子目錄下,被用於后續的過程,所以即使本地沒有安裝這些工具也不要緊。
    這條指令執行完后,大致會下載700-800左右的內容,最后會提示錯誤,因為后續只需要用來同步webrtc源碼以及構建編譯腳本等,所以忽略這個報錯即可。
    WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be created.
    Error: client not configured; see 'gclient config'

  4. 創建chrome/4147d的分支

    git checkout -b m84 origin/chrome/4147
    

    並再次執行 gclient sync

編譯webrtc

下載源碼

按照以下命令一步一步執行,第三步的fetch最花費時間,大概需要下載10G的內容,所以留意你代理的流量套餐!

mkdir webrtc
cd webrtc
fetch --nohooks webrtc
gclient sync

編譯

我這里按照mediasoap要求的m84版本的webrtc編譯為例

  1. 先創建m84版本(branch-heads/4147)的分支m84,然后執行 gclient sync

    git checkout -b m84 refs/remotes/branch-heads/4147
    
  2. 在環境變量中先設置 DEPOT_TOOLS_WIN_TOOLCHAIN 為0,否則在生成ninja工程時會報錯

    set DEPOT_TOOLS_WIN_TOOLCHAIN=0
    
  3. 生成ninja工程

    gn gen out/m84 --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"
    

    如果本地已安裝有python3,並且被首選為python3的執行路徑,這里有可能會出現報錯,如:ValueError: path is on mount 'C:', start on mount 'F:',此時可以將本地安裝的python3卸載或者去掉其環境變量,讓depot_tool使用自帶的python組件即可。

  4. 編譯

    ninja -C out/m84 >> compile.log
    
  5. 編譯過程中出現錯誤終端,打開compile.log文件查看失敗的地方:

    [1466/3605] CC obj/third_party/ffmpeg/ffmpeg_internal/pcm.obj
    FAILED: obj/third_party/ffmpeg/ffmpeg_internal/pcm.obj 
    ...
    ...
    ...
    ../../third_party/ffmpeg/libavcodec/pcm.c(623): error C2059: 語法錯誤:“字符串”
    

    這里我將源文件中對應報錯的行注釋掉。

  6. 繼續執行第4步,然后又出現下列錯誤

    [1834/2133] CXX obj/modules/video_coding/webrtc_h264/h264.obj
    FAILED: obj/modules/video_coding/webrtc_h264/h264.obj 
    ...
    ...
    ...
    E:\google\webrtc\src\modules/video_coding/codecs/h264/h264_decoder_impl.h(21): fatal error C1189: #error:  "See: bugs.webrtc.org/9213#c13."
    

    仍然注釋掉報錯行之后繼續第4步,發現后續還會出現類似的報錯,所以這里一次性注釋掉另外三個文件中的行:See: bugs.webrtc.org/9213#c13.。三個文件分別是:

    • webrtc\src\modules/video_coding/codecs/h264/h264_decoder_impl.h(21)
    • webrtc\src\modules/video_coding/codecs/h264/h264_encoder_impl.h(21)
    • webrtc\src\modules/video_coding/codecs/h264/h264_color_space.h(20)
  7. 最終生成結果顯示一大堆鏈接錯誤

    [286/289] LINK peerconnection_client.exe peerconnection_client.exe.pdb
    FAILED: peerconnection_client.exe peerconnection_client.exe.pdb 
    ...
    error LNK2001: 無法解析的外部符號 avpriv_emms_asm
    ...
    ./peerconnection_client.exe : fatal error LNK1120: 1 個無法解析的外部命令
    [287/289] LINK(DLL) webrtc_unity_plugin.dll webrtc_unity_plugin.dll.lib webrtc_unity_plugin.dll.pdb
    FAILED: webrtc_unity_plugin.dll webrtc_unity_plugin.dll.lib webrtc_unity_plugin.dll.pdb 
    ...
    error LNK2001: 無法解析的外部符號 avpriv_emms_as
    ...
    ./webrtc_unity_plugin.dll : fatal error LNK1120: 1 個無法解析的外部命令
    

    忽略,反正在out/m84/obj目錄下已經生成我要的webrtc.lib文件了。

Linux

安裝depot_tools

  1. 拉取depot_tools

    先設置git的代理,然后拉取depot_tools的代碼,之后設置depot_tools的路徑到 PATH 環變量。

  2. gclient sync

    在depot_tools目錄下執行 gclient sync 之前,先做兩件事:

    • 修改 update_depot_tools 文件
      將depot_tools目錄下的 update_depot_tools 文件中關於使用root用戶時就退出的地方去掉,否則運行這條指令的時候會提示Running depot tools as root is sad.,然后就沒了反應。
    • 設置 curl 或者整個linux環境代理
      這里直接設置整個linux環境的代理,否則執行這條指令之后會提示curl https://chrome-infra-packages.appspot.com/ 失敗之類的提示。
      可以在 ~/.bashrc 文件中最后加入下列兩條,之后每次進入終端后,輸入命令setproxy就可以了。
      alias setproxy="export http_proxy=http://10.18.0.60:10080;export https_proxy=http://10.18.0.60:10080;echo 'HTTP Proxy on';"
      alias unsetproxy="unset http_proxy; unset https_proxy; echo 'HTTP Proxy off';"
      

編譯webrtc

參考windows上編譯webrtc的步驟。

ubuntu上gcc版本最好在6.3之上,並且pkg-config和python已經安裝,若pkg-config未安裝,則會在生成ninja工程時報錯,若gcc版本過低,則在編譯時會報錯!

參考

WebRTC development
WebRTC Development
depot_tools_tutorial
Git設置代理
curl 設置代理
Windows配置代理下載depot_tools
在win10上編譯webRTC(問題篇)
Windows上WebRTC的源碼下載和編譯
Windows下webrtc.lib 的編譯及vs工程中使用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM