Skip to content

Commit fe28567

Browse files
arch1t3chtwangqr
andcommitted
avisynth: Allow compilation on Linux
Co-authored-by: wangqr <[email protected]>
1 parent e2a49b3 commit fe28567

File tree

5 files changed

+47
-12
lines changed

5 files changed

+47
-12
lines changed

meson.build

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ foreach dep: [
220220
endif
221221
endforeach
222222

223-
if host_machine.system() == 'windows' and get_option('avisynth').enabled()
223+
if get_option('avisynth').enabled()
224224
conf.set('WITH_AVISYNTH', 1) # bundled separately with installer
225-
deps += cc.find_library('avifil32', required: true)
225+
dep_avail += 'AviSynth'
226226

227227
avs_opt = cmake.subproject_options()
228228
avs_opt.add_cmake_defines({
@@ -231,6 +231,10 @@ if host_machine.system() == 'windows' and get_option('avisynth').enabled()
231231

232232
avs = cmake.subproject('avisynth', options: avs_opt)
233233
deps_inc += avs.include_directories('AviSynth-Headers')
234+
235+
if host_machine.system() == 'windows'
236+
deps += cc.find_library('avifil32', required: true)
237+
endif
234238
endif
235239

236240
if host_machine.system() == 'windows' and not get_option('directsound').disabled()

src/avisynth_wrap.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,24 @@
4040

4141
#include <mutex>
4242

43+
#ifndef _WIN32
44+
#include <dlfcn.h>
45+
#endif
46+
47+
#ifdef _WIN32
48+
#define AVISYNTH_SO "avisynth.dll"
49+
#else
50+
#define AVISYNTH_SO "libavisynth.so"
51+
#endif
52+
4353
// Allocate storage for and initialise static members
4454
namespace {
4555
int avs_refcount = 0;
56+
#ifdef _WIN32
4657
HINSTANCE hLib = nullptr;
58+
#else
59+
void* hLib = nullptr;
60+
#endif
4761
IScriptEnvironment *env = nullptr;
4862
std::mutex AviSynthMutex;
4963
}
@@ -54,14 +68,26 @@ typedef IScriptEnvironment* __stdcall FUNC(int);
5468

5569
AviSynthWrapper::AviSynthWrapper() {
5670
if (!avs_refcount++) {
57-
hLib = LoadLibrary(L"avisynth.dll");
71+
#ifdef _WIN32
72+
#define CONCATENATE(x, y) x ## y
73+
#define _Lstr(x) CONCATENATE(L, x)
74+
hLib = LoadLibraryW(_Lstr(AVISYNTH_SO));
75+
#undef _Lstr
76+
#undef CONCATENATE
77+
#else
78+
hLib = dlopen(AVISYNTH_SO, RTLD_LAZY | RTLD_LOCAL | RTLD_DEEPBIND);
79+
#endif
5880

5981
if (!hLib)
60-
throw AvisynthError("Could not load avisynth.dll");
82+
throw AvisynthError("Could not load " AVISYNTH_SO);
6183

62-
FUNC *CreateScriptEnv = (FUNC*)GetProcAddress(hLib, "CreateScriptEnvironment");
84+
#ifdef _WIN32
85+
FUNC* CreateScriptEnv = (FUNC*)GetProcAddress(hLib, "CreateScriptEnvironment");
86+
#else
87+
FUNC* CreateScriptEnv = (FUNC*)dlsym(hLib, "CreateScriptEnvironment");
88+
#endif
6389
if (!CreateScriptEnv)
64-
throw AvisynthError("Failed to get address of CreateScriptEnv from avisynth.dll");
90+
throw AvisynthError("Failed to get address of CreateScriptEnv from " AVISYNTH_SO);
6591

6692
env = CreateScriptEnv(AVISYNTH_INTERFACE_VERSION);
6793

@@ -80,8 +106,12 @@ AviSynthWrapper::AviSynthWrapper() {
80106
AviSynthWrapper::~AviSynthWrapper() {
81107
if (!--avs_refcount) {
82108
delete env;
83-
AVS_linkage = nullptr;
109+
#ifdef _WIN32
84110
FreeLibrary(hLib);
111+
#else
112+
dlclose(hLib);
113+
#endif
114+
AVS_linkage = nullptr;
85115
}
86116
}
87117

src/libresrc/default_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
}
336336
},
337337
"Avisynth" : {
338-
"Memory Max" : 128
338+
"Memory Max" : 1024
339339
},
340340
"FFmpegSource" : {
341341
"Cache" : {

src/libresrc/osx/default_config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@
335335
}
336336
},
337337
"Avisynth" : {
338-
"Memory Max" : 128
338+
"Memory Max" : 1024
339339
},
340340
"FFmpegSource" : {
341341
"Cache" : {

src/meson.build

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,8 @@ if host_machine.system() == 'darwin'
171171
)
172172
elif host_machine.system() == 'windows'
173173
aegisub_src += files(
174-
'avisynth_wrap.cpp',
175174
'font_file_lister_gdi.cpp',
176175
# 'libass_gdi_fontselect.cpp',
177-
'audio_provider_avs.cpp',
178-
'video_provider_avs.cpp',
179176
)
180177

181178
if cc.has_header('wingdi.h')
@@ -238,6 +235,10 @@ opt_src = [
238235
'video_provider_ffmpegsource.cpp',
239236
'ffmpegsource_common.cpp']],
240237

238+
['AviSynth', ['avisynth_wrap.cpp',
239+
'audio_provider_avs.cpp',
240+
'video_provider_avs.cpp']],
241+
241242
['Hunspell', 'spellchecker_hunspell.cpp'],
242243
]
243244

0 commit comments

Comments
 (0)