添加契约和网络传输类库
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<BaseOutputPath>D:\Codes\Ayay\SHH.CameraService\bin</BaseOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user