summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-01-12 17:37:11 +0100
committerwm4 <wm4@nowhere>2017-01-12 17:45:11 +0100
commit44e06b70d504d5a9073990851a353820370f3667 (patch)
treeffda223303ae592718ae8c2daadfc40b77f37808 /player
parentac98ff71ddf3da7d864f149fc290fa07600b311a (diff)
downloadmpv-44e06b70d504d5a9073990851a353820370f3667.tar.bz2
mpv-44e06b70d504d5a9073990851a353820370f3667.tar.xz
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.
Diffstat (limited to 'player')
-rw-r--r--player/scripting.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/player/scripting.c b/player/scripting.c
index 4b92f7bf1b..2469b67678 100644
--- a/player/scripting.c
+++ b/player/scripting.c
@@ -37,11 +37,15 @@
#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 <dlfcn.h>
+
+#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