ossrs / srs-gb28181

GB28181 server based on SRS
https://ossrs.net
MIT License
83 stars 41 forks source link

GB28181: http-callback 功能无效,无法触发回调 #1822 #17

Open winlinvip opened 2 years ago

winlinvip commented 2 years ago

描述(Description)

feature/gb28181 分支编译时附带了 --with-http-callback , 当设备推流时, http_hooks 配置均没有产生回调, 上一个版本的 feature/gb28181 分支的 http_hooks 功能正常

  1. SRS版本(Version): 4.0.29 , commitId 为 0aea46ac8bf1090ab6167ec870d93f328017e1a8
  2. SRS的日志如下(Log):
    
    2020-06-28 09:48:41.232][Trace][17728][0] XCORE-SRS/4.0.29(Leo)
    [2020-06-28 09:48:41.233][Trace][17728][0] config parse complete
    [2020-06-28 09:48:41.233][Trace][17728][0] write log to console
    [2020-06-28 09:48:41.233][Trace][17728][0] SRS/4.0.29(Leo), MIT
    [2020-06-28 09:48:41.233][Trace][17728][0] authors: Winlin,Wenjie,Runner365,John,B.P.Y,Lixin
    [2020-06-28 09:48:41.233][Trace][17728][0] contributors: winlin<winlin@vip.126.com> wenjie.zhao<740936897@qq.com> xiangcheng.liu<liuxc0116@foxmail.com> naijia.liu<youngcow@youngcow.net> alcoholyi<alcoholyi@qq.com> byteman<wangchen2011@gmail.com> chad.wang<chad.wang.cn@gmail.com> suhetao<suhetao@gmail.com> Johnny<fengjihu@163.com> karthikeyan<keyanmca@gmail.com> StevenLiu<lq@chinaffmpeg.org> zhengfl<zhengfl_1989@126.com> tufang14<breadbean1449@gmail.com> allspace<allspace@gmail.com> niesongsong<nie950@gmail.com> rudeb0t<nimrod@themanxgroup.tw> CallMeNP<np.liamg@gmail.com> synote<synote@qq.com> lovecat<littlefawn@163.com> panda1986<542638787@qq.com> YueHonghui<hongf.yue@hotmail.com> ThomasDreibholz<dreibh@simula.no> JuntaoLiu<juntliu@gmail.com> RocFang<fangpeng1986@gmail.com> MakarovYaroslav<yaroslav.makarov.97@mail.ru> MirkoVelic<mvelic@inoxx.net> HuiZhang(huzhang2)<huzhang2@cisco.com> OtterWa<simpleotter23@gmail.com> walkermi<172192667@qq.com> haofz<fuzhuang.hao@vhall.com> ME_Kun_Han<hanvskun@hotmail.com> ljx0305<ljx0305@gmail.com> cenxinwei<censhanhe@163.com> StarBrilliant<m13253@hotmail.com> xubin<xubin@chnvideo.com> intliang<yintiliang@gmail.com> flowerwrong<sysuyangkang@gmail.com> YLX<568414379@qq.com> J<guotaojiang@qq.com> Harlan<hailiang@gvrcraft.com> hankun<hankun@bravovcloud.com> JonathanBarratt<jonathan.barratt@gmail.com> KeeganH<keeganwharris@gmail.com> StevenLiu<lingjiujianke@gmail.com> liuxc0116<liuxc0116@gmail.com> ChengdongZhang<lmajzcd@sina.com> lovacat<lovecat@china.sina.com> qiang.li<qiang.li@verycdn.com.cn> HungMingWu<u9089000@gmail.com> Himer<xishizhaohua@qq.com> xialixin<xlx0625@163.com> alphonsetai<tyh_123@163.com> Michael.Ma<wnpllr@gmail.com> lam2003<linmin3@yy.com> runner365<shi.weibd@hotmail.com> XiaofengWang<wasphin@gmail.com> XiaLixin<xialx@yuntongxun.com> xiaozhihong<xiaozhihong8@gmail.com> HuyaJohn<xiaozhihong@huya.com> yanghuiwen<cainiaodj@qq.com> Bepartofyou<309554135@qq.com> l<22312935+lam2003@users.noreply.github.com> xfalcon<x-falcon@users.noreply.github.com> cgh<jinxue.cgh@alibaba-inc.com> LiPeng<mozhan.lp@alibaba-inc.com> 
    [2020-06-28 09:48:41.233][Trace][17728][0] cwd=/Users/joe/Workspace/GitHub/srs/trunk, work_dir=./, build: 2020-06-28 09:43:39, configure: --gb28181=on --http-callback=on --ssl=on --hls=on --http-api=on --stat=on --http-server=on --osx, uname: Darwin Lim-MacBook-Pro.local 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64, osx: 1
    [2020-06-28 09:48:41.233][Trace][17728][0] configure detail: --prefix=/usr/local/srs --hls=on --hds=off --dvr=on --ssl=on --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 --nasm=off --srtp-nasm=off --sendmmsg=off --clean=on --gperf=off --gmc=off --gmd=off --gmp=off --gcp=off --gprof=off --log-trace --cc=gcc --cxx=g++ --ar=ar --ld=ld --randlib=randlib
    [2020-06-28 09:48:41.233][Trace][17728][0] srs checking config...
    [2020-06-28 09:48:41.234][Trace][17728][0] ips, iface[0] en0 ipv4 0x8863 192.168.3.2, iface[1] llw0 ipv6 0x8863 fe80::ec71:acff:fef3:af39w0
    [2020-06-28 09:48:41.234][Trace][17728][0] devices, intranet en0 192.168.3.2, intranet llw0 fe80::ec71:acff:fef3:af39w0
    [2020-06-28 09:48:41.234][Warn][17728][0][0] stats network use index=0, ip=192.168.3.2, ifname=en0
    [2020-06-28 09:48:41.234][Warn][17728][0][0] stats disk not configed, disk iops disabled.
    [2020-06-28 09:48:41.234][Trace][17728][0] write log to console
    [2020-06-28 09:48:41.234][Trace][17728][0] 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-06-28 09:48:41.234][Trace][17728][0] SRS on  amd64 x86_64, conf:conf/push.gb28181.conf, limit:1000, writev:1024, encoding:little-endian, HZ:100
    [2020-06-28 09:48:41.234][Trace][17728][0] mw sleep:350ms. mr enabled:on, default:0, sleep:350ms
    [2020-06-28 09:48:41.234][Trace][17728][0] gc:on, pq:30000ms, cscc:[0,16), csa:on, tn:on(may hurts performance), ss:auto(guess by merged write)
    [2020-06-28 09:48:41.236][Trace][17728][0] system default latency(ms): mw(0-350) + mr(0-350) + play-queue(0-30000)
    [2020-06-28 09:48:41.236][Warn][17728][0][0] SRS/4.0.29 is develop
    [2020-06-28 09:48:41.236][Trace][17728][0] st_init success, use kqueue
    [2020-06-28 09:48:41.236][Trace][17728][0] RTC server init ok
    [2020-06-28 09:48:41.236][Trace][17728][0] http: root mount to ./objs/nginx/html
    [2020-06-28 09:48:41.236][Trace][17728][828] server main cid=828, pid=17728, ppid=42622, asprocess=0
    [2020-06-28 09:48:41.236][Trace][17728][828] write pid=17728 to ./objs/srs.pid success!
    [2020-06-28 09:48:41.236][Trace][17728][828] RTMP listen at tcp://0.0.0.0:1935, fd=7
    [2020-06-28 09:48:41.236][Trace][17728][828] HTTP-API listen at tcp://0.0.0.0:1985, fd=8
    [2020-06-28 09:48:41.237][Warn][17728][828][55] set SO_SNDBUF failed, expect=10485760, r0=-1
    [2020-06-28 09:48:41.237][Warn][17728][828][55] set SO_RCVBUF failed, expect=10485760, r0=-1
    [2020-06-28 09:48:41.237][Trace][17728][828] UDP #9 LISTEN at 0.0.0.0:5060, SO_SNDBUF(default=9216, expect=10485760, actual=9216, r0=-1), SO_RCVBUF(default=786896, expect=10485760, actual=786896, r0=-1)
    [2020-06-28 09:48:41.237][Trace][17728][828] GB28181-SIP over UDP listen at udp://0.0.0.0:5060, fd=9
    [2020-06-28 09:48:41.237][Warn][17728][828][55] set SO_SNDBUF failed, expect=10485760, r0=-1
    [2020-06-28 09:48:41.237][Warn][17728][828][55] set SO_RCVBUF failed, expect=10485760, r0=-1
    [2020-06-28 09:48:41.237][Trace][17728][828] UDP #10 LISTEN at 0.0.0.0:9000, SO_SNDBUF(default=9216, expect=10485760, actual=9216, r0=-1), SO_RCVBUF(default=786896, expect=10485760, actual=786896, r0=-1)
    [2020-06-28 09:48:41.237][Trace][17728][828] GB28181-Stream over RTP listen at udp://0.0.0.0:9000, fd=10
    [2020-06-28 09:48:41.237][Trace][17728][828] signal installed, reload=1, reopen=30, fast_quit=15, grace_quit=3
    [2020-06-28 09:48:41.237][Trace][17728][828] http: api mount /console to ./objs/nginx/html/console

