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 /libmpv/stream_cb.h | |
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 'libmpv/stream_cb.h')
-rw-r--r-- | libmpv/stream_cb.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/libmpv/stream_cb.h b/libmpv/stream_cb.h index 9d1c2cc8d3..9ae6f31a16 100644 --- a/libmpv/stream_cb.h +++ b/libmpv/stream_cb.h @@ -233,6 +233,13 @@ typedef int (*mpv_stream_cb_open_ro_fn)(void *user_data, char *uri, MPV_EXPORT int mpv_stream_cb_add_ro(mpv_handle *ctx, const char *protocol, void *user_data, mpv_stream_cb_open_ro_fn open_fn); +#ifdef MPV_CPLUGIN_DYNAMIC_SYM + +MPV_DEFINE_SYM_PTR(mpv_stream_cb_add_ro) +#define mpv_stream_cb_add_ro pfn_mpv_stream_cb_add_ro + +#endif + #ifdef __cplusplus } #endif |