refactor: 升级依赖版本并优化构建系统

- 升级核心依赖 (axum 0.8, tower-http 0.6, alsa 0.11 等)
- 简化交叉编译配置,切换至 Debian 11 提高兼容性
- 新增 Debian 包打包支持 (debuerreotype 模板)
- 移除独立的 mjpeg 解码器,简化视频模块
- 静态链接 libx264/libx265/libopus 到二进制
This commit is contained in:
mofeng-git
2026-01-10 10:59:00 +08:00
parent 3fa91772f0
commit e670f1ffd1
46 changed files with 893 additions and 1156 deletions

View File

@@ -59,11 +59,6 @@ fn generate_bindings(cpp_dir: &Path) {
.allowlist_function("UYVYToARGB")
.allowlist_function("ARGBToRGB24")
.allowlist_function("ARGBToRAW")
// MJPEG decoding
.allowlist_function("MJPGToI420")
.allowlist_function("MJPGToNV12")
.allowlist_function("MJPGToARGB")
.allowlist_function("MJPGSize")
// Scaling
.allowlist_function("I420Scale")
.allowlist_function("NV12Scale")
@@ -152,25 +147,15 @@ fn link_vcpkg(mut path: PathBuf) -> bool {
let use_static = env::var("LIBYUV_STATIC").map(|v| v == "1").unwrap_or(false);
let static_lib = lib_path.join("libyuv.a");
let jpeg_static = lib_path.join("libjpeg.a");
let turbojpeg_static = lib_path.join("libturbojpeg.a");
if use_static && static_lib.exists() {
// Static linking (for deb packaging)
println!("cargo:rustc-link-lib=static=yuv");
if turbojpeg_static.exists() {
println!("cargo:rustc-link-lib=static=turbojpeg");
} else if jpeg_static.exists() {
println!("cargo:rustc-link-lib=static=jpeg");
} else {
println!("cargo:rustc-link-lib=jpeg");
}
println!("cargo:rustc-link-lib=stdc++");
println!("cargo:info=Using libyuv from vcpkg (static linking)");
} else {
// Dynamic linking (default for development)
println!("cargo:rustc-link-lib=yuv");
println!("cargo:rustc-link-lib=jpeg");
println!("cargo:rustc-link-lib=stdc++");
println!("cargo:info=Using libyuv from vcpkg (dynamic linking)");
}
@@ -204,23 +189,6 @@ fn link_pkg_config() -> bool {
}
}
// Also need libjpeg
if let Ok(jpeg_output) = Command::new("pkg-config")
.args(["--libs", "libjpeg"])
.output()
{
if jpeg_output.status.success() {
let jpeg_flags = String::from_utf8_lossy(&jpeg_output.stdout);
for flag in jpeg_flags.split_whitespace() {
if flag.starts_with("-L") {
println!("cargo:rustc-link-search=native={}", &flag[2..]);
} else if flag.starts_with("-l") {
println!("cargo:rustc-link-lib={}", &flag[2..]);
}
}
}
}
#[cfg(target_os = "linux")]
println!("cargo:rustc-link-lib=stdc++");
@@ -240,9 +208,9 @@ fn link_system() -> bool {
format!("{}/lib", path)
} else {
match target_arch.as_str() {
"x86_64" => "/opt/one-kvm-libs/x86_64-linux-gnu/lib",
"aarch64" => "/opt/one-kvm-libs/aarch64-linux-gnu/lib",
"arm" => "/opt/one-kvm-libs/armv7-linux-gnueabihf/lib",
"x86_64" => "/usr/local/lib",
"aarch64" => "/usr/aarch64-linux-gnu/lib",
"arm" => "/usr/arm-linux-gnueabihf/lib",
_ => "",
}
.to_string()
@@ -276,19 +244,6 @@ fn link_system() -> bool {
if use_static && libyuv_static.exists() {
println!("cargo:rustc-link-search=native={}", path);
println!("cargo:rustc-link-lib=static=yuv");
// Check for static libjpeg-turbo in the same directory
let turbojpeg_static = lib_path.join("libturbojpeg.a");
let jpeg_static = lib_path.join("libjpeg.a");
if turbojpeg_static.exists() {
println!("cargo:rustc-link-lib=static=turbojpeg");
} else if jpeg_static.exists() {
println!("cargo:rustc-link-lib=static=jpeg");
} else {
// Fall back to dynamic jpeg
println!("cargo:rustc-link-lib=jpeg");
}
println!("cargo:rustc-link-lib=stdc++");
println!("cargo:info=Using system libyuv from {} (static linking)", path);
return true;
@@ -298,7 +253,6 @@ fn link_system() -> bool {
if libyuv_so.exists() {
println!("cargo:rustc-link-search=native={}", path);
println!("cargo:rustc-link-lib=yuv");
println!("cargo:rustc-link-lib=jpeg");
#[cfg(target_os = "linux")]
println!("cargo:rustc-link-lib=stdc++");

View File

@@ -58,8 +58,6 @@ pub enum YuvError {
BufferTooSmall,
/// libyuv function returned an error code
ConversionFailed(i32),
/// MJPEG data is invalid or corrupt
InvalidMjpeg,
}
impl fmt::Display for YuvError {
@@ -68,7 +66,6 @@ impl fmt::Display for YuvError {
YuvError::InvalidDimensions => write!(f, "Invalid dimensions (must be even)"),
YuvError::BufferTooSmall => write!(f, "Buffer too small"),
YuvError::ConversionFailed(code) => write!(f, "Conversion failed with code {}", code),
YuvError::InvalidMjpeg => write!(f, "Invalid MJPEG data"),
}
}
}
@@ -915,129 +912,6 @@ pub fn bgr24_to_nv12(src: &[u8], dst: &mut [u8], width: i32, height: i32) -> Res
i420_to_nv12(&i420_buffer, dst, width, height)
}
// ============================================================================
// MJPEG decoding
// ============================================================================
/// Decode MJPEG to I420
///
/// # Arguments
/// * `src` - Source MJPEG data
/// * `dst` - Destination I420 buffer
/// * `width` - Expected frame width
/// * `height` - Expected frame height
///
/// # Note
/// This function requires libyuv to be compiled with JPEG support
pub fn mjpeg_to_i420(src: &[u8], dst: &mut [u8], width: i32, height: i32) -> Result<()> {
if width % 2 != 0 || height % 2 != 0 {
return Err(YuvError::InvalidDimensions);
}
let w = width as usize;
let h = height as usize;
let y_size = w * h;
let uv_size = (w / 2) * (h / 2);
if dst.len() < i420_size(w, h) {
return Err(YuvError::BufferTooSmall);
}
if src.len() < 2 || src[0] != 0xFF || src[1] != 0xD8 {
return Err(YuvError::InvalidMjpeg);
}
call_yuv!(MJPGToI420(
src.as_ptr(),
usize_to_size_t(src.len()),
dst.as_mut_ptr(),
width,
dst[y_size..].as_mut_ptr(),
width / 2,
dst[y_size + uv_size..].as_mut_ptr(),
width / 2,
width,
height,
width,
height,
))
}
/// Decode MJPEG to NV12 (optimal for VAAPI)
pub fn mjpeg_to_nv12(src: &[u8], dst: &mut [u8], width: i32, height: i32) -> Result<()> {
if width % 2 != 0 || height % 2 != 0 {
return Err(YuvError::InvalidDimensions);
}
let w = width as usize;
let h = height as usize;
let y_size = w * h;
if dst.len() < nv12_size(w, h) {
return Err(YuvError::BufferTooSmall);
}
if src.len() < 2 || src[0] != 0xFF || src[1] != 0xD8 {
return Err(YuvError::InvalidMjpeg);
}
call_yuv!(MJPGToNV12(
src.as_ptr(),
usize_to_size_t(src.len()),
dst.as_mut_ptr(),
width,
dst[y_size..].as_mut_ptr(),
width,
width,
height,
width,
height,
))
}
/// Decode MJPEG to BGRA
pub fn mjpeg_to_bgra(src: &[u8], dst: &mut [u8], width: i32, height: i32) -> Result<()> {
let w = width as usize;
let h = height as usize;
if dst.len() < argb_size(w, h) {
return Err(YuvError::BufferTooSmall);
}
if src.len() < 2 || src[0] != 0xFF || src[1] != 0xD8 {
return Err(YuvError::InvalidMjpeg);
}
call_yuv!(MJPGToARGB(
src.as_ptr(),
usize_to_size_t(src.len()),
dst.as_mut_ptr(),
width * 4,
width,
height,
width,
height,
))
}
/// Get MJPEG frame dimensions without decoding
pub fn mjpeg_size(src: &[u8]) -> Result<(i32, i32)> {
if src.len() < 2 || src[0] != 0xFF || src[1] != 0xD8 {
return Err(YuvError::InvalidMjpeg);
}
let mut width: i32 = 0;
let mut height: i32 = 0;
let ret = unsafe { MJPGSize(src.as_ptr(), usize_to_size_t(src.len()), &mut width, &mut height) };
if ret != 0 || width <= 0 || height <= 0 {
return Err(YuvError::InvalidMjpeg);
}
Ok((width, height))
}
// ============================================================================
// Scaling
// ============================================================================
@@ -1199,18 +1073,6 @@ impl Converter {
Ok(&self.nv12_buffer)
}
/// Decode MJPEG to NV12, returns reference to internal buffer
pub fn mjpeg_to_nv12(&mut self, src: &[u8]) -> Result<&[u8]> {
mjpeg_to_nv12(src, &mut self.nv12_buffer, self.width, self.height)?;
Ok(&self.nv12_buffer)
}
/// Decode MJPEG to I420, returns reference to internal buffer
pub fn mjpeg_to_i420(&mut self, src: &[u8]) -> Result<&[u8]> {
mjpeg_to_i420(src, &mut self.i420_buffer, self.width, self.height)?;
Ok(&self.i420_buffer)
}
/// Convert I420 to NV12, returns reference to internal buffer
pub fn i420_to_nv12(&mut self, src: &[u8]) -> Result<&[u8]> {
i420_to_nv12(src, &mut self.nv12_buffer, self.width, self.height)?;