From 44e06b70d504d5a9073990851a353820370f3667 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 12 Jan 2017 17:37:11 +0100 Subject: player: add experimental C plugin interface This basically reuses the scripting infrastructure. Note that this needs to be explicitly enabled at compilation. For one, enabling export for certain symbols from an executable seems to be quite toolchain-specific. It might not work outside of Linux and cause random problems within Linux. If C plugins actually become commonly used and this approach is starting to turn out as a problem, we can build mpv CLI as a wrapper for libmpv, which would remove the requirement that plugins pick up host symbols. I'm being lazy, so implementation/documentation are parked in existing files, even if that stuff doesn't necessarily belong there. Sue me, or better send patches. --- player/scripting.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'player') diff --git a/player/scripting.c b/player/scripting.c index 4b92f7bf1b..2469b67678 100644 --- a/player/scripting.c +++ b/player/scripting.c @@ -37,10 +37,14 @@ #include "libmpv/client.h" extern const struct mp_scripting mp_scripting_lua; +extern const struct mp_scripting mp_scripting_cplugin; static const struct mp_scripting *const scripting_backends[] = { #if HAVE_LUA &mp_scripting_lua, +#endif +#if HAVE_CPLUGINS + &mp_scripting_cplugin, #endif NULL }; @@ -228,3 +232,33 @@ void mp_load_scripts(struct MPContext *mpctx) } talloc_free(tmp); } + +#if HAVE_CPLUGINS + +#include + +#define MPV_DLOPEN_FN "mpv_open_cplugin" +typedef int (*mpv_open_cplugin)(mpv_handle *handle); + +static int load_cplugin(struct mpv_handle *client, const char *fname) +{ + int r = -1; + void *lib = dlopen(fname, RTLD_NOW | RTLD_LOCAL); + if (!lib) + goto error; + mpv_open_cplugin sym = (mpv_open_cplugin)dlsym(lib, MPV_DLOPEN_FN); + if (!sym) + goto error; + r = sym(client) ? -1 : 0; +error: + if (lib) + dlclose(lib); + return r; +} + +const struct mp_scripting mp_scripting_cplugin = { + .file_ext = "so", + .load = load_cplugin, +}; + +#endif -- cgit v1.2.3