1#![allow(non_upper_case_globals)]
5#![allow(non_camel_case_types)]
6#![allow(non_snake_case)]
7#![allow(clippy::type_complexity)]
8#![allow(clippy::missing_safety_doc)]
9#![allow(clippy::too_many_arguments)]
10
11include!("ffi.rs");
12
13pub use libloading;
15
16use std::sync::{Mutex, OnceLock};
17
18static LIBRARY: OnceLock<VideoStreamLibrary> = OnceLock::new();
19static INIT_LOCK: Mutex<()> = Mutex::new(());
20
21pub fn init() -> Result<&'static VideoStreamLibrary, libloading::Error> {
26 if let Some(lib) = LIBRARY.get() {
27 return Ok(lib);
28 }
29
30 let _guard = INIT_LOCK.lock().unwrap();
31
32 if let Some(lib) = LIBRARY.get() {
34 return Ok(lib);
35 }
36
37 let lib = unsafe { VideoStreamLibrary::new("libvideostream.so")? };
38
39 LIBRARY.set(lib).ok().expect("Failed to initialize library");
40
41 Ok(LIBRARY.get().unwrap())
42}
43
44pub fn library() -> &'static VideoStreamLibrary {
48 LIBRARY
49 .get()
50 .expect("VideoStream library not initialized - call videostream_sys::init() first")
51}
52
53pub fn try_library() -> Option<&'static VideoStreamLibrary> {
55 LIBRARY.get()
56}