支持通过网页增加、删除、修改摄像头配置信息
支持摄像头配置信息中句柄的设置,并实测有效
This commit is contained in:
@@ -8,11 +8,15 @@ public class CamerasController : ControllerBase
|
||||
{
|
||||
private readonly CameraManager _manager;
|
||||
|
||||
// 1. 新增:我们需要配置管理器
|
||||
private readonly ProcessingConfigManager _configManager;
|
||||
|
||||
// 构造函数注入管理器
|
||||
public CamerasController(CameraManager manager, DisplayWindowManager displayManager)
|
||||
public CamerasController(CameraManager manager, DisplayWindowManager displayManager, ProcessingConfigManager configManager)
|
||||
{
|
||||
_manager = manager;
|
||||
_displayManager = displayManager;
|
||||
_configManager = configManager;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
@@ -191,7 +195,10 @@ public class CamerasController : ControllerBase
|
||||
Password = dto.Password,
|
||||
ChannelIndex = dto.ChannelIndex,
|
||||
StreamType = dto.StreamType,
|
||||
RtspPath = dto.RtspPath
|
||||
RtspPath = dto.RtspPath,
|
||||
MainboardPort = dto.MainboardPort,
|
||||
MainboardIp = dto.MainboardIp,
|
||||
RenderHandle =dto.RenderHandle,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -212,8 +219,7 @@ public class CamerasController : ControllerBase
|
||||
ChannelIndex = dto.ChannelIndex,
|
||||
Brand = dto.Brand,
|
||||
RtspPath = dto.RtspPath,
|
||||
MainboardIp = dto.MainboardIp,
|
||||
MainboardPort = dto.MainboardPort,
|
||||
|
||||
|
||||
// ==========================================
|
||||
// 2. 热更新参数 (运行时属性)
|
||||
@@ -222,6 +228,9 @@ public class CamerasController : ControllerBase
|
||||
Location = dto.Location,
|
||||
StreamType = dto.StreamType,
|
||||
|
||||
MainboardIp = dto.MainboardIp,
|
||||
MainboardPort = dto.MainboardPort,
|
||||
RenderHandle = dto.RenderHandle,
|
||||
// 注意:通常句柄是通过 bind-handle 接口单独绑定的,
|
||||
// 但如果 ConfigDto 里包含了上次保存的句柄,也可以映射
|
||||
// RenderHandle = dto.RenderHandle,
|
||||
@@ -281,7 +290,7 @@ public class CamerasController : ControllerBase
|
||||
}
|
||||
|
||||
// 5. 将需求注册到流控控制器
|
||||
controller.Register(dto.AppId, dto.DisplayFps);
|
||||
controller.Register(new FrameRequirement(dto));
|
||||
|
||||
// 6. 路由显示逻辑 (核心整合点)
|
||||
if (dto.Type == SubscriptionType.LocalWindow)
|
||||
@@ -333,4 +342,61 @@ public class CamerasController : ControllerBase
|
||||
// var bytes = await cam.CaptureCurrentFrameAsync();
|
||||
// return File(bytes, "image/jpeg");
|
||||
//}
|
||||
|
||||
// =============================================================
|
||||
// 3. 新增:更新图像处理/分辨率参数的接口
|
||||
// URL 示例: POST /api/cameras/1001/processing
|
||||
// =============================================================
|
||||
[HttpPost("{id}/processing")]
|
||||
public IActionResult UpdateProcessingOptions(long id, [FromBody] ProcessingOptions options)
|
||||
{
|
||||
// A. 检查相机是否存在
|
||||
var camera = _manager.GetDevice(id);
|
||||
if (camera == null)
|
||||
{
|
||||
return NotFound(new { error = $"Camera {id} not found." });
|
||||
}
|
||||
|
||||
// B. 参数校验 (防止宽高为0导致报错)
|
||||
if (options.TargetWidth <= 0 || options.TargetHeight <= 0)
|
||||
{
|
||||
return BadRequest(new { error = "Target dimensions must be greater than 0." });
|
||||
}
|
||||
|
||||
// C. 执行更新 (热更,立即生效)
|
||||
// ScaleWorker 下一帧处理时会自动读取这个新配置
|
||||
_configManager.UpdateOptions(id, options);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
success = true,
|
||||
message = "Image processing options updated.",
|
||||
currentConfig = options
|
||||
});
|
||||
}
|
||||
|
||||
// 在 CamerasController 类中添加
|
||||
|
||||
// =============================================================
|
||||
// 新增:获取/回显图像处理参数的接口
|
||||
// URL: GET /api/cameras/{id}/processing
|
||||
// =============================================================
|
||||
[HttpGet("{id}/processing")]
|
||||
public IActionResult GetProcessingOptions(long id)
|
||||
{
|
||||
// 1. 检查相机是否存在
|
||||
var camera = _manager.GetDevice(id);
|
||||
if (camera == null)
|
||||
{
|
||||
return NotFound(new { error = $"Camera {id} not found." });
|
||||
}
|
||||
|
||||
// 2. 从配置管理器中获取当前配置
|
||||
// 注意:ProcessingConfigManager 内部应该处理好逻辑:
|
||||
// 如果该设备还没配过,它会自动返回 new ProcessingOptions() (默认值)
|
||||
var options = _configManager.GetOptions(id);
|
||||
|
||||
// 3. 返回 JSON 给前端
|
||||
return Ok(options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user