summaryrefslogtreecommitdiffstats
path: root/player/client.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-03-23 16:24:49 +0100
committerKevin Mitchell <kevmitch@gmail.com>2018-03-26 23:02:23 -0700
commitf60826c3a14ba3b49077f17e5364b7347f9b468a (patch)
tree285f39963a9f978939743b12527539e1ec8a3f54 /player/client.c
parent6d7cfdfae582353e1f10797bb2c587e6ada0aed7 (diff)
downloadmpv-f60826c3a14ba3b49077f17e5364b7347f9b468a.tar.bz2
mpv-f60826c3a14ba3b49077f17e5364b7347f9b468a.tar.xz
client API: add a first class hook API, and deprecate old API
As it turns out, there are multiple libmpv users who saw a need to use the hook API. The API is kind of shitty and was never meant to be actually public (it was mostly a hack for the ytdl script). Introduce a proper API and deprecate the old one. The old one will probably continue to work for a few releases, but will be removed eventually. There are some slight changes to the old API, but if a user followed the manual properly, it won't break. Mostly untested. Appears to work with ytdl_hook.
Diffstat (limited to 'player/client.c')
-rw-r--r--player/client.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/player/client.c b/player/client.c
index c6803806c9..1fe38881ad 100644
--- a/player/client.c
+++ b/player/client.c
@@ -728,7 +728,7 @@ void mp_client_broadcast_event(struct MPContext *mpctx, int event, void *data)
// If client_name == NULL, then broadcast and free the event.
int mp_client_send_event(struct MPContext *mpctx, const char *client_name,
- int event, void *data)
+ uint64_t reply_userdata, int event, void *data)
{
if (!client_name) {
mp_client_broadcast_event(mpctx, event, data);
@@ -742,6 +742,7 @@ int mp_client_send_event(struct MPContext *mpctx, const char *client_name,
struct mpv_event event_data = {
.event_id = event,
.data = data,
+ .reply_userdata = reply_userdata,
};
pthread_mutex_lock(&clients->lock);
@@ -773,7 +774,7 @@ int mp_client_send_event_dup(struct MPContext *mpctx, const char *client_name,
};
dup_event_data(&event_data);
- return mp_client_send_event(mpctx, client_name, event, event_data.data);
+ return mp_client_send_event(mpctx, client_name, 0, event, event_data.data);
}
int mpv_request_event(mpv_handle *ctx, mpv_event_id event, int enable)
@@ -1558,6 +1559,23 @@ static bool gen_property_change_event(struct mpv_handle *ctx)
return false;
}
+int mpv_hook_add(mpv_handle *ctx, uint64_t reply_userdata,
+ const char *name, int priority)
+{
+ lock_core(ctx);
+ mp_hook_add(ctx->mpctx, ctx->name, name, reply_userdata, priority, false);
+ unlock_core(ctx);
+ return 0;
+}
+
+int mpv_hook_continue(mpv_handle *ctx, uint64_t id)
+{
+ lock_core(ctx);
+ int r = mp_hook_continue(ctx->mpctx, ctx->name, id);
+ unlock_core(ctx);
+ return r;
+}
+
int mpv_load_config_file(mpv_handle *ctx, const char *filename)
{
int flags = ctx->mpctx->initialized ? M_SETOPT_RUNTIME : 0;
@@ -1708,6 +1726,7 @@ static const char *const event_table[] = {
[MPV_EVENT_PROPERTY_CHANGE] = "property-change",
[MPV_EVENT_CHAPTER_CHANGE] = "chapter-change",
[MPV_EVENT_QUEUE_OVERFLOW] = "event-queue-overflow",
+ [MPV_EVENT_HOOK] = "hook",
};
const char *mpv_event_name(mpv_event_id event)