#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(clippy::type_complexity)]
#![allow(clippy::missing_safety_doc)]
#![allow(clippy::too_many_arguments)]
include!("ffi.rs");
pub use libloading;
use std::sync::{Mutex, OnceLock};
static LIBRARY: OnceLock<&'static VideoStreamLibrary> = OnceLock::new();
static INIT_LOCK: Mutex<()> = Mutex::new(());
pub fn init() -> Result<&'static VideoStreamLibrary, libloading::Error> {
if let Some(lib) = LIBRARY.get() {
return Ok(lib);
}
let _guard = INIT_LOCK.lock().unwrap();
if let Some(lib) = LIBRARY.get() {
return Ok(lib);
}
let lib_path = std::env::var("VIDEOSTREAM_LIBRARY")
.ok()
.unwrap_or_else(|| "libvideostream.so".to_string());
let lib = unsafe { VideoStreamLibrary::new(lib_path.as_str())? };
let leaked_lib: &'static VideoStreamLibrary = Box::leak(Box::new(lib));
LIBRARY
.set(leaked_lib)
.ok()
.expect("Failed to initialize library");
Ok(*LIBRARY.get().unwrap())
}
pub fn library() -> &'static VideoStreamLibrary {
LIBRARY
.get()
.expect("VideoStream library not initialized - call videostream_sys::init() first")
}
pub fn try_library() -> Option<&'static VideoStreamLibrary> {
LIBRARY.get().copied()
}