feat: 前端添加切换摄像头功能

This commit is contained in:
2025-07-21 17:24:22 +08:00
parent d1c9710afe
commit e872f24936
3 changed files with 246 additions and 164 deletions

View File

@@ -13,6 +13,45 @@ public class VideoStreamController : ControllerBase
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private readonly server.Services.HttpVideoStreamService _videoStreamService;
/// <summary>
/// 视频流信息结构体
/// </summary>
public class StreamInfoResult
{
/// <summary>
/// TODO:
/// </summary>
public int FrameRate { get; set; }
/// <summary>
/// TODO:
/// </summary>
public int FrameWidth { get; set; }
/// <summary>
/// TODO:
/// </summary>
public int FrameHeight { get; set; }
/// <summary>
/// TODO:
/// </summary>
public string Format { get; set; } = "MJPEG";
/// <summary>
/// TODO:
/// </summary>
public string HtmlUrl { get; set; } = "";
/// <summary>
/// TODO:
/// </summary>
public string MjpegUrl { get; set; } = "";
/// <summary>
/// TODO:
/// </summary>
public string SnapshotUrl { get; set; } = "";
/// <summary>
/// TODO:
/// </summary>
public string UsbCameraUrl { get; set; } = "";
}
/// <summary>
/// 摄像头配置请求模型
/// </summary>
@@ -96,23 +135,25 @@ public class VideoStreamController : ControllerBase
/// <returns>流信息</returns>
[HttpGet("StreamInfo")]
[EnableCors("Users")]
[ProducesResponseType(typeof(object), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(StreamInfoResult), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(Exception), StatusCodes.Status500InternalServerError)]
public IResult GetStreamInfo()
{
try
{
logger.Info("获取 HTTP 视频流信息");
return TypedResults.Ok(new
var result = new StreamInfoResult
{
frameRate = _videoStreamService.FrameRate,
frameWidth = _videoStreamService.FrameWidth,
frameHeight = _videoStreamService.FrameHeight,
format = "MJPEG",
htmlUrl = $"http://localhost:{_videoStreamService.ServerPort}/video-feed.html",
mjpegUrl = $"http://localhost:{_videoStreamService.ServerPort}/video-stream",
snapshotUrl = $"http://localhost:{_videoStreamService.ServerPort}/snapshot",
});
FrameRate = _videoStreamService.FrameRate,
FrameWidth = _videoStreamService.FrameWidth,
FrameHeight = _videoStreamService.FrameHeight,
Format = "MJPEG",
HtmlUrl = $"http://localhost:{_videoStreamService.ServerPort}/video-feed.html",
MjpegUrl = $"http://localhost:{_videoStreamService.ServerPort}/video-stream",
SnapshotUrl = $"http://localhost:{_videoStreamService.ServerPort}/snapshot",
UsbCameraUrl = $"http://localhost:{_videoStreamService.ServerPort}/usb-camera"
};
return TypedResults.Ok(result);
}
catch (Exception ex)
{
@@ -382,7 +423,7 @@ public class VideoStreamController : ControllerBase
logger.Info("收到初始化自动对焦请求");
var result = await _videoStreamService.InitAutoFocusAsync();
if (result)
{
logger.Info("自动对焦初始化成功");
@@ -427,7 +468,7 @@ public class VideoStreamController : ControllerBase
logger.Info("收到执行自动对焦请求");
var result = await _videoStreamService.PerformAutoFocusAsync();
if (result)
{
logger.Info("自动对焦执行成功");
@@ -484,7 +525,7 @@ public class VideoStreamController : ControllerBase
}
var result = await _videoStreamService.PerformAutoFocusAsync();
if (result)
{
logger.Info("对焦执行成功");