diff options
author | Kacper Michajłow <kasper93@gmail.com> | 2023-08-17 16:19:26 +0200 |
---|---|---|
committer | Dudemanguy <random342@airmail.cc> | 2023-09-20 02:16:45 +0000 |
commit | eab3842d8bb5ff5465e075fc42d171ac3757903d (patch) | |
tree | 17be06e09ab5abdd4185df734ec9595393e268cd /DOCS | |
parent | 4435b1a0d5ac620eda3b18689dff3cb46fd2a732 (diff) | |
download | mpv-eab3842d8bb5ff5465e075fc42d171ac3757903d.tar.bz2 mpv-eab3842d8bb5ff5465e075fc42d171ac3757903d.tar.xz |
cplugin: allow loading mpv_* symbols dynamically
Defining MPV_CPLUGIN_DYNAMIC_SYM during plugin compilation will replace mpv_*
functions with function pointers. Those pointer will be initialized when
loading the plugin.
It is recommended to use this symbol table when targeting Windows. The loader
does not have notion of global symbols. Loading cplugin into mpv process will
not allow this plugin to call any of the symbols that may be available in
other modules. Instead cplugin has to link explicitly to specific PE binary,
libmpv-2.dll/mpv.exe or any other binary that may have linked mpv statically.
This limits portability of cplugin as it would need to be compiled separately
for each of target PE binary that includes mpv's symbols. Which in practice
is unrealictis, as we want one cplugin to be loaded without those restrictions.
Instead of linking to any PE binary, we create function pointer for all mpv's
exported symbols. For convinience names of entrypoints are redefined to those
pointer so no changes are required in cplugin source code, except defining
MPV_CPLUGIN_DYNAMIC_SYM. Those function pointer are exported to make them
available for mpv to init with correct values during runtime, before calling
`mpv_open_cplugin`.
Note that those pointer are decorated with `selectany` attribute, so no need
to worry about multiple definitions, linker will keep only single instance.
This fixes cplugin usability on Windows. Without any API changes, only
recompilation with -DMPV_CPLUGIN_DYNAMIC_SYM is needed.
Diffstat (limited to 'DOCS')
-rw-r--r-- | DOCS/man/libmpv.rst | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/DOCS/man/libmpv.rst b/DOCS/man/libmpv.rst index 2b8020ae94..e00f8b9050 100644 --- a/DOCS/man/libmpv.rst +++ b/DOCS/man/libmpv.rst @@ -21,15 +21,15 @@ C PLUGINS You can write C plugins for mpv. These use the libmpv API, although they do not use the libmpv library itself. -They are available on Linux/BSD platforms only and enabled by default if the -compiler supports linking with the ``-rdynamic`` flag. +They are enabled by default if compiler supports linking with the ``-rdynamic`` +flag on Linux/BSD platforms. On Windows the are always enabled. C plugins location ------------------ C plugins are put into the mpv scripts directory in its config directory -(see the `FILES`_ section for details). They must have a ``.so`` file extension. -They can also be explicitly loaded with the ``--script`` option. +(see the `FILES`_ section for details). They must have a ``.so`` or ``.dll`` +file extension. They can also be explicitly loaded with the ``--script`` option. API --- @@ -67,6 +67,10 @@ The current implementation requires that your plugins are **not** linked against libmpv. What your plugins use are not symbols from a libmpv binary, but symbols from the mpv host binary. +On Windows to make symbols from the host binary available, you have to define +MPV_CPLUGIN_DYNAMIC_SYM when compiling cplugin. This will load symbols +dynamically, before calling ``mpv_open_cplugin()``. + Examples -------- |