diff --git a/EC.Util/CameraSDK/Common/CameraFactory.cs b/EC.Util/CameraSDK/Common/CameraFactory.cs index e54edcb..e9793e8 100644 --- a/EC.Util/CameraSDK/Common/CameraFactory.cs +++ b/EC.Util/CameraSDK/Common/CameraFactory.cs @@ -1,7 +1,52 @@ -namespace EC.Util.CameraSDK; +using System.IO.Compression; +using System.Runtime.InteropServices; + +namespace EC.Util.CameraSDK; public class CameraFactory { + static CameraFactory() + { + string zipPath = Path.Combine("libs", "cameraSdks.zip"); + if (!File.Exists(zipPath)) throw new FileNotFoundException(zipPath); + using ZipArchive archive = ZipFile.OpenRead(zipPath); + bool isWin = RuntimeInformation.IsOSPlatform(OSPlatform.Windows), is64 = Environment.Is64BitProcess; + string sysEnv = string.Format("{0}{1}", isWin ? "win" : "linux", is64 ? "64" : "32"); + string hkOrDir = $"cameraSdks/hik/{sysEnv}/"; + string dhOrDir = $"cameraSdks/dahua/{sysEnv}/"; + string ysOrDir = $"cameraSdks/yushi/{sysEnv}/"; + foreach (ZipArchiveEntry entry in archive.Entries) + { + if (entry.Length == 0) continue; + string fullName = entry.FullName, fileExtPath = string.Empty; + if (fullName.StartsWith(hkOrDir)) + fileExtPath = Path.Join("libs", "hik", fullName[(hkOrDir.Length - 1)..]); + else if (fullName.StartsWith(dhOrDir)) + fileExtPath = Path.Join("libs", "dahua", fullName[(dhOrDir.Length - 1)..]); + else if (fullName.StartsWith(ysOrDir)) + fileExtPath = Path.Join("libs", "yushi", fullName[(ysOrDir.Length - 1)..]); + if (string.IsNullOrEmpty(fileExtPath)) continue; + FileInfo fi = new(fileExtPath); + if (fi.Directory != null && !fi.Directory.Exists) fi.Directory.Create(); + if (!fi.Exists) entry.ExtractToFile(fileExtPath); + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + string[] hikLibsName = new string[] { "libAudioRender.so", "libSuperRender.so" }; + foreach (string name in hikLibsName) + { + if (File.Exists(Path.Join(".", name))) continue; + string path = Path.Join("libs", "hik", name); + FileInfo fi = new(path); + if (!fi.Exists) throw new FileNotFoundException(path); + fi.CopyTo(Path.Join(".", name), false); + } + } + } + + public static void VirtualInit() + { } + public static ICameraSdk BuildCameraSdk(CameraInfo info) { ICameraSdk sdk = (info.Manufactor) switch diff --git a/EC.Util/CameraSDK/DaHua/DaHuaOriSdk.cs b/EC.Util/CameraSDK/DaHua/DaHuaOriSdk.cs index 0245c9e..ad7a786 100644 --- a/EC.Util/CameraSDK/DaHua/DaHuaOriSdk.cs +++ b/EC.Util/CameraSDK/DaHua/DaHuaOriSdk.cs @@ -1,8 +1,5 @@ -//#define Win32 -#define Win64 +//#define Win -//#define Linux32 -//#define Linux64 using System.Runtime.InteropServices; namespace EC.Util.CameraSDK; @@ -11,14 +8,10 @@ public static class DaHuaOriSdk { #region Fields -#if Win32 - public const string LibSdkPath = @"./libs/dahua/win32/dhnetsdk.dll"; -#elif Win64 - public const string LibSdkPath = @"./libs/dahua/win64/dhnetsdk.dll"; -#elif Linux32 - public const string LibSdkPath = @"./libs/dahua/linux32/libdhnetsdk.so"; -#elif Linux64 - public const string LibSdkPath = @"./libs/dahua/linux64/libdhnetsdk.so"; +#if Win + public const string LibSdkPath = @"./libs/dahua/dhnetsdk.dll"; +#else + public const string LibSdkPath = @"./libs/dahua/libdhnetsdk.so"; #endif private const bool Debug = true; @@ -40,6 +33,17 @@ public static class DaHuaOriSdk bool ret = CLIENT_InitEx(null, IntPtr.Zero, IntPtr.Zero); InitSuccess = ret; if (!ret) throw new Exception("DaHuaOriSdk global init failure."); + //打开日志 + if (Debug) + { + NET_LOG_SET_PRINT_INFO logInfo = new() + { + dwSize = (uint)Marshal.SizeOf(typeof(NET_LOG_SET_PRINT_INFO)), + bSetFilePath = 1, + szLogFilePath = Path.Combine("./log", "dahuaSdkLog", "sdk_log.log") + }; + CLIENT_LogOpen(ref logInfo); + } return ret; } @@ -1265,6 +1269,86 @@ public static class DaHuaOriSdk #region Sdk Struct + // SDK日志回调 + public delegate int fSDKLogCallBack(IntPtr lUploadFileHandle, uint nLogSize, IntPtr dwUser); + + /// + /// SDK全局日志打印信息 + /// SDK global log print + /// + public struct NET_LOG_SET_PRINT_INFO + { + public uint dwSize; + + /// + /// 是否重设日志路径 + /// reset log path + /// + public int bSetFilePath; + + /// + /// 日志路径(默认"./sdk_log/sdk_log.log") + /// log path(default"./sdk_log/sdk_log.log") + /// + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] + public string szLogFilePath; + + /// + /// 是否重设日志文件大小 + /// reset log size + /// + public int bSetFileSize; + + /// + /// 每个日志文件的大小(默认大小10240), 单位:比特 + /// each log file size(default size 10240), unit:bit + /// + public uint nFileSize; + + /// + /// 是否重设日志文件个数 + /// reset log file number + /// + public int bSetFileNum; + + /// + /// 绕接日志文件个数(默认大小10) + /// log file quantity(default size 10) + /// + public uint nFileNum; + + /// + /// 是否重设日志打印输出策略 + /// reset log print strategy + /// + public int bSetPrintStrategy; + + /// + /// 日志输出策略, 0:输出到文件(默认); 1:输出到窗口 + /// log out strategy, 0: output to file(defualt); 1:output to window + /// + public uint nPrintStrategy; + + /// + /// 字节对齐 + /// Byte alignment + /// + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + public byte[] byReserved; + + /// + /// 日志回调,需要将sdk日志回调出来时设置,默认为NULL + /// log callback, (default NULL) + /// + public fSDKLogCallBack cbSDKLogCallBack; + + /// + /// 用户数据 + /// UserData + /// + public IntPtr dwUser; + } + /// /// CLIENT_LoginWithHighLevelSecurity 输入参数 /// @@ -1462,6 +1546,9 @@ public static class DaHuaOriSdk [DllImport(LibSdkPath)] public static extern void CLIENT_Cleanup(); + [DllImport(LibSdkPath)] + public static extern bool CLIENT_LogOpen(ref NET_LOG_SET_PRINT_INFO pstLogPrintInfo); + [DllImport(LibSdkPath)] public static extern int CLIENT_GetLastError(); diff --git a/EC.Util/CameraSDK/HiK/HiKOriSdk.cs b/EC.Util/CameraSDK/HiK/HiKOriSdk.cs index f435066..d7492f1 100644 --- a/EC.Util/CameraSDK/HiK/HiKOriSdk.cs +++ b/EC.Util/CameraSDK/HiK/HiKOriSdk.cs @@ -1,8 +1,6 @@ -//#define Win32 -#define Win64 +//#define Win +#define Linux64 -//#define Linux32 -//#define Linux64 using System.Runtime.InteropServices; namespace EC.Util.CameraSDK; @@ -11,17 +9,13 @@ public class HiKOriSdk { #region Fields -#if Win32 - public const string LibSdkPath = @"./libs/hik/win32/HCNetSDK.dll"; -#elif Win64 - public const string LibSdkPath = @"./libs/hik/win64/HCNetSDK.dll"; -#elif Linux32 - public const string LibSdkPath = @"./libs/hik/linux32/libhcnetsdk.so"; -#elif Linux64 - public const string LibSdkPath = @"./libs/hik/linux64/libhcnetsdk.so"; +#if Win + public const string LibSdkPath = @"./libs/hik/HCNetSDK.dll"; +#else + public const string LibSdkPath = @"./libs/hik/libhcnetsdk.so"; #endif - private const bool Debug = true; + private const bool Debug = false; #endregion Fields @@ -293,8 +287,16 @@ public class HiKOriSdk public struct NET_DVR_PREVIEWINFO { public int lChannel; //通道号 +#if !Linux64 public uint dwStreamType; // 码流类型,0-主码流,1-子码流,2-码流3,3-码流4 等以此类推 +#else + public ulong dwStreamType; // 码流类型,0-主码流,1-子码流,2-码流3,3-码流4 等以此类推 +#endif +#if !Linux64 public uint dwLinkMode; // 0:TCP方式,1:UDP方式,2:多播方式,3 - RTP方式,4-RTP/RTSP,5-RSTP/HTTP +#else + public ulong dwLinkMode; // 0:TCP方式,1:UDP方式,2:多播方式,3 - RTP方式,4-RTP/RTSP,5-RSTP/HTTP +#endif public IntPtr hPlayWnd; //播放窗口的句柄,为NULL表示不播放图象 public bool bBlocked; //0-非阻塞取流, 1-阻塞取流, 如果阻塞SDK内部connect失败将会有5s的超时才能够返回,不适合于轮询取流操作. public bool bPassbackRecord; //0-不启用录像回传,1启用录像回传 @@ -387,6 +389,18 @@ public class HiKOriSdk [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] public static extern int NET_DVR_RealPlay_V40(int iUserID, ref NET_DVR_PREVIEWINFO lpPreviewInfo, RealDataCallBack fRealDataCallBack_V30, IntPtr pUser); + /********************************************************* + Function: REALDATACALLBACK + Desc: (�ص�����) + Input: + Output: + Return: + **********************************************************/ + //public delegate void SETREALDATACALLBACK(int lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, uint dwUser); + + [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + public static extern bool NET_DVR_SetRealDataCallBack(int lRealHandle, RealDataCallBack fRealDataCallBack, IntPtr pUser); + /********************************************************* Function: NET_DVR_StopRealPlay Desc: 停止预览。 diff --git a/EC.Util/CameraSDK/HiK/HiKSdk.cs b/EC.Util/CameraSDK/HiK/HiKSdk.cs index 6f50986..8be31d2 100644 --- a/EC.Util/CameraSDK/HiK/HiKSdk.cs +++ b/EC.Util/CameraSDK/HiK/HiKSdk.cs @@ -66,7 +66,7 @@ public class HiKSdk : ICameraSdk throw CameraException.New(CameraInfo, (int)errCode); } - private void BuildPlayCtrlException(int nPort) + public void BuildPlayCtrlException(int nPort) { string err = $"PlayCtrlSdk failed, error code={PlayCtrlSdk.PlayM4_GetLastError(nPort)}"; throw CameraException.New(CameraInfo, -1, err); @@ -101,7 +101,7 @@ public class HiKSdk : ICameraSdk Marshal.StructureToPtr(entity, ptrBuf, true); try { - ret = HiKOriSdk.NET_DVR_GetDVRConfig(LoginId, HiKOriSdk.NET_DVR_GET_PTZPOS, 0, ptrBuf, (uint)dwSize, ref dwReturned); + ret = HiKOriSdk.NET_DVR_GetDVRConfig(LoginId, HiKOriSdk.NET_DVR_GET_PTZPOS, Channel, ptrBuf, (uint)dwSize, ref dwReturned); if (!ret) { BuildException(); return PtzInfo.Default; } object? objBuf = Marshal.PtrToStructure(ptrBuf, GPIParams.Type); if (objBuf == null) return PtzInfo.Default; @@ -126,7 +126,7 @@ public class HiKSdk : ICameraSdk Marshal.StructureToPtr(entity, ptrBuf, true); try { - ret = HiKOriSdk.NET_DVR_GetDVRConfig(LoginId, HiKOriSdk.NET_DVR_GET_PTZPOS, 0, ptrBuf, (uint)dwSize, ref dwReturned); + ret = HiKOriSdk.NET_DVR_GetDVRConfig(LoginId, HiKOriSdk.NET_DVR_GET_PTZPOS, Channel, ptrBuf, (uint)dwSize, ref dwReturned); if (!ret) { BuildException(); ptzInfo = PtzInfo.Default; return false; } object? objBuf = Marshal.PtrToStructure(ptrBuf, GPIParams.Type); if (objBuf == null) { ptzInfo = PtzInfo.Default; return false; } @@ -162,7 +162,7 @@ public class HiKSdk : ICameraSdk private int RealplayHandle { get; set; } = -1; - private int RealpalyPort { get; set; } = -1; + private int RealplayPort { get; set; } = -1; private IntPtr Hwnd { get; set; } @@ -180,7 +180,7 @@ public class HiKSdk : ICameraSdk HiKOriSdk.NET_DVR_PREVIEWINFO previewInfo = new() { hPlayWnd = Hwnd, //预览窗口 - lChannel = 1, //预览的设备通道 + lChannel = Channel, //预览的设备通道 dwStreamType = 0, //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推 dwLinkMode = 0, //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP bBlocked = true, //0- 非阻塞取流,1- 阻塞取流 @@ -192,50 +192,26 @@ public class HiKSdk : ICameraSdk private void StartPlayLinux() { - if (RealpalyPort < 0) + if (RealplayPort < 0 && RealDataCallBack == null) { int nPort = -1; bool ret = PlayCtrlSdk.PlayM4_GetPort(ref nPort); if (!ret) BuildPlayCtrlException(nPort); - RealpalyPort = nPort; + RealplayPort = nPort; } HiKOriSdk.NET_DVR_PREVIEWINFO previewInfo = new() { hPlayWnd = IntPtr.Zero, //预览窗口 - lChannel = 1, //预览的设备通道 + lChannel = Channel, //预览的设备通道 dwStreamType = 0, //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推 dwLinkMode = 0, //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP bBlocked = true, //0- 非阻塞取流,1- 阻塞取流 }; + RealDataCallBack ??= DefaultRealDataCallBack; RealplayHandle = HiKOriSdk.NET_DVR_RealPlay_V40(LoginId, ref previewInfo, RealDataCallBack, IntPtr.Zero); if (RealplayHandle < 0) BuildException(); } - private void RealDataCallBack(int lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr pUser) - { - if (dwBufSize <= 0) return; - switch (dwDataType) - { - case HiKOriSdk.NET_DVR_SYSHEAD: - try - { - PlayCtrlSdk.PlayM4_SetStreamOpenMode(RealpalyPort, 0); - PlayCtrlSdk.PlayM4_OpenStream(RealpalyPort, pBuffer, dwBufSize, 2 * 1024 * 1024); - if (!PlayCtrlSdk.PlayM4_Play(RealpalyPort, Hwnd)) BuildPlayCtrlException(RealpalyPort); - } - catch (Exception) - { - StopPlay(); - throw; - } - break; - - case HiKOriSdk.NET_DVR_STREAMDATA: - PlayCtrlSdk.PlayM4_InputData(RealpalyPort, pBuffer, dwBufSize); - break; - } - } - public override void StopPlay() { if (!IsPlaying()) return; @@ -244,28 +220,48 @@ public class HiKSdk : ICameraSdk Hwnd = IntPtr.Zero; } - public void StopPlayWindows() + private void StopPlayWindows() { bool ret = HiKOriSdk.NET_DVR_StopRealPlay(RealplayHandle); RealplayHandle = -1; if (!ret) BuildException(); } - public void StopPlayLinux() + private void StopPlayLinux() { bool ret = HiKOriSdk.NET_DVR_StopRealPlay(RealplayHandle); RealplayHandle = -1; - if (RealpalyPort >= 0) + RealDataCallBack = null; + if (RealplayPort >= 0) { - //if(!PlayCtrlSdk.PlayM4_Stop(RealpalyPort)) BuildPlayCtrlException(RealpalyPort); - PlayCtrlSdk.PlayM4_Stop(RealpalyPort); - PlayCtrlSdk.PlayM4_CloseStream(RealpalyPort); - PlayCtrlSdk.PlayM4_FreePort(RealpalyPort); - RealpalyPort = -1; + PlayCtrlSdk.PlayM4_Stop(RealplayPort); + PlayCtrlSdk.PlayM4_CloseStream(RealplayPort); + PlayCtrlSdk.PlayM4_FreePort(RealplayPort); + RealplayPort = -1; } if (!ret) BuildException(); } + public HiKOriSdk.RealDataCallBack? RealDataCallBack { get; set; } + + private void DefaultRealDataCallBack(int lRealHandle, uint dwDataType, IntPtr pBuffer, uint dwBufSize, IntPtr pUser) + { + if (RealplayPort < 0 || dwBufSize <= 0) return; + switch (dwDataType) + { + case HiKOriSdk.NET_DVR_SYSHEAD: + PlayCtrlSdk.PlayM4_SetStreamOpenMode(RealplayPort, 0); + PlayCtrlSdk.PlayM4_OpenStream(RealplayPort, pBuffer, dwBufSize, 2 * 1024 * 1024); + PlayCtrlSdk.PlayM4_SetDisplayBuf(RealplayPort, 5); + if (!PlayCtrlSdk.PlayM4_Play(RealplayPort, Hwnd)) BuildPlayCtrlException(RealplayPort); + break; + + case HiKOriSdk.NET_DVR_STREAMDATA: + PlayCtrlSdk.PlayM4_InputData(RealplayPort, pBuffer, dwBufSize); + break; + } + } + public override bool IsPlaying() { return RealplayHandle >= 0; diff --git a/EC.Util/CameraSDK/HiK/PlayCtrlSdk.cs b/EC.Util/CameraSDK/HiK/PlayCtrlSdk.cs index 9af7477..50ccb50 100644 --- a/EC.Util/CameraSDK/HiK/PlayCtrlSdk.cs +++ b/EC.Util/CameraSDK/HiK/PlayCtrlSdk.cs @@ -1,8 +1,5 @@ -//#define Win32 -#define Win64 +//#define Win -//#define Linux32 -//#define Linux64 using System.Runtime.InteropServices; namespace EC.Util.CameraSDK; @@ -11,14 +8,10 @@ public class PlayCtrlSdk { #region Fields -#if Win32 - public const string LibSdkPath = @"./libs/hik/win32/PlayCtrl.dll"; -#elif Win64 - public const string LibSdkPath = @"./libs/hik/win64/PlayCtrl.dll"; -#elif Linux32 - public const string LibSdkPath = @"./libs/hik/linux32/libPlayCtrl.so"; -#elif Linux64 - public const string LibSdkPath = @"./libs/hik/linux64/libPlayCtrl.so"; +#if Win + public const string LibSdkPath = @"./libs/hik/PlayCtrl.dll"; +#else + public const string LibSdkPath = @"./libs/hik/libPlayCtrl.so"; #endif #endregion Fields @@ -43,34 +36,34 @@ public class PlayCtrlSdk #region Sdk Method - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern bool PlayM4_GetPort(ref int nPort); - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern bool PlayM4_FreePort(int nPort); - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern uint PlayM4_GetLastError(int nPort); - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern bool PlayM4_SetStreamOpenMode(int nPort, uint nMode); - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern bool PlayM4_OpenStream(int nPort, IntPtr pFileHeadBuf, uint nSize, uint nBufPoolSize); - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern bool PlayM4_CloseStream(int nPort); - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern bool PlayM4_SetDisplayBuf(int nPort, uint nNum); - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern bool PlayM4_InputData(int nPort, IntPtr pBuf, uint nSize); - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern bool PlayM4_Play(int nPort, IntPtr hWnd); - [DllImport(LibSdkPath, CallingConvention = CallingConvention.StdCall)] + [DllImport(LibSdkPath)] public static extern bool PlayM4_Stop(int nPort); #endregion Sdk Method diff --git a/EC.Util/CameraSDK/YuShi/YuShiOriSdk.cs b/EC.Util/CameraSDK/YuShi/YuShiOriSdk.cs index b784210..9a84c32 100644 --- a/EC.Util/CameraSDK/YuShi/YuShiOriSdk.cs +++ b/EC.Util/CameraSDK/YuShi/YuShiOriSdk.cs @@ -1,8 +1,5 @@ -//#define Win32 -#define Win64 +//#define Win -//#define Linux32 -//#define Linux64 using System.Runtime.InteropServices; namespace EC.Util.CameraSDK; @@ -11,14 +8,10 @@ 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"; +#if Win + public const string LibSdkPath = @"./libs/yushi/NetDEVSDK.dll"; +#else + public const string LibSdkPath = @"./libs/yushi/libNetDEVSDK.so"; #endif private const bool Debug = true; @@ -40,6 +33,12 @@ public class YuShiOriSdk bool ret = NETDEV_Init(); InitSuccess = ret; if (!ret) throw new Exception("YuShiOriSdk global init failure."); + if (Debug) + { + string logPath = Path.Combine("./log", "yushiSdkLog"); + Directory.CreateDirectory(logPath); + NETDEV_SetLogPath(logPath); + } return ret; } @@ -211,6 +210,9 @@ public class YuShiOriSdk [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_SetLogPath(string strLogPath); + [DllImport(LibSdkPath, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)] public static extern int NETDEV_GetLastError(); diff --git a/EC.Util/CameraSDK/YuShi/YuShiSdk.cs b/EC.Util/CameraSDK/YuShi/YuShiSdk.cs index c14fc89..94874b6 100644 --- a/EC.Util/CameraSDK/YuShi/YuShiSdk.cs +++ b/EC.Util/CameraSDK/YuShi/YuShiSdk.cs @@ -1,4 +1,7 @@ -namespace EC.Util.CameraSDK; +using System.Runtime.InteropServices; +using static EC.Util.CameraSDK.YuShiOriSdk; + +namespace EC.Util.CameraSDK; public class YuShiSdk : ICameraSdk { @@ -20,15 +23,21 @@ public class YuShiSdk : ICameraSdk { bool ret = ConnectSuccess(); if (ret) return true; - YuShiOriSdk.NETDEV_DEVICE_LOGIN_INFO_S loginInfo = new(); - loginInfo.szIPAddr = CameraInfo.Ip; - loginInfo.dwPort = CameraInfo.Port; - loginInfo.szUserName = CameraInfo.UserName; - loginInfo.szPassword = CameraInfo.Password; + YuShiOriSdk.NETDEV_DEVICE_LOGIN_INFO_S loginInfo = new() + { + szIPAddr = CameraInfo.Ip, + dwPort = CameraInfo.Port, + szUserName = CameraInfo.UserName, + szPassword = CameraInfo.Password + }; YuShiOriSdk.NETDEV_SELOG_INFO_S logInfo = new(); LoginId = YuShiOriSdk.NETDEV_Login_V30(ref loginInfo, ref logInfo); ret = ConnectSuccess(); - if(!ret) BuildException(); + if (!ret) BuildException(); + //别删 NETDEV_QueryVideoChlDetailList,否则 NETDEV_PTZPreset_Other 教做人 + int pdwChlCount = 16; + IntPtr pstVideoChlList = Marshal.AllocHGlobal(pdwChlCount * Marshal.SizeOf(typeof(NETDEV_VIDEO_CHL_DETAIL_INFO_S))); + YuShiOriSdk.NETDEV_QueryVideoChlDetailList(LoginId, ref pdwChlCount, pstVideoChlList); return ret; } diff --git a/EC.Util/Common/LogUnit.cs b/EC.Util/Common/LogUnit.cs index f31b657..a6ccba7 100644 --- a/EC.Util/Common/LogUnit.cs +++ b/EC.Util/Common/LogUnit.cs @@ -9,13 +9,13 @@ public class LogUnit static LogUnit() { - string fileName = Path.Combine("config", "log4net.config"); - if (!File.Exists(fileName)) throw new FileNotFoundException(fileName); - XmlConfigurator.Configure(new FileInfo(fileName)); + string filePath = Path.Combine("config", "log4net.config"); + if (!File.Exists(filePath)) throw new FileNotFoundException(filePath); + XmlConfigurator.Configure(new FileInfo(filePath)); logger = LogManager.GetLogger(typeof(LogUnit)); } - public static void Init() + public static void VirtualInit() { } public static void Debug(string msg) => logger.Debug(msg); diff --git a/EC.Util/Common/SystemUtil.cs b/EC.Util/Common/SystemUtil.cs new file mode 100644 index 0000000..900b312 --- /dev/null +++ b/EC.Util/Common/SystemUtil.cs @@ -0,0 +1,12 @@ +using System.Runtime.InteropServices; + +namespace EC.Util.Common; + +public static class SystemUtil +{ + [DllImport("Kernel32")] + public static extern void AllocConsole(); + + [DllImport("Kernel32")] + public static extern void FreeConsole(); +} \ No newline at end of file diff --git a/EC.Util/EC.Util.csproj b/EC.Util/EC.Util.csproj index ae9e75f..5d3e0f2 100644 --- a/EC.Util/EC.Util.csproj +++ b/EC.Util/EC.Util.csproj @@ -16,10 +16,9 @@ PreserveNewest - - - - + + PreserveNewest + diff --git a/EC.Util/libs/cameraSdks.zip b/EC.Util/libs/cameraSdks.zip new file mode 100644 index 0000000..b2836ef Binary files /dev/null and b/EC.Util/libs/cameraSdks.zip differ diff --git a/JiLinApp.Biz/TransmitAlarm/Service/AlarmMqttService.cs b/JiLinApp.Biz/TransmitAlarm/Service/AlarmMqttService.cs index 609b5db..707f820 100644 --- a/JiLinApp.Biz/TransmitAlarm/Service/AlarmMqttService.cs +++ b/JiLinApp.Biz/TransmitAlarm/Service/AlarmMqttService.cs @@ -39,7 +39,6 @@ public class AlarmMqttService : IAlarmService public AlarmMqttService(MqttConfig config) { MqttFactory factory = new(); - ClientOptions = factory.CreateClientOptionsBuilder() .WithTcpServer(config.Ip, config.Port) .WithClientId(config.ClientId) @@ -50,21 +49,6 @@ public class AlarmMqttService : IAlarmService SubscribeOptions = factory.CreateSubscribeOptionsBuilder() .WithTopicFilter(f => f.WithTopic(config.SubCmdTopic)) .Build(); - - //if (config.Local) - //{ - // ServerOptions = factory.CreateServerOptionsBuilder() - // .WithDefaultEndpoint() - // .WithDefaultEndpointPort(config.Port) - // .Build(); - // MqttServer server = factory.CreateMqttServer(ServerOptions); - // server.ValidatingConnectionAsync += Server_ValidatingConnectionAsync; - // server.ClientConnectedAsync += Server_ClientConnectedAsync; - // server.ClientDisconnectedAsync += Server_ClientDisconnectedAsync; - // server.ClientAcknowledgedPublishPacketAsync += Server_ClientAcknowledgedPublishPacketAsync; - // Server = server; - //} - IMqttClient client = factory.CreateMqttClient(); client.ApplicationMessageReceivedAsync += Client_ApplicationMessageReceivedAsync; diff --git a/JiLinApp.Docking/Alarm/AlarmCodeHelper.cs b/JiLinApp.Docking/Alarm/AlarmCodeHelper.cs index 5a9ce1f..0b2f31c 100644 --- a/JiLinApp.Docking/Alarm/AlarmCodeHelper.cs +++ b/JiLinApp.Docking/Alarm/AlarmCodeHelper.cs @@ -14,7 +14,9 @@ public class AlarmCodeHelper static AlarmCodeHelper() { - using StreamReader r = new(Path.Combine("config", "alarmcode.json")); + string filePath = Path.Combine("config", "alarmcodes.json"); + if (!File.Exists(filePath)) throw new FileNotFoundException(filePath); + using StreamReader r = new(filePath); string jsonStr = r.ReadToEnd(); List list = JsonConvert.DeserializeObject>(jsonStr) ?? new(); AlarmCodeDict = list.ToDictionary(item => item.Id, item => item); @@ -22,9 +24,8 @@ public class AlarmCodeHelper TypeList = list.GroupBy(item => item.Type).Select(it => it.First().Type).ToList(); } - public static void Init() - { - } + public static void VirtualInit() + { } public static AlarmCode Get(string id) { diff --git a/JiLinApp.Docking/JiLinApp.Docking.csproj b/JiLinApp.Docking/JiLinApp.Docking.csproj index c893745..493af1f 100644 --- a/JiLinApp.Docking/JiLinApp.Docking.csproj +++ b/JiLinApp.Docking/JiLinApp.Docking.csproj @@ -17,7 +17,7 @@ - + PreserveNewest diff --git a/JiLinApp.Docking/Ptz/PtzCmd.cs b/JiLinApp.Docking/Ptz/PtzCmd.cs index 35d3e45..9a73f19 100644 --- a/JiLinApp.Docking/Ptz/PtzCmd.cs +++ b/JiLinApp.Docking/Ptz/PtzCmd.cs @@ -162,7 +162,8 @@ public class PtzCameraCmd public static void HikPtzMove(ICameraSdk sdk, PtzCmdType cmdType, int[] args) { int stop = args[0], presetId = args[0]; - int speed = (HiKOriSdk.PtzSpeedMin + HiKOriSdk.PtzSpeedMax) / 2; + int speed = HiKOriSdk.PtzSpeedMax; + //int speed = (HiKOriSdk.PtzSpeedMin + HiKOriSdk.PtzSpeedMax) / 2; switch (cmdType) { case PtzCmdType.Left: @@ -237,7 +238,8 @@ public class PtzCameraCmd private static void DaHuaPtzMove(ICameraSdk sdk, PtzCmdType cmdType, int[] args) { int stop = args[0], presetId = args[0]; - int speed = (DaHuaOriSdk.PtzSpeedMin + DaHuaOriSdk.PtzSpeedMax) / 2; + int speed = DaHuaOriSdk.PtzSpeedMax; + //int speed = (DaHuaOriSdk.PtzSpeedMin + DaHuaOriSdk.PtzSpeedMax) / 2; switch (cmdType) { case PtzCmdType.Left: @@ -312,7 +314,8 @@ public class PtzCameraCmd public static void YuShiPtzMove(ICameraSdk sdk, PtzCmdType cmdType, int[] args) { int stop = args[0], presetId = args[0]; - int speed = (YuShiOriSdk.PtzSpeedMax + YuShiOriSdk.PtzSpeedMin) / 2; + int speed = YuShiOriSdk.PtzSpeedMax; + //int speed = (YuShiOriSdk.PtzSpeedMax + YuShiOriSdk.PtzSpeedMin) / 2; switch (cmdType) { case PtzCmdType.Left: diff --git a/JiLinApp.Docking/VibrateAlarm/Service/AsyncTcpServer.cs b/JiLinApp.Docking/VibrateAlarm/Service/AsyncTcpServer.cs index 540808a..c00abf1 100644 --- a/JiLinApp.Docking/VibrateAlarm/Service/AsyncTcpServer.cs +++ b/JiLinApp.Docking/VibrateAlarm/Service/AsyncTcpServer.cs @@ -2,6 +2,7 @@ using System.Collections.Concurrent; using System.Net; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Text; namespace JiLinApp.Docking.VibrateAlarm; @@ -67,7 +68,7 @@ public class AsyncTcpServer : IDisposable Encoding = Encoding.Default; Listener = new(address, port); Clients = new(); - Listener.AllowNatTraversal(true); + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) Listener.AllowNatTraversal(true); } ~AsyncTcpServer() diff --git a/JiLinApp.Docking/VibrateAlarm/Service/TcpManager.cs b/JiLinApp.Docking/VibrateAlarm/Service/TcpManager.cs index 0d1209c..4d44171 100644 --- a/JiLinApp.Docking/VibrateAlarm/Service/TcpManager.cs +++ b/JiLinApp.Docking/VibrateAlarm/Service/TcpManager.cs @@ -676,7 +676,7 @@ public class TcpManager if (send) break; Thread.Sleep(SendTryInterval); } - Console.WriteLine("Send to {0}:{1} => {2}, send:{3}", clientMsg.ClientIp, clientMsg.ClientPort, cmd, send); + Console.WriteLine("Send to {0}:{1} => {2}, {3}", clientMsg.ClientIp, clientMsg.ClientPort, cmd, send); return send; } diff --git a/JiLinApp.Docking/config/alarmcode.json b/JiLinApp.Docking/config/alarmcodes.json similarity index 100% rename from JiLinApp.Docking/config/alarmcode.json rename to JiLinApp.Docking/config/alarmcodes.json diff --git a/JiLinApp/App.axaml b/JiLinApp/App.axaml index afd1117..9438be7 100644 --- a/JiLinApp/App.axaml +++ b/JiLinApp/App.axaml @@ -1,10 +1,18 @@ - - - - - + + + + + + + \ No newline at end of file diff --git a/JiLinApp/Components/CameraRealPlay.axaml b/JiLinApp/Components/CameraRealPlay.axaml new file mode 100644 index 0000000..5274c53 --- /dev/null +++ b/JiLinApp/Components/CameraRealPlay.axaml @@ -0,0 +1,156 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +