mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 04:55:42 +09:00
refactor(media-proxy): split into modules and harden streaming (#2437)
This commit is contained in:
1 parent
16ae98e189
commit
d7d4e8da03
214 files changed
+47213
-18092
No files matched your search
+105
-13
@@ -1,17 +1,76 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::{collections::HashSet, path::PathBuf, process::Command};
|
||||
|
||||
const NATIVE_SHIM_SOURCES: [&str; 16] = [
|
||||
"src/webp_animation.c",
|
||||
"src/native_shim/av_input.c",
|
||||
"src/native_shim/av_frame_rgba.c",
|
||||
"src/native_shim/vips_image.c",
|
||||
"src/native_shim/gif_validation.c",
|
||||
"src/native_shim/gif_timing.c",
|
||||
"src/native_shim/gif_filter.c",
|
||||
"src/native_shim/gif_transform.c",
|
||||
"src/native_shim/apng_validation.c",
|
||||
"src/native_shim/animation_decode.c",
|
||||
"src/native_shim/heif_pixels.c",
|
||||
"src/native_shim/heif_decode.c",
|
||||
"src/native_shim/animated_webp.c",
|
||||
"src/native_shim/video_frame.c",
|
||||
"src/native_shim/nsfw_frame.c",
|
||||
"src/native_shim/nsfw_webp.c",
|
||||
];
|
||||
|
||||
const NATIVE_SHIM_HEADERS: [&str; 3] = [
|
||||
"src/vips_shim.h",
|
||||
"src/webp_animation.h",
|
||||
"src/native_shim/native_shim_internal.h",
|
||||
];
|
||||
|
||||
const NATIVE_BUILD_ENVIRONMENT: [&str; 6] = [
|
||||
"CARGO_CFG_TARGET_OS",
|
||||
"HOMEBREW_PREFIX",
|
||||
"PKG_CONFIG",
|
||||
"PKG_CONFIG_LIBDIR",
|
||||
"PKG_CONFIG_PATH",
|
||||
"PKG_CONFIG_SYSROOT_DIR",
|
||||
];
|
||||
|
||||
fn homebrew_prefix() -> PathBuf {
|
||||
if let Ok(prefix) = std::env::var("HOMEBREW_PREFIX") {
|
||||
return PathBuf::from(prefix);
|
||||
}
|
||||
let output = Command::new("brew")
|
||||
.arg("--prefix")
|
||||
.output()
|
||||
.expect("libyuv needs a Homebrew prefix: set HOMEBREW_PREFIX or install Homebrew");
|
||||
assert!(output.status.success(), "`brew --prefix` failed");
|
||||
PathBuf::from(
|
||||
String::from_utf8(output.stdout)
|
||||
.expect("`brew --prefix` printed invalid UTF-8")
|
||||
.trim(),
|
||||
)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("cargo:rerun-if-changed=src/vips_shim.c");
|
||||
println!("cargo:rerun-if-changed=src/vips_shim.h");
|
||||
println!("cargo:rerun-if-changed=src/srgb_profile.h");
|
||||
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
|
||||
for variable in NATIVE_BUILD_ENVIRONMENT {
|
||||
println!("cargo:rerun-if-env-changed={variable}");
|
||||
}
|
||||
for header in NATIVE_SHIM_HEADERS {
|
||||
println!("cargo:rerun-if-changed={header}");
|
||||
}
|
||||
for source in NATIVE_SHIM_SOURCES {
|
||||
println!("cargo:rerun-if-changed={source}");
|
||||
}
|
||||
|
||||
let mut build = cc::Build::new();
|
||||
build
|
||||
.file("src/vips_shim.c")
|
||||
.include("src")
|
||||
.flag_if_supported("-std=gnu11");
|
||||
let mut shim = cc::Build::new();
|
||||
shim.include("src")
|
||||
.flag("-std=c11")
|
||||
.warnings_into_errors(true);
|
||||
for source in NATIVE_SHIM_SOURCES {
|
||||
shim.file(source);
|
||||
}
|
||||
|
||||
let mut link_paths: Vec<PathBuf> = Vec::new();
|
||||
let mut link_files: Vec<PathBuf> = Vec::new();
|
||||
@@ -21,7 +80,6 @@ fn main() {
|
||||
let mut ld_args: Vec<Vec<String>> = Vec::new();
|
||||
|
||||
for lib in [
|
||||
"libcurl",
|
||||
"vips",
|
||||
"libheif",
|
||||
"libavformat",
|
||||
@@ -29,7 +87,8 @@ fn main() {
|
||||
"libavfilter",
|
||||
"libavutil",
|
||||
"libswscale",
|
||||
"libswresample",
|
||||
"lcms2",
|
||||
"libwebpdemux",
|
||||
"libwebpmux",
|
||||
"libwebp",
|
||||
] {
|
||||
@@ -38,7 +97,7 @@ fn main() {
|
||||
.probe(lib)
|
||||
.unwrap_or_else(|err| panic!("pkg-config could not find {lib}: {err}"));
|
||||
for include in probed.include_paths {
|
||||
build.include(include);
|
||||
shim.include(include);
|
||||
}
|
||||
link_paths.extend(probed.link_paths);
|
||||
link_files.extend(probed.link_files);
|
||||
@@ -48,10 +107,39 @@ fn main() {
|
||||
ld_args.extend(probed.ld_args);
|
||||
}
|
||||
|
||||
build.compile("fluxer_vips_shim");
|
||||
libs.push("yuv".into());
|
||||
|
||||
if target_os == "macos" {
|
||||
let prefix = homebrew_prefix();
|
||||
let header = prefix.join("include/libyuv.h");
|
||||
assert!(
|
||||
header.is_file(),
|
||||
"libyuv header missing at {}: run `brew install libyuv`",
|
||||
header.display()
|
||||
);
|
||||
let has_library = ["lib/libyuv.dylib", "lib/libyuv.a"]
|
||||
.iter()
|
||||
.any(|candidate| prefix.join(candidate).is_file());
|
||||
assert!(
|
||||
has_library,
|
||||
"libyuv library missing under {}: run `brew install libyuv`",
|
||||
prefix.join("lib").display()
|
||||
);
|
||||
shim.include(prefix.join("include"));
|
||||
link_paths.push(prefix.join("lib"));
|
||||
}
|
||||
|
||||
shim.compile("fluxer_vips_shim");
|
||||
|
||||
let mut emitted_link_paths: HashSet<PathBuf> = HashSet::new();
|
||||
for path in link_paths {
|
||||
if !emitted_link_paths.insert(path.clone()) {
|
||||
continue;
|
||||
}
|
||||
println!("cargo:rustc-link-search=native={}", path.display());
|
||||
if target_os == "macos" {
|
||||
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", path.display());
|
||||
}
|
||||
}
|
||||
for path in framework_paths {
|
||||
println!("cargo:rustc-link-search=framework={}", path.display());
|
||||
@@ -67,7 +155,11 @@ fn main() {
|
||||
for framework in frameworks {
|
||||
println!("cargo:rustc-link-lib=framework={framework}");
|
||||
}
|
||||
let mut emitted_libs: HashSet<String> = HashSet::new();
|
||||
for lib in libs {
|
||||
if !emitted_libs.insert(lib.clone()) {
|
||||
continue;
|
||||
}
|
||||
println!("cargo:rustc-link-lib={lib}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user