v4_CN_Home · ossrs/srs Wiki · GitHub
v4_CN_SampleRTMP · ossrs/srs Wiki · GitHub
海康摄像头发起注册后,srs能停在sip入口函数处
Windows + VMware player + Ubuntu + clion
Windows + vscode
不要直接在远程真机调试,因为本地虚拟机可以开放所有端口,开发好后再部署到真机上。
其中建议Windows配置高一点,内存最好16G,i5处理器,不然时间都浪费在卡顿上面了
其中Ubuntu使用韦东山老师的开发板资料给一个虚拟机,里面安装了常见的开发工具,资料包里也包括了VMware player
用clion打开srs的本地目录
参考 Remote server configuration—CLion 配置下sftp部署参数,其中web server用
sudo python -m http.server 80 -d /home/book >/dev/null 2>&1 & 来配置如下
再参考 使用Clion优雅的完全远程自动同步和远程调试c++ - 云+社区 - 腾讯云
再参考上面博客里配置其他参数
可以发现本地clion里的修改立即上传了,因为同步是更改端发起的,所以只有自动上传并没有自动下载同步的功能,因为修改是clion端能感知的。
远程调试
安装工具,其实那个虚拟机里都安装,不需要安装,这里备注下
apt install cmake -y
apt install gcc-c++ -y
apt install gdb -y
apt install gdb-gdbserver -y
参考 使用Clion优雅的完全远程自动同步和远程调试c++ - 云+社区 - 腾讯云 里面的远程调试配置
./configure --with-gb28181 --debug && make clean && make # 打开调试
参考004-SRS配置和热加载_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili
我们还是把日志打印到文件,这样便于查看,截图里是打印到控制台了
国标配置参考国产开源流媒体SRS4.0对视频监控GB28181的支持,我这里用的是一台海康摄像头
killall -9 srs # 先杀死系统中多余的srs进程
启动服务,直接二进制运行即可,也可以后台以服务形式运行
./objs/srs -c conf/push.gb28181.conf # 先正常运行下,用的是一台海康摄像头
tail -f ./objs/srs.log # 查看日志,待会可以根据里面的关键词在代码里面全局搜索
GB28181-SIP over UDP
gb28181: request client
book@100ask:~/git/srs/trunk$ tail -f ./objs/srs.log [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1][MAIN] SRS/4.0.56(Leo), MIT [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] authors: Winlin,Wenjie,Runner365,John,B.P.Y,Lixin [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] contributors: winlinwenjie.zhao<[email protected]> xiangcheng.liu naijia.liu alcoholyi byteman chad.wang suhetao Johnny karthikeyan StevenLiu zhengfl tufang14 allspace niesongsong rudeb0t CallMeNP synote lovecat panda1986<[email protected]> YueHonghui ThomasDreibholz JuntaoLiu RocFang MakarovYaroslav MirkoVelic HuiZhang(huzhang2) OtterWa walkermi<[email protected]> haofz ME_Kun_Han ljx0305 cenxinwei StarBrilliant xubin intliang flowerwrong YLX<[email protected]> J Harlan hankun JonathanBarratt KeeganH StevenLiu liuxc0116 ChengdongZhang lovacat qiang.li HungMingWu Himer xialixin alphonsetai Michael.Ma lam2003 runner365 XiaofengWang XiaLixin xiaozhihong HuyaJohn yanghuiwen Bepartofyou<[email protected]> l<[email protected]> xfalcon cgh LiPeng xiaozhihong yajun18 liulichuan yapingcat chenchengbin chenhaibo jasongwq [email protected] yinjiaoyuan PieerePi JesseXi PieerePi<[email protected]> ghostsf [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] cwd=/home/book/git/srs/trunk, work_dir=./, build: 2020-12-23 01:11:26, configure: --x86-x64 --with-gb28181 --debug, uname: Linux 100ask 5.4.0-56-generic #62~18.04.1-Ubuntu SMP Tue Nov 24 10:07:50 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux, osx: 0 [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] configure detail: --prefix=/usr/local/srs --hls=on --hds=off --dvr=on --ssl=on --https=on --ssl-1-0=off --sys-ssl=off --transcode=on --ingest=on --stat=on --http-callback=on --http-server=on --stream-caster=on --http-api=on --utest=off --srt=off --rtc=on --simulator=off --gb28181=on --cxx11=off --cxx14=off --ffmpeg-fit=on --nasm=off --srtp-nasm=off --sendmmsg=off --clean=on --gperf=off --gmc=off --gmd=off --gmp=off --gcp=off --gprof=off --log-trace --debug --cc=gcc --cxx=g++ --ar=ar --ld=ld --randlib=randlib [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] srs checking config... [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] ips, iface[0] ens33 ipv4 0x11043 192.168.10.44, iface[1] ens33 ipv6 0x11043 fe80::c8cc:71f1:b333:863c4.683077e-310ns33 [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] devices, intranet ens33 192.168.10.44, intranet ens33 fe80::c8cc:71f1:b333:863c4.683077e-310ns33 [2020-12-23 01:49:33.464][Warn][101601][14dlb7v1][0] stats network use index=0, ip=192.168.10.44, ifname=ens33 [2020-12-23 01:49:33.464][Warn][101601][14dlb7v1][0] stats disk not configed, disk iops disabled. [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] you can check log by: tail -f ./objs/srs.log (@see https://github.com/ossrs/srs/wiki/v1_CN_SrsLog) [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] please check SRS by: ./etc/init.d/srs status [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] features, rch:on, dash:on, hls:on, hds:off, srt:off, hc:on, ha:on, hs:on, hp:on, dvr:on, trans:on, inge:on, stat:on, sc:on [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] SRS on amd64 x86_64, conf:conf/push.gb28181.conf, limit:1000, writev:1024, encoding:little-endian, HZ:100 [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] mw sleep:350ms. mr enabled:on, default:0, sleep:350ms [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] gc:on, pq:30000ms, cscc:[0,16), csa:on, tn:on(may hurts performance), ss:auto(guess by merged write) [2020-12-23 01:49:33.464][Trace][101601][14dlb7v1] system default latency(ms): mw(0-350) + mr(0-350) + play-queue(0-30000) [2020-12-23 01:49:33.464][Warn][101601][14dlb7v1][0] SRS/4.0.56 is not stable [2020-12-23 01:49:33.465][Trace][101601][14dlb7v1] st_init success, use epoll [2020-12-23 01:49:33.469][Trace][101601][14dlb7v1] fingerprint=BD:31:61:C4:77:70:AC:48:60:91:F3:6A:9E:35:09:DE:29:F9:2E:36:1A:3C:0F:FF:A8:F0:C1:80:AF:D2:7B:DE [2020-12-23 01:49:33.469][Trace][101601][14dlb7v1] RTC server init ok [2020-12-23 01:49:33.469][Trace][101601][14dlb7v1] http: root mount to ./objs/nginx/html [2020-12-23 01:49:33.469][Trace][101601][14dlb7v1] server main cid=14dlb7v1, pid=101601, ppid=81702, asprocess=0 [2020-12-23 01:49:33.470][Trace][101601][14dlb7v1] write pid=101601 to ./objs/srs.pid success! [2020-12-23 01:49:33.470][Trace][101601][14dlb7v1] RTMP listen at tcp://0.0.0.0:1935, fd=8 [2020-12-23 01:49:33.470][Trace][101601][14dlb7v1] HTTP-API listen at tcp://0.0.0.0:1985, fd=9 [2020-12-23 01:49:33.470][Trace][101601][14dlb7v1] HTTP-Server listen at tcp://0.0.0.0:8080, fd=10 [2020-12-23 01:49:33.471][Trace][101601][14dlb7v1] UDP #11 LISTEN at 0.0.0.0:5060, SO_SNDBUF(default=212992, expect=10485760, actual=425984, r0=0), SO_RCVBUF(default=212992, expect=10485760, actual=425984, r0=0) [2020-12-23 01:49:33.471][Trace][101601][14dlb7v1] GB28181-SIP over UDP listen at udp://0.0.0.0:5060, fd=11 [2020-12-23 01:49:33.471][Trace][101601][14dlb7v1] signal installed, reload=1, reopen=10, fast_quit=15, grace_quit=3 [2020-12-23 01:49:33.471][Trace][101601][14dlb7v1] http: api mount /console to ./objs/nginx/html/console [2020-12-23 01:49:33.471][Trace][101601][19202024] RTC: connection manager run [2020-12-23 01:49:33.471][Trace][101601][9q754719] GB28181: connection manager run [2020-12-23 01:49:33.471][Trace][101601][51636wat] GB28181TCP: connection manager run [2020-12-23 01:49:33.471][Trace][101601][1nl5402f] TCP: connection manager run [2020-12-23 01:49:36.882][Trace][101601][14dlb7v1] gb28181: request client id=34020000001320000001 peer(192.168.10.5, 5060) [2020-12-23 01:49:36.882][Trace][101601][14dlb7v1] gb28181: request method=REGISTER, uri=sip:34020000002000000001@3402000000, version=SIP/2.0 expires=3600 [2020-12-23 01:49:38.884][Trace][101601][v1p09yu4] gb28181: sip session=34020000001320000001 peer(192.168.10.5, 5060) status(RegisterOk,AliveOk) duration(2,1) [2020-12-23 01:49:39.884][Trace][101601][v1p09yu4] gb28181: generate ssrc id=34020000001320000001@34020000001320000001, ssrc=9093125 [2020-12-23 01:49:39.885][Trace][101601][v1p09yu4] new source, stream_url=/live/34020000001320000001@34020000001320000001 [2020-12-23 01:49:39.888][Trace][101601][v1p09yu4] hls: win=60000ms, frag=10000ms, prefix=, path=./objs/nginx/html, m3u8=[app]/[stream].m3u8, ts=[app]/[stream]-[seq].ts, aof=2.00, floor=0, clean=1, waitk=1, dispose=0ms, dts_directly=1 [2020-12-23 01:49:39.888][Trace][101601][v1p09yu4] ignore disabled exec for vhost= [2020-12-23 01:49:39.888][Trace][101601][v1p09yu4] gb28181: create new stream channel id:34020000001320000001@34020000001320000001 rtmp url=rtmp://127.0.0.1:1935/live/34020000001320000001@34020000001320000001 [2020-12-23 01:49:39.893][Trace][101601][14dlb7v1] gb28181: request client id=34020000001320000001, peer(192.168.10.5, 5060) [2020-12-23 01:49:39.893][Trace][101601][14dlb7v1] gb28181: respone method=INVITE, uri=34020000002000000001@3402000000, version=SIP/2.0 [2020-12-23 01:49:39.894][Trace][101601][14dlb7v1] gb28181: INVITE response 34020000001320000001 client status=100 [2020-12-23 01:49:39.934][Trace][101601][14dlb7v1] gb28181: ssrc in y line is 9093125:8ac005 [2020-12-23 01:49:39.934][Trace][101601][14dlb7v1] gb28181: request client id=34020000001320000001, peer(192.168.10.5, 5060) [2020-12-23 01:49:39.934][Trace][101601][14dlb7v1] gb28181: respone method=INVITE, uri=34020000002000000001@3402000000, version=SIP/2.0 [2020-12-23 01:49:39.934][Trace][101601][14dlb7v1] gb28181: INVITE response 34020000001320000001 client status=200 [2020-12-23 01:49:39.934][Trace][101601][14dlb7v1] gb28181: device unique id is 34020000001320000001@34020000001320000001 [2020-12-23 01:49:39.938][Trace][101601][88806x62] rtsp: serve 192.168.10.5:15060 [2020-12-23 01:49:40.036][Trace][101601][73516905] gb28181: SrsPsJitterBuffer key=34020000001320000001@34020000001320000001 reallocate ps buffer size(4724>0) resize(14964) [2020-12-23 01:49:40.037][Trace][101601][73516905] gb28181: ps map video es_type=h264(1b), es_id=e0, es_info_length=28 [2020-12-23 01:49:40.037][Trace][101601][73516905] 35B video sh, codec(7, profile=Main, level=3.1, 1280x720, 0kbps, 0.0fps, 0.0s) [2020-12-23 01:49:40.884][Trace][101601][v1p09yu4] gb28181: 34020000001320000001 clients device=34020000001320000001 send invite code=0 [2020-12-23 01:49:46.814][Trace][101601][73516905] gb28181: client id=34020000001320000001@34020000001320000001, ssrc=0x8ac005, peer(192.168.10.5, 15060), rtmp muxer is alive [2020-12-23 01:49:49.491][Trace][101601][73516905] -> HLS time=10010919ms, sno=1, [email protected], dur=0.00, dva=9471p [2020-12-23 01:49:56.829][Trace][101601][73516905] gb28181: client id=34020000001320000001@34020000001320000001, ssrc=0x8ac005, peer(192.168.10.5, 15060), rtmp muxer is alive [2020-12-23 01:49:59.544][Trace][101601][73516905] -> HLS time=20064011ms, sno=2, [email protected], dur=0.00, dva=7513p [2020-12-23 01:50:06.832][Trace][101601][88806x62] <- GBS SrsGb28181TcpPsRtpProcessor::on_rtp_packet_jitter gb28181: client_id , peer(, 15060) ps rtp packet 732B, age=33361561, vt=2/96, sts=714/2419200/0x8ac005, paylod=720B [2020-12-23 01:50:09.581][Trace][101601][73516905] -> HLS time=30100639ms, sno=3, [email protected], dur=0.00, dva=5554p [2020-12-23 01:50:16.851][Trace][101601][73516905] gb28181: client id=34020000001320000001@34020000001320000001, ssrc=0x8ac005, peer(192.168.10.5, 15060), rtmp muxer is alive [2020-12-23 01:50:19.597][Trace][101601][73516905] -> HLS time=40116476ms, sno=4, [email protected], dur=0.00, dva=3597p [2020-12-23 01:50:26.851][Trace][101601][88806x62] <- GBS SrsGb28181TcpPsRtpProcessor::on_rtp_packet_jitter gb28181: client_id , peer(, 15060) ps rtp packet 344B, age=53366509, vt=2/96, sts=1245/4222800/0x8ac005, paylod=332B [2020-12-23 01:50:29.616][Trace][101601][73516905] -> HLS time=50136465ms, sno=5, [email protected], dur=0.00, dva=1639p [2020-12-23 01:50:36.874][Trace][101601][73516905] gb28181: client id=34020000001320000001@34020000001320000001, ssrc=0x8ac005, peer(192.168.10.5, 15060), rtmp muxer is alive [2020-12-23 01:50:38.901][Trace][101601][v1p09yu4] gb28181: sip session=34020000001320000001 peer(192.168.10.5, 5060) status(RegisterOk,AliveOk) duration(62,0) [2020-12-23 01:50:38.901][Trace][101601][v1p09yu4] gb28181: sip session=34020000001320000001 device=34020000001320000001 status(ON, InviteOk), duration(58) [2020-12-23 01:50:39.669][Trace][101601][73516905] -> HLS time=60188819ms, sno=6, [email protected], dur=0.00, dva=879p [2020-12-23 01:50:45.210][Trace][101601][38ir4367] RTMP client ip=127.0.0.1:37466, fd=15 [2020-12-23 01:50:45.220][Trace][101601][38ir4367] complex handshake success [2020-12-23 01:50:45.223][Trace][101601][38ir4367] connect app, tcUrl=rtmp://127.0.0.1:1935/live, pageUrl=, swfUrl=, schema=rtmp, vhost=127.0.0.1, port=1935, app=live, args=null [2020-12-23 01:50:45.223][Trace][101601][38ir4367] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=128, out.chunk=128 [2020-12-23 01:50:45.305][Trace][101601][38ir4367] ignore AMF0/AMF3 command message. [2020-12-23 01:50:45.306][Trace][101601][38ir4367] ignore AMF0/AMF3 command message. [2020-12-23 01:50:45.307][Trace][101601][38ir4367] client identified, type=Play, vhost=127.0.0.1, app=live, stream=34020000001320000001@34020000001320000001, param=, duration=-1ms [2020-12-23 01:50:45.307][Trace][101601][38ir4367] connected stream, tcUrl=rtmp://127.0.0.1:1935/live, pageUrl=, swfUrl=, schema=rtmp, vhost=__defaultVhost__, port=1935, app=live, stream=34020000001320000001@34020000001320000001, param=, args=null [2020-12-23 01:50:45.307][Trace][101601][38ir4367] source url=/live/34020000001320000001@34020000001320000001, ip=127.0.0.1, cache=1, is_edge=0, source_id=v1p09yu4/v1p09yu4 [2020-12-23 01:50:45.307][Trace][101601][38ir4367] dispatch cached gop success. count=14, duration=529 [2020-12-23 01:50:45.307][Trace][101601][38ir4367] create consumer, active=1, queue_size=0.00, jitter=30000000 [2020-12-23 01:50:45.307][Trace][101601][38ir4367] set fd=15, SO_SNDBUF=2626560=>175000, buffer=350ms [2020-12-23 01:50:45.307][Trace][101601][38ir4367] start play smi=0ms, mw_sleep=350, mw_msgs=8, realtime=0, tcp_nodelay=0 [2020-12-23 01:50:46.871][Trace][101601][88806x62] <- GBS SrsGb28181TcpPsRtpProcessor::on_rtp_packet_jitter gb28181: client_id , peer(, 15060) ps rtp packet 280B, age=73399891, vt=2/96, sts=1782/6026400/0x8ac005, paylod=268B [2020-12-23 01:50:49.724][Trace][101601][73516905] -> HLS time=70243799ms, sno=6, [email protected], dur=0.00, dva=10949p [2020-12-23 01:50:55.716][Trace][101601][38ir4367] -> PLA time=10090329, msgs=9, okbps=91,0,0, ikbps=2,0,0, mw=350/8 [2020-12-23 01:50:56.901][Trace][101601][88806x62] <- GBS SrsGb28181TcpPsRtpProcessor::on_rtp_packet_jitter gb28181: client_id , peer(, 15060) ps rtp packet 244B, age=83403366, vt=2/96, sts=2048/6930000/0x8ac005, paylod=232B
从上面的打印日志里我们也能找到rtmp和hls链接,这里可以发现就是下级是自动就开始推流,实际使用应用是上级主动invite后才推流过来
其中hls比实时流慢56秒一共
有了正常运行的打印日志,我们大概知道了流程,下面可以载入调试器运行程序,调试流程的各个环节
killall -9 srs && # killall -1 srs # 则表示重新加载配置文件,但是不重启进程,这样不用影响线上用户
gdb --args ./objs/srs -c conf/push.gb28181.conf # 我们打断点,操作方法如下面截图
b SrsGb28181SipService::on_udp_sip
或者 b 行号 # 在行号处打断点
c # 继续运行
p 变量名 # 打印变量值
然后我们启动程序,也就是输入r(c是继续执行的意思),和visual studio一模一样
bt显示堆栈,断点处那一行是已经执行过的
前面已经学会本地gdb调试了,那么远程的唯一区别就是命令和打印是通过网络交互的
这里我们参考 Remote Development with CLion - YouTube
配置下调试工具链如下:
注意下面的Path mapping是错的,路径应该是服务端程序的执行路径 /home/book/git/srs/trunk D:\git\srs\trunk,注意斜杠方向
接下来就是打断点了,因为配置了路径映射,所以断点会被同步到gebserver执行
Run SSH terminal—CLion 也可以在clion里面连接到服务器,不过这里我们还用vscode比较方便的多
gdbserver localhost:1234 ./objs/srs -c conf/push.gb28181.conf
点击右上角的开始调试就进入了
更详细的看帮助
Remote Development with CLion - YouTube
GDB Remote Debug—CLion