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/render.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/render.h')
-rw-r--r-- | libmpv/render.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libmpv/render.h b/libmpv/render.h index 29f9b91e96..5c9e052bc8 100644 --- a/libmpv/render.h +++ b/libmpv/render.h @@ -731,6 +731,27 @@ MPV_EXPORT void mpv_render_context_report_swap(mpv_render_context *ctx); */ MPV_EXPORT void mpv_render_context_free(mpv_render_context *ctx); +#ifdef MPV_CPLUGIN_DYNAMIC_SYM + +MPV_DEFINE_SYM_PTR(mpv_render_context_create) +#define mpv_render_context_create pfn_mpv_render_context_create +MPV_DEFINE_SYM_PTR(mpv_render_context_set_parameter) +#define mpv_render_context_set_parameter pfn_mpv_render_context_set_parameter +MPV_DEFINE_SYM_PTR(mpv_render_context_get_info) +#define mpv_render_context_get_info pfn_mpv_render_context_get_info +MPV_DEFINE_SYM_PTR(mpv_render_context_set_update_callback) +#define mpv_render_context_set_update_callback pfn_mpv_render_context_set_update_callback +MPV_DEFINE_SYM_PTR(mpv_render_context_update) +#define mpv_render_context_update pfn_mpv_render_context_update +MPV_DEFINE_SYM_PTR(mpv_render_context_render) +#define mpv_render_context_render pfn_mpv_render_context_render +MPV_DEFINE_SYM_PTR(mpv_render_context_report_swap) +#define mpv_render_context_report_swap pfn_mpv_render_context_report_swap +MPV_DEFINE_SYM_PTR(mpv_render_context_free) +#define mpv_render_context_free pfn_mpv_render_context_free + +#endif + #ifdef __cplusplus } #endif |