refactor: 视频流前后端适配

This commit is contained in:
2025-08-11 13:09:30 +08:00
parent b95a61c532
commit c1d641c20c
7 changed files with 752 additions and 229 deletions

View File

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using System.Security.Claims;
using DotNext;
using server.Services;
/// <summary>
/// 视频流控制器,支持动态配置摄像头连接
@@ -15,7 +16,7 @@ public class VideoStreamController : ControllerBase
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private readonly server.Services.HttpVideoStreamService _videoStreamService;
private readonly HttpVideoStreamService _videoStreamService;
private readonly Database.UserManager _userManager;
/// <summary>
@@ -24,7 +25,7 @@ public class VideoStreamController : ControllerBase
/// <param name="videoStreamService">HTTP视频流服务</param>
/// <param name="userManager">用户管理服务</param>
public VideoStreamController(
server.Services.HttpVideoStreamService videoStreamService, Database.UserManager userManager)
HttpVideoStreamService videoStreamService, Database.UserManager userManager)
{
logger.Info("创建VideoStreamController命名空间{Namespace}", this.GetType().Namespace);
_videoStreamService = videoStreamService;
@@ -62,11 +63,11 @@ public class VideoStreamController : ControllerBase
/// 获取 HTTP 视频流服务状态
/// </summary>
/// <returns>服务状态信息</returns>
[HttpGet("Status")]
[HttpGet("ServiceStatus")]
[EnableCors("Users")]
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(VideoStreamServiceStatus), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
public IResult GetStatus()
public IResult GetServiceStatus()
{
try
{
@@ -85,7 +86,7 @@ public class VideoStreamController : ControllerBase
[HttpGet("MyEndpoint")]
[EnableCors("Users")]
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(VideoStreamEndpoint), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
public IResult MyEndpoint()
{
@@ -141,14 +142,14 @@ public class VideoStreamController : ControllerBase
}
}
[HttpPost("DisableTransmission")]
public async Task<IActionResult> DisableHdmiTransmission()
[HttpPost("SetVideoStreamEnable")]
public async Task<IActionResult> SetVideoStreamEnable(bool enable)
{
try
{
var boardId = TryGetBoardId().OrThrow(() => new ArgumentException("Board ID is required"));
await _videoStreamService.DisableHdmiTransmissionAsync(boardId.ToString());
await _videoStreamService.SetVideoStreamEnableAsync(boardId.ToString(), enable);
return Ok($"HDMI transmission for board {boardId} disabled.");
}
catch (Exception ex)
@@ -210,7 +211,7 @@ public class VideoStreamController : ControllerBase
/// <returns>支持的分辨率列表</returns>
[HttpGet("SupportedResolutions")]
[EnableCors("Users")]
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(AvailableResolutionsResponse[]), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(string), StatusCodes.Status500InternalServerError)]
public IResult GetSupportedResolutions()
{
@@ -319,6 +320,39 @@ public class VideoStreamController : ControllerBase
}
}
/// <summary>
/// 配置摄像头连接参数
/// </summary>
/// <returns>配置结果</returns>
[HttpPost("ConfigureCamera")]
[EnableCors("Users")]
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(object), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
public async Task<IResult> ConfigureCamera()
{
try
{
var boardId = TryGetBoardId().OrThrow(() => new Exception("Board ID not found"));
var ret = await _videoStreamService.ConfigureCameraAsync(boardId);
if (ret)
{
return TypedResults.Ok(new { Message = "配置成功" });
}
else
{
return TypedResults.BadRequest(new { Message = "配置失败" });
}
}
catch (Exception ex)
{
logger.Error(ex, "配置摄像头连接失败");
return TypedResults.InternalServerError(ex.Message);
}
}
/// <summary>
/// 分辨率配置请求模型
/// </summary>