添加项目文件。
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
using FlashCap;
|
||||
|
||||
namespace HardwareControl.Core.UsbCamera
|
||||
{
|
||||
/// <summary>
|
||||
/// 当前采集格式。前端用它选择正确的 data URL MIME,
|
||||
/// MJPG/PNG 帧可直接显示,YUV 等格式由 FlashCap 转码为 BMP。
|
||||
/// </summary>
|
||||
public sealed record CameraFrameFormat(
|
||||
int Width,
|
||||
int Height,
|
||||
string PixelFormat,
|
||||
double FramesPerSecond,
|
||||
string MimeType)
|
||||
{
|
||||
public bool IsCompressed => MimeType is "image/jpeg" or "image/png";
|
||||
|
||||
public static string ResolveMimeType(PixelFormats pixelFormat) =>
|
||||
pixelFormat switch
|
||||
{
|
||||
PixelFormats.JPEG => "image/jpeg",
|
||||
PixelFormats.PNG => "image/png",
|
||||
_ => "image/bmp",
|
||||
};
|
||||
|
||||
public static CameraFrameFormat From(VideoCharacteristics characteristics) =>
|
||||
new(
|
||||
characteristics.Width,
|
||||
characteristics.Height,
|
||||
characteristics.PixelFormat.ToString(),
|
||||
(double)characteristics.FramesPerSecond,
|
||||
ResolveMimeType(characteristics.PixelFormat));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
namespace HardwareControl.Core.UsbCamera
|
||||
{
|
||||
/// <summary>
|
||||
/// 一帧图像。ImageData 由 <c>CopyImage()</c> 生成,
|
||||
/// 调用方可以安全地在回调返回后继续持有、排队或异步发送。
|
||||
/// </summary>
|
||||
public class FrameArrivedEventArgs : EventArgs
|
||||
{
|
||||
public byte[] ImageData { get; }
|
||||
public long FrameIndex { get; }
|
||||
public TimeSpan Timestamp { get; }
|
||||
public DateTimeOffset CapturedAt { get; }
|
||||
|
||||
/// <summary>采集格式与 MIME 类型,随帧一起传递。</summary>
|
||||
public CameraFrameFormat Format { get; }
|
||||
|
||||
public string MimeType => Format.MimeType;
|
||||
public int Width => Format.Width;
|
||||
public int Height => Format.Height;
|
||||
|
||||
public FrameArrivedEventArgs(
|
||||
byte[] imageData,
|
||||
long frameIndex,
|
||||
TimeSpan timestamp,
|
||||
DateTimeOffset capturedAt,
|
||||
CameraFrameFormat format)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(imageData);
|
||||
ArgumentNullException.ThrowIfNull(format);
|
||||
|
||||
ImageData = imageData;
|
||||
FrameIndex = frameIndex;
|
||||
Timestamp = timestamp;
|
||||
CapturedAt = capturedAt;
|
||||
Format = format;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace HardwareControl.Core.UsbCamera
|
||||
{
|
||||
/// <summary>
|
||||
/// Usb相机操作类
|
||||
/// </summary>
|
||||
public class UsbCameraOptions
|
||||
{
|
||||
// 设备名称关键词,null 表示取第一个设备
|
||||
public string? DeviceNameKeyword { get; set; }
|
||||
|
||||
// 优先使用的格式关键词,例如 "MJPG" 或 "640x480"
|
||||
// 为 null 时取该设备的第一个格式
|
||||
public string? PreferredFormatKeyword { get; set; }
|
||||
|
||||
// 重连基础间隔,单位毫秒
|
||||
public int ReconnectBaseDelayMs { get; set; } = 1000;
|
||||
|
||||
// 重连最大间隔,单位毫秒
|
||||
public int ReconnectMaxDelayMs { get; set; } = 10_000;
|
||||
|
||||
// 抓帧超时,单位毫秒
|
||||
public int FrameTimeoutMs { get; set; } = 5000;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace HardwareControl.Core.UsbCamera
|
||||
{
|
||||
public class UsbCameraStatusChangedEventArgs : EventArgs
|
||||
{
|
||||
public bool IsConnected { get; }
|
||||
public string Message { get; }
|
||||
|
||||
public UsbCameraStatusChangedEventArgs(bool isConnected, string message)
|
||||
{
|
||||
IsConnected = isConnected;
|
||||
Message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user