avisynth: Allow compilation on Linux
Co-authored-by: wangqr <wangqr@wangqr.tk>
This commit is contained in:
parent
e2a49b3313
commit
fe285678a3
|
@ -220,9 +220,9 @@ foreach dep: [
|
||||||
endif
|
endif
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
if host_machine.system() == 'windows' and get_option('avisynth').enabled()
|
if get_option('avisynth').enabled()
|
||||||
conf.set('WITH_AVISYNTH', 1) # bundled separately with installer
|
conf.set('WITH_AVISYNTH', 1) # bundled separately with installer
|
||||||
deps += cc.find_library('avifil32', required: true)
|
dep_avail += 'AviSynth'
|
||||||
|
|
||||||
avs_opt = cmake.subproject_options()
|
avs_opt = cmake.subproject_options()
|
||||||
avs_opt.add_cmake_defines({
|
avs_opt.add_cmake_defines({
|
||||||
|
@ -231,6 +231,10 @@ if host_machine.system() == 'windows' and get_option('avisynth').enabled()
|
||||||
|
|
||||||
avs = cmake.subproject('avisynth', options: avs_opt)
|
avs = cmake.subproject('avisynth', options: avs_opt)
|
||||||
deps_inc += avs.include_directories('AviSynth-Headers')
|
deps_inc += avs.include_directories('AviSynth-Headers')
|
||||||
|
|
||||||
|
if host_machine.system() == 'windows'
|
||||||
|
deps += cc.find_library('avifil32', required: true)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if host_machine.system() == 'windows' and not get_option('directsound').disabled()
|
if host_machine.system() == 'windows' and not get_option('directsound').disabled()
|
||||||
|
|
|
@ -40,10 +40,24 @@
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define AVISYNTH_SO "avisynth.dll"
|
||||||
|
#else
|
||||||
|
#define AVISYNTH_SO "libavisynth.so"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Allocate storage for and initialise static members
|
// Allocate storage for and initialise static members
|
||||||
namespace {
|
namespace {
|
||||||
int avs_refcount = 0;
|
int avs_refcount = 0;
|
||||||
|
#ifdef _WIN32
|
||||||
HINSTANCE hLib = nullptr;
|
HINSTANCE hLib = nullptr;
|
||||||
|
#else
|
||||||
|
void* hLib = nullptr;
|
||||||
|
#endif
|
||||||
IScriptEnvironment *env = nullptr;
|
IScriptEnvironment *env = nullptr;
|
||||||
std::mutex AviSynthMutex;
|
std::mutex AviSynthMutex;
|
||||||
}
|
}
|
||||||
|
@ -54,14 +68,26 @@ typedef IScriptEnvironment* __stdcall FUNC(int);
|
||||||
|
|
||||||
AviSynthWrapper::AviSynthWrapper() {
|
AviSynthWrapper::AviSynthWrapper() {
|
||||||
if (!avs_refcount++) {
|
if (!avs_refcount++) {
|
||||||
hLib = LoadLibrary(L"avisynth.dll");
|
#ifdef _WIN32
|
||||||
|
#define CONCATENATE(x, y) x ## y
|
||||||
|
#define _Lstr(x) CONCATENATE(L, x)
|
||||||
|
hLib = LoadLibraryW(_Lstr(AVISYNTH_SO));
|
||||||
|
#undef _Lstr
|
||||||
|
#undef CONCATENATE
|
||||||
|
#else
|
||||||
|
hLib = dlopen(AVISYNTH_SO, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!hLib)
|
if (!hLib)
|
||||||
throw AvisynthError("Could not load avisynth.dll");
|
throw AvisynthError("Could not load " AVISYNTH_SO);
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
FUNC* CreateScriptEnv = (FUNC*)GetProcAddress(hLib, "CreateScriptEnvironment");
|
FUNC* CreateScriptEnv = (FUNC*)GetProcAddress(hLib, "CreateScriptEnvironment");
|
||||||
|
#else
|
||||||
|
FUNC* CreateScriptEnv = (FUNC*)dlsym(hLib, "CreateScriptEnvironment");
|
||||||
|
#endif
|
||||||
if (!CreateScriptEnv)
|
if (!CreateScriptEnv)
|
||||||
throw AvisynthError("Failed to get address of CreateScriptEnv from avisynth.dll");
|
throw AvisynthError("Failed to get address of CreateScriptEnv from " AVISYNTH_SO);
|
||||||
|
|
||||||
env = CreateScriptEnv(AVISYNTH_INTERFACE_VERSION);
|
env = CreateScriptEnv(AVISYNTH_INTERFACE_VERSION);
|
||||||
|
|
||||||
|
@ -80,8 +106,12 @@ AviSynthWrapper::AviSynthWrapper() {
|
||||||
AviSynthWrapper::~AviSynthWrapper() {
|
AviSynthWrapper::~AviSynthWrapper() {
|
||||||
if (!--avs_refcount) {
|
if (!--avs_refcount) {
|
||||||
delete env;
|
delete env;
|
||||||
AVS_linkage = nullptr;
|
#ifdef _WIN32
|
||||||
FreeLibrary(hLib);
|
FreeLibrary(hLib);
|
||||||
|
#else
|
||||||
|
dlclose(hLib);
|
||||||
|
#endif
|
||||||
|
AVS_linkage = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -335,7 +335,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Avisynth" : {
|
"Avisynth" : {
|
||||||
"Memory Max" : 128
|
"Memory Max" : 1024
|
||||||
},
|
},
|
||||||
"FFmpegSource" : {
|
"FFmpegSource" : {
|
||||||
"Cache" : {
|
"Cache" : {
|
||||||
|
|
|
@ -335,7 +335,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Avisynth" : {
|
"Avisynth" : {
|
||||||
"Memory Max" : 128
|
"Memory Max" : 1024
|
||||||
},
|
},
|
||||||
"FFmpegSource" : {
|
"FFmpegSource" : {
|
||||||
"Cache" : {
|
"Cache" : {
|
||||||
|
|
|
@ -171,11 +171,8 @@ if host_machine.system() == 'darwin'
|
||||||
)
|
)
|
||||||
elif host_machine.system() == 'windows'
|
elif host_machine.system() == 'windows'
|
||||||
aegisub_src += files(
|
aegisub_src += files(
|
||||||
'avisynth_wrap.cpp',
|
|
||||||
'font_file_lister_gdi.cpp',
|
'font_file_lister_gdi.cpp',
|
||||||
# 'libass_gdi_fontselect.cpp',
|
# 'libass_gdi_fontselect.cpp',
|
||||||
'audio_provider_avs.cpp',
|
|
||||||
'video_provider_avs.cpp',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if cc.has_header('wingdi.h')
|
if cc.has_header('wingdi.h')
|
||||||
|
@ -238,6 +235,10 @@ opt_src = [
|
||||||
'video_provider_ffmpegsource.cpp',
|
'video_provider_ffmpegsource.cpp',
|
||||||
'ffmpegsource_common.cpp']],
|
'ffmpegsource_common.cpp']],
|
||||||
|
|
||||||
|
['AviSynth', ['avisynth_wrap.cpp',
|
||||||
|
'audio_provider_avs.cpp',
|
||||||
|
'video_provider_avs.cpp']],
|
||||||
|
|
||||||
['Hunspell', 'spellchecker_hunspell.cpp'],
|
['Hunspell', 'spellchecker_hunspell.cpp'],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue