基于GB28181协议实现语音对讲方案(局域网环境)
一。GB28181语音对讲流程:
二。GB28181技术实现方案:
1.关键模块:
1)前端页面:负责启动语音对讲流程,采集麦克风的音频流,并发送给流媒体服务。
2)信令服务:负责与摄像头直接进行SIP信令交互,协商摄像头用于接收音频流的IP地址、端口、音频流码率信息。
3)流媒体服务:负责接收前端页面发送的PCM音频流,转码为PCMA格式,按照RTP封装后将音频流发送到摄像头。
4)摄像头:通过与信令服务之间的SIP交互,开启接收音频流的端口,接收到流媒体服务推送的音频流之后进行播放。
2.业务流程:
1)前端页面向信令服务发送HTTP请求,告知要进行声音广播的设备GB编码。
2)信令服务接收到前端页面请求后根据GB编码查询到对应的摄像头设备,发送SIP广播通知,并接收摄像头的广播应答。应答中包含摄像头的IP地址,端口号,音频编码信息。
3)信令服务向流媒体服务发送HTTP请求,告知要发送的摄像头RTP相关信息。流媒体服务打开websocket服务,等待前端页面发送视频流。
4)前端页面接收到步骤1的HTTP返回后,打开电脑的麦克风,进行拾音操作,将PCM格式的音频流以websocket方式发送给流媒体服务。
5)流媒体服务将接收到的PCM音频流转码为PCMA格式。
6)流媒体服务将PCMA音频数据进行RTP封装,以UDP的方式发送到对应的摄像头。
三。GB28181信令抓包:
![](https://img2022.cnblogs.com/blog/2607547/202210/2607547-20221010163446853-23753604.png)
1.广播请求:(信令服务-->摄像头)
MESSAGE sip:32011100491327000001@10.0.15.209:5061 SIP/2.0
Call-ID: f0c3cae033b8daa8fd948da42b8b0fa6@10.0.16.115
CSeq: 18897 MESSAGE
From: <sip:32011100492007000001@3201110049>;tag=df7c9ec31ef44b9884b3f037eaba76d7
To: <sip:32011100491327000001@10.0.15.209:5061>
Via: SIP/2.0/UDP 10.0.16.115:5060;branch=z9hG4bK1665384263762;rport
Max-Forwards: 70
User-Agent: WVP-Pro vnull.null
Content-Type: Application/MANSCDP+xml
Content-Length: 203
<?xml version="1.0" encoding="GB2312"?>
<Notify>
<CmdType>Broadcast</CmdType>
<SN>804111</SN>
<SourceID>32011100491327000001</SourceID>
<TargetID>32011100491377000002</TargetID>
</Notify>
2.信令OK回复:(摄像头-->信令服务)
SIP/2.0 200 OK
Via: SIP/2.0/UDP 10.0.16.115:5060;branch=z9hG4bK1665384263762;rport=5060
Contact: <sip:32011100491327000001@10.0.15.209:5061>
To: <sip:32011100491327000001@10.0.15.209:5061>;tag=75897d56
From: <sip:32011100492007000001@3201110049>;tag=df7c9ec31ef44b9884b3f037eaba76d7
Call-ID: f0c3cae033b8daa8fd948da42b8b0fa6@10.0.16.115
CSeq: 18897 MESSAGE
Content-Length: 0
3.摄像头语音广播应答:(摄像头-->信令服务)
MESSAGE sip:32011100492007000001@3201110049 SIP/2.0
Via: SIP/2.0/UDP 10.0.15.209:5061;branch=z9hG4bK-d8754z-a597cc5673c96103-1---d8754z-;rport
Max-Forwards: 70
Contact: <sip:32011100491327000001@10.0.15.209:5061>
To: <sip:32011100492007000001@3201110049>
From: <sip:32011100491327000001@10.0.15.209:5061>;tag=65624c6d
Call-ID: MTMwMGRjMGE1NjdiM2Q4YmIwZmEwYWU4MDJlNjA5ZWQ.
CSeq: 59 MESSAGE
Content-Type: Application/MANSCDP+xml
Content-Length: 164
<?xml version="1.0" encoding="gb2312"?><Response><CmdType>Broadcast</CmdType><SN>804111</SN><DeviceID>32011100491377000002</DeviceID><Result>OK</Result></Response>
4.信令OK回复:(信令服务-->摄像头)
SIP/2.0 200 OK
CSeq: 59 MESSAGE
Call-ID: MTMwMGRjMGE1NjdiM2Q4YmIwZmEwYWU4MDJlNjA5ZWQ.
From: <sip:32011100491327000001@10.0.15.209:5061>;tag=65624c6d
To: <sip:32011100492007000001@3201110049>;tag=1665384263840
Via: SIP/2.0/UDP 10.0.15.209:5061;branch=z9hG4bK-d8754z-a597cc5673c96103-1---d8754z-;rport=5061;received=10.0.15.209
Content-Length: 0
5.摄像头INVITE请求:(摄像头-->信令服务)
INVITE sip:32011100491327000001@10.0.16.115:5060 SIP/2.0
Via: SIP/2.0/UDP 10.0.15.209:5061;branch=z9hG4bK-d8754z-59f0de5b9a7b881e-1---d8754z-;rport
Max-Forwards: 70
Contact: <sip:10.0.15.209:5061>
To: <sip:32011100491327000001@10.0.16.115:5060>
From: <sip:32011100491327000001@10.0.15.209:5061>;tag=c214425e
Call-ID: YjlkODFkNTVlYTVlNTRiMjcwM2Q2ODJlNjI1ZTU5Zjk.
CSeq: 1 INVITE
Subject: 32011100491327000001:023456,32011100491327000001:789954
Content-Type: APPLICATION/SDP
Content-Length: 195
v=0
o=32011100491327000001 0 0 IN IP4 10.0.15.209
s=Play
c=IN IP4 10.0.15.209
t=0 0
m=audio 15218 RTP/AVP 8
a=recvonly
a=rtpmap:8 PCMA/8000
a=setup:active
y=0000000033
f=v/////a/1/8/1
6.信令服务回复INVITE请求:(信令服务-->摄像头)
SIP/2.0 200 OK
CSeq: 1 INVITE
Call-ID: YjlkODFkNTVlYTVlNTRiMjcwM2Q2ODJlNjI1ZTU5Zjk.
From: <sip:32011100491327000001@10.0.15.209:5061>;tag=c214425e
To: <sip:32011100491327000001@10.0.16.115:5060>;tag=1665384263999
Via: SIP/2.0/UDP 10.0.15.209:5061;branch=z9hG4bK-d8754z-59f0de5b9a7b881e-1---d8754z-;rport=5061;received=10.0.15.209
Contact: <sip:32011100491327000001@10.0.16.115:5060>
Content-Type: APPLICATION/SDP
Content-Length: 183
v=0
o=32011100492007000001 0 0 IN IP4 10.0.16.115
s=Play
c=IN IP4 10.0.16.115
t=0 0
m=audio 8010 RTP/AVP 8
a=rtpmap:8 PCMA/8000
a=sendonly
a=rtpmap:96 PS/90000
y=0000000033
7.信令OK回复:(摄像头-->信令服务)
ACK sip:32011100491327000001@10.0.16.115:5060 SIP/2.0
Via: SIP/2.0/UDP 10.0.15.209:5061;branch=z9hG4bK-d8754z-a79be85f5744fb0e-1---d8754z-;rport
Max-Forwards: 70
Contact: <sip:10.0.15.209:5061>
To: <sip:32011100491327000001@10.0.16.115:5060>;tag=1665384263999
From: <sip:32011100491327000001@10.0.15.209:5061>;tag=c214425e
Call-ID: YjlkODFkNTVlYTVlNTRiMjcwM2Q2ODJlNjI1ZTU5Zjk.
CSeq: 1 ACK
Content-Length: 0