vapoursynth: add withPlugins interface
Co-authored-by: Simon Bruder <simon@sbruder.de>
This commit is contained in:
parent
9c42db00dc
commit
c373e6ddb2
@ -0,0 +1,74 @@
|
|||||||
|
From 9b05a6f331506afa5aca8865677af83403d2a32d Mon Sep 17 00:00:00 2001
|
||||||
|
From: Tadeo Kondrak <me@tadeo.ca>
|
||||||
|
Date: Mon, 25 Jan 2021 11:17:44 -0700
|
||||||
|
Subject: [PATCH] Call weak function to allow adding preloaded plugins after
|
||||||
|
compile
|
||||||
|
|
||||||
|
---
|
||||||
|
src/core/vscore.cpp | 19 +++++++++++++++++++
|
||||||
|
src/core/vscore.h | 5 +++++
|
||||||
|
2 files changed, 24 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/src/core/vscore.cpp b/src/core/vscore.cpp
|
||||||
|
index 2d29844d..35c509ed 100644
|
||||||
|
--- a/src/core/vscore.cpp
|
||||||
|
+++ b/src/core/vscore.cpp
|
||||||
|
@@ -1229,6 +1229,20 @@ void VSCore::destroyFilterInstance(VSNode *node) {
|
||||||
|
freeDepth--;
|
||||||
|
}
|
||||||
|
|
||||||
|
+extern "C" {
|
||||||
|
+void __attribute__((weak)) VSLoadPluginsNix(void (*load)(void *data, const char *path), void *data);
|
||||||
|
+
|
||||||
|
+struct VSLoadPluginsNixCallbackData {
|
||||||
|
+ VSCore *core;
|
||||||
|
+ const char *filter;
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+static void VSLoadPluginsNixCallback(void *data, const char *path) {
|
||||||
|
+ auto callbackData = static_cast<VSLoadPluginsNixCallbackData *>(data);
|
||||||
|
+ callbackData->core->loadAllPluginsInPath(path, callbackData->filter);
|
||||||
|
+}
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
VSCore::VSCore(int threads) :
|
||||||
|
coreFreed(false),
|
||||||
|
numFilterInstances(1),
|
||||||
|
@@ -1351,6 +1365,11 @@ VSCore::VSCore(int threads) :
|
||||||
|
} // If neither exists, an empty string will do.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
+ if (VSLoadPluginsNix != nullptr) {
|
||||||
|
+ VSLoadPluginsNixCallbackData data{this, filter.c_str()};
|
||||||
|
+ VSLoadPluginsNix(VSLoadPluginsNixCallback, &data);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
VSMap *settings = readSettings(configFile);
|
||||||
|
const char *error = vs_internal_vsapi.getError(settings);
|
||||||
|
if (error) {
|
||||||
|
diff --git a/src/core/vscore.h b/src/core/vscore.h
|
||||||
|
index 74df8a84..3efac811 100644
|
||||||
|
--- a/src/core/vscore.h
|
||||||
|
+++ b/src/core/vscore.h
|
||||||
|
@@ -582,6 +582,9 @@ public:
|
||||||
|
VSFunction() : functionData(nullptr), func(nullptr) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
+extern "C" {
|
||||||
|
+static void VSLoadPluginsNixCallback(void *data, const char *path);
|
||||||
|
+}
|
||||||
|
|
||||||
|
struct VSPlugin {
|
||||||
|
private:
|
||||||
|
@@ -683,6 +686,8 @@ public:
|
||||||
|
|
||||||
|
explicit VSCore(int threads);
|
||||||
|
void freeCore();
|
||||||
|
+
|
||||||
|
+ friend void VSLoadPluginsNixCallback(void *data, const char *path);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // VSCORE_H
|
||||||
|
--
|
||||||
|
2.30.0
|
||||||
|
|
@ -1,4 +1,5 @@
|
|||||||
{ lib, stdenv, fetchFromGitHub, pkg-config, autoreconfHook, makeWrapper
|
{ lib, stdenv, fetchFromGitHub, pkg-config, autoreconfHook, makeWrapper
|
||||||
|
, runCommandCC, runCommand, vapoursynth, writeText, patchelf, buildEnv
|
||||||
, zimg, libass, python3, libiconv
|
, zimg, libass, python3, libiconv
|
||||||
, ApplicationServices
|
, ApplicationServices
|
||||||
, ocrSupport ? false, tesseract ? null
|
, ocrSupport ? false, tesseract ? null
|
||||||
@ -21,6 +22,10 @@ stdenv.mkDerivation rec {
|
|||||||
sha256 = "1krfdzc2x2vxv4nq9kiv1c09hgj525qn120ah91fw2ikq8ldvmx4";
|
sha256 = "1krfdzc2x2vxv4nq9kiv1c09hgj525qn120ah91fw2ikq8ldvmx4";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
patches = [
|
||||||
|
./0001-Call-weak-function-to-allow-adding-preloaded-plugins.patch
|
||||||
|
];
|
||||||
|
|
||||||
nativeBuildInputs = [ pkg-config autoreconfHook makeWrapper ];
|
nativeBuildInputs = [ pkg-config autoreconfHook makeWrapper ];
|
||||||
buildInputs = [
|
buildInputs = [
|
||||||
zimg libass
|
zimg libass
|
||||||
@ -36,12 +41,17 @@ stdenv.mkDerivation rec {
|
|||||||
|
|
||||||
enableParallelBuilding = true;
|
enableParallelBuilding = true;
|
||||||
|
|
||||||
passthru = {
|
passthru = rec {
|
||||||
# If vapoursynth is added to the build inputs of mpv and then
|
# If vapoursynth is added to the build inputs of mpv and then
|
||||||
# used in the wrapping of it, we want to know once inside the
|
# used in the wrapping of it, we want to know once inside the
|
||||||
# wrapper, what python3 version was used to build vapoursynth so
|
# wrapper, what python3 version was used to build vapoursynth so
|
||||||
# the right python3.sitePackages will be used there.
|
# the right python3.sitePackages will be used there.
|
||||||
inherit python3;
|
inherit python3;
|
||||||
|
|
||||||
|
withPlugins = import ./plugin-interface.nix {
|
||||||
|
inherit lib python3 buildEnv writeText runCommandCC stdenv runCommand
|
||||||
|
vapoursynth makeWrapper withPlugins;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
@ -54,7 +64,7 @@ stdenv.mkDerivation rec {
|
|||||||
homepage = "http://www.vapoursynth.com/";
|
homepage = "http://www.vapoursynth.com/";
|
||||||
license = licenses.lgpl21;
|
license = licenses.lgpl21;
|
||||||
platforms = platforms.x86_64;
|
platforms = platforms.x86_64;
|
||||||
maintainers = with maintainers; [ rnhmjoj tadeokondrak ];
|
maintainers = with maintainers; [ rnhmjoj sbruder tadeokondrak ];
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
112
pkgs/development/libraries/vapoursynth/plugin-interface.nix
Normal file
112
pkgs/development/libraries/vapoursynth/plugin-interface.nix
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
{ lib, python3, buildEnv, writeText, runCommandCC, stdenv, runCommand
|
||||||
|
, vapoursynth, makeWrapper, withPlugins }:
|
||||||
|
|
||||||
|
plugins: let
|
||||||
|
pythonEnvironment = python3.buildEnv.override {
|
||||||
|
extraLibs = plugins;
|
||||||
|
};
|
||||||
|
|
||||||
|
getRecursivePropagatedBuildInputs = pkgs: lib.flatten
|
||||||
|
(map
|
||||||
|
(pkg: pkg.propagatedBuildInputs ++ (getRecursivePropagatedBuildInputs pkg.propagatedBuildInputs))
|
||||||
|
pkgs);
|
||||||
|
|
||||||
|
deepPlugins = plugins ++ (getRecursivePropagatedBuildInputs plugins);
|
||||||
|
|
||||||
|
pluginsEnv = buildEnv {
|
||||||
|
name = "vapoursynth-plugins-env";
|
||||||
|
pathsToLink = [ "/lib/vapoursynth" ];
|
||||||
|
paths = deepPlugins;
|
||||||
|
};
|
||||||
|
|
||||||
|
pluginLoader = let
|
||||||
|
source = writeText "vapoursynth-nix-plugins.c" ''
|
||||||
|
void VSLoadPluginsNix(void (*load)(void *data, const char *path), void *data) {
|
||||||
|
${lib.concatMapStringsSep "" (path: "load(data, \"${path}/lib/vapoursynth\");") deepPlugins}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
runCommandCC "vapoursynth-plugin-loader" {
|
||||||
|
executable = true;
|
||||||
|
preferLocalBuild = true;
|
||||||
|
allowSubstitutes = false;
|
||||||
|
} ''
|
||||||
|
mkdir -p $out/lib
|
||||||
|
$CC -shared -fPIC ${source} -o "$out/lib/libvapoursynth-nix-plugins${ext}"
|
||||||
|
'';
|
||||||
|
|
||||||
|
ext = stdenv.targetPlatform.extensions.sharedLibrary;
|
||||||
|
in
|
||||||
|
runCommand "${vapoursynth.name}-with-plugins" {
|
||||||
|
nativeBuildInputs = [ makeWrapper ];
|
||||||
|
passthru = {
|
||||||
|
inherit python3;
|
||||||
|
withPlugins = plugins': withPlugins (plugins ++ plugins');
|
||||||
|
};
|
||||||
|
} ''
|
||||||
|
mkdir -p \
|
||||||
|
$out/bin \
|
||||||
|
$out/lib/pkgconfig \
|
||||||
|
$out/lib/vapoursynth \
|
||||||
|
$out/${python3.sitePackages}
|
||||||
|
|
||||||
|
for textFile in \
|
||||||
|
lib/pkgconfig/vapoursynth{,-script}.pc \
|
||||||
|
lib/libvapoursynth.la \
|
||||||
|
lib/libvapoursynth-script.la \
|
||||||
|
${python3.sitePackages}/vapoursynth.la
|
||||||
|
do
|
||||||
|
substitute ${vapoursynth}/$textFile $out/$textFile \
|
||||||
|
--replace "${vapoursynth}" "$out"
|
||||||
|
done
|
||||||
|
|
||||||
|
for binaryPlugin in ${pluginsEnv}/lib/vapoursynth/*; do
|
||||||
|
ln -s $binaryPlugin $out/''${binaryPlugin#"${pluginsEnv}/"}
|
||||||
|
done
|
||||||
|
|
||||||
|
for pythonPlugin in ${pythonEnvironment}/${python3.sitePackages}/*; do
|
||||||
|
ln -s $pythonPlugin $out/''${pythonPlugin#"${pythonEnvironment}/"}
|
||||||
|
done
|
||||||
|
|
||||||
|
for binaryFile in \
|
||||||
|
lib/libvapoursynth${ext} \
|
||||||
|
lib/libvapoursynth-script${ext}.0.0.0
|
||||||
|
do
|
||||||
|
old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
|
||||||
|
new_rpath="$old_rpath:$out/lib"
|
||||||
|
patchelf \
|
||||||
|
--set-rpath "$new_rpath" \
|
||||||
|
--output $out/$binaryFile \
|
||||||
|
${vapoursynth}/$binaryFile
|
||||||
|
patchelf \
|
||||||
|
--add-needed libvapoursynth-nix-plugins${ext} \
|
||||||
|
$out/$binaryFile
|
||||||
|
done
|
||||||
|
|
||||||
|
for binaryFile in \
|
||||||
|
${python3.sitePackages}/vapoursynth${ext} \
|
||||||
|
bin/.vspipe-wrapped
|
||||||
|
do
|
||||||
|
old_rpath=$(patchelf --print-rpath ${vapoursynth}/$binaryFile)
|
||||||
|
new_rpath="''${old_rpath//"${vapoursynth}"/"$out"}"
|
||||||
|
patchelf \
|
||||||
|
--set-rpath "$new_rpath" \
|
||||||
|
--output $out/$binaryFile \
|
||||||
|
${vapoursynth}/$binaryFile
|
||||||
|
done
|
||||||
|
|
||||||
|
ln -s \
|
||||||
|
${pluginLoader}/lib/libvapoursynth-nix-plugins${ext} \
|
||||||
|
$out/lib/libvapoursynth-nix-plugins${ext}
|
||||||
|
ln -s ${vapoursynth}/include $out/include
|
||||||
|
ln -s ${vapoursynth}/lib/vapoursynth/* $out/lib/vapoursynth
|
||||||
|
ln -s \
|
||||||
|
libvapoursynth-script${ext}.0.0.0 \
|
||||||
|
$out/lib/libvapoursynth-script${ext}
|
||||||
|
ln -s \
|
||||||
|
libvapoursynth-script${ext}.0.0.0 \
|
||||||
|
$out/lib/libvapoursynth-script${ext}.0
|
||||||
|
|
||||||
|
makeWrapper $out/bin/.vspipe-wrapped $out/bin/vspipe \
|
||||||
|
--prefix PYTHONPATH : $out/${python3.sitePackages}
|
||||||
|
''
|
Loading…
x
Reference in New Issue
Block a user