feat: 深入适配 RK628D CSI 采集卡的设备识别、参数读取、自恢复和音频采集

This commit is contained in:
mofeng-git
2026-04-19 11:26:21 +08:00
parent 8eac31f69f
commit 7c703b8b4b
39 changed files with 3261 additions and 769 deletions

View File

@@ -141,8 +141,8 @@ impl PixelFormat {
match self {
PixelFormat::Mjpeg => 100,
PixelFormat::Jpeg => 99,
PixelFormat::Yuyv => 80,
PixelFormat::Nv12 => 75,
PixelFormat::Nv12 => 80,
PixelFormat::Yuyv => 75,
PixelFormat::Nv21 => 74,
PixelFormat::Yuv420 => 70,
PixelFormat::Uyvy => 65,
@@ -159,30 +159,18 @@ impl PixelFormat {
/// Get recommended format for video encoding (WebRTC)
///
/// Hardware encoding prefers: NV12 > YUYV
/// Software encoding prefers: YUYV > NV12
/// Prefers NV12 over YUYV (matches [`Self::priority`])
///
/// Returns None if no suitable format is available
pub fn recommended_for_encoding(
available: &[PixelFormat],
is_hardware: bool,
_is_hardware: bool,
) -> Option<PixelFormat> {
if is_hardware {
// Hardware encoding: NV12 > YUYV
if available.contains(&PixelFormat::Nv12) {
return Some(PixelFormat::Nv12);
}
if available.contains(&PixelFormat::Yuyv) {
return Some(PixelFormat::Yuyv);
}
} else {
// Software encoding: YUYV > NV12
if available.contains(&PixelFormat::Yuyv) {
return Some(PixelFormat::Yuyv);
}
if available.contains(&PixelFormat::Nv12) {
return Some(PixelFormat::Nv12);
}
if available.contains(&PixelFormat::Nv12) {
return Some(PixelFormat::Nv12);
}
if available.contains(&PixelFormat::Yuyv) {
return Some(PixelFormat::Yuyv);
}
// Fallback to any non-compressed format
available.iter().find(|f| !f.is_compressed()).copied()
@@ -280,19 +268,76 @@ impl Resolution {
self.width as u64 * self.height as u64
}
/// Common resolutions
/// Common resolutions.
///
/// All constants here are 8-pixel aligned on both axes so they survive
/// the `step=8` constraint imposed by most CSI bridge drivers (e.g.
/// `rkcif` on Rockchip). If you add a new entry, make sure
/// `width % 8 == 0 && height % 8 == 0`, otherwise the driver will
/// silently round it at `S_FMT` time and the UI will report a
/// different resolution than the one the user picked.
pub const VGA: Resolution = Resolution {
width: 640,
height: 480,
};
/// CEA-2/3 NTSC SD (480p)
pub const NTSC: Resolution = Resolution {
width: 720,
height: 480,
};
/// CEA-5/17/18 PAL SD (576p)
pub const PAL: Resolution = Resolution {
width: 720,
height: 576,
};
/// SVGA — legacy BIOS / POST output
pub const SVGA: Resolution = Resolution {
width: 800,
height: 600,
};
/// XGA — very common BIOS / server console output
pub const XGA: Resolution = Resolution {
width: 1024,
height: 768,
};
pub const HD720: Resolution = Resolution {
width: 1280,
height: 720,
};
/// WXGA — older laptop panels
pub const WXGA: Resolution = Resolution {
width: 1280,
height: 800,
};
/// SXGA — 4:3 / 5:4 legacy desktop displays
pub const SXGA: Resolution = Resolution {
width: 1280,
height: 1024,
};
/// 1360×768 — fallback for 8-aligned "1366×768"-like panels
pub const HDTV: Resolution = Resolution {
width: 1360,
height: 768,
};
/// UXGA — industrial / 4:3 legacy displays
pub const UXGA: Resolution = Resolution {
width: 1600,
height: 1200,
};
pub const HD1080: Resolution = Resolution {
width: 1920,
height: 1080,
};
/// WUXGA — 16:10 professional monitors
pub const WUXGA: Resolution = Resolution {
width: 1920,
height: 1200,
};
/// QHD / 2K — modern PC monitors
pub const QHD: Resolution = Resolution {
width: 2560,
height: 1440,
};
pub const UHD4K: Resolution = Resolution {
width: 3840,
height: 2160,