[2020-06-28 09:48:51.030][Trace][17728][834] new source, stream_url=/live/chid677252797 [2020-06-28 09:48:51.030][Trace][17728][834] ignore disabled exec for vhost= [2020-06-28 09:48:51.030][Trace][17728][834] gb28181: create new stream channel id:chid677252797 rtmp url=rtmp://127.0.0.1:1935/live/chid677252797 [2020-06-28 09:48:51.044][Trace][17728][837] 63B video sh, codec(7, profile=High, level=Other, 128x1072, 0kbps, 0.0fps, 0.0s) [2020-06-28 09:48:55.748][Trace][17728][837] gb28181: client id=chid677252797, ssrc=0x285e0ebd, peer(192.168.3.8, 15060), rtmp muxer is alive [2020-06-28 09:49:05.774][Trace][17728][837] gb28181: client id=chid677252797, ssrc=0x285e0ebd, peer(192.168.3.8, 15060), rtmp muxer is alive [2020-06-28 09:49:15.767][Trace][17728][834] <- GBS gb28181: client_id , peer(192.168.3.8, 15060) ps rtp packet 636B, age=34524909, vt=2/96, sts=9578/2228400/0x285e0ebd, paylod=624B [2020-06-28 09:49:26.162][Trace][17728][837] gb28181: client id=chid677252797, ssrc=0x285e0ebd, peer(192.168.3.8, 15060), rtmp muxer is alive [2020-06-28 09:49:27.372][Warn][17728][837][101] gb28181: client id=chid677252797 ssrc=0x285e0ebd, peer(192.168.3.8, 15060), no rtp data 2 in seconds, clean it, wait other port!

