Android平台GB28181设备接入端预置位查询(PresetQuery)探讨和技术实现

时间:2022-12-12 16:13:03

之前blog介绍了GB28181云台控制(PTZCmd)相关,本文主要是介绍下GB28181预置位查询。

预置位这块,在处理带云台的设备非常必要,我们主要是做Android平台的GB28181的设备接入端,也可以转发RTSP摄像头接入到国标平台,如果摄像头带云台,这块的处理就非常必要。

废话不多说,我们先看看GB/T28181规范里面,是怎么说的:

请求命令消息体

Message消息头 Content-type头域为 Content-type:Application/MANSCDP+xml。

设备预置位查询命令采用 MANSCDP协议格式定义,详细描述见 A.2.4预置位查询请求。
用设备预置位查询请求命令应包括命令类型(CmdType)、命令序列号(SN)、设备编码(DeviceID),采
IETFRFC3428的 Message方法的消息体携带。
相关设备在收到 Message消息后,应立即返回200OK 应答,200OK 应答均无消息体。

应答命令消息体

Message消息头 Content-type头域为 Content-type:Application/MANSCDP+xml。
设备预置位查询应答命令采用 MANSCDP 协议格式定义,详细描述见 A.2.6 设备预置位查询 
应答。
设备预置位查询应答命令应包括目标设备编码(DeviceID)、命令类型(CmdType)、命令序列号 
(SN)、设备预置位列表(PresetList)等,设备预置位列表应包括预置位编码(PresetID)、预置位名称(PresetName),采用 Message方法的消息体携带。 
相关设备在收到 Message消息后,应立即返回200OK 应答,200OK 应答均无消息体。

查询命令

国标平台侧发来RresetQuery:

MESSAGE sip:34020000001380000001@3402000000 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:15060;rport;branch=z9hG4bK86811279
From: <sip:34020000002000000001@3402000000>;tag=373811279
To: <sip:34020000001380000001@3402000000>
Call-ID: 633811279
CSeq: 707 MESSAGE
Content-Type: Application/MANSCDP+xml
Max-Forwards: 70
User-Agent: GBS Agent
Content-Length: 161

<?xml version="1.0" encoding="GB2312"?>
<Query>
<CmdType>PresetQuery</CmdType>
<SN>777811279</SN>
<DeviceID>34020000001380000001</DeviceID>
</Query>

Android平台GB28181接入端先回个200 OK:

SIP/2.0 200 OK
CSeq: 707 MESSAGE
Call-ID: 633811279
From: <sip:34020000002000000001@3402000000>;tag=373811279
To: <sip:34020000001380000001@3402000000>
Via: SIP/2.0/UDP 192.168.0.103:15060;rport=15060;branch=z9hG4bK86811279;received=192.168.0.103
Content-Length: 0

Android平台GB28181接入端准备发设备预置位查询应答:

大牛直播SDK针对PresetQuery处理如下:

@Override
public void ntsOnDevicePresetQueryCommand(String fromUserName, String fromUserNameAtDomain, String sn, String deviceId) {
handler_.postDelayed(new Runnable() {
@Override
public void run() {
Log.i(TAG, "DaniuSDK ntsOnDevicePresetQueryCommand from_user_name:" + from_user_name_ + ", sn:" + sn_ + ", device_id:" + device_id_);

List<com.gb.ntsignalling.PresetItem> preset_list = new LinkedList<>();


preset_list.add(new com.gb.ntsignalling.PresetItem("1", "Android PreSet1"));
preset_list.add(new com.gb.ntsignalling.PresetItem("2", "Android PreSet2"));

if (gb28181_agent_ != null )
gb28181_agent_.respondDevicePresetQueryCommand(this.from_user_name_, this.from_user_name_at_domain_, this.sn_, this.device_id_, preset_list);
}

private String from_user_name_;
private String from_user_name_at_domain_;
private String sn_;
private String device_id_;

public Runnable set(String from_user_name, String from_user_name_at_domain,String sn, String device_id) {
this.from_user_name_ = from_user_name;
this.from_user_name_at_domain_ = from_user_name_at_domain;
this.sn_ = sn;
this.device_id_ = device_id;
return this;
}

}.set(fromUserName, fromUserNameAtDomain, sn, deviceId),0);
}

对应的MESSAGE信令:

