mirror of https://github.com/odrling/Aegisub
106 lines
2.7 KiB
C++
106 lines
2.7 KiB
C++
|
// Copyright (c) 2022, arch1t3cht <arch1t3cht@gmail.com>
|
||
|
//
|
||
|
// Permission to use, copy, modify, and distribute this software for any
|
||
|
// purpose with or without fee is hereby granted, provided that the above
|
||
|
// copyright notice and this permission notice appear in all copies.
|
||
|
//
|
||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||
|
//
|
||
|
// Aegisub Project http://www.aegisub.org/
|
||
|
|
||
|
/// @file vapoursynth_wrap.cpp
|
||
|
/// @brief Wrapper-layer for Vapoursynth
|
||
|
/// @ingroup video_input audio_input
|
||
|
///
|
||
|
|
||
|
#ifdef WITH_VAPOURSYNTH
|
||
|
#include "vapoursynth_wrap.h"
|
||
|
|
||
|
#include "VSScript4.h"
|
||
|
|
||
|
#include "options.h"
|
||
|
|
||
|
#include <mutex>
|
||
|
|
||
|
#ifndef _WIN32
|
||
|
#include <dlfcn.h>
|
||
|
#endif
|
||
|
|
||
|
#ifdef _WIN32
|
||
|
#define VSSCRIPT_SO "vsscript.dll"
|
||
|
#else
|
||
|
#define VSSCRIPT_SO "libvapoursynth-script.so"
|
||
|
#endif
|
||
|
|
||
|
// Allocate storage for and initialise static members
|
||
|
namespace {
|
||
|
bool vs_loaded = false;
|
||
|
#ifdef _WIN32
|
||
|
HINSTANCE hLib = nullptr;
|
||
|
#else
|
||
|
void* hLib = nullptr;
|
||
|
#endif
|
||
|
const VSAPI *api = nullptr;
|
||
|
VSSCRIPTAPI *scriptapi = nullptr;
|
||
|
std::mutex VapourSynthMutex;
|
||
|
}
|
||
|
|
||
|
typedef VSSCRIPTAPI* VS_CC FUNC(int);
|
||
|
|
||
|
VapourSynthWrapper::VapourSynthWrapper() {
|
||
|
// VSScript assumes it's only loaded once, so unlike AVS we can't unload it when the refcount reaches zero
|
||
|
if (!vs_loaded) {
|
||
|
vs_loaded = true;
|
||
|
#ifdef _WIN32
|
||
|
#define CONCATENATE(x, y) x ## y
|
||
|
#define _Lstr(x) CONCATENATE(L, x)
|
||
|
hLib = LoadLibraryW(_Lstr(VSSCRIPT_SO));
|
||
|
#undef _Lstr
|
||
|
#undef CONCATENATE
|
||
|
#else
|
||
|
hLib = dlopen(VSSCRIPT_SO, RTLD_LAZY | RTLD_GLOBAL | RTLD_DEEPBIND);
|
||
|
#endif
|
||
|
|
||
|
if (!hLib)
|
||
|
throw VapoursynthError("Could not load " VSSCRIPT_SO);
|
||
|
|
||
|
#ifdef _WIN32
|
||
|
FUNC* getVSScriptAPI = (FUNC*)GetProcAddress(hLib, "getVSScriptAPI");
|
||
|
#else
|
||
|
FUNC* getVSScriptAPI = (FUNC*)dlsym(hLib, "getVSScriptAPI");
|
||
|
#endif
|
||
|
if (!getVSScriptAPI)
|
||
|
throw VapoursynthError("Failed to get address of getVSScriptAPI from " VSSCRIPT_SO);
|
||
|
|
||
|
scriptapi = getVSScriptAPI(VSSCRIPT_API_VERSION);
|
||
|
|
||
|
if (!scriptapi)
|
||
|
throw VapoursynthError("Failed to get Vapoursynth ScriptAPI");
|
||
|
|
||
|
api = scriptapi->getVSAPI(VAPOURSYNTH_API_VERSION);
|
||
|
|
||
|
if (!api)
|
||
|
throw VapoursynthError("Failed to get Vapoursynth API");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
std::mutex& VapourSynthWrapper::GetMutex() const {
|
||
|
return VapourSynthMutex;
|
||
|
}
|
||
|
|
||
|
const VSAPI *VapourSynthWrapper::GetAPI() const {
|
||
|
return api;
|
||
|
}
|
||
|
|
||
|
const VSSCRIPTAPI *VapourSynthWrapper::GetScriptAPI() const {
|
||
|
return scriptapi;
|
||
|
}
|
||
|
|
||
|
#endif
|