Skip to content

Commit cc168cc

Browse files
committed
Improve search for NDI library
1 parent 86175ff commit cc168cc

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/jockey/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl Jockey {
266266

267267
let pipeline = Pipeline::splash_screen();
268268
let midi = Midi::new(&config, config_folder_path.as_deref());
269-
let ndi = Ndi::new();
269+
let ndi = Ndi::with_config_path(config_folder_path.clone());
270270

271271
let console = "No pipeline has been built yet".into();
272272

src/jockey/network.rs

+41-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use ndi::{self, FindCreateError, FindSourcesTimeout};
77

88
use super::*;
99

10-
static NDI_RECEIVER_NAME: &'static str = "Sh4derJockey";
10+
static NDI_RECEIVER_NAME: &str = "Sh4derJockey";
1111

1212
#[derive(Debug)]
1313
pub struct Ndi {
@@ -18,18 +18,52 @@ pub struct Ndi {
1818
}
1919

2020
impl Ndi {
21-
pub fn new() -> Self {
22-
let result = ndi::load_library_default();
23-
if let Err(err) = &result {
24-
log::error!("Failed to load NDI library: {:?}", err);
21+
pub fn with_config_path(config_path: Option<PathBuf>) -> Self {
22+
let found = 'search: {
23+
#[cfg(target_os = "windows")]
24+
let names = ["Processing.NDI.Lib.x86.dll", "Processing.NDI.Lib.x64.dll"];
25+
#[cfg(target_os = "macos")]
26+
let names = ["libndi.dylib"];
27+
#[cfg(target_os = "linux")]
28+
let names = ["libndi.so.4", "libndi.so", "libndi"];
29+
30+
let mut errs = Vec::new();
31+
let paths = config_path
32+
.into_iter()
33+
.chain(std::env::current_exe())
34+
.chain(std::env::current_dir());
35+
36+
for mut path in paths {
37+
for name in names {
38+
path.set_file_name(name);
39+
match ndi::load_library(&path) {
40+
Ok(..) => {
41+
log::info!("Found NDI library at {}", path.to_string_lossy());
42+
break 'search true;
43+
}
44+
45+
Err(err) => {
46+
let path_string = path.to_string_lossy().into_owned();
47+
errs.push((path_string, err))
48+
}
49+
}
50+
}
51+
}
52+
53+
log::error!("Failed to load NDI library:");
54+
for (path, err) in errs {
55+
log::error!(" - {path} : {err}");
56+
}
57+
2558
log::info!("The program will continue to run without NDI functionality");
26-
}
59+
false
60+
};
2761

2862
Self {
2963
sources: Default::default(),
3064
videos: HashMap::new(),
3165
searching: false,
32-
disabled: result.is_err(),
66+
disabled: !found,
3367
}
3468
}
3569

0 commit comments

Comments
 (0)