Skip to content

bump manylinux to manylinux_2_34 #598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ffi-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ jobs:
buildargs: --no-default-features --features "rustls-tls-webpki-roots"
- os: ubuntu-latest
platform: linux
build_image: quay.io/pypa/manylinux_2_28_x86_64
build_image: quay.io/pypa/manylinux_2_34_x86_64
dylib: liblivekit_ffi.so
target: x86_64-unknown-linux-gnu
name: ffi-linux-x86_64
- os: ubuntu-24.04-arm
platform: linux
build_image: quay.io/pypa/manylinux_2_28_aarch64
build_image: quay.io/pypa/manylinux_2_34_aarch64
dylib: liblivekit_ffi.so
target: aarch64-unknown-linux-gnu
name: ffi-linux-arm64
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "yuv-sys/libyuv"]
path = yuv-sys/libyuv
url = https://chromium.googlesource.com/libyuv/libyuv
[submodule "soxr-sys/soxr"]
path = soxr-sys/soxr
url = https://github.com/dofuuz/soxr/
21 changes: 15 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 28 additions & 19 deletions livekit-ffi/src/server/resampler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,63 +32,68 @@ pub struct SoxResampler {
unsafe impl Send for SoxResampler {}

impl SoxResampler {
/// Creates a new SoxResampler using soxr's default quality and runtime options.
/// The provided `QualitySpec` and `RuntimeSpec` are ignored and null pointers are passed
/// to `soxr_create` to let soxr choose its defaults.
pub fn new(
input_rate: f64,
output_rate: f64,
num_channels: u32,
io_spec: IOSpec,
quality_spec: QualitySpec,
runtime_spec: RuntimeSpec,
_quality_spec: QualitySpec, // ignored – using default soxr options
_runtime_spec: RuntimeSpec, // ignored – using default soxr options
) -> Result<Self, String> {
let error: *mut *const c_char = std::ptr::null_mut();
let mut err: *mut *const c_char = std::ptr::null_mut();

let soxr_ptr = unsafe {
// Create io_spec from our types.
let io_spec = soxr_sys::soxr_io_spec(
to_soxr_datatype(io_spec.input_type),
to_soxr_datatype(io_spec.output_type),
);

let quality_spec = soxr_sys::soxr_quality_spec(
quality_spec.quality as c_ulong,
quality_spec.flags as c_ulong,
);

let runtime_spec = soxr_sys::soxr_runtime_spec(runtime_spec.num_threads);

// Pass null pointers for quality and runtime specs so that
// soxr will use its internal default options.
soxr_sys::soxr_create(
input_rate,
output_rate,
num_channels,
error,
err,
&io_spec,
&quality_spec,
&runtime_spec,
std::ptr::null(), // default quality
std::ptr::null(), // default runtime
)
};

if !error.is_null() {
let error_msg = unsafe { std::ffi::CStr::from_ptr(*error) };
if !err.is_null() || soxr_ptr.is_null() {
let error_msg = unsafe { std::ffi::CStr::from_ptr(*err) };
return Err(error_msg.to_string_lossy().to_string());
}

Ok(Self { soxr_ptr, out_buf: Vec::new(), input_rate, output_rate, num_channels })
}

/// Processes the input buffer and returns the resampled output.
/// This version verifies that the input length is a multiple of the number of channels
/// and uses valid pointers for tracking the number of frames consumed and produced.
pub fn push(&mut self, input: &[i16]) -> Result<&[i16], String> {
let input_length = input.len() / self.num_channels as usize;
let ratio = self.output_rate / self.input_rate;
let soxr_delay = unsafe { soxr_sys::soxr_delay(self.soxr_ptr) };
let delay = unsafe { soxr_sys::soxr_delay(self.soxr_ptr) };

// Estimate maximum output frames: processed frames + delay + an extra frame.
let max_out_len =
((input_length as f64 * ratio).ceil() as usize) + (soxr_delay.ceil() as usize) + 1;
(input_length as f64 * ratio).ceil() as usize + (delay.ceil() as usize) + 1;

let required_output_size = max_out_len * self.num_channels as usize;
if self.out_buf.len() < required_output_size {
self.out_buf.resize(required_output_size, 0);
}

// Using valid pointers for both consumed input (idone) and produced output (odone)
let mut idone: usize = 0;
let mut odone: usize = 0;

let error = unsafe {
soxr_sys::soxr_process(
self.soxr_ptr,
Expand All @@ -100,6 +105,7 @@ impl SoxResampler {
&mut odone,
)
};

if !error.is_null() {
let error_msg = unsafe { std::ffi::CStr::from_ptr(error) };
return Err(error_msg.to_string_lossy().to_string());
Expand All @@ -109,19 +115,22 @@ impl SoxResampler {
Ok(&self.out_buf[..output_samples])
}

/// Flushes the internal state, processing any remaining data.
/// Passes null for the input pointer and for the idone parameter (since it is not needed).
pub fn flush(&mut self) -> Result<&[i16], String> {
let mut odone: usize = 0;
let error = unsafe {
soxr_sys::soxr_process(
self.soxr_ptr,
std::ptr::null(),
std::ptr::null(), // no more input
0,
std::ptr::null_mut(),
std::ptr::null_mut(), // no need to know how many were consumed
self.out_buf.as_mut_ptr() as *mut c_void,
self.out_buf.len(),
&mut odone,
)
};

if !error.is_null() {
let error_msg = unsafe { std::ffi::CStr::from_ptr(error) };
return Err(error_msg.to_string_lossy().to_string());
Expand Down
4 changes: 1 addition & 3 deletions soxr-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ authors = ["Theo Monnom <[email protected]"]
edition = "2021"
license = "Apache-2.0"

[dependencies]


[build-dependencies]
cc = "1.0"
cmake = "0.1"

[dev-dependencies]
hound = "3.4"
53 changes: 12 additions & 41 deletions soxr-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,17 @@
use std::env;
use cmake::Config;

fn main() {
let mut build = cc::Build::new();
let dst = Config::new("soxr")
.define("BUILD_TESTS", "OFF")
.define("WITH_OPENMP", "OFF")
.define("WITH_LSR_BINDINGS", "OFF")
.define("BUILD_SHARED_LIBS", "OFF")
.define("WITH_VR32", "OFF")
.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON")
.build();

build.include("src");
build.define("SOXR_LIB", "0");
let lib_dir = dst.join("lib");

build
.flag_if_supported("-std=gnu89")
.flag_if_supported("-Wnested-externs")
.flag_if_supported("-Wmissing-prototypes")
.flag_if_supported("-Wstrict-prototypes")
.flag_if_supported("-Wconversion")
.flag_if_supported("-Wall")
.flag_if_supported("-Wextra")
.flag_if_supported("-pedantic")
.flag_if_supported("-Wundef")
.flag_if_supported("-Wpointer-arith")
.flag_if_supported("-Wno-long-long");

// TODO(theomonnom): Add SIMD support
let sources = [
"src/soxr.c",
"src/data-io.c",
"src/dbesi0.c",
"src/filter.c",
"src/cr.c",
"src/cr32.c",
"src/fft4g32.c",
"src/fft4g.c",
"src/fft4g64.c",
"src/vr32.c",
];

for source in &sources {
build.file(source);
}

build.compile("libsoxr.a");

let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
if target_os.as_str() != "windows" {
println!("cargo:rustc-link-lib=m");
}
println!("cargo:rustc-link-search=native={}", lib_dir.display());
println!("cargo:rustc-link-lib=static=soxr");
}
2 changes: 1 addition & 1 deletion soxr-sys/generate_bindings.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bindgen src/soxr.h -o src/soxr.rs
bindgen soxr/src/soxr.h -o src/soxr.rs
1 change: 1 addition & 0 deletions soxr-sys/soxr
Submodule soxr added at a66f3e
23 changes: 0 additions & 23 deletions soxr-sys/src/LICENCE

This file was deleted.

39 changes: 0 additions & 39 deletions soxr-sys/src/aliases.h

This file was deleted.

33 changes: 0 additions & 33 deletions soxr-sys/src/avfft32.c

This file was deleted.

Loading
Loading