command: remove legacy hook API

Hopefully nothing uses this. (I know one exception, but, well, what can
I do.)
This commit is contained in:
wm4 2020-03-06 19:23:14 +01:00
parent 7a76b577d8
commit 2337fa4e02
5 changed files with 13 additions and 104 deletions

View File

@ -35,6 +35,9 @@ Interface changes
- the OSX bundle now logs to "~/Library/Logs/mpv.log" by default
- deprecate the --cache-secs option (once removed, the cache cannot be
limited by time anymore)
- remove deprecated legacy hook API ("hook-add", "hook-ack"). Use either the
libmpv API (mpv_hook_add(), mpv_hook_continue()), or the Lua scripting
wrappers (mp.add_hook()).
--- mpv 0.32.0 ---
- change behavior when using legacy option syntax with options that start
with two dashes (``--`` instead of a ``-``). Now, using the recommended

View File

@ -1286,47 +1286,6 @@ The following hooks are currently defined:
Run before closing a file, and before actually uninitializing
everything. It's not possible to resume playback in this state.
Legacy hook API
~~~~~~~~~~~~~~~
.. warning::
The legacy API is deprecated and will be removed soon.
There are two special commands involved. Also, the client must listen for
client messages (``MPV_EVENT_CLIENT_MESSAGE`` in the C API).
``hook-add <hook-name> <id> <priority>``
Subscribe to the hook identified by the first argument (basically, the
name of event). The ``id`` argument is an arbitrary integer chosen by the
user. ``priority`` is used to sort all hook handlers globally across all
clients. Each client can register multiple hook handlers (even for the
same hook-name). Once the hook is registered, it cannot be unregistered.
When a specific event happens, all registered handlers are run serially.
This uses a protocol every client has to follow explicitly. When a hook
handler is run, a client message (``MPV_EVENT_CLIENT_MESSAGE``) is sent to
the client which registered the hook. This message has the following
arguments:
1. the string ``hook_run``
2. the ``id`` argument the hook was registered with as string (this can be
used to correctly handle multiple hooks registered by the same client,
as long as the ``id`` argument is unique in the client)
3. something undefined, used by the hook mechanism to track hook execution
Upon receiving this message, the client can handle the event. While doing
this, the player core will still react to requests, but playback will
typically be stopped.
When the client is done, it must continue the core's hook execution by
running the ``hook-ack`` command.
``hook-ack <string>``
Run the next hook in the global chain of hooks. The argument is the 3rd
argument of the client message that starts hook execution for the
current client.
Input Command Prefixes
----------------------

View File

@ -1728,7 +1728,7 @@ 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);
mp_hook_add(ctx->mpctx, ctx->name, name, reply_userdata, priority);
unlock_core(ctx);
return 0;
}

View File

@ -123,7 +123,6 @@ struct hook_handler {
uint64_t user_id; // user-chosen ID
int priority; // priority for global hook order
int64_t seq; // unique ID, != 0, also for fixed order on equal priorities
bool legacy; // old cmd based hook API
bool active; // hook is currently in progress (only 1 at a time for now)
};
@ -178,29 +177,13 @@ static int invoke_hook_handler(struct MPContext *mpctx, struct hook_handler *h)
h->active = true;
uint64_t reply_id = 0;
void *data;
int msg;
if (h->legacy) {
mpv_event_client_message *m = talloc_ptrtype(NULL, m);
*m = (mpv_event_client_message){0};
MP_TARRAY_APPEND(m, m->args, m->num_args, "hook_run");
MP_TARRAY_APPEND(m, m->args, m->num_args,
talloc_asprintf(m, "%llu", (long long)h->user_id));
MP_TARRAY_APPEND(m, m->args, m->num_args,
talloc_asprintf(m, "%llu", (long long)h->seq));
data = m;
msg = MPV_EVENT_CLIENT_MESSAGE;
} else {
mpv_event_hook *m = talloc_ptrtype(NULL, m);
*m = (mpv_event_hook){
.name = talloc_strdup(m, h->type),
.id = h->seq,
},
reply_id = h->user_id;
data = m;
msg = MPV_EVENT_HOOK;
}
int r = mp_client_send_event(mpctx, h->client, reply_id, msg, data);
mpv_event_hook *m = talloc_ptrtype(NULL, m);
*m = (mpv_event_hook){
.name = talloc_strdup(m, h->type),
.id = h->seq,
},
reply_id = h->user_id;
int r = mp_client_send_event(mpctx, h->client, reply_id, MPV_EVENT_HOOK, m);
if (r < 0) {
MP_WARN(mpctx, "Sending hook command failed. Removing hook.\n");
hook_remove(mpctx, h);
@ -261,11 +244,8 @@ static int compare_hook(const void *pa, const void *pb)
}
void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name,
uint64_t user_id, int pri, bool legacy)
uint64_t user_id, int pri)
{
if (legacy)
MP_WARN(mpctx, "The old hook API is deprecated! Use the libmpv API.\n");
struct command_ctx *cmd = mpctx->command_ctx;
struct hook_handler *h = talloc_ptrtype(cmd, h);
int64_t seq = ++cmd->hook_seq;
@ -275,7 +255,6 @@ void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name,
.user_id = user_id,
.priority = pri,
.seq = seq,
.legacy = legacy,
};
MP_TARRAY_APPEND(cmd, cmd->hooks, cmd->num_hooks, h);
qsort(cmd->hooks, cmd->num_hooks, sizeof(cmd->hooks[0]), compare_hook);
@ -5411,33 +5390,6 @@ static void cmd_write_watch_later_config(void *p)
mp_write_watch_later_conf(mpctx);
}
static void cmd_hook_add(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
if (!cmd->cmd->sender) {
MP_ERR(mpctx, "Can be used from client API only.\n");
cmd->success = false;
return;
}
mp_hook_add(mpctx, cmd->cmd->sender, cmd->args[0].v.s, cmd->args[1].v.i,
cmd->args[2].v.i, true);
}
static void cmd_hook_ack(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;
if (!cmd->cmd->sender) {
MP_ERR(mpctx, "Can be used from client API only.\n");
cmd->success = false;
return;
}
mp_hook_continue(mpctx, cmd->cmd->sender, cmd->args[0].v.i);
}
static void cmd_mouse(void *p)
{
struct mp_cmd_ctx *cmd = p;
@ -5950,11 +5902,6 @@ const struct mp_cmd_def mp_cmds[] = {
{ "write-watch-later-config", cmd_write_watch_later_config },
{ "hook-add", cmd_hook_add, { OPT_STRING("arg0", v.s, 0),
OPT_INT("arg1", v.i, 0),
OPT_INT("arg2", v.i, 0) }},
{ "hook-ack", cmd_hook_ack, { OPT_INT("arg0", v.i, 0) }},
{ "mouse", cmd_mouse, { OPT_INT("x", v.i, 0),
OPT_INT("y", v.i, 0),
OPT_INT("button", v.i, 0, OPTDEF_INT(-1)),

View File

@ -107,7 +107,7 @@ bool mp_hook_test_completion(struct MPContext *mpctx, char *type);
void mp_hook_start(struct MPContext *mpctx, char *type);
int mp_hook_continue(struct MPContext *mpctx, char *client, uint64_t id);
void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name,
uint64_t user_id, int pri, bool legacy);
uint64_t user_id, int pri);
void mark_seek(struct MPContext *mpctx);