针对界面显示的优化

This commit is contained in:
2025-12-27 14:16:50 +08:00
parent 127b07343e
commit 3718465463
14 changed files with 495 additions and 128 deletions

View File

@@ -237,60 +237,72 @@ public class CamerasController : ControllerBase
};
}
/// <summary>
/// [新增] 查询某台设备的当前流控策略
/// </summary>
[HttpGet("{id}/subscriptions")]
public IActionResult GetSubscriptions(long id)
{
var device = _manager.GetDevice(id);
if (device == null) return NotFound();
// 调用刚才在 FrameController 写的方法
var subs = device.Controller.GetCurrentRequirements();
return Ok(subs);
}
private readonly DisplayWindowManager _displayManager; // [新增]
/// <summary>
/// 综合订阅策略更新接口
/// 支持:本地 OpenCV 窗口、海康句柄穿透、本地录像、网络传输
/// </summary>
[HttpPost("{id}/subscriptions")]
public IActionResult UpdateSubscription(int id, [FromBody] SubscriptionDto dto)
{
var device = _manager.GetDevice(id);
if (device == null) return NotFound("设备不存在");
if (device is HikVideoSource hikCam)
// 1. 自动生成 ID 逻辑
if (string.IsNullOrWhiteSpace(dto.AppId))
{
// 1. 更新流控策略 (FrameController)
// 告诉底层:这个 AppId 需要多少帧
int totalFps = dto.DisplayFps + dto.AnalysisFps;
if (totalFps > 0)
{
// 情况 A: 这是一个新增或更新订阅
hikCam.Controller.Register(dto.AppId, totalFps);
// 如果是预览模式,启动窗口
if (dto.DisplayFps > 0)
{
_displayManager.StartDisplay(dto.AppId, id);
}
}
else
{
// 情况 B: 这是一个停止订阅请求 (FPS 为 0)
// 1. 【核心修复】从调度中心物理删除,不再出现在列表中
hikCam.Controller.Unregister(dto.AppId);
// 2. 关闭可能存在的本地窗口
_displayManager.StopDisplay(dto.AppId);
}
return Ok(new { message = "Policy updated", currentConfig = hikCam.Controller.GetCurrentRequirements() });
dto.AppId = $"SUB_{Guid.NewGuid().ToString("N").Substring(0, 8).ToUpper()}";
}
return BadRequest("Device implies no controller");
// 2. 获取流控控制器
var controller = device.Controller;
if (controller == null) return BadRequest("该设备类型不支持流控调度");
// 3. 处理注销逻辑 (FPS 为 0 代表停止订阅)
if (dto.DisplayFps <= 0)
{
controller.Unregister(dto.AppId);
// 停止显示管理器中所有相关的显示任务 (无论是本地窗口还是句柄绑定)
_displayManager.StopDisplay(dto.AppId);
device.AddAuditLog($"注销订阅: {dto.AppId}");
return Ok(new { Message = "Subscription removed", AppId = dto.AppId });
}
// 4. 业务参数合法性校验
switch (dto.Type)
{
case SubscriptionType.LocalRecord when string.IsNullOrEmpty(dto.SavePath):
return BadRequest("录像模式必须指定存放路径");
case SubscriptionType.HandleDisplay when string.IsNullOrEmpty(dto.Handle):
return BadRequest("句柄显示模式必须提供窗口句柄");
}
// 5. 将需求注册到流控控制器
controller.Register(dto.AppId, dto.DisplayFps);
// 6. 路由显示逻辑 (核心整合点)
if (dto.Type == SubscriptionType.LocalWindow)
{
// --- 保留旧版功能:启动本地 OpenCV 渲染窗口 ---
_displayManager.StartDisplay(dto.AppId, id);
}
else if (dto.Type == SubscriptionType.HandleDisplay && !string.IsNullOrEmpty(dto.Handle))
{
}
device.AddAuditLog($"更新订阅: {dto.AppId} ({dto.Type}), 目标 {dto.DisplayFps} FPS");
return Ok(new
{
Success = true,
AppId = dto.AppId,
Message = "订阅策略已应用",
CurrentConfig = controller.GetCurrentRequirements() // 返回当前所有订阅状态供前端同步
});
}
// 1. 获取单个设备详情(用于编辑回填)
@@ -302,14 +314,6 @@ public class CamerasController : ControllerBase
return Ok(cam.Config); // 返回原始配置对象
}
// 2. 更新设备(保存功能)
[HttpPut("{id}")]
public async Task<IActionResult> UpdateDevice(int id, [FromBody] VideoSourceConfig config)
{
// 核心逻辑:先停止旧设备 -> 更新配置 -> 重新添加到容器 -> 如果之前在运行则重新启动
await _manager.UpdateDeviceAsync(id, config);
return Ok();
}
// 3. 清除特定设备的日志
[HttpDelete("{id}/logs")]