新增 Mjpegplayer 用来播放 Web 流

This commit is contained in:
2026-01-21 19:03:59 +08:00
parent f79cb6e74d
commit c438edfa0d
71 changed files with 4538 additions and 452 deletions

View File

@@ -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);