在GB28181的2016版中,对于媒体流的传输在原有UDP传输的基础中,增加了主动tcp和被动tcp的方式。
1.UDP的传输
这个是普遍的传输方式,GB28181服务端在发invite时,在携带的SDP中包含了接收媒体的端口,设备端(被呼叫端)收到invite后,解析该端口,通过UDP将媒体流发向该端口。
2.TCP被动
GB28181服务端在发invite时,在携带的SDP中包含了接收媒体的端口,并监听该端口的媒体数据,设备端(被呼叫端)收到invite后,解析该端口,通过TCP将媒体流发向该端口。
3.TCP主动
设备端(被呼叫端)告知服务端自己的媒体流tcp端口,服务端主动去连接设备端(被呼叫端)的该端口,获取数据。
基于新的2016版GB28181协议,我们在设备端开发时除了传统的udp发流外,还要考虑tcp主动和tcp被动两种方式,在代码的实现中,我们通过被服务端invite所携带的sdp进行区分,代码如下:
enum SYMediaProtocol
{
SYUdp = 0, //UDP传输
SYTcpActive, //tcp主动
SYTcpPassive //tcp被动
};
SYMediaProtocol CGbtDeviceAgent::getMediaProtocol(const sstd::string szProtocol )
{
SYMediaProtocol protocol = kUdp;
if (szProtocol == MediaMedium::RTP_AVP_TCP || szProtocol == MediaMedium::TCP_RTP_AVP)
{
if (medium.setup == MediaMedium::active)
{
protocol = SYTcpActive;
}
else
{
protocol = SYTcpPassive;
}
}
return protocol;
}
我们通过 sdp的信息解析后可以判断具体的媒体流传输协议,以下是tcp主动呼叫时服务端和设备端的GB28181报文,为了突出重点,限制篇幅,只截取invite和200OK的报文:
INVITE sip:53000000441329000515@120.229.43.100:14940 SIP/2.0
Via: SIP/2.0/UDP 106.58.169.248:5066;branch=z9hG4bK-524287-1---96235649734f9450;rport
Max-Forwards: 70
Contact: <sip:11010200082006180524@106.58.169.248:5066>
To: <sip:53000000441329000515@120.229.43.100:14940>
From: <sip:11010200082006180524@106.58.169.248:5066>;tag=4452781c
Call-ID: TReMwjEl4tWDd-O-uEJ9vw..
CSeq: 1 INVITE
Subject: 53000000441329000515:0,11010200082006180524:0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, NOTIFY, SUBSCRIBE, INFO, MESSAGE, ACK, CANCEL, OPTIONS, MESSAGE, SUBSCRIBE, INVITE, REGISTER
Content-Type: application/sdp
Supported: timer, outbound, path, path, 100rel
Content-Length: 190
v=0
o=53000000441329000515 0 0 IN IP4 106.58.169.248
s=Play
c=IN IP4 106.58.169.248
t=0 0
m=video 20000 TCP/RTP/AVP 96
a=rtpmap:96 PS/90000
a=recvonly
y=0999999999
a=setup:passive
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 106.58.169.248:5066;branch=z9hG4bK-524287-1---96235649734f9450;rport=5066
From: <sip:11010200082006180524@106.58.169.248:5066>;tag=4452781c
To: <sip:53000000441329000515@120.229.43.100:14940>
Call-ID: TReMwjEl4tWDd-O-uEJ9vw..
CSeq: 1 INVITE
User-Agent: GbtDeviceKit
Content-Length: 0
SIP/2.0 200 OK
Via: SIP/2.0/UDP 106.58.169.248:5066;branch=z9hG4bK-524287-1---96235649734f9450;rport=5066
From: <sip:11010200082006180524@106.58.169.248:5066>;tag=4452781c
To: <sip:53000000441329000515@120.229.43.100:14940>;tag=1591516984
Call-ID: TReMwjEl4tWDd-O-uEJ9vw..
CSeq: 1 INVITE
Contact: <sip:53000000441329000515@120.229.43.100:14940>
Content-Type: Application/SDP
User-Agent: GbtDeviceKit
Content-Length: 216
v=0
o=53000000441319000515 0 0 IN IP4 192.168.137.180
s=Play
c=IN IP4 192.168.137.180
t=0 0
a=setup:active
m=video 12006 TCP/RTP/AVP 96
a=sendonly
a=rtpmap:96 PS/90000
y=0999999999
f=v/2/15/2/524288/a/1/8
ACK sip:53000000441329000515@120.229.43.100:14940 SIP/2.0
Via: SIP/2.0/UDP 106.58.169.248:5066;branch=z9hG4bK-524287-1---38246b00e73cc219;rport
Max-Forwards: 70
Contact: <sip:11010200082006180524@106.58.169.248:5066>
To: <sip:53000000441329000515@120.229.43.100:14940>;tag=1591516984
From: <sip:11010200082006180524@106.58.169.248:5066>;tag=4452781c
Call-ID: TReMwjEl4tWDd-O-uEJ9vw..
CSeq: 1 ACK
Content-Length: 0
从上图可以看到,TCP/RTP/AVP表示请求tcp进行流媒体的传输,a=setup:active表示主动tcp,根据sdp的内容,这样大家就可以很清楚的了解GB28181的媒体的3种传输方式了。
更多信息
e-mail: yujesoft@163.com
tel: 13971177602
web:www.founu.com