在 AiVideo 中能看到图像
增加了在线状态同步逻辑
This commit is contained in:
103
SHH.Contracts/Commands/VideoPayload.cs
Normal file
103
SHH.Contracts/Commands/VideoPayload.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using MessagePack;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
// 注意:如果不想依赖 Newtonsoft,也可以用 System.Text.Json,但 Newtonsoft 在 Std 2.0 中兼容性更好
|
||||
|
||||
namespace SHH.Contracts
|
||||
{
|
||||
/// <summary>
|
||||
/// 视频数据传输契约(纯净版 POCO)
|
||||
/// </summary>
|
||||
[MessagePackObject]
|
||||
public class VideoPayload
|
||||
{
|
||||
public VideoPayload()
|
||||
{
|
||||
SubscriberIds = new List<string>(16);
|
||||
Diagnostics = new Dictionary<string, object>(4);
|
||||
}
|
||||
|
||||
#region --- 1. 元数据 (Metadata) ---
|
||||
|
||||
[Key(0)]
|
||||
public string CameraId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 采集时间戳 (Unix 毫秒)
|
||||
/// </summary>
|
||||
[Key(1)]
|
||||
public long CaptureTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分发时间戳 (Unix 毫秒)
|
||||
/// </summary>
|
||||
[Key(2)]
|
||||
public long DispatchTimestamp { get; set; }
|
||||
|
||||
[Key(3)]
|
||||
public int OriginalWidth { get; set; }
|
||||
|
||||
[Key(4)]
|
||||
public int OriginalHeight { get; set; }
|
||||
|
||||
[Key(5)]
|
||||
public int TargetWidth { get; set; }
|
||||
|
||||
[Key(6)]
|
||||
public int TargetHeight { get; set; }
|
||||
|
||||
[Key(7)]
|
||||
public List<string> SubscriberIds { get; set; }
|
||||
|
||||
[Key(8)]
|
||||
public Dictionary<string, object> Diagnostics { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 指示标志:是否存在原始图
|
||||
/// </summary>
|
||||
[Key(9)]
|
||||
public bool HasOriginalImage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 指示标志:是否存在处理图
|
||||
/// </summary>
|
||||
[Key(10)]
|
||||
public bool HasTargetImage { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- 2. 二进制数据 (Binary) ---
|
||||
|
||||
// 标记 JsonIgnore,防止被错误序列化
|
||||
[JsonIgnore]
|
||||
[IgnoreMember]
|
||||
public byte[] OriginalImageBytes { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
[IgnoreMember]
|
||||
public byte[] TargetImageBytes { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- 3. 辅助方法 (仅保留 JSON 逻辑) ---
|
||||
|
||||
/// <summary>
|
||||
/// 获取纯元数据的 JSON 字符串
|
||||
/// </summary>
|
||||
public string GetMetadataJson()
|
||||
{
|
||||
// 在序列化前自动更新标志位,防止逻辑不同步
|
||||
this.HasOriginalImage = (OriginalImageBytes != null && OriginalImageBytes.Length > 0);
|
||||
this.HasTargetImage = (TargetImageBytes != null && TargetImageBytes.Length > 0);
|
||||
|
||||
return JsonConvert.SerializeObject(this);
|
||||
}
|
||||
|
||||
public static VideoPayload FromMetadataJson(string json)
|
||||
{
|
||||
return JsonConvert.DeserializeObject<VideoPayload>(json);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user