You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

337 lines
13 KiB

2 years ago
using System.Runtime.InteropServices;
namespace EC.Util.CameraSDK;
public static class HiKOriSDK
{
#region Lib Attr
public const string LibHcNetSDK = @"./libs/hik-win64/HCNetSDK.dll";
#endregion Lib Attr
static HiKOriSDK()
{
GlobalInit();
}
#region Global
public static bool InitSuccess { get; private set; }
public static bool GlobalInit()
{
if (InitSuccess) return true;
bool ret = NET_DVR_Init();
InitSuccess = ret;
if (!ret) throw new Exception("HiKOriSDK global init failure.");
return ret;
}
public static bool GlobalDestory()
{
if (!InitSuccess) return true;
bool ret = NET_DVR_Cleanup();
if (ret) InitSuccess = false;
return ret;
}
#endregion Global
#region SDK Const
public const int SERIALNO_LEN = 48; //序列号长度
#region 用于 NET_DVR_SetDVRConfig 和 NET_DVR_GetDVRConfig
public const int NET_DVR_SET_PTZPOS = 292; //云台设置PTZ位置
public const int NET_DVR_GET_PTZPOS = 293; //云台获取PTZ位置
public const int NET_DVR_GET_PTZSCOPE = 294; //云台获取PTZ范围
#endregion 用于 NET_DVR_SetDVRConfig 和 NET_DVR_GetDVRConfig
#region PtzMove
public const int TILT_UP = 21; /* 云台以SS的速度上仰 */
public const int TILT_DOWN = 22; /* 云台以SS的速度下俯 */
public const int PAN_LEFT = 23; /* 云台以SS的速度左转 */
public const int PAN_RIGHT = 24; /* 云台以SS的速度右转 */
public const int UP_LEFT = 25; /* 云台以SS的速度上仰和左转 */
public const int UP_RIGHT = 26; /* 云台以SS的速度上仰和右转 */
public const int DOWN_LEFT = 27; /* 云台以SS的速度下俯和左转 */
public const int DOWN_RIGHT = 28; /* 云台以SS的速度下俯和右转 */
public const int PAN_AUTO = 29; /* 云台以SS的速度左右自动扫描 */
public const int GOTO_PRESET = 39; /* 快球转到预置点 */
#endregion PtzMove
#endregion SDK Const
#region SDK Struct
//NET_DVR_Login()参数结构
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NET_DVR_DEVICEINFO
{
[MarshalAsAttribute(
UnmanagedType.ByValArray,
SizeConst = SERIALNO_LEN,
ArraySubType = UnmanagedType.I1
)]
public byte[] sSerialNumber; //序列号
public byte byAlarmInPortNum; //DVR报警输入个数
public byte byAlarmOutPortNum; //DVR报警输出个数
public byte byDiskNum; //DVR硬盘个数
public byte byDVRType; //DVR类型, 1:DVR 2:ATM DVR 3:DVS ......
public byte byChanNum; //DVR 通道个数
public byte byStartChan; //起始通道号,例如DVS-1,DVR - 1
}
//NET_DVR_Login_V30()参数结构
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NET_DVR_DEVICEINFO_V30
{
[MarshalAsAttribute(
UnmanagedType.ByValArray,
SizeConst = SERIALNO_LEN,
ArraySubType = UnmanagedType.I1
)]
public byte[] sSerialNumber; //序列号
public byte byAlarmInPortNum; //报警输入个数
public byte byAlarmOutPortNum; //报警输出个数
public byte byDiskNum; //硬盘个数
public byte byDVRType; //设备类型, 1:DVR 2:ATM DVR 3:DVS ......
public byte byChanNum; //模拟通道个数
public byte byStartChan; //起始通道号,例如DVS-1,DVR - 1
public byte byAudioChanNum; //语音通道数
public byte byIPChanNum; //最大数字通道个数,低位
public byte byZeroChanNum; //零通道编码个数 //2010-01-16
public byte byMainProto; //主码流传输协议类型 0-private, 1-rtsp,2-同时支持private和rtsp
public byte bySubProto; //子码流传输协议类型0-private, 1-rtsp,2-同时支持private和rtsp
public byte bySupport; //能力,位与结果为0表示不支持,1表示支持,
//bySupport & 0x1, 表示是否支持智能搜索
//bySupport & 0x2, 表示是否支持备份
//bySupport & 0x4, 表示是否支持压缩参数能力获取
//bySupport & 0x8, 表示是否支持多网卡
//bySupport & 0x10, 表示支持远程SADP
//bySupport & 0x20, 表示支持Raid卡功能
//bySupport & 0x40, 表示支持IPSAN 目录查找
//bySupport & 0x80, 表示支持rtp over rtsp
public byte bySupport1; // 能力集扩充,位与结果为0表示不支持,1表示支持
//bySupport1 & 0x1, 表示是否支持snmp v30
//bySupport1 & 0x2, 支持区分回放和下载
//bySupport1 & 0x4, 是否支持布防优先级
//bySupport1 & 0x8, 智能设备是否支持布防时间段扩展
//bySupport1 & 0x10, 表示是否支持多磁盘数(超过33个)
//bySupport1 & 0x20, 表示是否支持rtsp over http
//bySupport1 & 0x80, 表示是否支持车牌新报警信息2012-9-28, 且还表示是否支持NET_DVR_IPPARACFG_V40结构体
public byte bySupport2; /*00
bySupport2 & 0x1, URL取流解码
bySupport2 & 0x2, FTPV40
bySupport2 & 0x4, ANR
bySupport2 & 0x8, CCD的通道参数配置
bySupport2 & 0x10,
bySupport2 & 0x20,
bySupport2 & 0x40, */
public ushort wDevType; //设备型号
public byte bySupport3; //能力集扩展,位与结果为0表示不支持,1表示支持
//bySupport3 & 0x1, 表示是否多码流
// bySupport3 & 0x4 表示支持按组配置, 具体包含 通道图像参数、报警输入参数、IP报警输入、输出接入参数、
// 用户参数、设备工作状态、JPEG抓图、定时和时间抓图、硬盘盘组管理
//bySupport3 & 0x8为1 表示支持使用TCP预览、UDP预览、多播预览中的"延时预览"字段来请求延时预览(后续都将使用这种方式请求延时预览)。而当bySupport3 & 0x8为0时,将使用 "私有延时预览"协议。
//bySupport3 & 0x10 表示支持"获取报警主机主要状态(V40)"。
//bySupport3 & 0x20 表示是否支持通过DDNS域名解析取流
public byte byMultiStreamProto; //是否支持多码流,按位表示,0-不支持,1-支持,bit1-码流3,bit2-码流4,bit7-主码流,bit-8子码流
public byte byStartDChan; //起始数字通道号,0表示无效
public byte byStartDTalkChan; //起始数字对讲通道号,区别于模拟对讲通道号,0表示无效
public byte byHighDChanNum; //数字通道个数,高位
public byte bySupport4;
public byte byLanguageType; // 支持语种能力,按位表示,每一位0-不支持,1-支持
// byLanguageType 等于0 表示 老设备
// byLanguageType & 0x1表示支持中文
// byLanguageType & 0x2表示支持英文
[MarshalAsAttribute(
UnmanagedType.ByValArray,
SizeConst = 9,
ArraySubType = UnmanagedType.I1
)]
public byte[] byRes2; //保留
}
//球机位置信息
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NET_DVR_PTZPOS
{
public ushort wAction; //获取时该字段无效
public ushort wPanPos; //水平参数
public ushort wTiltPos; //垂直参数
public ushort wZoomPos; //变倍参数
}
//球机范围信息
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NET_DVR_PTZSCOPE
{
public ushort wPanPosMin; //水平参数min
public ushort wPanPosMax; //水平参数max
public ushort wTiltPosMin; //垂直参数min
public ushort wTiltPosMax; //垂直参数max
public ushort wZoomPosMin; //变倍参数min
public ushort wZoomPosMax; //变倍参数max
}
//邦诺CVR
public const int MAX_ID_COUNT = 256;
public const int MAX_STREAM_ID_COUNT = 1024;
public const int STREAM_ID_LEN = 32;
public const int PLAN_ID_LEN = 32;
//预览V40接口
[StructLayoutAttribute(LayoutKind.Sequential)]
public struct NET_DVR_PREVIEWINFO
{
public Int32 lChannel; //通道号
public uint dwStreamType; // 码流类型,0-主码流,1-子码流,2-码流3,3-码流4 等以此类推
public uint dwLinkMode; // 0:TCP方式,1:UDP方式,2:多播方式,3 - RTP方式,4-RTP/RTSP,5-RSTP/HTTP
public IntPtr hPlayWnd; //播放窗口的句柄,为NULL表示不播放图象
public bool bBlocked; //0-非阻塞取流, 1-阻塞取流, 如果阻塞SDK内部connect失败将会有5s的超时才能够返回,不适合于轮询取流操作.
public bool bPassbackRecord; //0-不启用录像回传,1启用录像回传
public byte byPreviewMode; //预览模式,0-正常预览,1-延迟预览
[MarshalAsAttribute(
UnmanagedType.ByValArray,
SizeConst = STREAM_ID_LEN,
ArraySubType = UnmanagedType.I1
)]
public byte[] byStreamID; //流ID,lChannel为0xffffffff时启用此参数
public byte byProtoType; //应用层取流协议,0-私有协议,1-RTSP协议
public byte byRes1;
public byte byVideoCodingType; //码流数据编解码类型 0-通用编码数据 1-热成像探测器产生的原始数据(温度数据的加密信息,通过去加密运算,将原始数据算出真实的温度值)
public uint dwDisplayBufNum; //播放库播放缓冲区最大缓冲帧数,范围1-50,置0时默认为1
public byte byNPQMode; //NPQ是直连模式,还是过流媒体 0-直连 1-过流媒体
[MarshalAsAttribute(
UnmanagedType.ByValArray,
SizeConst = 215,
ArraySubType = UnmanagedType.I1
)]
public byte[] byRes;
}
2 years ago
#endregion SDK Struct
#region Common Method
[DllImport(LibHcNetSDK)]
public static extern bool NET_DVR_Init();
[DllImport(LibHcNetSDK)]
public static extern bool NET_DVR_Cleanup();
[DllImport(LibHcNetSDK)]
public static extern uint NET_DVR_GetLastError();
[DllImport(LibHcNetSDK)]
public static extern int NET_DVR_Login_V30(
string sDVRIP,
int wDVRPort,
string sUserName,
string sPassword,
ref NET_DVR_DEVICEINFO_V30 lpDeviceInfo
);
[DllImport(LibHcNetSDK)]
public static extern bool NET_DVR_Logout(int iUserID);
//参数配置 begin
[DllImport(LibHcNetSDK)]
public static extern bool NET_DVR_GetDVRConfig(
int lUserID,
uint dwCommand,
int lChannel,
IntPtr lpOutBuffer,
uint dwOutBufferSize,
ref uint lpBytesReturned
);
[DllImport(LibHcNetSDK)]
public static extern bool NET_DVR_PTZControlWithSpeed_Other(
int lUserID,
int lChannel,
uint dwPTZCommand,
uint dwStop,
uint dwSpeed
);
[DllImport(LibHcNetSDK)]
public static extern bool NET_DVR_PTZPreset_Other(
int lUserID,
int lChannel,
uint dwPTZPresetCmd,
uint dwPresetIndex
);
/*********************************************************
Function: REALDATACALLBACK
Desc:
Input: lRealHandle
dwDataType
pBuffer
dwBufSize
pUser
Output:
Return: void
**********************************************************/
public delegate void REALDATACALLBACK(
Int32 lRealHandle,
UInt32 dwDataType,
IntPtr pBuffer,
UInt32 dwBufSize,
IntPtr pUser
);
/*********************************************************
Function: NET_DVR_RealPlay_V40
Desc:
Input: lUserID [in] NET_DVR_Login()NET_DVR_Login_V30()
lpPreviewInfo [in]
fRealDataCallBack_V30 [in]
pUser [in]
Output:
Return: 1NET_DVR_StopRealPlay等函数的句柄参数
**********************************************************/
[DllImport(LibHcNetSDK)]
public static extern int NET_DVR_RealPlay_V40(
int iUserID,
ref NET_DVR_PREVIEWINFO lpPreviewInfo,
REALDATACALLBACK fRealDataCallBack_V30,
IntPtr pUser
);
// [DllImport(@".\HCNetSDK.dll")]
// public static extern int NET_DVR_GetRealPlayerIndex(int lRealHandle);
/*********************************************************
Function: NET_DVR_StopRealPlay
Desc:
Input: lRealHandle [in] NET_DVR_RealPlay或者NET_DVR_RealPlay_V30的返回值
Output:
Return:
**********************************************************/
[DllImport(LibHcNetSDK)]
public static extern bool NET_DVR_StopRealPlay(int iRealHandle);
2 years ago
#endregion Common Method
}