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.
244 lines
9.6 KiB
244 lines
9.6 KiB
//#define Win32
|
|
#define Win64
|
|
|
|
//#define Linux32
|
|
//#define Linux64
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace EC.Util.CameraSDK;
|
|
|
|
public class YuShiOriSdk
|
|
{
|
|
#region Fields
|
|
|
|
#if Win32
|
|
public const string LibSdkPath = @"./libs/yushi/win32/NetDEVSDK.dll";
|
|
#elif Win64
|
|
public const string LibSdkPath = @"./libs/yushi/win64/NetDEVSDK.dll";
|
|
#elif Linux32
|
|
public const string LibSdkPath = @"./libs/yushi/linux64/libNetDEVSDK.so";
|
|
#elif Linux64
|
|
public const string LibSdkPath = @"./libs/yushi/linux64/libNetDEVSDK.so";
|
|
#endif
|
|
|
|
private const bool Debug = true;
|
|
|
|
#endregion Fields
|
|
|
|
static YuShiOriSdk()
|
|
{
|
|
GlobalInit();
|
|
}
|
|
|
|
#region Global
|
|
|
|
public static bool InitSuccess { get; private set; }
|
|
|
|
public static bool GlobalInit()
|
|
{
|
|
if (InitSuccess) return true;
|
|
bool ret = NETDEV_Init();
|
|
InitSuccess = ret;
|
|
if (!ret) throw new Exception("YuShiOriSdk global init failure.");
|
|
return ret;
|
|
}
|
|
|
|
public static bool GlobalDestory()
|
|
{
|
|
if (!InitSuccess) return true;
|
|
bool ret = NETDEV_Cleanup();
|
|
if (ret) InitSuccess = false;
|
|
return ret;
|
|
}
|
|
|
|
#endregion Global
|
|
|
|
#region Sdk Const
|
|
|
|
public const int TRUE = 1;
|
|
public const int FALSE = 0;
|
|
|
|
public const int PtzSpeedMin = 1;
|
|
public const int PtzSpeedMax = 9;
|
|
|
|
/* Common length */
|
|
public const int NETDEV_LEN_64 = 64;
|
|
public const int NETDEV_LEN_128 = 128;
|
|
public const int NETDEV_LEN_132 = 132;
|
|
public const int NETDEV_LEN_260 = 260;
|
|
|
|
/* NETDEV_PTZ_E */
|
|
public const int IRISCLOSE_STOP = 0x0101; /* Iris close stop */
|
|
public const int IRISCLOSE = 0x0102; /* Iris close */
|
|
public const int IRISOPEN_STOP = 0x0103; /* Iris open stop */
|
|
public const int IRISOPEN = 0x0104; /* Iris open */
|
|
public const int FOCUSNEAR_STOP = 0x0201; /* Focus near stop */
|
|
public const int FOCUSNEAR = 0x0202; /* Focus near */
|
|
public const int FOCUSFAR_STOP = 0x0203; /* Focus far stop */
|
|
public const int FOCUSFAR = 0x0204; /* Focus far */
|
|
public const int ZOOMTELE_STOP = 0x0301; /* Zoom in stop */
|
|
public const int ZOOMTELE = 0x0302; /* Zoom in */
|
|
public const int ZOOMWIDE_STOP = 0x0303; /* Zoom out stop */
|
|
public const int ZOOMWIDE = 0x0304; /* Zoom out */
|
|
public const int TILTUP = 0x0402; /* Tilt up */
|
|
public const int TILTDOWN = 0x0404; /* Tilt down */
|
|
public const int PANRIGHT = 0x0502; /* Pan right */
|
|
public const int PANLEFT = 0x0504; /* Pan left */
|
|
public const int LEFTUP = 0x0702; /* Move up left */
|
|
public const int LEFTDOWN = 0x0704; /* Move down left */
|
|
public const int RIGHTUP = 0x0802; /* Move up right */
|
|
public const int RIGHTDOWN = 0x0804; /* Move down right */
|
|
public const int ALLSTOP = 0x0901; /* All-stop command word */
|
|
public const int FOCUS_AND_IRIS_STOP = 0x0907; /* Focus & Iris-stop command word */
|
|
public const int MOVE_STOP = 0x0908; /* move stop command word */
|
|
public const int ZOOM_STOP = 0x0909; /* zoom stop command word */
|
|
/* NETDEV_PTZ_PRESETCMD_E */
|
|
public const int PRESET_SET = 0; /* Set preset */
|
|
public const int PRESET_CLE = 1; /* Clear preset */
|
|
public const int PRESET_GOTO = 2; /* Go to preset */
|
|
|
|
public enum NETDEV_LIVE_STREAM_INDEX_E : int
|
|
{
|
|
NETDEV_LIVE_STREAM_INDEX_MAIN = 0, /* Main stream */
|
|
NETDEV_LIVE_STREAM_INDEX_SUB = 1, /* Sub stream */
|
|
NETDEV_LIVE_STREAM_INDEX_THIRD = 2, /* Third stream */
|
|
|
|
NETDEV_LIVE_STREAM_INDEX_INVALID
|
|
}
|
|
|
|
public enum NETDEV_PROTOCAL_E : int
|
|
{
|
|
NETDEV_TRANSPROTOCAL_RTPUDP = 0, /* UDP */
|
|
NETDEV_TRANSPROTOCAL_RTPTCP = 1 /* TCP */
|
|
}
|
|
|
|
public enum NETDEV_PICTURE_FLUENCY_E
|
|
{
|
|
NETDEV_PICTURE_REAL = 0, /* Real-time first */
|
|
NETDEV_PICTURE_FLUENCY = 1, /* Fluency first */
|
|
NETDEV_PICTURE_BALANCE_NEW = 3, /* Balance */
|
|
NETDEV_PICTURE_RTMP_FLUENCY = 4, /* RTMP fluency first */
|
|
|
|
NETDEV_PICTURE_FLUENCY_INVALID = 0xff /* Invalid value */
|
|
}
|
|
|
|
#endregion Sdk Const
|
|
|
|
#region Sdk Struct
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct NETDEV_DEVICE_LOGIN_INFO_S
|
|
{
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NETDEV_LEN_260)]
|
|
public string szIPAddr; /* IP地址/域名 */
|
|
|
|
public int dwPort; /* 端口号 */
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NETDEV_LEN_132)]
|
|
public string szUserName; /* 用户名 */
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NETDEV_LEN_128)]
|
|
public string szPassword; /* 密码 */
|
|
|
|
public int dwLoginProto; /* 登录协议, 参见NETDEV_LOGIN_PROTO_E */
|
|
public int dwDeviceType; /* 设备类型, 参见NETDEV_DEVICE_TYPE_E */
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]
|
|
public byte[] byRes; /* Reserved */
|
|
};
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct NETDEV_SELOG_INFO_S
|
|
{
|
|
public int dwSELogCount;
|
|
public int dwSELogTime;
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
|
|
public byte[] byRes;
|
|
};
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct NETDEV_VIDEO_CHL_DETAIL_INFO_S
|
|
{
|
|
public int dwChannelID;
|
|
public int bPtzSupported; /* Whether ptz is supported */
|
|
public int enStatus; /* Channel status */
|
|
public int dwStreamNum; /* Number of streams */
|
|
|
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = NETDEV_LEN_64)]
|
|
public string szChnName; /* Device serial number */
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
|
public byte[] szReserve;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct NETDEV_PTZ_STATUS_S
|
|
{
|
|
public float fPanTiltX; /* 绝对水平坐标 Absolute horizontal coordinates*/
|
|
public float fPanTiltY; /* 绝对竖直坐标 Absolute vertical coordinates*/
|
|
public float fZoomX; /* 绝对聚焦倍数 Absolute multiples*/
|
|
public int enPanTiltStatus;/* 云台状态 PTZ Status*/
|
|
public int enZoomStatus; /* 聚焦状态 Focus Status*/
|
|
};
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct NETDEV_PREVIEWINFO_S
|
|
{
|
|
public int dwChannelID; /* ID Channel ID */
|
|
public int dwStreamType; /* #NETDEV_LIVE_STREAM_INDEX_E Stream type, see enumeration #NETDEV_LIVE_STREAM_INDEX_E */
|
|
public int dwLinkMode; /* #NETDEV_PROTOCAL_E Transport protocol, see enumeration #NETDEV_PROTOCAL_E */
|
|
public IntPtr hPlayWnd; /* Play window handle */
|
|
public int dwFluency; /* #NETDEV_PICTURE_FLUENCY_E image play fluency*/
|
|
public int dwStreamMode; /* #NETDEV_STREAM_MODE_E start stream mode see #NETDEV_STREAM_MODE_E*/
|
|
public int dwLiveMode; /* #NETDEV_PULL_STREAM_MODE_E Rev. Flow pattern */
|
|
public int dwDisTributeCloud; /* #NETDEV_DISTRIBUTE_CLOUD_SRV_E distribution */
|
|
public int dwallowDistribution; /* allow or no distribution*/
|
|
public int dwTransType; /* 传输类型,参见枚举# NETDEV_TRANS_TYPE_E */
|
|
public int dwStreamProtocol; /* 起流协议,参见枚举# NETDEV_START_STREAM_PROT_E */
|
|
|
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 236)]
|
|
public byte[] szReserve; /* Reserved */
|
|
}
|
|
|
|
#endregion Sdk Struct
|
|
|
|
#region Common Method
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern bool NETDEV_Init();
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern bool NETDEV_Cleanup();
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int NETDEV_GetLastError();
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern IntPtr NETDEV_Login_V30(ref NETDEV_DEVICE_LOGIN_INFO_S pstDevLoginInfo, ref NETDEV_SELOG_INFO_S pstSELogInfo);
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern bool NETDEV_Logout(IntPtr lpUserID);
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int NETDEV_QueryVideoChlDetailList(IntPtr lpUserID, ref int pdwChlCount, IntPtr pstVideoChlList);
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern bool NETDEV_PTZGetStatus(IntPtr lpUserID, int dwChannelID, ref NETDEV_PTZ_STATUS_S pstPTZStaus);
|
|
|
|
//public boolean NETDEV_GetDevConfig(Pointer lpUserID, int dwChannelID, int dwCommand, Pointer lpOutBuffer, int dwOutBufferSize, IntByReference pdwBytesReturned);
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int NETDEV_PTZControl_Other(IntPtr lpUserID, int dwChannelID, int dwPTZCommand, int dwSpeed);
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int NETDEV_PTZPreset_Other(IntPtr lpUserID, int dwChannelID, int dwPTZPresetCmd, byte[] szPresetName, int dwPresetID);
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern IntPtr NETDEV_RealPlay(IntPtr lpUserID, ref NETDEV_PREVIEWINFO_S pstPreviewInfo, IntPtr cbPlayDataCallBack, IntPtr lpUserData);
|
|
|
|
[DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
|
|
public static extern int NETDEV_StopRealPlay(IntPtr lpRealHandle);
|
|
|
|
#endregion Common Method
|
|
}
|