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.

97 lines
3.3 KiB

//#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
}