@@ -7,7 +7,7 @@ use ndi::{self, FindCreateError, FindSourcesTimeout};
7
7
8
8
use super :: * ;
9
9
10
- static NDI_RECEIVER_NAME : & ' static str = "Sh4derJockey" ;
10
+ static NDI_RECEIVER_NAME : & str = "Sh4derJockey" ;
11
11
12
12
#[ derive( Debug ) ]
13
13
pub struct Ndi {
@@ -18,18 +18,52 @@ pub struct Ndi {
18
18
}
19
19
20
20
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
+
25
58
log:: info!( "The program will continue to run without NDI functionality" ) ;
26
- }
59
+ false
60
+ } ;
27
61
28
62
Self {
29
63
sources : Default :: default ( ) ,
30
64
videos : HashMap :: new ( ) ,
31
65
searching : false ,
32
- disabled : result . is_err ( ) ,
66
+ disabled : !found ,
33
67
}
34
68
}
35
69
0 commit comments