MESSAGE sip:34020000002000000001@3402000000 SIP/2.0
Call-ID: 1b5a50faff369b89c45a5f212a1d45ee@192.168.0.101
CSeq: 1524938865 MESSAGE
From: <sip:31011500991320000069@3402000000>;tag=15640a33
To: <sip:34020000002000000001@3402000000>
Via: SIP/2.0/UDP 192.168.0.101:5060;rport;branch=z9hG4bK-393533-93979b9fc4dcf1edee6742c861522fb4
Max-Forwards: 70
User-Agent: NT GB UserAgent V1.9-20221027
Content-Type: Application/MANSCDP+xml
Content-Length: 364

<?xml version="1.0" encoding="GB2312"?>
<Response>
<CmdType>PresetQuery</CmdType>
<SN>777811279</SN>
<DeviceID>34020000001380000001</DeviceID>
<PresetList Num="2">
<Item>
<PresetID>1</PresetID>
<PresetName>Android PreSet1</PresetName>
</Item>
<Item>
<PresetID>2</PresetID>
<PresetName>Android PreSet2</PresetName>
</Item>
</PresetList>
</Response>

国标平台侧回个200 OK:

SIP/2.0 200 OK
Via: SIP/2.0/UDP 192.168.0.101:5060;rport=5060;received=192.168.0.101;branch=z9hG4bK-393533-93979b9fc4dcf1edee6742c861522fb4
From: <sip:31011500991320000069@3402000000>;tag=15640a33
To: <sip:34020000002000000001@3402000000>;tag=578811338
CSeq: 1524938865 MESSAGE
Call-ID: 1b5a50faff369b89c45a5f212a1d45ee@192.168.0.101
User-Agent: GBS Agent
Content-Length: 0

国标平台侧拿到预置位信息后,可以针对预置位进行设置、调用或删除,GB/T28181-2016技术规范书上对应的预置位指令如下:

Android平台GB28181设备接入端预置位查询(PresetQuery)探讨和技术实现

我们以设置预置位为例:

国标平台侧发来设置指令:

MESSAGE sip:34020000001380000001@3402000000 SIP/2.0
Via: SIP/2.0/UDP 192.168.0.103:15060;rport=15060;branch=z9hG4bK615818572;received=192.168.0.103
From: <sip:34020000002000000001@3402000000>;tag=696818572
To: <sip:34020000001380000001@3402000000>
Call-ID: 578818572
CSeq: 709 MESSAGE
Content-Type: Application/MANSCDP+xml
Max-Forwards: 70
User-Agent: GBS Agent
Content-Length: 267

<?xml version="1.0" encoding="GB2312"?>
<Control>
<CmdType>DeviceControl</CmdType>
<SN>347818572</SN>
<DeviceID>34020000001380000001</DeviceID>
<PTZCmd>A50F018100010037</PTZCmd>
<Info>
<ControlPriority>5</ControlPriority>
</Info>
</Control>

Android平台GB28181设备接入端处理如下:

@Override
public void ntsOnDeviceControlPTZCmd(String deviceId, String typeValue) {
handler_.postDelayed(new Runnable() {
@Override
public void run() {
Log.i(TAG, "DaniuSDK ntsOnDeviceControlPTZCmd device_id:" + device_id_ + " PTZType:" + ptz_type_);

if (null == ptz_type_)
return;

ptz_type_ = ptz_type_.trim();
if (ptz_type_.length() != 16)
return;

int instruction = hexStringToInt(ptz_type_.substring(6, 8));
int combination_code2 = hexStringToInt(ptz_type_.substring(12, 14));

//Android平台GB28181设备接入端,针对性的解析处理即可,这里不再赘述

private String device_id_;
private String ptz_type_;

public Runnable set(String device_id, String ptz_type) {
this.device_id_ = device_id;
this.ptz_type_ = ptz_type;
return this;
}

}.set(deviceId, typeValue),0);
}

预置位调用、删除也是上述类似处理。

总结

Android平台GB28181设备接入端,特别是针对RTSP转GB28181的场景下,如摄像头带云台,预置位的查询、调用设置可酌情考虑添加。当然,单纯地Android平台GB28181设备接入端,也可以针对预置位这块,做技术层面的扩展,通过技术拉通,让设备测接入端更灵活,更能满足客制化需求。