[2020-06-28 09:49:46.165][Trace][17728][837] gb28181: client id=chid677252797, ssrc=0x285e0ebd, peer(, 0), rtmp muxer is alive [2020-06-28 09:49:55.371][Trace][17728][837] gb28181: client id=chid677252797, stream idle timeout, stop!!! [2020-06-28 09:49:55.371][Trace][17728][837] gb28181: client id=chid677252797 rtmp muxer is remove [2020-06-28 09:49:55.371][Trace][17728][837] client finished.

1. SRS的配置如下(Config):

push gb28181 stream to SRS.

listen 1935; max_connections 1000; daemon off; srs_log_tank console;

http_api { enabled on; listen 1985; }

stats { network 0; }

stream_caster { enabled on; caster gb28181;

# 转发流到rtmp服务器地址与端口
# TODO: https://github.com/ossrs/srs/pull/1679/files#r400875104
# [stream] is VideoChannelCodecID(视频通道编码ID) for sip
# 自动创建的道通[stream] 是‘chid[ssrc]’ [ssrc]是rtp的ssrc
# [ssrc] rtp中的ssrc
output              rtmp://127.0.0.1:1935/live/[stream];

# 接收设备端rtp流的多路复用端口
listen              9000;

# rtp接收监听端口范围,最小值
rtp_port_min        58200;
# rtp接收监听端口范围,最大值
rtp_port_max        58300;

# 是否等待关键帧之后,再转发,
# off:不需等待,直接转发
# on:等第一个关键帧后,再转发
wait_keyframe       on;

# rtp包空闲等待时间,如果指定时间没有收到任何包
# rtp监听连接自动停止,发送BYE命令
rtp_idle_timeout    30;

# 是否转发音频流
# 目前只支持aac格式,所以需要设备支持aac格式
# on:转发音频
# off:不转发音频,只有视频
# *注意*!!!:flv 只支持11025  22050  44100 三种
# 如果设备端没有三种中任何一个,转发时为自动选择一种格式
# 同时也会将adts的头封装在flv aac raw数据中
# 这样的话播放器为自动通过adts头自动选择采样频率
# 像ffplay, vlc都可以,但是flash是没有声音,
# 因为flash,只支持11025 22050 44100
audio_enable        off;

# 是否开启rtp缓冲
# 开启之后能有效解决rtp乱序等问题
jitterbuffer_enable  on;

# 服务器主机号,可以域名或ip地址
# 也就是设备端将媒体发送的地址,如果是服务器是内外网
# 需要写外网地址,
# 调用api创建stream session时返回ip地址也是host
# $CANDIDATE 是系统环境变量,从环境变量获取地址,如果没有配置,用*
# *代表指定stats network 的网卡号地址,如果没有配置network,默认则是第0号网卡地址
# TODO: https://github.com/ossrs/srs/pull/1679/files#r400917594
host       $CANDIDATE;

#根据收到ps rtp包自带创建rtmp媒体通道,不需要api接口创建
#rtmp地址参数[stream] 就是通道id  格式chid[ssrc]
auto_create_channel   on;

sip {
    # 是否启用srs内部sip信令
    # 为on信令走srs, off 只转发ps流
    enabled on;

    # sip监听udp端口
    listen              5060;

    # SIP server ID(SIP服务器ID).
    # 设备端配置编号需要与该值一致,否则无法注册
    serial              34020000002000000001;

    # SIP server domain(SIP服务器域)
    realm               3402000000;

    # 服务端发送ack后,接收回应的超时时间,单位为秒
    # 如果指定时间没有回应,认为失败
    ack_timeout         30;

    # 设备心跳维持时间,如果指定时间内(秒)没有接收一个心跳
    # 认为设备离线
    keepalive_timeout   120;

    # 注册之后是否自动给设备端发送invite
    # on: 是  off 不是,需要通过api控制
    auto_play           on;
    # 设备将流发送的端口,是否固定
    # on 发送流到多路复用端口 如9000
    # off 自动从rtp_mix_port - rtp_max_port 之间的值中
    # 选一个可以用的端口
    invite_port_fixed     on;

    # 向设备或下级域查询设备列表的间隔,单位(秒)
    # 默认60秒
    query_catalog_interval  60;
}

} vhost defaultVhost { http_hooks { enabled on; on_publish http://192.168.3.2:3000/v1/webhooks/streams; on_unpublish http://192.168.3.2:3000/v1/webhooks/streams; } }



**重现(Replay)**

> 重现Bug的步骤(How to replay bug?)

1.  编译时附带 --with-http-callback, 配置为自动创建 channel,  启动自己的hooks API
1.  设备开始推流
1. 观察是否有回调的日志

**期望行为(Expect)**

> http_hooks 功能正常