录像下载的流程与录像点播、录像回放类似,主要区别为INVITE请求时xml格式有差异:
关于实时点播可查看:
实时点播(信令处理):https://blog.csdn.net/www_dong/article/details/132950064
实时点播(数据处理):https://blog.csdn.net/www_dong/article/details/133581370
注意:
static std::string CreateRealStreamSDP(const GB28181MediaContext& mediaContext)
{
char str[500] = { 0 };
pj_ansi_snprintf(str, 500,
"v=0\n"
"o=%s 0 0 IN IP4 %s\n"
"s=Play\n"
"c=IN IP4 %s\n"
"t=0 0\n"
"m=video %d RTP/AVP 96 98 97\n"
"a=recvonly\n"
"a=rtpmap:96 PS/90000\n"
"a=rtpmap:98 H264/90000\n"
"a=rtpmap:97 MPEG4/90000\n"
"y=001\n",
mediaContext.GetDeviceId().c_str(),
mediaContext.GetRecvAddress().c_str(),
mediaContext.GetRecvAddress().c_str(),
mediaContext.GetRecvPort()
);
return str;
}
历史视音频回放:https://blog.csdn.net/www_dong/article/details/133826739
注意:
static std::string CreatePlayBackSDP(const GB28181MediaContext& mediaContext)
{
char str[500] = { 0 };
pj_ansi_snprintf(str, 500,
"v=0\n"
"o=%s 0 0 IN IP4 %s\n"
"s=Playback\n"
"c=IN IP4 %s\n"
"t=%lld %lld\n"
"m=video %d RTP/AVP 96 98 97\n"
"a=recvonly\n"
"a=rtpmap:96 PS/90000\n"
"a=rtpmap:98 H264/90000\n"
"a=rtpmap:97 MPEG4/90000\n"
"y=001\n",
mediaContext.GetDeviceId().c_str(),
mediaContext.GetRecvAddress().c_str(),
mediaContext.GetRecvAddress().c_str(),
mediaContext.GetPBStartTime(),
mediaContext.GetPBEndTime(),
mediaContext.GetRecvPort()
);
return str;
}
注意:
static std::string CreateSDPForDownload(const GB28181MediaContext& mediaContext)
{
char str[500] = { 0 };
pj_ansi_snprintf(str, 500,
"v=0\n"
"o=%s 0 0 IN IP4 %s\n"
"s=Download\n"
"c=IN IP4 %s\n"
"t=%lld %lld\n"
"m=video %d RTP/AVP 96 98 97\n"
"a=recvonly\n"
"a=rtpmap:96 PS/90000\n"
"a=rtpmap:98 H264/90000\n"
"a=rtpmap:97 MPEG4/90000\n"
"a=downloadspeed:%d\n"
"y=0100000001\n",
mediaContext.GetDeviceId().c_str(),
mediaContext.GetRecvAddress().c_str(),
mediaContext.GetRecvAddress().c_str(),
mediaContext.GetDownloadStartTime(),
mediaContext.GetDownloadEndTime(),
mediaContext.GetRecvPort(),
mediaContext.GetDownloadSpeed()
);
return str;
}
INVITE sip:[email protected]:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.107:5060;rport;branch=xxx
Max-Forwards: 70
From: sip:[email protected];tag=xxx
To: sip:[email protected]
Contact: <sip:[email protected]:5060>
Call-ID: xxx
CSeq: 15724 INVITE
Allow: SUBSCRIBE, NOTIFY, INVITE, ACK, BYE, CANCEL, UPDATE
Supported:
Subject: xxx:xx,xxx:xx
Content-Type: application/sdp
Content-Length: 251
v=0
o=xxx 0 0 IN IP4 192.168.0.107
s=Download
c=IN IP4 192.168.0.107
t=1697955233 1697958114 # 下载的文件开始时间和结束时间
m=video 36000 RTP/AVP 96 98 97
a=recvonly
a=rtpmap:96 PS/90000
a=rtpmap:98 H264/90000
a=rtpmap:97 MPEG4/90000
a=downloadspeed:8 # 8倍速下载
y=001
# 100 Trying
SIP/2.0 100 Trying
Via: SIP/2.0/UDP 192.168.0.107:5060;rport=5060;branch=xxx
From: <sip:[email protected]7>;tag=xxx
To: <sip:[email protected]1>
Call-ID: xxx
CSeq: 15724 INVITE
User-Agent: IP Camera
Content-Length: 0
# 200 OK
SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.107:5060;rport=5060;branch=xxx
From: <sip:[email protected]7>;tag=xxx
To: <sip:[email protected]1>;tag=904233038
Call-ID: xxx
CSeq: 15724 INVITE
Contact: <sip:[email protected]:5060>
Content-Type: application/sdp
User-Agent: IP Camera
Content-Length: 198
v=0
o=xxx 2131 2131 IN IP4 192.168.0.111
s=Download
c=IN IP4 192.168.0.111
t=0 0
m=video 15060 RTP/AVP 96
a=sendonly
a=rtpmap:96 PS/90000
a=filesize:62224924 # 请求的文件大小
y=001
当接收到MediaStatus命令且NotifyType为121是表示历史媒体文件发送结束。
抓包如下所示:
MESSAGE sip:[email protected]:5060 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.111:5060;rport;branch=xxx
From: <sip:[email protected]1>;tag=xxx
To: <sip:[email protected]7>;tag=xxx
Call-ID: xxx
CSeq: 2 MESSAGE
Contact: <sip:[email protected]:5060>
Content-Type: Application/MANSCDP+xml
Max-Forwards: 70
User-Agent: IP Camera
Content-Length: 174
<?xml version="1.0" encoding="GB2312"?>
<Notify>
<CmdType>MediaStatus</CmdType>
<SN>151</SN>
<DeviceID>xxx</DeviceID>
<NotifyType>121</NotifyType>
</Notify>
下载的文件如下: