iOS開發-ossrs服務WebRTC本地視頻通話服務搭建
之前開發中使用到了ossrs,這里記錄一下ossrs支持的WebRTC本地服務搭建。
一、ossrs是什么?
ossrs是什么呢?
SRS(Simple Realtime Server)是一個簡單高效的實時視頻服務器,支持RTMP、WebRTC、HLS、HTTP-FLV、SRT等多種實時流媒體協議。
官網地址:https://ossrs.net/lts/zh-cn/
二、為電腦安裝cmake
由于電腦未安裝cmake,后續會用到cmake,先安裝好這個cmake。
通過brew來安裝
brew install cmake
執行命令發現了錯誤
Running brew update --auto-update
…
fatal: not in a git directory
當我這里使用brew update --auto-update還是報fatal: not in a git directory錯誤提示。
解決方式
brew -v
看到了兩個錯誤提示:
我們需要執行
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
和
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
執行命令后在執行brew -v沒有報錯了,可以正常安裝軟件了。
下一步繼續安裝cmake
brew install cmake
耐心等待安裝結果
結果如圖所示
安裝好cmake后,我們繼續配置SRS的WebRTC服務。
二、SRS的WebRTC配置
SRS支持WebRTC,可以做會議或視頻聊天。
下載源碼,推薦用Ubuntu20:
git clone -b develop https://gitee.com/ossrs/srs.git
編譯,注意需要切換到srs/trunk目錄:
cd srs/trunk./configure
make
提示還需要安裝
trunk/objs, OS_IS_OSX: YES, OS_IS_X86_64: YES
Please install automake
執行
brew install automake
結果
To link this version, run:
brew link automake
在執行
brew link automake
成功之后繼續執行
./configure
make
耐心等待編譯結果
下一步
ifconfig查看ip地址192.168.10.100
我這里使用WebRTC中HTTPS服務
WebRTC using HTTPS
若需要在非本機使用WebRTC,比如SRS運行在遠程服務器,在筆記本或者手機上使用WebRTC,則需要開啟HTTPS API。
啟動服務器:
CANDIDATE="192.168.10.100"
./objs/srs -c conf/https.rtc.conf
Note: 請將IP換成你的SRS的IP地址。
Note: 請將CANDIDATE設置為服務器的外網地址,詳細請閱讀WebRTC: CANDIDATE。
發現結果srs(49644,0x11bbcc600) malloc: nano zone abandoned due to inability to preallocate reserved vm space.
如圖
解決方案查看https://stackoverflow.com/a/70209891/17679565
我這里使用的是環境變量配置
open ~/.bash_profile
添加
export MallocNanoZone=‘0’
執行使配置生效
source ~/.bash_profile
之后在執行,啟動服務器
CANDIDATE="192.168.10.100"
./objs/srs -c conf/https.rtc.conf
出現錯誤如下
找到trunk > conf > https.rtc.conf 修改http_server的listen端口為9090(由于我電腦已經安裝nginx,8080端口被占用了)
再執行
CANDIDATE="192.168.10.100"
./objs/srs -c conf/https.rtc.conf
最終啟動成功了。
檢查SRS是否成功啟動,可以打開 http://localhost:9090/ ,
Note: 請將IP換成你的SRS的IP地址。
Note: 請將CANDIDATE設置為服務器的外網地址,詳細請閱讀WebRTC: CANDIDATE。
Remark: 請使用你的證書文件,代替上面配置中的key和cert,請參考 HTTPS API 以及 HTTPS Callback 以及 HTTPS Live Streaming, 當然了HTTPS的反向代理也能和SRS工作很好,比如Nginx代理到SRS。
http://localhost:9090/players/srs_player.html?schema=http&port=9090&api=9090
使用WebRTC推流到SRS:WebRTC: Publish
打開頁面觀看WebRTC流:WebRTC: Play
https://192.168.10.100:8088/players/rtc_player.html?autostart=true&stream=livestream&api=1990&schema=https
注意:自簽名證書,在空白處輸入thisisunsafe(注意沒空格)。
Note: 可以打開不同的頁面,推拉不同的流,就可以實現視頻聊天了。
之后的通過iOS端使用GoogleWebRTC庫實現調用ossrs的服務
三、小結
iOS開發-ossrs服務WebRTC本地視頻服務搭建以及出現了各種問題解決。
https://blog.csdn.net/gloryFlow/article/details/132257196
學習記錄,每天不停進步。