srs的webrtc信令分析

关于webrtc的流信令只有四个

/rtc/v1/publish/,这是推流接口,是推流客户端跟SRS交换SDP的接口
/rtc/v1/play/,这是拉流接口,是拉流客户端跟SRS交换SDP的接口
/rtc/v1/whip/,这也是推流接口,作用是也是交换SDP,只是采用的是WebRTC 的标准信令
/rtc/v1/whip-play/,这是拉流接口,作用是也是交换SDP,只是采用的是WebRTC 的标准信令

POST /rtc/v1/publish/
Body in JSON:

{
  "api": "https://d.ossrs.net/rtc/v1/publish/"
  "streamurl": "webrtc://d.ossrs.net/live/3abd9f34",
  "sdp": "v=0\r\n......\r\na=ssrc:2064016335 label:c8243ce9-ace5-4d17-9184-41a2543101b5\r\n"
}

返回如下

{
  "code": 0
  "sdp": "v=0\r\n......\r\na=candidate:1 1 udp 2130706431 172.18.0.4 8000 typ host generation 0\r\n"
  "sessionid": "186tj710:hMub"
}

这个是srs自定义的信令,更多详细见上文给到的官网
关于whip和whep,webrtc官方没有指定标准信令,但这个几乎快成为公认的webrtc信令了,obs最新版也开始支持whip信令推流webrtc了。
什么是whip
全称: WebRTC-HTTP ingestion protocol (WHIP).
rfc地址: rfc-draft-murillo-whip-00

webrtc publish/
方法: http post
uri: http://hostname:hostport/publish/roomId/uid
http post body: offerSdp
返回:
http body: answerSdp
这个srs官网没有给出,因为他是公开的标准,详细见:whip和whep

除此之外srs还有很多其他特别好用的信令,可以用curl命令执行这些信令作测试。
1.查看当前有多少人在推流拉流

GET http://yourip:1985/api/v1/streams

“clients”:2共有2个客户端在推拉流,“send_bytes”,“recv_bytes”,srs总共收到了多少流和推出了多少流。publish,推流客户端的id等。

{"code":0,"server":"vid-k73qd86","service":"d131vgjy","pid":"14885",
"streams":[{"id":"vid-31x2o91",
"name":"livestreamShow","vhost":"vid-5735q8a",
"app":"live",
"tcUrl":"webrtc://118.190.201.242:1990/live",
"url":"/live/livestreamShow","live_ms":1700663886254,
"clients":2,"frames":0,
"send_bytes":86035991,"recv_bytes":70223513,
"kbps":{"recv_30s":279,"send_30s":335},
"publish":{"active":true,"cid":"980tr2m6"},
"video":null,"audio":null}]}

2.可以看到获得了这个2个客户端详细的信息,他们的ip,name,id等

GET http://yourip:1985/api/v1/clients
{"code":0,"server":"vid-k73qd86","service":"d131vgjy","pid":"14885","clients":[

{"id":"980tr2m6","vhost":"vid-5735q8a","stream":"vid-31x2o91",
"ip":"111.32.97.245","pageUrl":"","swfUrl":"","tcUrl":"webrtc://118.190.201.242:1990/live",
"url":"/live/livestreamShow","name":"livestreamShow","type":"rtc-publish",
"publish":true,"alive":2355.50,"send_bytes":1607988,"recv_bytes":83824825,"kbps":{"recv_30s":263,"send_30s":5}},

{"id":"flmxmk29","vhost":"vid-5735q8a","stream":"vid-31x2o91",
"ip":"111.32.97.245","pageUrl":"","swfUrl":"","tcUrl":"webrtc://118.190.201.242:1990/live",
"url":"/live/livestreamShow","name":"livestreamShow","type":"rtc-play",
"publish":false,"alive":2393.43,"send_bytes":102710561,"recv_bytes":2065048,"kbps":{"recv_30s":3,"send_30s":167}}]}

3.包括踢掉一些用户:
DELETE /api/v1/clients/{id}
srs的控制台踢人的按钮,就是使用的这个信令。
srs的webrtc信令分析_第1张图片4.以下两条跟上面的功能相同,在/clients/id,查找特定id的信息

curl -v -X GET http://192.168.1.170:1985/api/v1/clients/426 && echo ""
curl -v -X DELETE http://192.168.1.170:1985/api/v1/clients/426 && echo ""

curl -v -X GET http://118.190.201.242:1985/api/v1/vhosts/ && echo “”

{"code":0,"server":"vid-k73qd86","service":"d131vgjy","pid":"14885",
"vhosts":[{"id":"vid-5735q8a","name":"__defaultVhost__","enabled":true,"clients":2,
"streams":1,"send_bytes":246360125,"recv_bytes":223127278,
"kbps":{"recv_30s":256,"send_30s":296},"hls":{"enabled":false}}]}

5.SRS提供系统的摘要信息接口,譬如当前的内存、CPU、网络、负载使用率。

GET http://118.190.201.242:1985/api/v1/summaries/ && echo ""
{"code":0,"server":"vid-k73qd86","service":"d131vgjy","pid":"14885","urls":{"versions":"the version of SRS","summaries":"the summary(pid, argv, pwd, cpu, mem) of SRS","rusages":"the rusage of SRS","self_proc_stats":"the self process stats","system_proc_stats":"the system process stats","meminfos":"the meminfo of system","authors":"the license, copyright, authors and contributors","features":"the supported features of SRS","requests":"the request itself, for http debug","vhosts":"manage all vhosts or specified vhost","streams":"manage all streams or specified stream","clients":"manage all clients or specified client, default query top 10 clients","raw":"raw api for srs, support CUID srs for instance the config","clusters":"origin cluster server API","perf":"System performance stat","tcmalloc":"tcmalloc api with params ?page=summary|api"},"tests":{"requests":"show the request info","errors":"always return an error 100","redirects":"always redirect to /api/v1/test/errors","[vhost]":"http vhost for http://error.srs.com:1985/api/v1/tests/errors"}}

srs全部的api如下:
地址是:http://192.168.1.170:1985/api/v1,主要包含的子api有:

API	     Example	 Description
server	4481	服务器标识
versions	/api/v1/versions	获取服务器版本信息
summaries	/api/v1/summaries	获取服务器的摘要信息
rusages	/api/v1/rusages	获取服务器资源使用信息
self_proc_stats	/api/v1/self_proc_stats	获取服务器进程信息
system_proc_stats	/api/v1/system_proc_stats	获取服务器所有进程情况
meminfos	/api/v1/meminfos	获取服务器内存使用情况
authors	/api/v1/authors	获取作者、版权和License信息
features	/api/v1/features	获取系统支持的功能列表
requests	/api/v1/requests	获取请求的信息,即当前发起的请求的详细信息
vhosts	/api/v1/vhosts	获取服务器上的vhosts信息
streams	/api/v1/streams	获取服务器的streams信息
clients	/api/v1/clients	获取服务器的clients信息,默认获取前10个
configs	/api/v1/configs	CUID配置,RAW API
publish	/rtc/v1/publish/	WebRTC推流的API
play	/rtc/v1/play/	WebRTC播放流的API

详细见官网:
http-api 信令https://ossrs.net/lts/zh-cn/docs/v4/doc/http-api

srs官网还有个在线的curl界面类型的工具
http://ossrs.net/srs.release/http-rest/
srs的webrtc信令分析_第2张图片

你可能感兴趣的:(Server,webrtc,srs)