语音对讲
定义
- 用户端向设备通过视音频点播请求音频数据;
- 用户端接收音频数据并通过特定的播放设备(如音响)播放;
- 用户端向设备发送广播请求;
- 设备解析广播成功后通过INVITE方法向用户请求音频数据;
- 用户通过音频采集设备获取音频数据;
- 用户将采集的音频数据发送至设备;
可以总结为:音频数据的双向传输。
抓包
- 发送INVITE请求( mysipsdk—>设备)
INVITE sip:xxx@192.168.0.111:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.107:5060;rport;branch=xxx
Max-Forwards: 70
From: sip:xxx@192.168.0.107;tag=xxx
To: sip:xxx@192.168.0.111
Contact: <sip:xxx@192.168.0.107:5060>
Call-ID: xxx
CSeq: 18467 INVITE
Allow: SUBSCRIBE, NOTIFY, INVITE, ACK, BYE, CANCEL, UPDATE
Supported:
Subject: xxx:xx,xxx:xx
Content-Type: application/sdp
Content-Length: 169
v=0
o=xxx 0 0 IN IP4 192.168.0.107
<!--请求媒体流的操作类型:Talk-->
s=Talk
c=IN IP4 192.168.0.107
t=0 0
<!--媒体类型:音频(audio) 传输端口:38000 传输方式:UDP 负载类型:8(PCMA)-->
m=audio 38000 RTP/AVP 8
a=sendrecv
<!--负载类型:8(PCMA) 时钟频率:8000-->
a=rtpmap:8 PCMA/8000
<!--"f=v/编码格式/分辨率/帧率/码率/码率大小a/编码格式/码率大小/采样率"-->
f=v/a/1/8/1
y=0100000001
- 接收设备响应(设备—>mysipsdk)
SIP/2.0 200 OK
Call-ID: xxx
Contact: <sip:xxx@192.168.0.111:5060>
Content-Length: 270
Content-Type: application/sdp
CSeq: 18467 INVITE
From: <sip:xxx@192.168.0.107>;tag=xxx
To: <sip:xxx@192.168.0.111>;tag=xxx
User-Agent: SIP UAS V.2016.xxxx
Via: SIP/2.0/UDP 192.168.0.107:5060;rport=5060;branch=xxx
v=0
o=xxx 0 0 IN IP4 192.168.0.111
s=Talk
i=VCam Talk Session
c=IN IP4 192.168.0.111
t=0 0
m=audio 9712 RTP/AVP 8
a=recvonly
a=rtpmap:8 PCMA/8000/1
m=audio 9712 RTP/AVP 8
a=sendonly
a=rtpmap:8 PCMA/8000/1
y=0100000001
f=v/0/0/0/0/0a/0/0/0
- 发送ACK到设备(mysipsdk—>设备)
ACK sip:xxx@192.168.0.111:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.107:5060;rport;branch=xxx
Max-Forwards: 70
From: sip:xxx@192.168.0.107;tag=xxx
To: sip:xxx@192.168.0.111;tag=xxx
Call-ID: xxx
CSeq: 18467 ACK
Content-Length: 0
- 接收音频数据(设备—>mysipsdk)
代码
- 组装sdp
static std::string CreateSDPForAudio(const GB28181MediaContext& mediaContext)
{
char str[500] = { 0 };
pj_ansi_snprintf(str, 500,
"v=0\n"
"o=%s 0 0 IN IP4 %s\n"
"s=Talk\n"
"c=IN IP4 %s\n"
"t=0 0\n"
"m=audio %d RTP/AVP 8\n"
"a=sendrecv\n"
"a=rtpmap:8 PCMA/8000\n"
"f=v/a/1/8/1\n"
"y=0100000001\n",
mediaContext.GetDeviceId().c_str(),
mediaContext.GetRecvAddress().c_str(),
mediaContext.GetRecvAddress().c_str(),
mediaContext.GetRecvPort()
);
return str;
}
- 音频数据接收与视频数据接收类似,根据sdp协商确定接收的音频格式;
语音广播
要求
文章来源:https://www.toymoban.com/news/detail-739182.html
流程
文章来源地址https://www.toymoban.com/news/detail-739182.html
抓包
- 发送广播通知(mysipsdk—>设备)
MESSAGE sip:xxx@192.168.0.111:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.107:5060;rport;branch=xxx
Max-Forwards: 70
From: <sip:xxx@192.168.0.107>;tag=xxx
To: <sip:xxx@xx>
Contact: <sip:xxx@192.168.0.107:5060>
Call-ID: xxx
CSeq: 18467 MESSAGE
Content-Type: Application/MANSCDP+xml
Content-Length: 186
<?xml version="1.0" encoding="UTF-8"?>
<Notify>
<CmdType>Broadcast</CmdType>
<SN>130</SN>
<!--语音输入设备的设备编码-->
<SourceID>xxx</SourceID>
<!--语音输出设备的设备编码-->
<TargetID>xxx</TargetID>
</Notify>
- 广播通知响应(设备—>mysipsdk)
SIP/2.0 200 OK
Call-ID: xxx
Content-Length: 0
CSeq: 18467 MESSAGE
From: <sip:xxx@192.168.0.107>;tag=xxx
To: <sip:xxx@xxx>;tag=xxx
User-Agent: SIP UAS V.2016.xxxx
Via: SIP/2.0/UDP 192.168.0.107:5060;rport=5060;branch=xxx
- 广播通知结果(设备—>mysipsdk)
MESSAGE sip:xxx@192.168.0.107 SIP/2.0
Call-ID: xxx
Content-Length: 180
Content-Type: Application/MANSCDP+xml
CSeq: 2 MESSAGE
From: <sip:xxx@192.168.0.111:5060>;tag=xxx
Max-Forwards: 70
To: <sip:xxx@192.168.0.107>
User-Agent: SIP UAS V.2016.xxxx
Via: SIP/2.0/UDP 192.168.0.111:5060;rport;branch=xxx
<?xml version="1.0" encoding="GB2312" standalone="yes" ?>
<Response>
<CmdType>Broadcast</CmdType>
<SN>130</SN>
<DeviceID>xxx</DeviceID>
<Result>OK</Result>
</Response>
- 广播通知结果响应(mysipsdk—>设备)
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.111:5060;rport=5060;received=192.168.0.111;branch=xxx
Call-ID: xxx
From: <sip:xxx@192.168.0.111>;tag=xxx
To: <sip:xxx@192.168.0.107>;tag=xxx
CSeq: 2 MESSAGE
Content-Length: 0
- 广播请求(设备—>mysipsdk)
INVITE sip:xxx@192.168.0.107:5060 SIP/2.0
Call-ID: xxx
Contact: <sip:xxx@192.168.0.111:5060>
Content-Length: 240
Content-Type: application/sdp
CSeq: 1 INVITE
Expires: 120
From: <sip:xxx@192.168.0.111:5060>;tag=xxx
Max-Forwards: 70
Subject: xxx:xxx,xxx:xxx
To: <sip:xxx@192.168.0.107:5060>
User-Agent: SIP UAS V.2016.xxxx
Via: SIP/2.0/UDP 192.168.0.111:5060;rport;branch=xxx
v=0
o=xxx 0 0 IN IP4 192.168.0.111
s=Play
i=VCam BroadCast Session
c=IN IP4 192.168.0.111
t=0 0
m=audio 9712 RTP/AVP 8 96
a=recvonly
a=rtpmap:8 PCMA/8000/1
a=rtpmap:96 PS/90000
y=0022371912
f=v/0/0/0/0/0a/1/8/1
- 广播请求响应(mysipsdk—>设备)
SIP/2.0 200 OK
From: <sip:xxx@192.168.0.107:5060>;tag=xxx
To: <sip:xxx@192.168.0.111:5060>;tag=xxx
Call-ID: xxx
CSeq: 1 INVITE
User-Agent: General SIP UAS V1.0
Via: SIP/2.0/UDP 192.168.0.111:5060;rport;branch=xxx
Contact: <sip:xxx@192.168.0.107:5060>
Content-Type: application/SDP
Content-Length: 182
v=0
o=xxx 0 0 IN IP4 192.168.0.107
s=Play
c=IN IP4 192.168.0.107
t=0 0
m=audio 40000 RTP/AVP 8
a=rtpmap:8 PCMA/8000
a=sendonly
y=0022371912
- 广播请求响应ACK(设备—>mysipsdk)
ACK sip:xxx@192.168.0.107:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.111:5060;rport;branch=xxx
From: <sip:xxx@192.168.0.111:5060>;tag=xxx
To: <sip:xxx@192.168.0.107:5060>;tag=xxx
Call-ID: xxx
CSeq: 1 ACK
Contact: <sip:xxx@192.168.0.111:5060>
Max-Forwards: 70
User-Agent: IP Camera
Content-Length: 0
- 关闭广播(设备—>mysipsdk)
BYE sip:xxx@xxx SIP/2.0
From: <sip:xxx@xxx>;tag=xxx
To: <sip:xxx@xxx>;tag=xxx
CSeq: 2 BYE
Call-ID: xxx
Via: SIP/2.0/UDP 192.168.0.111:5060;branch=xxx
Max-Forwards: 70
Content-Length: 0
- 关闭广播响应(mysipsdk—>设备)
到了这里,关于GB28181学习(十四)——语音广播与语音对讲的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!