summaryrefslogtreecommitdiffstats
path: root/libmpv
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-03-21 19:31:58 +0100
committerwm4 <wm4@nowhere>2020-03-21 19:33:48 +0100
commit218d6643e940dde2a01260cf8def70efc100cd43 (patch)
treef7ce9e059456eeaa3e33b08d8fa96512573c6a99 /libmpv
parent7e885a3bc3af4df93681b6e760a34e59e2f47ef7 (diff)
downloadmpv-218d6643e940dde2a01260cf8def70efc100cd43.tar.bz2
mpv-218d6643e940dde2a01260cf8def70efc100cd43.tar.xz
client API, lua, ipc: unify event struct return
Both Lua and the JSON IPC code need to convert the mpv_event struct (and everything it points to) to Lua tables or JSON. I was getting sick of having to make the same changes to Lua and IPC. Do what has been done everywhere else, and let the core handle this by going through mpv_node (which is supposed to serve both Lua tables and JSON, and potentially other scripting language backends). Expose it as new libmpv API function. The new API is still a bit "rough" and support for other event types might be added in the future. This silently adds support for the playlist_entry_id fields to both Lua and JSON IPC. There is a small API change for Lua; I don't think this matters, so I didn't care about compatibility. The new code in client.c is mashed up from the Lua and the IPC code. The manpage additions are moved from the Lua docs, and made slightly more "general". Some danger for unintended regressions both in Lua and IPC. Also damn these node functions suck, expect crashes due to UB. Not sure why this became more code instead of less compared to before (according to the diff stat), even though some code duplication across Lua and IPC was removed. Software development sucks.
Diffstat (limited to 'libmpv')
-rw-r--r--libmpv/client.h25
-rw-r--r--libmpv/mpv.def1
2 files changed, 26 insertions, 0 deletions
diff --git a/libmpv/client.h b/libmpv/client.h
index ef9ba0d423..e57f727846 100644
--- a/libmpv/client.h
+++ b/libmpv/client.h
@@ -1718,6 +1718,31 @@ typedef struct mpv_event {
} mpv_event;
/**
+ * Convert the given src event to a mpv_node, and set *dst to the result. *dst
+ * is set to a MPV_FORMAT_NODE_MAP, with fields for corresponding mpv_event and
+ * mpv_event.data/mpv_event_* fields.
+ *
+ * The exact details are not completely documented out of laziness. A start
+ * is located in the "Events" section of the manpage.
+ *
+ * *dst may point to newly allocated memory, or pointers in mpv_event. You must
+ * copy the entire mpv_node if you want to reference it after mpv_event becomes
+ * invalid (such as making a new mpv_wait_event() call, or destroying the
+ * mpv_handle from which it was returned). Call mpv_free_node_contents() to free
+ * any memory allocations made by this API function.
+ *
+ * Safe to be called from mpv render API threads.
+ *
+ * @param dst Target. This is not read and fully overwritten. Must be released
+ * with mpv_free_node_contents(). Do not write to pointers returned
+ * by it. (On error, this may be left as an empty node.)
+ * @param src The source event. Not modified (it's not const due to the author's
+ * prejudice of the C version of const).
+ * @return error code (MPV_ERROR_NOMEM only, if at all)
+ */
+int mpv_event_to_node(mpv_node *dst, mpv_event *src);
+
+/**
* Enable or disable the given event.
*
* Some events are enabled by default. Some events can't be disabled.
diff --git a/libmpv/mpv.def b/libmpv/mpv.def
index a2c6fd1ac9..6e20a668de 100644
--- a/libmpv/mpv.def
+++ b/libmpv/mpv.def
@@ -13,6 +13,7 @@ mpv_create_weak_client
mpv_destroy
mpv_detach_destroy
mpv_error_string
+mpv_event_to_node
mpv_event_name
mpv_free
mpv_free_node_contents