Browse Source
todolist: 1.CameraFactory.cs 下库文件,解压后需要赋予 777 权限.目前是手动赋予 777 权限 2.CameraFactory.cs 下库文件,LD_LIBRARY_PATH,海康不需要设置,大华将相关库文件放在软件根目录下解决,宇视需要设置LD_LIBRARAY_PATH.master
fajiao
2 years ago
29 changed files with 956 additions and 201 deletions
@ -0,0 +1,97 @@ |
|||
//#define Win
|
|||
|
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace EC.Util.CameraSDK; |
|||
|
|||
/// <summary>
|
|||
/// linux下 需要安装 opengl
|
|||
/// </summary>
|
|||
public class DhPlaySdk |
|||
{ |
|||
#region Fields
|
|||
|
|||
#if Win
|
|||
public const string LibSdkPath = @"./libs/dahua/dhplay.dll"; |
|||
#else
|
|||
public const string LibSdkPath = @"./libs/dahua/libdhplay.so"; |
|||
#endif
|
|||
|
|||
#endregion Fields
|
|||
|
|||
static DhPlaySdk() |
|||
{ |
|||
} |
|||
|
|||
#region struct enum
|
|||
|
|||
public enum LogLevel |
|||
{ |
|||
LOG_LevelUnknown = 0, // 未知等级
|
|||
LOG_LevelFatal, // fatal等级,当设置为此等级时,有一种打印输出(fatal)都有输出
|
|||
LOG_LevelError, // error等级,当设置为此等级时,有两种打印输出(fatal,error)都有输出
|
|||
LOG_LevelWarn, // warn等级,当设置为此等级时,有三种打印输出(fatal,error,warn)都有输出
|
|||
LOG_LevelInfo, // info等级,当设置为此等级时,有四种打印输出(fatal,error,warn,info)都有输出
|
|||
LOG_LevelTrace, // Trace等级,当设置为此等级时,有五种打印输出(fatal,error,warn,info,trace)都有输出
|
|||
LOG_LevelDebug // Debug等级,当设置为此等级时,以上六种打印(fatal,error,warn,info,trace,debug)都有输出
|
|||
} |
|||
|
|||
/* 渲染模式 */ |
|||
public enum RenderType |
|||
{ |
|||
RENDER_NOTSET = 0, // 未设置
|
|||
RENDER_GDI, // GDI渲染
|
|||
RENDER_X11 = RENDER_GDI, // 非windows平台X11渲染
|
|||
RENDER_DDRAW, // ddraw渲染
|
|||
RENDER_OPENGL = RENDER_DDRAW, // 非windows平台opengl渲染
|
|||
RENDER_D3D, // D3D渲染,默认等同于D3D9渲染
|
|||
RENDER_D3D9 = RENDER_D3D, // D3D9渲染
|
|||
RENDER_WGL, // windows平台opengl渲染
|
|||
RENDER_D3D11 // D3D11渲染
|
|||
} |
|||
|
|||
#endregion struct enum
|
|||
|
|||
#region PlaySdk
|
|||
|
|||
public static void BuildException(ICameraSdk cameraSdk, int nPort) |
|||
{ |
|||
string err = $"DhPlaySdk failed, error code={PLAY_GetLastErrorEx()}"; |
|||
throw CameraException.New(cameraSdk.CameraInfo, -1, err); |
|||
} |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern bool PLAY_GetFreePort(ref int nPort); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern bool PLAY_ReleasePort(int nPort); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern bool PLAY_SetRenderMode(int nPort, RenderType nMode); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern uint PLAY_GetLastErrorEx(); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern uint PLAY_SetPrintLogLevel(LogLevel logLevel); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern bool PLAY_SetStreamOpenMode(int nPort, uint nMode); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern bool PLAY_OpenStream(int nPort, IntPtr pFileHeadBuf, uint nSize, uint nBufPoolSize); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern bool PLAY_Play(int nPort, IntPtr hWnd); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern bool PLAY_InputData(int nPort, IntPtr pBuf, uint nSize); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern bool PLAY_Stop(int nPort); |
|||
|
|||
[DllImport(LibSdkPath)] |
|||
public static extern bool PLAY_CloseStream(int nPort); |
|||
|
|||
#endregion PlaySdk
|
|||
} |
@ -0,0 +1,94 @@ |
|||
using System.Reflection; |
|||
|
|||
namespace EC.Util.Common; |
|||
|
|||
public class ReflectUtil |
|||
{ |
|||
private static readonly BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; |
|||
|
|||
public static bool ContainProperty(object instance, string propertyName) |
|||
{ |
|||
if (instance == null || string.IsNullOrEmpty(propertyName)) return false; |
|||
PropertyInfo? property = instance.GetType()?.GetProperty(propertyName, bindingAttr); |
|||
return property != null; |
|||
} |
|||
|
|||
public static T? GetProperty<T>(object instance, string propertyName) |
|||
{ |
|||
if (instance == null || string.IsNullOrEmpty(propertyName)) return default; |
|||
PropertyInfo? property = instance.GetType()?.GetProperty(propertyName, bindingAttr); |
|||
try |
|||
{ |
|||
return (T?)property?.GetValue(instance, null); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return default; |
|||
} |
|||
} |
|||
|
|||
public static bool GetProperty<T>(object instance, string propertyName, out T? val) |
|||
{ |
|||
val = GetProperty<T>(instance, propertyName); |
|||
return val != null; |
|||
} |
|||
|
|||
public static bool ContainField(object instance, string propertyName) |
|||
{ |
|||
if (instance == null || string.IsNullOrEmpty(propertyName)) return false; |
|||
FieldInfo? field = instance.GetType()?.GetField(propertyName, bindingAttr); |
|||
return field != null; |
|||
} |
|||
|
|||
public static T? GetField<T>(object instance, string propertyName) |
|||
{ |
|||
if (instance == null || string.IsNullOrEmpty(propertyName)) return default; |
|||
FieldInfo? field = instance.GetType()?.GetField(propertyName, bindingAttr); |
|||
try |
|||
{ |
|||
return (T?)field?.GetValue(instance); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return default; |
|||
} |
|||
} |
|||
|
|||
public static bool GetField<T>(object instance, string propertyName, out T? val) |
|||
{ |
|||
val = GetField<T>(instance, propertyName); |
|||
return val != null; |
|||
} |
|||
|
|||
public static void SetField<T>(object instance, string propertyName, T? val) |
|||
{ |
|||
if (instance == null || string.IsNullOrEmpty(propertyName)) return; |
|||
FieldInfo? field = instance.GetType()?.GetField(propertyName, bindingAttr); |
|||
try |
|||
{ |
|||
field?.SetValue(instance, val); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
} |
|||
} |
|||
|
|||
public static MethodInfo? GetMethod(object instance, string name) |
|||
{ |
|||
MethodInfo? method = instance.GetType().GetMethod(name); |
|||
return method; |
|||
} |
|||
|
|||
public static T? RunMethod<T>(object instance, string name, object?[]? parameters) |
|||
{ |
|||
try |
|||
{ |
|||
MethodInfo? method = instance.GetType().GetMethod(name); |
|||
return (T?)method?.Invoke(instance, parameters); |
|||
} |
|||
catch (Exception) |
|||
{ |
|||
return default; |
|||
} |
|||
} |
|||
} |
@ -1,12 +0,0 @@ |
|||
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(); |
|||
} |
@ -0,0 +1,155 @@ |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace EC.Util.Platform; |
|||
|
|||
public static class LinuxUtil |
|||
{ |
|||
#region const
|
|||
|
|||
private const string libX11 = "libX11.so.6"; |
|||
private const string libX11Randr = "libXrandr.so.2"; |
|||
private const string libX11Ext = "libXext.so.6"; |
|||
private const string libXInput = "libXi.so.6"; |
|||
private const string libXCursor = "libXcursor.so.1"; |
|||
|
|||
private enum PropertyMode |
|||
{ |
|||
Replace = 0, |
|||
Prepend = 1, |
|||
Append = 2 |
|||
} |
|||
|
|||
[Flags] |
|||
private enum MotifFlags |
|||
{ |
|||
Functions = 1, |
|||
Decorations = 2, |
|||
InputMode = 4, |
|||
Status = 8 |
|||
} |
|||
|
|||
[Flags] |
|||
private enum MotifFunctions |
|||
{ |
|||
All = 0x01, |
|||
Resize = 0x02, |
|||
Move = 0x04, |
|||
Minimize = 0x08, |
|||
Maximize = 0x10, |
|||
Close = 0x20 |
|||
} |
|||
|
|||
[Flags] |
|||
private enum MotifDecorations |
|||
{ |
|||
All = 0x01, |
|||
Border = 0x02, |
|||
ResizeH = 0x04, |
|||
Title = 0x08, |
|||
Menu = 0x10, |
|||
Minimize = 0x20, |
|||
Maximize = 0x40, |
|||
} |
|||
|
|||
[Flags] |
|||
private enum MotifInputMode |
|||
{ |
|||
Modeless = 0, |
|||
ApplicationModal = 1, |
|||
SystemModal = 2, |
|||
FullApplicationModal = 3 |
|||
} |
|||
|
|||
#endregion const
|
|||
|
|||
#region struct
|
|||
|
|||
[StructLayout(LayoutKind.Sequential)] |
|||
private struct MotifWmHints |
|||
{ |
|||
public IntPtr flags; |
|||
public IntPtr functions; |
|||
public IntPtr decorations; |
|||
public IntPtr input_mode; |
|||
public IntPtr status; |
|||
|
|||
public override string ToString() |
|||
{ |
|||
return string.Format("MotifWmHints <flags={0}, functions={1}, decorations={2}, input_mode={3}, status={4}", (MotifFlags)flags.ToInt32(), (MotifFunctions)functions.ToInt32(), (MotifDecorations)decorations.ToInt32(), (MotifInputMode)input_mode.ToInt32(), status.ToInt32()); |
|||
} |
|||
} |
|||
|
|||
[StructLayout(LayoutKind.Sequential)] |
|||
private struct XSizeHints |
|||
{ |
|||
private IntPtr flags; |
|||
private int x; |
|||
private int y; |
|||
private int width; |
|||
private int height; |
|||
private int min_width; |
|||
private int min_height; |
|||
private int max_width; |
|||
private int max_height; |
|||
private int width_inc; |
|||
private int height_inc; |
|||
private int min_aspect_x; |
|||
private int min_aspect_y; |
|||
private int max_aspect_x; |
|||
private int max_aspect_y; |
|||
private int base_width; |
|||
private int base_height; |
|||
private int win_gravity; |
|||
} |
|||
|
|||
[Flags] |
|||
private enum XSizeHintsFlags |
|||
{ |
|||
USPosition = (1 << 0), |
|||
USSize = (1 << 1), |
|||
PPosition = (1 << 2), |
|||
PSize = (1 << 3), |
|||
PMinSize = (1 << 4), |
|||
PMaxSize = (1 << 5), |
|||
PResizeInc = (1 << 6), |
|||
PAspect = (1 << 7), |
|||
PAllHints = (PPosition | PSize | PMinSize | PMaxSize | PResizeInc | PAspect), |
|||
PBaseSize = (1 << 8), |
|||
PWinGravity = (1 << 9), |
|||
} |
|||
|
|||
#endregion struct
|
|||
|
|||
#region lib
|
|||
|
|||
[DllImport(libX11, CharSet = CharSet.Unicode)] |
|||
private static extern IntPtr XInternAtom(IntPtr display, string atom_name, bool only_if_exists); |
|||
|
|||
[DllImport(libX11)] |
|||
private static extern int XChangeProperty(IntPtr display, IntPtr window, IntPtr property, IntPtr type, |
|||
int format, PropertyMode mode, ref MotifWmHints data, int nelements); |
|||
|
|||
[DllImport(libX11)] |
|||
private static extern void XSetWMNormalHints(IntPtr display, IntPtr window, ref XSizeHints hints); |
|||
|
|||
#endregion lib
|
|||
|
|||
#region cmd
|
|||
|
|||
public static void DisableMinMaximizeButton(IntPtr display, IntPtr handle, IntPtr atom) |
|||
{ |
|||
MotifDecorations decorations = MotifDecorations.Title | MotifDecorations.Border; |
|||
MotifFunctions functions = MotifFunctions.Move | MotifFunctions.Close; |
|||
MotifWmHints hints = new() |
|||
{ |
|||
flags = (nint)(MotifFlags.Decorations | MotifFlags.Functions), |
|||
decorations = (nint)decorations, |
|||
functions = (nint)functions, |
|||
input_mode = 0, |
|||
status = 0, |
|||
}; |
|||
int result = XChangeProperty(display, handle, atom, atom, 32, PropertyMode.Replace, ref hints, 5); |
|||
} |
|||
|
|||
#endregion cmd
|
|||
} |
@ -0,0 +1,5 @@ |
|||
namespace EC.Util.Platform; |
|||
|
|||
public class SystemUtil |
|||
{ |
|||
} |
@ -0,0 +1,96 @@ |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace EC.Util.Platform; |
|||
|
|||
public class WinUtil |
|||
{ |
|||
#region const
|
|||
|
|||
private const int GWL_STYLE = -16; |
|||
private const int WS_MAXIMIZEBOX = 0x10000; |
|||
private const int WS_MINIMIZEBOX = 0x20000; |
|||
private const int WS_SYSMENU = 0x80000; |
|||
private const int SWP_NOSIZE = 0x0001; |
|||
private const int SWP_NOMOVE = 0x0002; |
|||
private const int SWP_NOZORDER = 0x0004; |
|||
private const int SWP_FRAMECHANGED = 0x0020; |
|||
|
|||
#endregion const
|
|||
|
|||
#region lib
|
|||
|
|||
[DllImport("Kernel32")] |
|||
public static extern void AllocConsole(); |
|||
|
|||
[DllImport("Kernel32")] |
|||
public static extern void FreeConsole(); |
|||
|
|||
[DllImport("user32", EntryPoint = "GetWindowLong", CharSet = CharSet.Auto)] |
|||
private static extern int GetWindowLong32(IntPtr hWnd, int nIndex); |
|||
|
|||
[DllImport("user32", EntryPoint = "SetWindowLong", CharSet = CharSet.Auto)] |
|||
private static extern int SetWindowLong32(IntPtr hwnd, int index, int value); |
|||
|
|||
[DllImport("user32")] |
|||
private static extern int GetWindowLongPtr(IntPtr hwnd, int index); |
|||
|
|||
[DllImport("user32")] |
|||
private static extern int SetWindowLongPtr(IntPtr hwnd, int index, int value); |
|||
|
|||
[DllImport("user32")] |
|||
private static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags); |
|||
|
|||
#endregion lib
|
|||
|
|||
#region cmd
|
|||
|
|||
public static void DisableMinimizeButton(IntPtr handle) |
|||
{ |
|||
if (IntPtr.Size == 4) |
|||
{ |
|||
int currentStyle = GetWindowLong32(handle, GWL_STYLE); |
|||
_ = SetWindowLong32(handle, GWL_STYLE, (currentStyle & ~WS_MINIMIZEBOX)); |
|||
} |
|||
else |
|||
{ |
|||
int currentStyle = GetWindowLongPtr(handle, GWL_STYLE); |
|||
_ = SetWindowLongPtr(handle, GWL_STYLE, (currentStyle & ~WS_MINIMIZEBOX)); |
|||
} |
|||
//call SetWindowPos to make sure the SetWindowLongPtr take effect according to MSDN
|
|||
SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED); |
|||
} |
|||
|
|||
public static void DisableMaximizeButton(IntPtr handle) |
|||
{ |
|||
if (IntPtr.Size == 4) |
|||
{ |
|||
int currentStyle = GetWindowLong32(handle, GWL_STYLE); |
|||
_ = SetWindowLong32(handle, GWL_STYLE, (currentStyle & ~WS_MAXIMIZEBOX)); |
|||
} |
|||
else |
|||
{ |
|||
int currentStyle = GetWindowLongPtr(handle, GWL_STYLE); |
|||
_ = SetWindowLongPtr(handle, GWL_STYLE, (currentStyle & ~WS_MAXIMIZEBOX)); |
|||
} |
|||
//call SetWindowPos to make sure the SetWindowLongPtr take effect according to MSDN
|
|||
SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED); |
|||
} |
|||
|
|||
public static void DisableMinMaximizeButton(IntPtr handle) |
|||
{ |
|||
if (IntPtr.Size == 4) |
|||
{ |
|||
int currentStyle = GetWindowLong32(handle, GWL_STYLE); |
|||
_ = SetWindowLong32(handle, GWL_STYLE, (currentStyle & ~WS_MINIMIZEBOX & ~WS_MAXIMIZEBOX)); |
|||
} |
|||
else |
|||
{ |
|||
int currentStyle = GetWindowLongPtr(handle, GWL_STYLE); |
|||
_ = SetWindowLongPtr(handle, GWL_STYLE, (currentStyle & ~WS_MINIMIZEBOX & ~WS_MAXIMIZEBOX)); |
|||
} |
|||
//call SetWindowPos to make sure the SetWindowLongPtr take effect according to MSDN
|
|||
SetWindowPos(handle, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED); |
|||
} |
|||
|
|||
#endregion cmd
|
|||
} |
Binary file not shown.
Loading…
Reference in new issue