Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Stefan Oltmanns via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Stefan Oltmanns <stefan-oltmanns@gmx.net>
Subject: Re: [FFmpeg-devel] [PATCH v3 2/2] libavformat/vapoursynth: Update to API version 4, load library at runtime
Date: Tue, 23 Jul 2024 16:59:29 +0200
Message-ID: <33cb91e2-a4d3-47c5-8f15-d0ccb1107eaa@gmx.net> (raw)
In-Reply-To: <fdcdcdb3-ce6c-4dec-9759-489d1aa501a4@gmx.net>

[-- Attachment #1: Type: text/plain, Size: 1261 bytes --]

This is the second part for loading the library at runtime, changes
compared to previous patch revisions:

-No atexit anymore
-No global states anymore
-Moved the registry read for Windows from a separate function inside the
function to load the dynamic library and simplified it, reducing the
amount windows-specific code.

Tested with 2 VapourSynth inputs on these platforms, no problems and
clean exit:

-Linux x86_64 (Ubuntu 22.04)
-Windows 10 x86_64
-macOS 14 aarch64

Best regards
Stefan


Am 23.07.24 um 16:51 schrieb Stefan Oltmanns via ffmpeg-devel:
> Hello,
>
> this is revised patch, this is the first part that just updates to the
> API v4 of VapourSynth.
>
> Changes in API v4:
> -All functions previously in header are now part of the "vssapi" object
> -Renames of different types and functions
> -YCoCg is not treated as different format to YUV anymore
> -Some pointers to arrays are now arrays inside a struct.
>
> Best regards
> Stefan
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

[-- Attachment #2: 0002-avformat-vapoursynth-load-library-at-runtime.patch --]
[-- Type: text/x-patch, Size: 4544 bytes --]

From 6a8e8b7d5bfcfb8eb3cb24ea1f7e14ca117882c4 Mon Sep 17 00:00:00 2001
From: Stefan Oltmanns <stefan-oltmanns@gmx.net>
Date: Tue, 23 Jul 2024 16:19:46 +0200
Subject: [PATCH 2/2] avformat/vapoursynth: load library at runtime

Signed-off-by: Stefan Oltmanns <stefan-oltmanns@gmx.net>
---
 configure                 |  2 +-
 libavformat/vapoursynth.c | 65 +++++++++++++++++++++++++++++++++++++--
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/configure b/configure
index c50b5ad4b4..1b6670505a 100755
--- a/configure
+++ b/configure
@@ -7085,7 +7085,7 @@ enabled rkmpp             && { require_pkg_config rkmpp rockchip_mpp  rockchip/r
                                { enabled libdrm ||
                                  die "ERROR: rkmpp requires --enable-libdrm"; }
                              }
-enabled vapoursynth       && require_pkg_config vapoursynth "vapoursynth-script >= 55" VSScript4.h getVSScriptAPI
+enabled vapoursynth       && require_headers "vapoursynth/VSScript4.h vapoursynth/VapourSynth4.h"
 
 
 if enabled gcrypt; then
diff --git a/libavformat/vapoursynth.c b/libavformat/vapoursynth.c
index ce15f68180..ad1d6eac61 100644
--- a/libavformat/vapoursynth.c
+++ b/libavformat/vapoursynth.c
@@ -25,7 +25,7 @@
 
 #include <limits.h>
 
-#include <VSScript4.h>
+#include <vapoursynth/VSScript4.h>
 
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
@@ -39,11 +39,26 @@
 #include "demux.h"
 #include "internal.h"
 
+/* Platform-specific directives. */
+#ifdef _WIN32
+  #include <windows.h>
+  #include "compat/w32dlfcn.h"
+  #include "libavutil/wchar_filename.h"
+  #undef EXTERN_C
+  #define VSSCRIPT_LIB "VSScript.dll"
+#else
+  #include <dlfcn.h>
+  #define VSSCRIPT_NAME "libvapoursynth-script"
+  #define VSSCRIPT_LIB VSSCRIPT_NAME SLIBSUF
+#endif
+
 struct VSState {
     const VSSCRIPTAPI *vssapi;
     VSScript *vss;
 };
 
+typedef const VSSCRIPTAPI *(*VSScriptGetAPIFunc)(int version);
+
 typedef struct VSContext {
     const AVClass *class;
 
@@ -51,6 +66,7 @@ typedef struct VSContext {
 
     const VSSCRIPTAPI *vssapi;
     const VSAPI *vsapi;
+    void *vslibrary;
 
     VSNode *outnode;
     int is_cfr;
@@ -70,6 +86,40 @@ static const AVOption options[] = {
     {NULL}
 };
 
+static av_cold void* vs_load_library(VSScriptGetAPIFunc *get_vssapi)
+{
+    void *vslibrary = NULL;
+#ifdef _WIN32
+    const HKEY hkeys[] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE};
+    LONG r;
+    WCHAR vss_path[512];
+    DWORD buf_size = sizeof(vss_path) - 2;
+    char *vss_path_utf8;
+    int i;
+
+    for (i = 0; i < sizeof(hkeys); i++) {
+        if ((r = RegGetValueW(hkeys[i], L"SOFTWARE\\VapourSynth",
+                      L"VSScriptDLL", RRF_RT_REG_SZ, NULL,
+                      &vss_path, &buf_size)) == ERROR_SUCCESS)
+            break;
+    }
+    if (r == ERROR_SUCCESS && wchartoutf8(vss_path, &vss_path_utf8) == 0) {
+        vslibrary = dlopen(vss_path_utf8, RTLD_NOW | RTLD_GLOBAL);
+        av_free(vss_path_utf8);
+    }
+    else
+#endif
+    vslibrary = dlopen(VSSCRIPT_LIB, RTLD_NOW | RTLD_GLOBAL);
+
+    if (vslibrary != NULL) {
+        if (!(*get_vssapi = (VSScriptGetAPIFunc)dlsym(vslibrary, "getVSScriptAPI"))) {
+            dlclose(vslibrary);
+            return NULL;
+        }
+    }
+    return vslibrary;
+}
+
 static void free_vss_state(void *opaque, uint8_t *data)
 {
     struct VSState *vss = opaque;
@@ -91,6 +141,9 @@ static av_cold int read_close_vs(AVFormatContext *s)
     vs->vsapi = NULL;
     vs->outnode = NULL;
 
+    if (vs->vslibrary)
+        dlclose(vs->vslibrary);
+
     return 0;
 }
 
@@ -170,6 +223,7 @@ static av_cold int read_header_vs(AVFormatContext *s)
     AVStream *st;
     AVIOContext *pb = s->pb;
     VSContext *vs = s->priv_data;
+    VSScriptGetAPIFunc get_vssapi;
     int64_t sz = avio_size(pb);
     char *buf = NULL;
     char dummy;
@@ -178,7 +232,14 @@ static av_cold int read_header_vs(AVFormatContext *s)
     struct VSState *vss_state;
     int err = 0;
 
-    if (!(vs->vssapi = getVSScriptAPI(VSSCRIPT_API_VERSION))) {
+    if (!(vs->vslibrary = vs_load_library(&get_vssapi))) {
+        av_log(s, AV_LOG_ERROR, "Could not open " VSSCRIPT_LIB ". "
+                                "Check VapourSynth installation.\n");
+        err = AVERROR_EXTERNAL;
+        goto done;
+    }
+
+    if (!(vs->vssapi = get_vssapi(VSSCRIPT_API_VERSION))) {
         av_log(s, AV_LOG_ERROR, "Failed to initialize VSScript (possibly PYTHONPATH not set).\n");
         err = AVERROR_EXTERNAL;
         goto done;
-- 
2.34.1


[-- Attachment #3: Type: text/plain, Size: 251 bytes --]

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  reply	other threads:[~2024-07-23 14:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-23 14:51 [FFmpeg-devel] [PATCH v3 1/2] " Stefan Oltmanns via ffmpeg-devel
2024-07-23 14:59 ` Stefan Oltmanns via ffmpeg-devel [this message]
2024-07-28 13:15   ` [FFmpeg-devel] [PATCH v3 2/2] " Ramiro Polla
2024-07-29  3:46     ` Stefan Oltmanns via ffmpeg-devel
2024-07-30 14:12       ` Ramiro Polla
2024-08-11 10:21         ` Stefan Oltmanns via ffmpeg-devel
2024-07-28 13:09 ` [FFmpeg-devel] [PATCH v3 1/2] " Ramiro Polla
2024-07-29  3:31   ` [FFmpeg-devel] [PATCH v4 " Stefan Oltmanns via ffmpeg-devel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33cb91e2-a4d3-47c5-8f15-d0ccb1107eaa@gmx.net \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=stefan-oltmanns@gmx.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git