feat&fix: 完善JPEGClient逻辑,前端新增编码器组件

This commit is contained in:
alivender
2025-08-17 14:55:38 +08:00
parent 3644c75304
commit fdfc5729ec
5 changed files with 541 additions and 109 deletions

View File

@@ -235,7 +235,19 @@ public class HttpHdmiVideoStreamService : BackgroundService
}
var jpegData = frameResult.Value[0];
var jpegImage = Common.Image.CompleteJpegData(jpegData, client.Width, client.Height);
var quantTableResult = await client.JpegClient.GetQuantizationTable();
if (!quantTableResult.IsSuccessful || quantTableResult.Value == null)
{
logger.Error("获取JPEG量化表失败: {Error}", quantTableResult.Error);
response.StatusCode = 500;
var errorBytes = System.Text.Encoding.UTF8.GetBytes("Failed to get quantization table");
await response.OutputStream.WriteAsync(errorBytes, 0, errorBytes.Length, cancellationToken);
response.Close();
return;
}
var jpegImage = Common.Image.CompleteJpegData(jpegData, client.Width, client.Height, quantTableResult.Value);
if (!jpegImage.IsSuccessful)
{
logger.Error("JPEG数据补全失败");
@@ -280,6 +292,18 @@ public class HttpHdmiVideoStreamService : BackgroundService
logger.Debug("开始HDMI MJPEG流传输");
var quantTableResult = await client.JpegClient.GetQuantizationTable();
if (!quantTableResult.IsSuccessful || quantTableResult.Value == null)
{
logger.Error("获取JPEG量化表失败: {Error}", quantTableResult.Error);
response.StatusCode = 500;
await response.OutputStream.WriteAsync(
System.Text.Encoding.UTF8.GetBytes("Failed to get quantization table"), 0, 0, cancellationToken);
response.Close();
return;
}
var quantTable = quantTableResult.Value;
int frameCounter = 0;
while (!cancellationToken.IsCancellationRequested)
@@ -297,7 +321,7 @@ public class HttpHdmiVideoStreamService : BackgroundService
foreach (var framebytes in frameResult.Value)
{
var jpegImage = Common.Image.CompleteJpegData(framebytes, client.Width, client.Height);
var jpegImage = Common.Image.CompleteJpegData(framebytes, client.Width, client.Height, quantTable);
if (!jpegImage.IsSuccessful)
{
logger.Error("JPEG数据不完整");