增加大华设备对云台移动、缩放、聚集、光圈、校时、重启的支持
增加海康、大华对预置点的支持
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
using Lennox.LibYuvSharp;
|
||||
using OpenCvSharp;
|
||||
using Serilog;
|
||||
using SHH.CameraSdk.DahuaFeatures;
|
||||
using SHH.CameraSdk.HikFeatures;
|
||||
using System;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using System.Security;
|
||||
using static SHH.CameraSdk.DahuaPlaySDK;
|
||||
@@ -12,12 +15,15 @@ namespace SHH.CameraSdk;
|
||||
/// [大华驱动] 工业级视频源实现 (依照官方 Demo 逻辑重构版)
|
||||
/// <para>当前模块: AiVideo | 核心原则: 低耦合、高并发、零拷贝</para>
|
||||
/// </summary>
|
||||
public class DahuaVideoSource : BaseVideoSource
|
||||
public class DahuaVideoSource : BaseVideoSource,
|
||||
IDahuaContext, ITimeSyncFeature, IRebootFeature, IPtzFeature, IPresetFeature
|
||||
{
|
||||
protected override ILogger _sdkLog => Log.ForContext("SourceContext", LogModules.DaHuaSdk);
|
||||
|
||||
#region --- 1. 静态资源与回调持有 (Static Resources) ---
|
||||
|
||||
/// <summary> 大华 SDK 专用日志实例 </summary>
|
||||
protected override ILogger _sdkLog => Log.ForContext("SourceContext", LogModules.DaHuaSdk);
|
||||
|
||||
/// <summary> 全局句柄映射表:用于静态异常回调分发至具体实例 </summary>
|
||||
private static readonly ConcurrentDictionary<IntPtr, DahuaVideoSource> _instances = new();
|
||||
|
||||
// 必须保持静态引用,防止被 GC 回收导致回调崩溃
|
||||
@@ -29,6 +35,11 @@ public class DahuaVideoSource : BaseVideoSource
|
||||
|
||||
#region --- 2. 实例成员 (Instance Members) ---
|
||||
|
||||
private readonly DahuaRebootProvider _rebootProvider;
|
||||
private readonly DahuaTimeSyncProvider _timeProvider;
|
||||
private readonly DahuaPtzProvider _ptzProvider;
|
||||
private readonly DahuaPresetProvider _presetProvider;
|
||||
|
||||
private IntPtr _loginId = IntPtr.Zero;
|
||||
private IntPtr _realPlayId = IntPtr.Zero;
|
||||
private int _playPort = -1;
|
||||
@@ -42,9 +53,76 @@ public class DahuaVideoSource : BaseVideoSource
|
||||
|
||||
#endregion
|
||||
|
||||
public DahuaVideoSource(VideoSourceConfig config) : base(config) { }
|
||||
#region --- 3. 构造函数 (Constructor) ---
|
||||
|
||||
#region --- 3. 生命周期实现 (Lifecycle Overrides) ---
|
||||
/// <summary>大华视频源实现</summary>
|
||||
/// <param name="config"></param>
|
||||
public DahuaVideoSource(VideoSourceConfig config) : base(config)
|
||||
{
|
||||
_rebootProvider = new DahuaRebootProvider(this);
|
||||
_timeProvider = new DahuaTimeSyncProvider(this);
|
||||
_ptzProvider = new DahuaPtzProvider(this);
|
||||
_presetProvider = new DahuaPresetProvider(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- 4. 接口实现:IHikContext & Features (Interface Impls) ---
|
||||
|
||||
/// <summary>获取登录句柄</summary>
|
||||
/// <returns></returns>
|
||||
public IntPtr GetUserId() => _loginId; // 暴露父类或私有的 _loginId
|
||||
|
||||
/// <summary>获取设备IP</summary>
|
||||
/// <returns></returns>
|
||||
public string GetDeviceIp() => Config.IpAddress;
|
||||
|
||||
/// <summary>
|
||||
/// 核心逻辑:全部委托给 _timeProvider 处理,自己不写一行逻辑
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Task<DateTime> GetTimeAsync() => _timeProvider.GetTimeAsync();
|
||||
|
||||
/// <summary>设置设备时间</summary>
|
||||
/// <param name="time"></param>
|
||||
/// <returns></returns>
|
||||
public Task SetTimeAsync(DateTime time) => _timeProvider.SetTimeAsync(time);
|
||||
|
||||
/// <summary>重启设备</summary>
|
||||
/// <returns></returns>
|
||||
public Task RebootAsync() => _rebootProvider.RebootAsync();
|
||||
|
||||
/// <summary>PTZ 控制</summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="stop"></param>
|
||||
/// <param name="speed"></param>
|
||||
/// <returns></returns>
|
||||
public Task PtzControlAsync(PtzAction action, bool stop, int speed = 4)
|
||||
=> _ptzProvider.PtzControlAsync(action, stop, speed);
|
||||
|
||||
/// <summary>PTZ 步长</summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="durationMs"></param>
|
||||
/// <param name="speed"></param>
|
||||
/// <returns></returns>
|
||||
public Task PtzStepAsync(PtzAction action, int durationMs, int speed = 4)
|
||||
=> _ptzProvider.PtzStepAsync(action, durationMs, speed);
|
||||
|
||||
/// <summary>跳转到预置点</summary>
|
||||
public Task GotoPresetAsync(int presetIndex)
|
||||
=> _presetProvider.GotoPresetAsync(presetIndex);
|
||||
|
||||
/// <summary>设置/保存当前位置为预置点</summary>
|
||||
public Task SetPresetAsync(int presetIndex)
|
||||
=> _presetProvider.SetPresetAsync(presetIndex);
|
||||
|
||||
/// <summary>删除预置点</summary>
|
||||
public Task RemovePresetAsync(int presetIndex)
|
||||
=> _presetProvider.RemovePresetAsync(presetIndex);
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- 5. 生命周期实现 (Lifecycle Overrides) ---
|
||||
|
||||
protected override async Task OnStartAsync(CancellationToken token)
|
||||
{
|
||||
@@ -137,7 +215,7 @@ public class DahuaVideoSource : BaseVideoSource
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- 4. 核心逻辑:解码与分发 (Core Logic) ---
|
||||
#region --- 6. 核心逻辑:解码与分发 (Core Logic) ---
|
||||
|
||||
/// <summary>
|
||||
/// 静态回调:分发数据至具体实例
|
||||
@@ -325,8 +403,8 @@ public class DahuaVideoSource : BaseVideoSource
|
||||
// 如果发现图像发蓝,请将 pU 和 pV 的位置对调
|
||||
LibYuv.I420ToRGB24(
|
||||
pY, width,
|
||||
pU, width / 2,
|
||||
pV, width / 2,
|
||||
pU, width / 2,
|
||||
pDst, width * 3,
|
||||
width, height
|
||||
);
|
||||
@@ -378,7 +456,7 @@ public class DahuaVideoSource : BaseVideoSource
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- 5. 静态初始化器 (Statics) ---
|
||||
#region --- 7. 静态初始化器 (Statics) ---
|
||||
|
||||
private static void InitSdkGlobal()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user