GB28181学习(十)——视音频文件下载

要求

  • SIP服务器接收到媒体接收者发送的视音频文件下载请求后向媒体流发送者发送媒体文件下载命令,媒体流发送者采用RTP将视频流传输给媒体流接收者,媒体流接收者直接将视频流保存为媒体文件;
  • 媒体流接收者或SIP服务器可通过配置查询等方式获取媒体流发送者支持的下载发送倍速,并在请求的SDP消息体中携带下载倍速;
  • 视音频文件下载宜支持媒体流保活机制;

流程

GB28181学习(十)——视音频文件下载_第1张图片

录像下载的流程与录像点播、录像回放类似,主要区别为INVITE请求时xml格式有差异:

  • 实时点播

关于实时点播可查看:

实时点播(信令处理):https://blog.csdn.net/www_dong/article/details/132950064
实时点播(数据处理):https://blog.csdn.net/www_dong/article/details/133581370

注意:

  • “t=0 0”中开始时间和结束时间均为0表示实时点播
  • "s=Play“
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

注意:

  • “t=%lld %lld”中开始时间和结束时间为点播的开始时间和结束时间
  • “s=Playback”
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;
}
  • 录像下载

注意:

  • “t=%lld %lld”中开始时间和结束时间为需要下载文件的开始时间和结束时间
  • “s=Download”
  • "a=downloadspeed:8"表示8倍速下载
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;
	}

抓包

在这里插入图片描述

  1. 查询历史视音频文件,查询结果如图所示:

GB28181学习(十)——视音频文件下载_第2张图片

  1. 选中一条文件记录,右键选择录像下载,弹出如下界面:

GB28181学习(十)——视音频文件下载_第3张图片

  1. 选择8倍速,点击开始下载,向设备发送下载请求:
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
  1. 设备返回下载请求结果:
# 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
  1. 接收数据
    GB28181学习(十)——视音频文件下载_第4张图片

  2. 文件下载结束通知

当接收到MediaStatus命令且NotifyType为121是表示历史媒体文件发送结束。

GB28181学习(十)——视音频文件下载_第5张图片

抓包如下所示:

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>

下载的文件如下:

GB28181学习(十)——视音频文件下载_第6张图片

你可能感兴趣的:(GB28181,GB28181,c++)