|
42 | 42 | #include "video/sws_utils.h" |
43 | 43 |
|
44 | 44 | #ifdef _WIN32 |
45 | | -#include <Windows.h> |
| 45 | +#include "osdep/io.h" |
46 | 46 | #else |
47 | 47 | #include <dlfcn.h> |
48 | 48 | #endif |
@@ -809,57 +809,56 @@ static const m_option_t vf_opts_fields[] = { |
809 | 809 |
|
810 | 810 | static int drv_vss_init(struct priv *p) |
811 | 811 | { |
812 | | - typedef VS_CC const VSSCRIPTAPI *(*getVSScriptAPI_fn)(int); |
813 | | - typedef VS_CC const char *(*getVSScriptAPILastError_fn)(void); |
814 | | - |
815 | | - getVSScriptAPI_fn getVSScriptAPI_func = NULL; |
816 | | - getVSScriptAPILastError_fn getVSScriptAPILastError_func = NULL; |
| 812 | + const char *vsscript_path = getenv("VSSCRIPT_PATH"); |
| 813 | + const int dl_mode = RTLD_NOW | RTLD_LOCAL; |
| 814 | + void *vsscript_lib = NULL; |
817 | 815 |
|
818 | 816 | #ifdef _WIN32 |
819 | | - const wchar_t *vsscript_path = _wgetenv(L"VSSCRIPT_PATH"); |
820 | | - const HMODULE lib = LoadLibraryExW(vsscript_path ? vsscript_path : L"VSScript.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH); |
821 | | - if (lib) { |
822 | | - getVSScriptAPI_func = (getVSScriptAPI_fn) GetProcAddress(lib, "getVSScriptAPI"); |
823 | | - getVSScriptAPILastError_func = (getVSScriptAPILastError_fn) GetProcAddress(lib, "getVSScriptAPILastError"); |
824 | | - } |
825 | | -#else |
826 | | - |
| 817 | + vsscript_lib = dlopen(vsscript_path ? vsscript_path : "VSScript.dll", dl_mode); |
| 818 | +#else // _WIN32 |
| 819 | + if (vsscript_path) { |
| 820 | + vsscript_lib = dlopen(vsscript_path, dl_mode); |
| 821 | + } else { |
827 | 822 | #ifdef __APPLE__ |
828 | 823 | const char *lib_name_r74 = "libvsscript.4.dylib"; |
829 | 824 | const char *lib_name_old = "libvapoursynth-script.4.dylib"; |
830 | | -#else |
| 825 | +#else // __APPLE__ |
831 | 826 | const char *lib_name_r74 = "libvsscript.so.4"; |
832 | 827 | const char *lib_name_old = "libvapoursynth-script.so.4"; |
833 | | -#endif |
| 828 | +#endif // __APPLE__ |
834 | 829 |
|
835 | | - const char *vsscript_path = getenv("VSSCRIPT_PATH"); |
836 | | - const int dl_mode = RTLD_LAZY | RTLD_GLOBAL; |
837 | | - void *lib; |
838 | | - |
839 | | - if (vsscript_path) { |
840 | | - lib = dlopen(vsscript_path, dl_mode); |
841 | | - } else { |
842 | | - lib = dlopen(lib_name_r74, dl_mode); |
843 | | - if (!lib) { |
844 | | - lib = dlopen(lib_name_old, dl_mode); |
| 830 | + vsscript_lib = dlopen(lib_name_r74, dl_mode); |
| 831 | + if (!vsscript_lib) { |
| 832 | + vsscript_lib = dlopen(lib_name_old, dl_mode); |
845 | 833 | } |
846 | 834 | } |
| 835 | +#endif // _WIN32 |
| 836 | + |
| 837 | + typedef VS_CC const VSSCRIPTAPI *(*getVSScriptAPI_fn)(int); |
| 838 | + typedef VS_CC const char *(*getVSScriptAPILastError_fn)(void); |
| 839 | + |
| 840 | + getVSScriptAPI_fn getVSScriptAPI_func = NULL; |
| 841 | + getVSScriptAPILastError_fn getVSScriptAPILastError_func = NULL; |
847 | 842 |
|
848 | | - if (lib) { |
849 | | - getVSScriptAPI_func = (getVSScriptAPI_fn) dlsym(lib, "getVSScriptAPI"); |
850 | | - getVSScriptAPILastError_func = (getVSScriptAPILastError_fn) dlsym(lib, "getVSScriptAPILastError"); |
| 843 | + if (vsscript_lib) { |
| 844 | + getVSScriptAPI_func = (getVSScriptAPI_fn) dlsym(vsscript_lib, "getVSScriptAPI"); |
| 845 | + getVSScriptAPILastError_func = (getVSScriptAPILastError_fn) dlsym(vsscript_lib, "getVSScriptAPILastError"); |
851 | 846 | } |
852 | | -#endif |
| 847 | + |
| 848 | + const char *unknown_error_msg = "Last error unknown"; |
853 | 849 |
|
854 | 850 | if (getVSScriptAPI_func) { |
855 | 851 | p->vs_script_api = getVSScriptAPI_func(VSSCRIPT_API_VERSION); |
856 | 852 | if (!p->vs_script_api) { |
857 | | - const char *last_error_msg = getVSScriptAPILastError_func ? getVSScriptAPILastError_func() : "Last error unknown"; |
| 853 | + const char *vs_error_msg = getVSScriptAPILastError_func ? getVSScriptAPILastError_func() : NULL; |
| 854 | + const char *last_error_msg = vs_error_msg ? vs_error_msg : unknown_error_msg; |
858 | 855 | MP_FATAL(p, "Failed to initialize VapourSynth VSScript library: %s\n", last_error_msg); |
859 | 856 | return -1; |
860 | 857 | } |
861 | 858 | } else { |
862 | | - MP_FATAL(p, "Failed to load VapourSynth VSScript library\n"); |
| 859 | + const char *dl_error_msg = dlerror(); |
| 860 | + const char *last_error_msg = dl_error_msg ? dl_error_msg : unknown_error_msg; |
| 861 | + MP_FATAL(p, "Failed to load VapourSynth VSScript library: %s\n", last_error_msg); |
863 | 862 | return -1; |
864 | 863 | } |
865 | 864 |
|
|
0 commit comments