新增 Mjpegplayer 用来播放 Web 流
This commit is contained in:
@@ -49,4 +49,25 @@ public static class DahuaPlaySDK
|
||||
|
||||
[DllImport(DLL_PATH)]
|
||||
public static extern bool PLAY_SetStreamOpenMode(int nPort, uint nMode);
|
||||
|
||||
// 解码模式枚举
|
||||
public enum DecodeType
|
||||
{
|
||||
DECODE_SW = 1, // 软解 (CPU)
|
||||
DECODE_HW = 2, // 硬解拷贝模式 (GPU解码后拷贝回内存)
|
||||
DECODE_HW_FAST = 3, // 硬解直接显示模式 (GPU解码直接渲染,最高性能)
|
||||
DECODE_HW_NV_CUDA = 7, // 英伟达显卡 CUDA 硬解 (Ayay 推荐,多路并发最强)
|
||||
DECODE_HW_D3D11 = 8 // D3D11 硬解
|
||||
}
|
||||
|
||||
// 渲染模式枚举
|
||||
public enum RenderType
|
||||
{
|
||||
RENDER_GDI = 1,
|
||||
RENDER_D3D9 = 4,
|
||||
RENDER_D3D11 = 7
|
||||
}
|
||||
|
||||
[DllImport(DLL_PATH, EntryPoint = "PLAY_SetEngine")]
|
||||
public static extern bool PLAY_SetEngine(int nPort, DecodeType decodeType, RenderType renderType);
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using OpenCvSharp;
|
||||
using Serilog;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Security;
|
||||
using static SHH.CameraSdk.DahuaPlaySDK;
|
||||
|
||||
namespace SHH.CameraSdk;
|
||||
|
||||
@@ -173,8 +174,35 @@ public class DahuaVideoSource : BaseVideoSource
|
||||
{
|
||||
_playPort = port;
|
||||
DahuaPlaySDK.PLAY_SetStreamOpenMode(_playPort, 0);
|
||||
|
||||
// 打开流
|
||||
DahuaPlaySDK.PLAY_OpenStream(_playPort, IntPtr.Zero, 0, 1024 * 1024 * 2);
|
||||
|
||||
// =================================================================================
|
||||
// 🚀 [新增代码] 性能优化:尝试开启大华 GPU 硬解码
|
||||
// 位置:必须在 PLAY_OpenStream 之后,PLAY_Play 之前
|
||||
// =================================================================================
|
||||
try
|
||||
{
|
||||
// nDecodeEngine: 1 = 开启硬解码 (Nvidia/Intel)
|
||||
// 注意:大华 SDK 若不支持会自动降级,try-catch 仅为了防止 P/Invoke 签名缺失崩溃
|
||||
// Optimized: 使用新版接口开启硬件解码,优先尝试 CUDA 以保证 Ayay 的多路并发性能
|
||||
// nPort 是通过 PLAY_GetFreePort 获取的播放通道号
|
||||
bool success = PLAY_SetEngine(_playPort, DecodeType.DECODE_HW_NV_CUDA, RenderType.RENDER_D3D11);
|
||||
|
||||
if (!success)
|
||||
{
|
||||
// 如果显卡不支持 CUDA,降级为普通硬解或软解
|
||||
PLAY_SetEngine(_playPort, DecodeType.DECODE_HW, RenderType.RENDER_D3D9);
|
||||
}
|
||||
_sdkLog.Information($"[Perf] Dahua 尝试开启硬解码. ID:{_config.Id} Port:{_playPort}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_sdkLog.Warning($"[Perf] Dahua 开启硬解码失败: {ex.Message}");
|
||||
}
|
||||
|
||||
// 设置回调与播放
|
||||
_decCallBack = new DahuaPlaySDK.DECCBFUN(SafeOnDecodingCallBack);
|
||||
DahuaPlaySDK.PLAY_SetDecCallBack(_playPort, _decCallBack);
|
||||
DahuaPlaySDK.PLAY_Play(_playPort, IntPtr.Zero);
|
||||
|
||||
Reference in New Issue
Block a user