添加契约和网络传输类库

This commit is contained in:
2025-12-29 08:09:14 +08:00
parent 231247c80f
commit 8cd36f44ac
14 changed files with 748 additions and 0 deletions

View File

@@ -9,6 +9,8 @@ namespace SHH.CameraSdk;
/// </summary>
public class SmartFrame : IDisposable
{
public List<string> SubscriberIds { get; } = new List<string>(16);
#region --- (Private Resources & States) ---
/// <summary> 所属帧池:用于引用归零后自动回收复用 </summary>
@@ -114,6 +116,10 @@ public class SmartFrame : IDisposable
TargetMat = null;
}
ScaleType = FrameScaleType.None;
// 2. [核心逻辑] 清空订阅者列表
// 注意Clear() 只是把 Count 设为 0底层数组容量不变不会触发 GC
SubscriberIds.Clear();
}
#endregion

View File

@@ -30,6 +30,38 @@ public static class GlobalStreamDispatcher
#endregion
// =================================================================
// 1. 新增:真正的全局广播总线 (上帝模式)
// 任何订阅了这个事件的人,都能收到【所有设备】的每一帧
// =================================================================
public static event Action<long, SmartFrame> OnGlobalFrame;
// =================================================================
// 2. 原有:定向分发逻辑 (保留不动,给图像处理集群用)
// =================================================================
// private static ConcurrentDictionary<string, ...> _subscribers ...
/// <summary>
/// 统一入口:驱动层调用此方法分发图像
/// </summary>
public static void Dispatch(long deviceId, SmartFrame frame)
{
// A. 优先触发全局广播 (给 ZeroMQ 用)
try
{
// ?.Invoke 是线程安全的,如果设备被删除了,驱动层不调用 Dispatch这里自然就不会触发
// 如果新设备增加了,驱动层开始调用 Dispatch这里自动就会触发
OnGlobalFrame?.Invoke(deviceId, frame);
}
catch (Exception ex)
{
Console.WriteLine($"[GlobalBus Error] 广播异常: {ex.Message}");
}
// B. 执行你原有的定向分发逻辑 (给处理链用)
// DispatchToTargets(deviceId, frame);
}
#region --- 2. (Dynamic Routing Table) ---
/// <summary>

View File

@@ -377,6 +377,13 @@ public class HikVideoSource : BaseVideoSource,
Cv2.CvtColor(rawYuvWrapper, smartFrame.InternalMat, ColorConversionCodes.YUV2BGR_YV12);
}
// =========================================================================
// 【新增】插入这一行!
// 此时 smartFrame.InternalMat 已经有了图像数据
// 我们把它交给全局分发器,触发 ZeroMQ 广播
// =========================================================================
GlobalStreamDispatcher.Dispatch(Id, smartFrame);
// 4. [分发] 将决策结果传递给处理中心
// decision.TargetAppIds 包含了 "谁需要这一帧" 的信息
//GlobalProcessingCenter.Submit(this.Id, smartFrame, decision);

View File

@@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PlatformTarget>AnyCPU</PlatformTarget>
<BaseOutputPath>D:\Codes\Ayay\SHH.CameraService\bin</BaseOutputPath>
</PropertyGroup>
<ItemGroup>