Skip to content

Commit 75b2ccf

Browse files
CrendKingkasper93
authored andcommitted
vf_vapoursynth: update for VapourSynth R74
VapourSynth R74 changed two things relevant to mpv build process: 1) VSScript no longer has static library to link to, and only support runtime loading. This is reflected on the new VSScript example in VapourSynth SDK. 2) The VSScript library name is changed from libvapoursynth-script to libvsscript for Linux and MacOS. The new VSScript initialization code is modified from their SDK example to utilize mpv's mechanisms. Build dependency is also updated accordingly.
1 parent f5939d0 commit 75b2ccf

3 files changed

Lines changed: 51 additions & 9 deletions

File tree

meson.build

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,11 +772,9 @@ if features['uchardet']
772772
endif
773773

774774
vapoursynth = dependency('vapoursynth', version: '>= 56', required: get_option('vapoursynth'))
775-
vapoursynth_script = dependency('vapoursynth-script', version: '>= 56',
776-
required: get_option('vapoursynth'))
777-
features += {'vapoursynth': vapoursynth.found() and vapoursynth_script.found()}
775+
features += {'vapoursynth': vapoursynth.found()}
778776
if features['vapoursynth']
779-
dependencies += [vapoursynth, vapoursynth_script]
777+
dependencies += vapoursynth.partial_dependency(compile_args: true, includes: true)
780778
sources += files('video/filter/vf_vapoursynth.c')
781779
endif
782780

osdep/io.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,13 @@ locale_t newlocale(int, const char *, locale_t);
247247
locale_t uselocale(locale_t);
248248
void freelocale(locale_t);
249249

250-
#else /* __MINGW32__ */
250+
#else /* _WIN32 */
251251

252+
#include <dlfcn.h>
252253
#include <sys/mman.h>
253254

254255
extern char **environ;
255256

256-
#endif /* __MINGW32__ */
257+
#endif /* _WIN32 */
257258

258259
#endif

video/filter/vf_vapoursynth.c

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <limits.h>
2323
#include <assert.h>
2424

25-
#include <VapourSynth4.h>
2625
#include <VSScript4.h>
2726

2827
#include <libavutil/rational.h>
@@ -37,11 +36,24 @@
3736
#include "filters/user_filters.h"
3837
#include "options/m_option.h"
3938
#include "options/path.h"
39+
#include "osdep/io.h"
4040
#include "osdep/threads.h"
4141
#include "video/img_format.h"
4242
#include "video/mp_image.h"
4343
#include "video/sws_utils.h"
4444

45+
static const char *const vsscript_lib_names[] = {
46+
#ifdef _WIN32
47+
"VSScript.dll",
48+
#elif defined(__APPLE__)
49+
"libvsscript.dylib",
50+
"libvapoursynth-script.dylib",
51+
#else
52+
"libvsscript.so",
53+
"libvapoursynth-script.so",
54+
#endif
55+
};
56+
4557
struct vapoursynth_opts {
4658
char *file;
4759
int maxbuffer;
@@ -804,11 +816,42 @@ static const m_option_t vf_opts_fields[] = {
804816

805817
static int drv_vss_init(struct priv *p)
806818
{
807-
p->vs_script_api = getVSScriptAPI(VSSCRIPT_API_VERSION);
819+
const char *vsscript_path = getenv("VSSCRIPT_PATH");
820+
const int dl_mode = RTLD_NOW | RTLD_LOCAL;
821+
void *vsscript_lib = NULL;
822+
823+
if (vsscript_path) {
824+
vsscript_lib = dlopen(vsscript_path, dl_mode);
825+
} else {
826+
for (size_t i = 0; i < MP_ARRAY_SIZE(vsscript_lib_names) && !vsscript_lib; ++i) {
827+
vsscript_lib = dlopen(vsscript_lib_names[i], dl_mode);
828+
}
829+
}
830+
831+
VS_CC const VSSCRIPTAPI *(*getVSScriptAPI_func)(int) = NULL;
832+
VS_CC const char *(*getVSScriptAPILastError_func)(void) = NULL;
833+
const char *unknown_error_msg = "Last error unknown";
834+
835+
if (vsscript_lib) {
836+
getVSScriptAPI_func = (void *) dlsym(vsscript_lib, "getVSScriptAPI");
837+
getVSScriptAPILastError_func = (void *) dlsym(vsscript_lib, "getVSScriptAPILastError");
838+
}
839+
840+
if (!getVSScriptAPI_func) {
841+
const char *dl_error_msg = dlerror();
842+
const char *last_error_msg = dl_error_msg ? dl_error_msg : unknown_error_msg;
843+
MP_FATAL(p, "Failed to load VapourSynth VSScript library: %s\n", last_error_msg);
844+
return -1;
845+
}
846+
847+
p->vs_script_api = getVSScriptAPI_func(VSSCRIPT_API_VERSION);
808848
if (!p->vs_script_api) {
809-
MP_FATAL(p, "Could not initialize VapourSynth scripting.\n");
849+
const char *vs_error_msg = getVSScriptAPILastError_func ? getVSScriptAPILastError_func() : NULL;
850+
const char *last_error_msg = vs_error_msg ? vs_error_msg : unknown_error_msg;
851+
MP_FATAL(p, "Failed to initialize VapourSynth VSScript library: %s\n", last_error_msg);
810852
return -1;
811853
}
854+
812855
return 0;
813856
}
814857

0 commit comments

Comments
 (0)