//#define Linux32
//#define Linux64
//#define Win32
//#define Win64
using System.Runtime.InteropServices;
namespace EC.Helper.CameraSDK;
public static class DaHuaOriSDK
{
#region Lib Attr
#if (Linux32)
private const string LibDhNetSDK = @"./libs/dahua/linux32/libdhnetsdk.so";
#elif (Linux64)
private const string LibDhNetSDK = @"./libs/dahua/linux64/libdhnetsdk.so";
#elif (Win32)
private const string LibDhNetSDK = @"./libs/dahua/win32/dhnetsdk.dll";
#elif (Win64)
private const string LibDhNetSDK = @"./libs/dahua/win64/dhnetsdk.dll";
#endif
#endregion Lib Attr
static DaHuaOriSDK()
{
GlobalInit();
}
#region Global
public static bool InitSuccess { get; private set; }
public static bool GlobalInit()
{
if (InitSuccess) return true;
bool ret = CLIENT_InitEx(null, IntPtr.Zero, IntPtr.Zero);
InitSuccess = ret;
if (!ret) throw new Exception("DaHuaOriSDK global init failure.");
return ret;
}
public static bool GlobalDestory()
{
if (!InitSuccess) return true;
CLIENT_Cleanup();
InitSuccess = false;
return true;
}
#endregion Global
#region SDK Enum
///
/// login device mode enumeration
/// 登陆设备方式枚举
///
public enum EM_LOGIN_SPAC_CAP_TYPE
{
///
/// TCP login, default
/// TCP登陆, 默认方式
///
TCP = 0,
///
/// No criteria login
/// 无条件登陆
///
ANY = 1,
///
/// auto sign up login
/// 主动注册的登入
///
SERVER_CONN = 2,
///
/// multicast login, default
/// 组播登陆
///
MULTICAST = 3,
///
/// UDP method login
/// UDP方式下的登入
///
UDP = 4,
///
/// only main connection login
/// 只建主连接下的登入
///
MAIN_CONN_ONLY = 6,
///
/// SSL encryption login
/// SSL加密方式登陆
///
SSL = 7,
///
/// login IVS box remote device
/// 登录智能盒远程设备
///
INTELLIGENT_BOX = 9,
///
/// login device do not config
/// 登录设备后不做取配置操作
///
NO_CONFIG = 10,
///
/// USB key device login
/// 用U盾设备的登入
///
U_LOGIN = 11,
///
/// LDAP login
/// LDAP方式登录
///
LDAP = 12,
///
/// AD login
/// AD(ActiveDirectory)登录方式
///
AD = 13,
///
/// Radius login
/// Radius 登录方式
///
RADIUS = 14,
///
/// Socks5 login
/// Socks5登陆方式
///
SOCKET_5 = 15,
///
/// cloud login
/// 云登陆方式
///
CLOUD = 16,
///
/// dual authentication loin
/// 二次鉴权登陆方式
///
AUTH_TWICE = 17,
///
/// TS stream client login
/// TS码流客户端登陆方式
///
TS = 18,
///
/// web private login
/// 为P2P登陆方式
///
P2P = 19,
///
/// mobile client login
/// 手机客户端登陆
///
MOBILE = 20,
///
/// invalid login
/// 无效的登陆方式
///
INVALID = 21,
}
///
/// device type enumeration
/// 设备类型枚举
///
public enum EM_NET_DEVICE_TYPE
{
///
/// Unknow
// 未知
///
NET_PRODUCT_NONE = 0,
///
/// Non real-time MACE
/// 非实时MACE
///
NET_DVR_NONREALTIME_MACE,
///
/// Non real-time
/// 非实时
///
NET_DVR_NONREALTIME,
///
/// Network video server
/// 网络视频服务器
///
NET_NVS_MPEG1,
///
/// MPEG1 2-ch DVR
/// MPEG1二路录像机
///
NET_DVR_MPEG1_2,
///
/// MPEG1 8-ch DVR
/// MPEG1八路录像机
///
NET_DVR_MPEG1_8,
///
/// MPEG4 8-ch DVR
/// MPEG4八路录像机
///
NET_DVR_MPEG4_8,
///
/// MPEG4 16-ch DVR
/// MPEG4 十六路录像机
///
NET_DVR_MPEG4_16,
///
/// LB series DVR
/// LB系列录像机
///
NET_DVR_MPEG4_SX2,
///
/// GB series DVR
/// GB系列录像机
///
NET_DVR_MEPG4_ST2,
///
/// HB series DVR
/// HB系列录像机
///
NET_DVR_MEPG4_SH2,
///
/// GBE series DVR
/// GBE系列录像机
///
NET_DVR_MPEG4_GBE,
///
/// II network video server
/// II代网络视频服务器
///
NET_DVR_MPEG4_NVSII,
///
/// New standard configuration protocol
/// 新标准配置协议
///
NET_DVR_STD_NEW,
///
/// DDNS server
/// DDNS服务器
///
NET_DVR_DDNS,
///
/// ATM series
/// ATM机
///
NET_DVR_ATM,
///
/// 2nd non real-time NB series DVR
/// 二代非实时NB系列机器
///
NET_NB_SERIAL,
///
/// LN series
/// LN系列产品
///
NET_LN_SERIAL,
///
/// BAV series
/// BAV系列产品
///
NET_BAV_SERIAL,
///
/// SDIP series
/// SDIP系列产品
///
NET_SDIP_SERIAL,
///
/// IPC series
/// IPC系列产品
///
NET_IPC_SERIAL,
///
/// NVS B series
/// NVS B系列
///
NET_NVS_B,
///
/// NVS H series
/// NVS H系列
///
NET_NVS_C,
///
/// NVS S series
/// NVS S系列
///
NET_NVS_S,
///
/// NVS E series
/// NVS E系列
///
NET_NVS_E,
///
/// Search device type from QueryDevState. it is in string format
/// 从QueryDevState中查询设备类型,以字符串格式
///
NET_DVR_NEW_PROTOCOL,
///
/// NVD
/// 解码器
///
NET_NVD_SERIAL,
///
/// N5
/// N5
///
NET_DVR_N5,
///
/// HDVR
/// 混合DVR
///
NET_DVR_MIX_DVR,
///
/// SVR series
/// SVR系列
///
NET_SVR_SERIAL,
///
/// SVR-BS
/// SVR-BS
///
NET_SVR_BS,
///
/// NVR series
/// NVR系列
///
NET_NVR_SERIAL,
///
/// N51
/// N51
///
NET_DVR_N51,
///
/// ITSE Intelligent Analysis Box
/// ITSE 智能分析盒
///
NET_ITSE_SERIAL,
///
/// Intelligent traffic camera equipment
/// 智能交通像机设备
///
NET_ITC_SERIAL,
///
/// radar speedometer HWS
/// 雷达测速仪HWS
///
NET_HWS_SERIAL,
///
/// portable video record
/// 便携式音视频录像机
///
NET_PVR_SERIAL,
///
/// IVS(intelligent video server series)
/// IVS(智能视频服务器系列)
///
NET_IVS_SERIAL,
///
/// universal intelligent detect video server series
/// 通用智能视频侦测服务器
///
NET_IVS_B,
///
/// face recognisation server
/// 人脸识别服务器
///
NET_IVS_F,
///
/// video quality diagnosis server
/// 视频质量诊断服务器
///
NET_IVS_V,
///
/// matrix
/// 矩阵
///
NET_MATRIX_SERIAL,
///
/// N52
/// N52
///
NET_DVR_N52,
///
/// N56
/// N56
///
NET_DVR_N56,
///
/// ESS
/// ESS
///
NET_ESS_SERIAL,
///
/// 人数统计服务器
///
NET_IVS_PC,
///
/// pc-nvr
/// pc-nvr
///
NET_PC_NVR,
///
/// screen controller
/// 大屏控制器
///
NET_DSCON,
///
/// network video storage server
/// 网络视频存储服务器
///
NET_EVS,
///
/// an embedded intelligent video analysis system
/// 嵌入式智能分析视频系统
///
NET_EIVS,
///
/// DVR-N6
/// DVR-N6
///
NET_DVR_N6,
///
/// K-Lite Codec Pack
/// 万能解码器
///
NET_UDS,
///
/// Bank alarm host
/// 银行报警主机
///
NET_AF6016,
///
/// Video network alarm host
/// 视频网络报警主机
///
NET_AS5008,
///
/// Network alarm host
/// 网络报警主机
///
NET_AH2008,
///
/// Alarm host series
/// 报警主机系列
///
NET_A_SERIAL,
///
/// Access control series of products
/// 门禁系列产品
///
NET_BSC_SERIAL,
///
/// NVS series product
/// NVS系列产品
///
NET_NVS_SERIAL,
///
/// VTO series product
/// VTO系列产品
///
NET_VTO_SERIAL,
///
/// VTNC series product
/// VTNC系列产品
///
NET_VTNC_SERIAL,
///
/// TPC series product, it is the thermal device
/// TPC系列产品, 即热成像设备
///
NET_TPC_SERIAL,
///
/// ASM series product
/// 无线中继设备
///
NET_ASM_SERIAL,
///
/// VTS series product
/// 管理机
///
NET_VTS_SERIAL,
///
/// Alarm host-ARC2016C
/// 报警主机ARC2016C
///
NET_ARC2016C,
///
/// ASA Attendance machine
/// 考勤机
///
NET_ASA,
///
/// Industry terminal walkie-talkie
/// 行业对讲终端
///
NET_VTT_SERIAL,
///
/// Alarm column
/// 报警柱
///
NET_VTA_SERIAL,
///
/// SIP Server
/// SIP服务器
///
NET_VTNS_SERIAL,
///
/// Indoor unit
/// 室内机
///
NET_VTH_SERIAL,
}
///
/// 查询设备信息参数
///
public enum EM_DEVICE_STATE
{
///
/// Query device online state(return a DWORD value, 1-online, 0-offline)
/// 查询设备的在线状态(返回一个DWORD, 1表示在线, 0表示断线)
///
ONLINE = 0x0035,
///
/// Query ptz state(struct DH_PTZ_LOCATION_INFO)
/// 查询云台状态信息(对应结构体 DH_PTZ_LOCATION_INFO)
///
PTZ_LOCATION = 0x0036,
}
///
/// 预置点状态枚举
///
public enum EM_DH_PTZ_PRESET_STATUS
{
UNKNOWN, // 未知
REACH, // 预置点到达
UNREACH, // 预置点未到达
}
#endregion SDK Enum
#region SDK Struct
///
/// CLIENT_LoginWithHighLevelSecurity 输入参数
///
public struct NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY
{
public uint dwSize;// 结构体大小
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string szIP; // IP
public int nPort; // 端口
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string szUserName; // 用户名
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string szPassword; // 密码
public EM_LOGIN_SPAC_CAP_TYPE emSpecCap; // 登录模式
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public byte[] byReserved; // 字节对齐
public IntPtr pCapParam; // 见 CLIENT_LoginEx 接口 pCapParam 与 nSpecCap 关系
}
///
/// device information structure
/// 设备信息结构体
///
public struct NET_DEVICEINFO_Ex
{
///
/// serial number
/// 序列号
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 48)]
public string sSerialNumber;
///
/// count of alarm input
/// 报警输入个数
///
public int nAlarmInPortNum;
///
/// count of alarm output
/// 报警输出个数
///
public int nAlarmOutPortNum;
///
/// number of disk
/// 硬盘个数
///
public int nDiskNum;
///
/// device type, refer to EM_NET_DEVICE_TYPE
/// 设备类型,见枚举NET_DEVICE_TYPE
///
public EM_NET_DEVICE_TYPE nDVRType;
///
/// number of channel
/// 通道个数
///
public int nChanNum;
///
/// Online Timeout, Not Limited Access to 0, not 0 Minutes Limit Said
/// 在线超时时间,为0表示不限制登陆,非0表示限制的分钟数
///
public byte byLimitLoginTime;
///
/// When login failed due to password error, notice user by this parameter.This parameter is invalid when remaining login times is zero
/// 当登陆失败原因为密码错误时,通过此参数通知用户,剩余登陆次数,为0时表示此参数无效
///
public byte byLeftLogTimes;
///
/// keep bytes for aligned
/// 保留字节,字节对齐
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
public byte[] bReserved;
///
/// when log in failed,the left time for users to unlock (seconds), -1 indicate the device haven't set the parameter
/// 当登陆失败,用户解锁剩余时间(秒数), -1表示设备未设置该参数
///
public int nLockLeftTime;
///
/// reserved
/// 保留字节
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 24)]
public byte[] Reserved;
}
///
/// CLIENT_LoginWithHighLevelSecurity 输出参数
///
public struct NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY
{
public uint dwSize;// 结构体大小
public NET_DEVICEINFO_Ex stuDeviceInfo; // 设备信息
public int nError; // 错误码,见 CLIENT_Login 接口错误码
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 132)]
public byte[] byReserved; // 保留字节
}
///
/// 云台定位中非归一化坐标和变倍
///
public struct NET_PTZSPACE_UNNORMALIZED
{
public int nPosX; // x坐标
public int nPosY; // y坐标
public int nZoom; // 放大倍率
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 52)]
public byte[] byReserved; // 预留字节
}
///
/// 云台定位信息
///
//云台定位信息
public struct DH_PTZ_LOCATION_INFO
{
public int nChannelID; // 通道号
public int nPTZPan; // 云台水平运动位置,有效范围:[0,3600]
public int nPTZTilt; // 云台垂直运动位置,有效范围:[-1800,1800]
public int nPTZZoom; // 云台光圈变动位置,有效范围:[0,128]
public byte bState; // 云台运动状态, 0-未知 1-运动 2-空闲
public byte bAction; // 云台动作,255-未知,0-预置点,1-线扫,2-巡航,3-巡迹,4-水平旋转,5-普通移动,6-巡迹录制,7-全景云台扫描,8-热度图
// 9-精确定位,10-设备校正,11-智能配置,12-云台重启
public byte bFocusState; // 云台聚焦状态, 0-未知, 1-运动状态, 2-空闲
public byte bEffectiveInTimeSection; // 在时间段内预置点状态是否有效
//如果当前上报的预置点是时间段内的预置点,则为1,其他情况为0
public int nPtzActionID; // 巡航ID号
public uint dwPresetID; // 云台所在预置点编号
public float fFocusPosition; // 聚焦位置
public byte bZoomState; // 云台ZOOM状态,0-未知,1-ZOOM,2-空闲
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public byte[] bReserved; // 对齐
public uint dwSequence; // 包序号,用于校验是否丢包
public uint dwUTC; // 对应的UTC(1970-1-1 00:00:00)秒数。
public EM_DH_PTZ_PRESET_STATUS emPresetStatus; // 预置点位置
///
/// 保留字段
///
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 248)]
public int[] reserved;
};
#endregion SDK Struct
#region Common Method
///
/// network disconnection callback function original shape
/// 断线回调函数
///
/// user LoginID:Login's returns value 登陆ID
/// device IP 设备IP
/// device prot 设备端口
/// user data from Init function 用户数据
public delegate void fDisConnectCallBack(IntPtr lLoginID, IntPtr pchDVRIP, int nDVRPort, IntPtr dwUser);
///
/// network re-connection callback function original shape
/// 重连回调函数
///
/// user LoginID:Login's returns value 登陆ID
/// device IP,string type 设备IP
/// device prot 设备端口
/// user data from SetAutoReconnect function 用户数据
public delegate void fHaveReConnectCallBack(IntPtr lLoginID, IntPtr pchDVRIP, int nDVRPort, IntPtr dwUser);
[DllImport(LibDhNetSDK)]
public static extern bool CLIENT_InitEx(fDisConnectCallBack? cbDisConnect, IntPtr dwUser, IntPtr lpInitParam);
[DllImport(LibDhNetSDK)]
public static extern void CLIENT_Cleanup();
[DllImport(LibDhNetSDK)]
public static extern int CLIENT_GetLastError();
[DllImport(LibDhNetSDK)]
public static extern IntPtr CLIENT_LoginWithHighLevelSecurity(ref NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstInParam, ref NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam);
[DllImport(LibDhNetSDK)]
public static extern bool CLIENT_Logout(IntPtr lLoginID);
[DllImport(LibDhNetSDK)]
public static extern void CLIENT_SetAutoReconnect(fHaveReConnectCallBack cbAutoConnect, IntPtr dwUser);
[DllImport(LibDhNetSDK)]
public static extern bool CLIENT_QueryDevState(IntPtr lLoginID, int nType, IntPtr pBuf, int nBufLen, ref int pRetLen, int waittime);
#endregion Common Method
}