mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-10-28 08:20:49 +08:00
feat: 迁移视频采集到 v4l2r,支持多平面设备并完善构建头文件
- 将 V4L2 采集依赖从 v4l 切换到 v4l2r - 新增基于 v4l2r 的 mmap 采集实现,优先使用 VIDEO_CAPTURE_MPLANE - 更新像素格式转换与设备枚举逻辑,探测阶段改为只读打开 - 增加采集错误日志节流,避免 dqbuf EINVAL 日志风暴 - 交叉编译镜像安装更新的 Linux 内核头文件供 bindgen 使用
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
use v4l::format::fourcc;
|
||||
use v4l2r::PixelFormat as V4l2rPixelFormat;
|
||||
|
||||
/// Supported pixel formats
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
@@ -41,30 +41,29 @@ pub enum PixelFormat {
|
||||
}
|
||||
|
||||
impl PixelFormat {
|
||||
/// Convert to V4L2 FourCC
|
||||
pub fn to_fourcc(&self) -> fourcc::FourCC {
|
||||
/// Convert to V4L2 FourCC bytes
|
||||
pub fn to_fourcc(&self) -> [u8; 4] {
|
||||
match self {
|
||||
PixelFormat::Mjpeg => fourcc::FourCC::new(b"MJPG"),
|
||||
PixelFormat::Jpeg => fourcc::FourCC::new(b"JPEG"),
|
||||
PixelFormat::Yuyv => fourcc::FourCC::new(b"YUYV"),
|
||||
PixelFormat::Yvyu => fourcc::FourCC::new(b"YVYU"),
|
||||
PixelFormat::Uyvy => fourcc::FourCC::new(b"UYVY"),
|
||||
PixelFormat::Nv12 => fourcc::FourCC::new(b"NV12"),
|
||||
PixelFormat::Nv21 => fourcc::FourCC::new(b"NV21"),
|
||||
PixelFormat::Nv16 => fourcc::FourCC::new(b"NV16"),
|
||||
PixelFormat::Nv24 => fourcc::FourCC::new(b"NV24"),
|
||||
PixelFormat::Yuv420 => fourcc::FourCC::new(b"YU12"),
|
||||
PixelFormat::Yvu420 => fourcc::FourCC::new(b"YV12"),
|
||||
PixelFormat::Rgb565 => fourcc::FourCC::new(b"RGBP"),
|
||||
PixelFormat::Rgb24 => fourcc::FourCC::new(b"RGB3"),
|
||||
PixelFormat::Bgr24 => fourcc::FourCC::new(b"BGR3"),
|
||||
PixelFormat::Grey => fourcc::FourCC::new(b"GREY"),
|
||||
PixelFormat::Mjpeg => *b"MJPG",
|
||||
PixelFormat::Jpeg => *b"JPEG",
|
||||
PixelFormat::Yuyv => *b"YUYV",
|
||||
PixelFormat::Yvyu => *b"YVYU",
|
||||
PixelFormat::Uyvy => *b"UYVY",
|
||||
PixelFormat::Nv12 => *b"NV12",
|
||||
PixelFormat::Nv21 => *b"NV21",
|
||||
PixelFormat::Nv16 => *b"NV16",
|
||||
PixelFormat::Nv24 => *b"NV24",
|
||||
PixelFormat::Yuv420 => *b"YU12",
|
||||
PixelFormat::Yvu420 => *b"YV12",
|
||||
PixelFormat::Rgb565 => *b"RGBP",
|
||||
PixelFormat::Rgb24 => *b"RGB3",
|
||||
PixelFormat::Bgr24 => *b"BGR3",
|
||||
PixelFormat::Grey => *b"GREY",
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to convert from V4L2 FourCC
|
||||
pub fn from_fourcc(fourcc: fourcc::FourCC) -> Option<Self> {
|
||||
let repr = fourcc.repr;
|
||||
pub fn from_fourcc(repr: [u8; 4]) -> Option<Self> {
|
||||
match &repr {
|
||||
b"MJPG" => Some(PixelFormat::Mjpeg),
|
||||
b"JPEG" => Some(PixelFormat::Jpeg),
|
||||
@@ -85,6 +84,17 @@ impl PixelFormat {
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert to v4l2r PixelFormat
|
||||
pub fn to_v4l2r(&self) -> V4l2rPixelFormat {
|
||||
V4l2rPixelFormat::from(&self.to_fourcc())
|
||||
}
|
||||
|
||||
/// Convert from v4l2r PixelFormat
|
||||
pub fn from_v4l2r(format: V4l2rPixelFormat) -> Option<Self> {
|
||||
let repr: [u8; 4] = format.into();
|
||||
Self::from_fourcc(repr)
|
||||
}
|
||||
|
||||
/// Check if format is compressed (JPEG/MJPEG)
|
||||
pub fn is_compressed(&self) -> bool {
|
||||
matches!(self, PixelFormat::Mjpeg | PixelFormat::Jpeg)
|
||||
|
||||
Reference in New Issue
Block a user