ossrs / srs-gb28181

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

gb28181 在设备推流或停止推流时,onpublish 和onunpublish回调没有触发 #2118 #20

Open winlinvip opened 2 years ago

winlinvip commented 2 years ago

描述(Description)

描述你遇到了什么问题(Please description your issue here)

  1. SRS版本(Version): develop
  2. SRS的日志如下(Log):
    
    [2020-12-28 08:29:27.235][Trace][1][0d01g535] TCP: clear zombies=1 resources, conns=1, removing=0, unsubs=0
    [2020-12-28 08:29:27.235][Trace][1][55dn58p0] TCP: disposing #0 resource(HttpConn)(0x556bd4fa6860), conns=1, disposing=1, zombies=0
    [2020-12-28 08:29:27.319][Trace][1][518w4956] RTMP client ip=192.168.0.93:55682, fd=12
    [2020-12-28 08:29:27.336][Trace][1][518w4956] complex handshake success
    [2020-12-28 08:29:27.336][Trace][1][518w4956] connect app, tcUrl=rtmp://192.168.0.79:1935/live/, pageUrl=http://192.168.0.79/hhgb/#/channel?deviceId=34020000001320000013, swfUrl=http://192.168.0.79/hhgb/liveplayer.swf,                                                                     schema=rtmp, vhost=192.168.0.79, port=1935, app=live, args=null
    [2020-12-28 08:29:27.336][Trace][1][518w4956] protocol in.buffer=0, in.ack=0, out.ack=0, in.chunk=128, out.chunk=128
    [2020-12-28 08:29:27.448][Trace][1][518w4956] client identified, type=Play, vhost=192.168.0.79, app=live, stream=34020000001320000013@34020000001320000014, param=, duration=-1ms
    [2020-12-28 08:29:27.454][Trace][1][518w4956] http: on_connect ok, client_id=518w4956, url=http://192.168.0.79:1999/gb28181/srs/onpublish, request={"action":"on_connect","client_id":"518w4956","ip":"192.168.0.93","vhos                                                                    t":"__defaultVhost__","app":"live","tcUrl":"rtmp://192.168.0.79:1935/live/","pageUrl":"http://192.168.0.79/hhgb/#/channel?deviceId=34020000001320000013"}, response={"code":0}
    [2020-12-28 08:29:27.454][Trace][1][518w4956] connected stream, tcUrl=rtmp://192.168.0.79:1935/live/, pageUrl=http://192.168.0.79/hhgb/#/channel?deviceId=34020000001320000013, swfUrl=http://192.168.0.79/hhgb/liveplayer                                                                    .swf, schema=rtmp, vhost=__defaultVhost__, port=1935, app=live, stream=34020000001320000013@34020000001320000014, param=, args=null
    [2020-12-28 08:29:27.454][Trace][1][518w4956] source url=/live/34020000001320000013@34020000001320000014, ip=192.168.0.93, cache=1, is_edge=0, source_id=k8975rl6/k8975rl6
    [2020-12-28 08:29:27.456][Trace][1][518w4956] http: on_play ok, client_id=518w4956, url=http://192.168.0.79:1999/gb28181/srs/onpublish, request={"action":"on_play","client_id":"518w4956","ip":"192.168.0.93","vhost":"__                                                                    defaultVhost__","app":"live","stream":"34020000001320000013@34020000001320000014","param":"","pageUrl":"http://192.168.0.79/hhgb/#/channel?deviceId=34020000001320000013"}, response={"code":0}
    [2020-12-28 08:29:27.456][Trace][1][518w4956] dispatch cached gop success. count=19, duration=720
    [2020-12-28 08:29:27.456][Trace][1][518w4956] create consumer, active=1, queue_size=0.00, jitter=30000000
    [2020-12-28 08:29:27.456][Trace][1][518w4956] set fd=12, SO_SNDBUF=87040=>175000, buffer=350ms
    [2020-12-28 08:29:27.456][Trace][1][518w4956] start play smi=0ms, mw_sleep=350, mw_msgs=8, realtime=0, tcp_nodelay=0
    [2020-12-28 08:29:29.242][Warn][1][2d9z99o7][2] gb28181: client id=34020000001320000013@34020000001320000014 ssrc=0x996104, peer(192.168.0.23, 15060), no rtp data 2 in seconds, clean it, wait other port!
    [2020-12-28 08:29:30.237][Trace][1][2d9z99o7] gb28181: client id=34020000001320000013@34020000001320000014, stream idle timeout, stop!!!
    [2020-12-28 08:29:30.237][Trace][1][2d9z99o7] gb28181: client id=34020000001320000013@34020000001320000014 rtmp muxer is remove
    [2020-12-28 08:29:30.237][Trace][1][2d9z99o7] client finished.
    [2020-12-28 08:29:30.237][Trace][1][122ycba5] cleanup when unpublish
    [2020-12-28 08:29:31.892][Trace][1][518w4956] http: on_stop ok, client_id=518w4956, url=http://192.168.0.79:1999/gb28181/srs/onpublish, request={"action":"on_stop","client_id":"518w4956","ip":"192.168.0.93","vhost":"__                                                                    defaultVhost__","app":"live","stream":"34020000001320000013@34020000001320000014","param":""}, response={"code":0}
    [2020-12-28 08:29:31.894][Trace][1][518w4956] http: on_close ok, client_id=518w4956, url=http://192.168.0.79:1999/gb28181/srs/onpublish, request={"action":"on_close","client_id":"518w4956","ip":"192.168.0.93","vhost":"                                                                    __defaultVhost__","app":"live","send_bytes":205799,"recv_bytes":3674}, response={"code":0}
    [2020-12-28 08:29:31.894][Trace][1][518w4956] TCP: before dispose resource(RtmpConn)(0x556bd510f350), conns=1, zombies=0, ign=0, inz=0, ind=0
    [2020-12-28 08:29:31.894][Warn][1][518w4956][2] client disconnect peer. ret=1007
    [2020-12-28 08:29:31.894][Trace][1][0d01g535] TCP: clear zombies=1 resources, conns=1, removing=0, unsubs=0
    [2020-12-28 08:29:31.894][Trace][1][518w4956] TCP: disposing #0 resource(RtmpConn)(0x556bd510f350), conns=1, disposing=1, zombies=0
