WebRTC音视频通话-WebRTC本地视频通话使用ossrs服务搭建

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

看到了两个错误提示:
在这里插入图片描述

扫描二维码关注公众号,回复: 16350033 查看本文章

我们需要执行

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
学习记录,每天不停进步。

猜你喜欢

转载自blog.csdn.net/gloryFlow/article/details/132257196