mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-07-29 10:41:45 +08:00
fix: 完善 libyuv 静态库构建
This commit is contained in:
@@ -86,6 +86,21 @@ fn generate_bindings(cpp_dir: &Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn link_libyuv() {
|
fn link_libyuv() {
|
||||||
|
println!("cargo:rerun-if-env-changed=ONE_KVM_LIBS_PATH");
|
||||||
|
println!("cargo:rerun-if-env-changed=LIBYUV_STATIC");
|
||||||
|
|
||||||
|
// An explicit library root must take precedence over host discovery.
|
||||||
|
if env::var("ONE_KVM_LIBS_PATH")
|
||||||
|
.ok()
|
||||||
|
.is_some_and(|path| !path.trim().is_empty())
|
||||||
|
{
|
||||||
|
if link_system() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
panic!("libyuv not found under ONE_KVM_LIBS_PATH");
|
||||||
|
}
|
||||||
|
|
||||||
// Try vcpkg first
|
// Try vcpkg first
|
||||||
if let Some(vcpkg_installed) = vcpkg_installed_root() {
|
if let Some(vcpkg_installed) = vcpkg_installed_root() {
|
||||||
if link_vcpkg(vcpkg_installed) {
|
if link_vcpkg(vcpkg_installed) {
|
||||||
@@ -232,17 +247,21 @@ fn link_system() -> bool {
|
|||||||
// Build custom library paths based on target architecture:
|
// Build custom library paths based on target architecture:
|
||||||
// 1. Check ONE_KVM_LIBS_PATH environment variable (explicit override)
|
// 1. Check ONE_KVM_LIBS_PATH environment variable (explicit override)
|
||||||
// 2. Fall back to architecture-based detection
|
// 2. Fall back to architecture-based detection
|
||||||
let custom_lib_path = if let Ok(path) = env::var("ONE_KVM_LIBS_PATH") {
|
let explicit_lib_root = env::var("ONE_KVM_LIBS_PATH")
|
||||||
format!("{}/lib", path)
|
.ok()
|
||||||
} else {
|
.filter(|path| !path.trim().is_empty());
|
||||||
match target_arch.as_str() {
|
let custom_lib_path = explicit_lib_root
|
||||||
"x86_64" => "/usr/local/lib",
|
.as_ref()
|
||||||
"aarch64" => "/usr/aarch64-linux-gnu/lib",
|
.map(|path| format!("{}/lib", path))
|
||||||
"arm" => "/usr/arm-linux-gnueabihf/lib",
|
.unwrap_or_else(|| {
|
||||||
_ => "",
|
match target_arch.as_str() {
|
||||||
}
|
"x86_64" => "/usr/local/lib",
|
||||||
.to_string()
|
"aarch64" => "/usr/aarch64-linux-gnu/lib",
|
||||||
};
|
"arm" => "/usr/arm-linux-gnueabihf/lib",
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
.to_string()
|
||||||
|
});
|
||||||
|
|
||||||
// Try common system library paths (custom paths first)
|
// Try common system library paths (custom paths first)
|
||||||
let mut lib_paths: Vec<String> = Vec::new();
|
let mut lib_paths: Vec<String> = Vec::new();
|
||||||
@@ -252,20 +271,22 @@ fn link_system() -> bool {
|
|||||||
lib_paths.push(custom_lib_path);
|
lib_paths.push(custom_lib_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Then standard paths
|
// An explicit root is strict: do not silently fall back to host libraries.
|
||||||
lib_paths.extend(
|
if explicit_lib_root.is_none() {
|
||||||
[
|
lib_paths.extend(
|
||||||
"/usr/local/lib", // Custom builds
|
[
|
||||||
"/usr/local/lib64",
|
"/usr/local/lib", // Custom builds
|
||||||
"/usr/lib",
|
"/usr/local/lib64",
|
||||||
"/usr/lib64",
|
"/usr/lib",
|
||||||
"/usr/lib/x86_64-linux-gnu", // Debian/Ubuntu x86_64
|
"/usr/lib64",
|
||||||
"/usr/lib/aarch64-linux-gnu", // Debian/Ubuntu ARM64
|
"/usr/lib/x86_64-linux-gnu", // Debian/Ubuntu x86_64
|
||||||
"/usr/lib/arm-linux-gnueabihf", // Debian/Ubuntu ARMv7
|
"/usr/lib/aarch64-linux-gnu", // Debian/Ubuntu ARM64
|
||||||
]
|
"/usr/lib/arm-linux-gnueabihf", // Debian/Ubuntu ARMv7
|
||||||
.iter()
|
]
|
||||||
.map(|s| s.to_string()),
|
.iter()
|
||||||
);
|
.map(|s| s.to_string()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for path in &lib_paths {
|
for path in &lib_paths {
|
||||||
let lib_path = Path::new(path);
|
let lib_path = Path::new(path);
|
||||||
|
|||||||
@@ -1088,17 +1088,17 @@ pub fn bgr24_to_nv12(src: &[u8], dst: &mut [u8], width: i32, height: i32) -> Res
|
|||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
{
|
{
|
||||||
let y_size = w * h;
|
let y_size = w * h;
|
||||||
call_yuv!(RGB24ToNV12(
|
call_yuv!(RGB24ToNV12(
|
||||||
src.as_ptr(),
|
src.as_ptr(),
|
||||||
width * 3,
|
width * 3,
|
||||||
dst.as_mut_ptr(),
|
dst.as_mut_ptr(),
|
||||||
width,
|
width,
|
||||||
dst[y_size..].as_mut_ptr(),
|
dst[y_size..].as_mut_ptr(),
|
||||||
width,
|
width,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1391,4 +1391,15 @@ mod tests {
|
|||||||
assert_eq!(converter.dimensions(), (8, 8));
|
assert_eq!(converter.dimensions(), (8, 8));
|
||||||
assert_eq!(converter.nv12_buffer().len(), nv12_size(8, 8));
|
assert_eq!(converter.nv12_buffer().len(), nv12_size(8, 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bgr24_to_nv12() {
|
||||||
|
let src = [0u8; 2 * 2 * 3];
|
||||||
|
let mut dst = [0xffu8; 2 * 2 * 3 / 2];
|
||||||
|
|
||||||
|
bgr24_to_nv12(&src, &mut dst, 2, 2).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(&dst[..4], &[16, 16, 16, 16]);
|
||||||
|
assert_eq!(&dst[4..], &[128, 128]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user