其他分享
首页 > 其他分享> > 数据推送选择GB28181、RTSP还是RTMP?

数据推送选择GB28181、RTSP还是RTMP?

作者:互联网

GB/T28181

国标GB/T28181协议全称《安全防范视频监控联网系统信息传输、交换、控制技术要求》,是一个定义视频联网传输和设备控制标准的白皮书,由公安部科技信息化局提出,该标准规定了城市监控报警联网系统中信息传输、交换、控制的互联结构、通信协议结构,传输、交换、控制的基本要求和安全性要求,以及控制、传输流程和协议接口等技术要求。解决了视频间互联互通,数据共享,以及设备控制的问题,这个问题从顶层解决了视频信息各自为战的问题,打通了视频联网的信息孤岛。

优势:GB28181相对RTMP,支持TCP和UDP模式,信令流负责session交互,数据流负责数据传输,适合标准协议规范的平台级产品对接。

除了支持常规的数据接入外,还支持针对摄像机的PTZ控制,支持标准28181服务对接。

劣势:外部支持GB28181的服务器不多,开源如SRS服务器针对GB28181的支持暂不够商用级,期待后续版本升级支持更好。

以海康摄像头对接28281平台为例,具体交互流程如下:

REGISTER sip:34020000002000000001@3402000000 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.120:15068;rport;branch=z9hG4bK1624213340
From: <sip:34020000001110000044@3402000000>;tag=2045629479
To: <sip:34020000001110000044@3402000000>
Call-ID: 1367363228
CSeq: 1 REGISTER
Contact: <sip:34020000001110000044@192.168.0.120:15068>
Max-Forwards: 70
User-Agent: IP Camera
Expires: 3600
Content-Length: 0

SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.120:15068;rport=15068;received=192.168.0.120;branch=z9hG4bK1624213340
From: <sip:34020000001110000044@3402000000>;tag=2045629479
To: <sip:34020000001110000044@3402000000>;tag=993246605
CSeq: 1 REGISTER
Call-ID: 1367363228
User-Agent: LiveGBS v210723
Contact: <sip:34020000001110000044@192.168.0.120:15068>
Content-Length: 0
Date: 2021-08-13T10:14:11.789
Expires: 3600

MESSAGE sip:34020000001110000044@3402000000 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.199:15060;rport;branch=z9hG4bK796247609
From: <sip:34020000002000000001@3402000000>;tag=180247609
To: <sip:34020000001110000044@3402000000>
Call-ID: 807247609
CSeq: 2 MESSAGE
Content-Type: Application/MANSCDP+xml
Max-Forwards: 70
User-Agent: LiveGBS v210723
Content-Length: 157

<?xml version="1.0" encoding="GB2312"?>
<Query>
  <CmdType>Catalog</CmdType>
  <SN>552247609</SN>
  <DeviceID>34020000001110000044</DeviceID>
</Query>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.199:15060;rport=15060;branch=z9hG4bK796247609
From: <sip:34020000002000000001@3402000000>;tag=180247609
To: <sip:34020000001110000044@3402000000>;tag=1518451596
Call-ID: 807247609
CSeq: 2 MESSAGE
User-Agent: IP Camera
Content-Length: 0

MESSAGE sip:34020000002000000001@3402000000 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.120:15068;rport;branch=z9hG4bK138770826
From: <sip:34020000001110000044@3402000000>;tag=2116434170
To: <sip:34020000002000000001@3402000000>
Call-ID: 111408894
CSeq: 20 MESSAGE
Content-Type: Application/MANSCDP+xml
Max-Forwards: 70
User-Agent: IP Camera
Content-Length:   590

<?xml version="1.0" encoding="GB2312"?>
<Response>
<CmdType>Catalog</CmdType>
<SN>552247609</SN>
<DeviceID>34020000001110000044</DeviceID>
<SumNum>1</SumNum>
<DeviceList Num="1">
<Item>
<DeviceID>34020000001320000001</DeviceID>
<Name>Camera 01</Name>
<Manufacturer>Hikvision</Manufacturer>
<Model>IP Camera</Model>
<Owner>Owner</Owner>
<CivilCode>CivilCode</CivilCode>
<Address>Address</Address>
<Parental>0</Parental>
<ParentID>34020000001110000044</ParentID>
<SafetyWay>0</SafetyWay>
<RegisterWay>1</RegisterWay>
<Secrecy>0</Secrecy>
<Status>ON</Status>
</Item>
</DeviceList>
</Response>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.120:15068;rport=15068;received=192.168.0.120;branch=z9hG4bK138770826
From: <sip:34020000001110000044@3402000000>;tag=2116434170
To: <sip:34020000002000000001@3402000000>;tag=514247616
CSeq: 20 MESSAGE
Call-ID: 111408894
User-Agent: LiveGBS v210723
Content-Length: 0

MESSAGE sip:34020000002000000001@3402000000 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.120:15068;rport;branch=z9hG4bK1946244729
From: <sip:34020000001110000044@3402000000>;tag=1705757152
To: <sip:34020000002000000001@3402000000>
Call-ID: 1030239866
CSeq: 20 MESSAGE
Content-Type: Application/MANSCDP+xml
Max-Forwards: 70
User-Agent: IP Camera
Content-Length:   177

