音视频-srs-国标-clion单步调试方法.md

原创
2020/12/29 13:47
阅读数 897

changelog

  • 2020年12月29日 整理

链接

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

用clion打开srs的本地目录

image.png

参考 Remote server configuration—CLion 配置下sftp部署参数,其中web server用

sudo python -m http.server 80 -d /home/book >/dev/null 2>&1 & 来配置如下

image.png

再参考 使用Clion优雅的完全远程自动同步和远程调试c++ - 云+社区 - 腾讯云

image.png

再参考上面博客里配置其他参数

image.png

可以发现本地clion里的修改立即上传了,因为同步是更改端发起的,所以只有自动上传并没有自动下载同步的功能,因为修改是clion端能感知的。

image.png

远程调试

安装工具,其实那个虚拟机里都安装,不需要安装,这里备注下

apt install cmake -y

apt install gcc-c++ -y

apt install gdb -y

apt install gdb-gdbserver -y

参考 使用Clion优雅的完全远程自动同步和远程调试c++ - 云+社区 - 腾讯云 里面的远程调试配置

image.png

SRS打开调试和编译 ./configure --with-gb28181 --debug && make clean && make # 打开调试

image.png

SRS修改配置文件

参考004-SRS配置和热加载_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili

我们还是把日志打印到文件,这样便于查看,截图里是打印到控制台了

国标配置参考国产开源流媒体SRS4.0对视频监控GB28181的支持,我这里用的是一台海康摄像头

image.png

SRS本地GDB调试

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: winlinwinlin@vip.126.com wenjie.zhao740936897@qq.com xiangcheng.liuliuxc0116@foxmail.com naijia.liuyoungcow@youngcow.net alcoholyialcoholyi@qq.com bytemanwangchen2011@gmail.com chad.wangchad.wang.cn@gmail.com suhetaosuhetao@gmail.com Johnnyfengjihu@163.com karthikeyankeyanmca@gmail.com StevenLiulq@chinaffmpeg.org zhengflzhengfl_1989@126.com tufang14breadbean1449@gmail.com allspaceallspace@gmail.com niesongsongnie950@gmail.com rudeb0tnimrod@themanxgroup.tw CallMeNPnp.liamg@gmail.com synotesynote@qq.com lovecatlittlefawn@163.com panda1986542638787@qq.com YueHonghuihongf.yue@hotmail.com ThomasDreibholzdreibh@simula.no JuntaoLiujuntliu@gmail.com RocFangfangpeng1986@gmail.com MakarovYaroslavyaroslav.makarov.97@mail.ru MirkoVelicmvelic@inoxx.net HuiZhang(huzhang2)huzhang2@cisco.com OtterWasimpleotter23@gmail.com walkermi172192667@qq.com haofzfuzhuang.hao@vhall.com ME_Kun_Hanhanvskun@hotmail.com ljx0305ljx0305@gmail.com cenxinweicenshanhe@163.com StarBrilliantm13253@hotmail.com xubinxubin@chnvideo.com intliangyintiliang@gmail.com flowerwrongsysuyangkang@gmail.com YLX568414379@qq.com Jguotaojiang@qq.com Harlanhailiang@gvrcraft.com hankunhankun@bravovcloud.com JonathanBarrattjonathan.barratt@gmail.com KeeganHkeeganwharris@gmail.com StevenLiulingjiujianke@gmail.com liuxc0116liuxc0116@gmail.com ChengdongZhanglmajzcd@sina.com lovacatlovecat@china.sina.com qiang.liqiang.li@verycdn.com.cn HungMingWuu9089000@gmail.com Himerxishizhaohua@qq.com xialixinxlx0625@163.com alphonsetaityh_123@163.com Michael.Mawnpllr@gmail.com lam2003linmin3@yy.com runner365shi.weibd@hotmail.com XiaofengWangwasphin@gmail.com XiaLixinxialx@yuntongxun.com xiaozhihongxiaozhihong8@gmail.com HuyaJohnxiaozhihong@huya.com yanghuiwencainiaodj@qq.com Bepartofyou309554135@qq.com l22312935+lam2003@users.noreply.github.com xfalconx-falcon@users.noreply.github.com cghjinxue.cgh@alibaba-inc.com LiPengmozhan.lp@alibaba-inc.com xiaozhihonghondaxiao@tencent.com yajun18yajun18@staff.sina.com.cn liulichuanliulichuan@kuaishou.com yapingcatcaoyapingneu@163.com chenchengbinchenchengbin@yy.com chenhaibochenhaibo@RD-CHB-0476-01 jasongwqjasongwq@gmail.com xialixin@kanzhun.comxialixin@kanzhun.com yinjiaoyuanyinjiaoyuan@163.com PieerePipihuibin@hotmail.com JesseXijesse.jinjin@wo.cn PieerePi40780488+PieerePi@users.noreply.github.com ghostsfghost_sf@163.com [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, ts=34020000001320000001@34020000001320000001-0.ts, 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, ts=34020000001320000001@34020000001320000001-1.ts, 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, ts=34020000001320000001@34020000001320000001-2.ts, 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, ts=34020000001320000001@34020000001320000001-3.ts, 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, ts=34020000001320000001@34020000001320000001-4.ts, 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, ts=34020000001320000001@34020000001320000001-5.ts, 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, ts=34020000001320000001@34020000001320000001-5.ts, 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秒一共

image.png

有了正常运行的打印日志,我们大概知道了流程,下面可以载入调试器运行程序,调试流程的各个环节

killall -9 srs && # killall -1 srs # 则表示重新加载配置文件,但是不重启进程,这样不用影响线上用户

gdb --args ./objs/srs -c conf/push.gb28181.conf # 我们打断点,操作方法如下面截图

b SrsGb28181SipService::on_udp_sip

或者 b 行号 # 在行号处打断点

c # 继续运行

p 变量名 # 打印变量值

image.png

然后我们启动程序,也就是输入r(c是继续执行的意思),和visual studio一模一样

image.png

bt显示堆栈,断点处那一行是已经执行过的

image.png

SRS远程调试

在本地设置断点

前面已经学会本地gdb调试了,那么远程的唯一区别就是命令和打印是通过网络交互的

这里我们参考 Remote Development with CLion - YouTube

image.png

配置下调试工具链如下:

注意下面的Path mapping是错的,路径应该是服务端程序的执行路径 /home/book/git/srs/trunk D:\git\srs\trunk,注意斜杠方向

image.png

接下来就是打断点了,因为配置了路径映射,所以断点会被同步到gebserver执行

image.png

在服务端启动GDB

Run SSH terminal—CLion 也可以在clion里面连接到服务器,不过这里我们还用vscode比较方便的多

gdbserver localhost:1234 ./objs/srs -c conf/push.gb28181.conf

image.png

点击右上角的开始调试就进入了

image.png

更详细的看帮助

Remote Development with CLion - YouTube

GDB Remote Debug—CLion

展开阅读全文
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部