nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 119 lines 4.4 kB view raw
1diff --git a/prpr-avc/Cargo.toml b/prpr-avc/Cargo.toml 2index 257c575..bf35b10 100644 3--- a/prpr-avc/Cargo.toml 4+++ b/prpr-avc/Cargo.toml 5@@ -9,3 +9,6 @@ edition = "2021" 6 sasa = { git = "https://github.com/Mivik/sasa", default-features = false } 7 thiserror = "1.0.56" 8 tracing = "0.1.37" 9+ 10+[build-dependencies] 11+pkg-config = "0.3" 12diff --git a/prpr-avc/build.rs b/prpr-avc/build.rs 13index 961b032..6d0b714 100644 14--- a/prpr-avc/build.rs 15+++ b/prpr-avc/build.rs 16@@ -1,10 +1,7 @@ 17 use std::path::Path; 18 19 fn main() { 20- let libs_dir = std::env::var("PRPR_AVC_LIBS").unwrap_or_else(|_| format!("{}/static-lib", std::env::var("CARGO_MANIFEST_DIR").unwrap())); 21- let libs_path = Path::new(&libs_dir).join(std::env::var("TARGET").unwrap()); 22- let libs_path = libs_path.display(); 23- println!("cargo:rustc-link-search={libs_path}"); 24- println!("cargo:rustc-link-lib=z"); 25- println!("cargo:rerun-if-changed={libs_path}"); 26+ for lib in ["libavformat", "libavcodec", "libavutil", "libswscale", "libswresample"] { 27+ let _ = pkg_config::Config::new().statik(false).probe(lib); 28+ } 29 } 30diff --git a/prpr-avc/src/ffi.rs b/prpr-avc/src/ffi.rs 31index 8218ef3..a2c7f6a 100644 32--- a/prpr-avc/src/ffi.rs 33+++ b/prpr-avc/src/ffi.rs 34@@ -6,7 +6,6 @@ pub const AV_SAMPLE_FMT_FLT: AVSampleFormat = 3; 35 36 pub const AV_ROUND_UP: AVRounding = 0; 37 38-#[link(name = "avformat", kind = "static")] 39 extern "C" { 40 pub fn avformat_alloc_context() -> *mut AVFormatContext; 41 pub fn avformat_free_context(s: *mut AVFormatContext); 42@@ -20,7 +19,6 @@ extern "C" { 43 pub fn av_read_frame(s: *mut AVFormatContext, pkt: *mut AVPacket) -> ::std::os::raw::c_int; 44 } 45 46-#[link(name = "avutil", kind = "static")] 47 extern "C" { 48 pub fn av_strerror(errnum: ::std::os::raw::c_int, errbuf: *mut ::std::os::raw::c_char, errbuf_size: usize) -> ::std::os::raw::c_int; 49 pub fn av_frame_alloc() -> *mut AVFrame; 50@@ -29,7 +27,6 @@ extern "C" { 51 pub fn av_rescale_rnd(a: i64, b: i64, c: i64, r: AVRounding) -> i64; 52 } 53 54-#[link(name = "avcodec", kind = "static")] 55 extern "C" { 56 pub fn avcodec_find_decoder(id: AVCodecID) -> *mut AVCodec; 57 pub fn avcodec_alloc_context3(codec: *const AVCodec) -> *mut AVCodecContext; 58@@ -43,7 +40,6 @@ extern "C" { 59 pub fn avcodec_default_get_format(s: *mut AVCodecContext, fmt: *const AVPixelFormat) -> AVPixelFormat; 60 } 61 62-#[link(name = "swscale", kind = "static")] 63 extern "C" { 64 pub fn sws_getContext( 65 srcW: ::std::os::raw::c_int, 66@@ -68,10 +64,9 @@ extern "C" { 67 ) -> ::std::os::raw::c_int; 68 } 69 70-#[link(name = "swresample", kind = "static")] 71 extern "C" { 72- pub fn swr_alloc_set_opts( 73- s: *mut SwrContext, 74+ pub fn swr_alloc_set_opts2( 75+ ps: *mut *mut SwrContext, 76 out_ch_layout: i64, 77 out_sample_fmt: AVSampleFormat, 78 out_sample_rate: ::std::os::raw::c_int, 79@@ -80,7 +75,7 @@ extern "C" { 80 in_sample_rate: ::std::os::raw::c_int, 81 log_offset: ::std::os::raw::c_int, 82 log_ctx: *mut ::std::os::raw::c_void, 83- ) -> *mut SwrContext; 84+ ) -> ::std::os::raw::c_int; 85 pub fn swr_init(s: *mut SwrContext) -> ::std::os::raw::c_int; 86 pub fn swr_get_delay(s: *const SwrContext, base: ::std::os::raw::c_int) -> i64; 87 pub fn swr_convert( 88diff --git a/prpr-avc/src/swr.rs b/prpr-avc/src/swr.rs 89index 7288a51..c00b874 100644 90--- a/prpr-avc/src/swr.rs 91+++ b/prpr-avc/src/swr.rs 92@@ -5,8 +5,9 @@ pub struct SwrContext(OwnedPtr<ffi::SwrContext>); 93 impl SwrContext { 94 pub fn new(in_format: &AudioStreamFormat, out_format: &AudioStreamFormat) -> Result<Self> { 95 unsafe { 96- OwnedPtr::new(ffi::swr_alloc_set_opts( 97- null_mut(), 98+ let mut raw: *mut ffi::SwrContext = null_mut(); 99+ let ret = ffi::swr_alloc_set_opts2( 100+ &mut raw, 101 out_format.channel_layout as _, 102 out_format.sample_fmt, 103 out_format.sample_rate, 104@@ -15,9 +16,12 @@ impl SwrContext { 105 in_format.sample_rate, 106 0, 107 null_mut(), 108- )) 109- .map(|ctx| Self(ctx)) 110- .ok_or(Error::AllocationFailed) 111+ ); 112+ if ret < 0 || raw.is_null() { 113+ Err(Error::AllocationFailed) 114+ } else { 115+ OwnedPtr::new(raw).map(|ctx| Self(ctx)).ok_or(Error::AllocationFailed) 116+ } 117 } 118 } 119