Files
Ayay/SHH.CameraSdk/Core/Pipeline/GlobalProcessingCenter.cs

64 lines
2.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using SHH.CameraSdk;
/// <summary>
/// 全局帧处理中心(静态类)
/// 功能:接收驱动层的帧数据与决策,封装为处理任务并投递至处理管道,是驱动层与处理管道的桥梁
/// 核心修复:初始化全链路追踪上下文并绑定到任务,避免空引用异常;管道满时记录丢弃日志并释放帧资源
/// </summary>
public static class GlobalProcessingCenter
{
#region --- (Private Resources) ---
/// <summary> 全局帧处理管道实例 </summary>
/// <remarks> 固定容量 50采用 DropWrite 模式,生产端永不阻塞 </remarks>
private static readonly ProcessingPipeline _pipeline = new ProcessingPipeline(capacity: 50);
#endregion
#region --- (Core Task Submission) ---
/// <summary>
/// 提交帧数据与决策到处理中心
/// 功能:封装帧为处理任务,初始化追踪上下文,投递至管道;投递失败时记录丢弃日志并释放资源
/// </summary>
/// <param name="deviceId">产生帧的设备唯一标识</param>
/// <param name="frame">待处理的智能帧数据</param>
/// <param name="decision">帧处理决策(包含是否保留、分发目标等信息)</param>
public static void Submit(long deviceId, SmartFrame frame, FrameDecision decision)
{
// 1. 初始化全链路追踪上下文:绑定决策信息,记录帧进入处理中心的初始日志
var context = new FrameContext
{
FrameSequence = decision.Sequence,
Timestamp = decision.Timestamp,
IsCaptured = true,
TargetAppIds = decision.TargetAppIds // 记录帧的分发目标列表
};
// 添加初始日志:标记帧由驱动层提交至处理中心
context.AddLog("Driver: Submitted to Global Center");
// 2. 封装为处理任务关联设备ID、帧数据、决策、追踪上下文
var task = new ProcessingTask
{
DeviceId = deviceId,
Frame = frame,
Decision = decision,
Context = context // 绑定上下文,修复空引用问题
};
// 3. 尝试投递任务到处理管道
if (!_pipeline.TrySubmit(task))
{
// 投递失败:管道已满,记录丢弃原因并更新上下文状态
context.DropReason = "GlobalPipelineFull";
context.IsCaptured = false;
// 归档丢弃日志到全局遥测,用于问题排查
GlobalTelemetry.RecordLog(decision.Sequence, context);
// 释放帧资源:避免内存泄漏
frame.Dispose();
}
}
#endregion
}