1. SRS的配置如下(Config):

push gb28181 stream to SRS.

listen 1935; max_connections 1000;

http_api { enabled on; listen 1985; crossdomain on; raw_api { enabled on; allow_reload on; allow_query on; allow_update on; } }

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;
# 多路复用端口类型,on为tcp,off为udp
# 默认:off
tcp_enable            off;

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

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

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

# 是否转发音频流
# 目前只支持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   off;

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

    # 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           off;
    # 设备将流发送的端口,是否固定
    # on 发送流到多路复用端口 如9000
    # off 自动从rtp_mix_port - rtp_max_port 之间的值中
    # 选一个可以用的端口
    invite_port_fixed     on;

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

}

http_server { enabled on; listen 8080; dir ./objs/nginx/html; }

vhost defaultVhost { http_hooks { enabled on; on_connect http://192.168.0.79:1999/gb28181/srs/onpublish; on_close http://192.168.0.79:1999/gb28181/srs/onpublish; on_publish http://192.168.0.79:1999/gb28181/srs/onpublish; on_unpublish http://192.168.0.79:1999/gb28181/srs/onpublish; on_play http://192.168.0.79:1999/gb28181/srs/onpublish; on_stop http://192.168.0.79:1999/gb28181/srs/onpublish; on_dvr http://192.168.0.79:1999/gb28181/srs/onpublish; on_hls http://192.168.0.79:1999/gb28181/srs/onpublish; on_hls_notify http://192.168.0.79:1999/gb28181/srs/onpublish; }

http_remux {
    enabled     on;
    mount       [vhost]/[app]/[stream].flv;
}

}



**重现(Replay)**

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

1. `./configure --with-gb28181  && make clean && make`
2. `gb28181设备推流`

**期望行为(Expect)**

> 能正常触发回调
woyaoqunaer commented 2 years ago

我也遇到了这个问题, 其他的推流能正常触发, gb28181的无法触发