<?xml version="1.0" encoding="GB2312"?>
<Notify>
<CmdType>Keepalive</CmdType>
<SN>11</SN>
<DeviceID>34020000001110000044</DeviceID>
<Status>OK</Status>
<Info>
</Info>
</Notify>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.120:15068;rport=15068;received=192.168.0.120;branch=z9hG4bK1946244729
From: <sip:34020000001110000044@3402000000>;tag=1705757152
To: <sip:34020000002000000001@3402000000>;tag=334251619
CSeq: 20 MESSAGE
Call-ID: 1030239866
User-Agent: LiveGBS v210723
Content-Length: 0

MESSAGE sip:34020000002000000001@3402000000 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.120:15068;rport;branch=z9hG4bK1402863583
From: <sip:34020000001110000044@3402000000>;tag=754663007
To: <sip:34020000002000000001@3402000000>
Call-ID: 187348500
CSeq: 20 MESSAGE
Content-Type: Application/MANSCDP+xml
Max-Forwards: 70
User-Agent: IP Camera
Content-Length:   177

<?xml version="1.0" encoding="GB2312"?>
<Notify>
<CmdType>Keepalive</CmdType>
<SN>12</SN>
<DeviceID>34020000001110000044</DeviceID>
<Status>OK</Status>
<Info>
</Info>
</Notify>
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.120:15068;rport=15068;received=192.168.0.120;branch=z9hG4bK1402863583
From: <sip:34020000001110000044@3402000000>;tag=754663007
To: <sip:34020000002000000001@3402000000>;tag=959261639
CSeq: 20 MESSAGE
Call-ID: 187348500
User-Agent: LiveGBS v210723
Content-Length: 0

RTSP推送

rtsp推送相关的资料和测试软件比较少,支持RTSP TCP模式和UDP模式,除非对接第三方平台,不建议使用RTSP推送。

具体流程如下:

1. rtsp推送流程.

主要分两部分:第一部分先发送信令;第二部分发送rtp包。

 信令流程:

 1.1 先发送OPTIONS, OPTIONS比较常用,就不做详细说明了。

1.2 发送ANNOUNCE, 发送ANNOUNCE主要是把要推送的音视频信息通过sdp格式传给服务器。关于sdp信息如何构造,对于h264请参考rfc6184. h265请参考rfc7798. 下面举两个例子.

h264+aac ANNOUNCE:

ANNOUNCE rtsp://192.168.0.188:554/livexxxx.sdp RTSP/1.0
Content-Type: application/sdp
CSeq: 2
User-Agent: xxxyyy
Content-Length: 489 

v=0
o=- 0 0 IN IP4 127.0.0.1
s=dddookkk
c=IN IP4 192.168.0.188
t=0 0
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z00AKp2oHgCJ+WbgICAoAAADAAgAAAMBlCA=,aO48gA==; profile-level-id=4D002A
a=control:streamid=0
m=audio 0 RTP/AVP 97
a=rtpmap:97 MPEG4-GENERIC/44100/1
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1208
a=control:streamid=1

h265(hevc) + aac ANNOUNCE:

ANNOUNCE rtsp://192.168.0.174:554/live3.sdp RTSP/1.0
Content-Type: application/sdp
CSeq: 2
User-Agent: mmmmd
Content-Length: 364

v=0
o=- 0 0 IN IP4 127.0.0.1
s=uvsdewewe
c=IN IP4 192.168.0.174
t=0 0
m=video 0 RTP/AVP 96
a=rtpmap:96 H265/90000
a=control:streamid=0
m=audio 0 RTP/AVP 97
a=rtpmap:97 MPEG4-GENERIC/44100/1
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=1208
a=control:streamid=1

1.3 发送 SETUP,这个和播放基本一样,请参考播放流程.

1.4 发送 RECORD,record之后,信令流程完成, 接下来发送rtp包即可。

关于rtp包的构造,h264 参考rfc6184。 h265参考 rfc7798。

以Android平台为例,相关接口设计如下:

    /*+++++++++++++++推送rtsp相关接口+++++++++++++++*/
    /*
     * 设置推送rtsp传输方式
     *
     * @param transport_protocol: 1表示UDP传输rtp包; 2表示TCP传输rtp包. 默认是1, UDP传输. 传其他值SDK报错。
     *
     * @return {0} if successful
     */
    public native int SetPushRtspTransportProtocol(long handle, int transport_protocol);

    /*
     * 设置推送RTSP的URL
     *
     * @param url: 推送的RTSP url
     *
     * @return {0} if successful
     */
    public native int SetPushRtspURL(long handle, String url);

    /*
     * 启动推送RTSP流
     *
     * @param reserve: 保留参数,传0
     *
     * @return {0} if successful
     */
    public native int StartPushRtsp(long handle, int reserve);

    /*
     * 停止推送RTSP流
     *
     * @return {0} if successful
     */
    public native int StopPushRtsp(long handle);

    /*---------------推送rtsp相关接口---------------*/

RTMP推送

 RTMP采用的是TCP传输,采用全自研框架,易于扩展,自适应算法让延迟更低、采集编码传输效率更高。延迟配合大牛直播SDK(官方)的播放器,依然可以实现毫秒级。

跨平台设计如下:

感兴趣的开发者可自行参考。

标签:编码,SIP,GB28181,RTSP,支持,2.0,RTMP,Android,推送
来源: https://blog.csdn.net/renhui1112/article/details/120235761