Files
Ayay/SHH.CameraSdk/Core/Services/ProcessingConfigManager.cs
2025-12-27 14:16:50 +08:00

37 lines
1.5 KiB
C#
Raw 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.
namespace SHH.CameraSdk;
/// <summary>
/// [配置中心] 预处理参数管理器
/// 职责:提供线程安全的配置读写接口,连接 Web API 与 底层 Worker
/// </summary>
public class ProcessingConfigManager
{
// 内存字典Key=设备ID, Value=配置对象
private readonly ConcurrentDictionary<long, ProcessingOptions> _configs = new();
/// <summary>
/// 获取指定设备的配置(如果不存在则返回默认值)
/// </summary>
/// <param name="deviceId">设备ID</param>
/// <returns>配置对象(非空)</returns>
public ProcessingOptions GetOptions(long deviceId)
{
// GetOrAdd 保证了永远能拿回一个有效的配置,防止 Worker 报空指针
return _configs.GetOrAdd(deviceId, _ => ProcessingOptions.Default);
}
/// <summary>
/// 更新指定设备的配置(实时生效)
/// </summary>
public void UpdateOptions(long deviceId, ProcessingOptions newOptions)
{
if (newOptions == null) return;
// 直接覆盖旧配置,由于是引用替换,原子性较高
_configs.AddOrUpdate(deviceId, newOptions, (key, old) => newOptions);
Console.WriteLine($"[ConfigManager] 设备 {deviceId} 预处理参数已更新: " +
$"Expand={newOptions.EnableExpand} Shrink:{newOptions.EnableShrink} 分辨率:({newOptions.TargetWidth}x{newOptions.TargetHeight}), " +
$"Enhance={newOptions.EnableEnhance}");
}
}