History

command: remove legacy hook API

Hopefully nothing uses this. (I know one exception, but, well, what can I do.)

wm4 committed 6 years ago

Commit 2337fa41 parent 7a76b575 files · +13 −104Browse files

Unified · Split

5 files
  1. DOCS/interface-changes.rst +3 −0
  2. DOCS/man/input.rst +0 −41
  3. player/client.c +1 −1
  4. player/command.c +8 −61
  5. player/command.h +1 −1
DOCS/interface-changes.rst+3−0
@@ -35,6 +35,9 @@ Interface changes · 34 unmodified lines
3535 - the OSX bundle now logs to "~/Library/Logs/mpv.log" by default
3636 - deprecate the --cache-secs option (once removed, the cache cannot be
3737 limited by time anymore)
38+ - remove deprecated legacy hook API ("hook-add", "hook-ack"). Use either the
39+ libmpv API (mpv_hook_add(), mpv_hook_continue()), or the Lua scripting
40+ wrappers (mp.add_hook()).
3841 --- mpv 0.32.0 ---
3942 - change behavior when using legacy option syntax with options that start
4043 with two dashes (``--`` instead of a ``-``). Now, using the recommended
DOCS/man/input.rst+0−41
@@ -1286,47 +1286,6 @@ The following hooks are currently defined: · 1285 unmodified lines
12861286 Run before closing a file, and before actually uninitializing
12871287 everything. It's not possible to resume playback in this state.
12881288
1289−Legacy hook API
1290−~~~~~~~~~~~~~~~
1291−
1292−.. warning::
1293−
1294− The legacy API is deprecated and will be removed soon.
1295−
1296−There are two special commands involved. Also, the client must listen for
1297−client messages (``MPV_EVENT_CLIENT_MESSAGE`` in the C API).
1298−
1299−``hook-add <hook-name> <id> <priority>``
1300− Subscribe to the hook identified by the first argument (basically, the
1301− name of event). The ``id`` argument is an arbitrary integer chosen by the
1302− user. ``priority`` is used to sort all hook handlers globally across all
1303− clients. Each client can register multiple hook handlers (even for the
1304− same hook-name). Once the hook is registered, it cannot be unregistered.
1305−
1306− When a specific event happens, all registered handlers are run serially.
1307− This uses a protocol every client has to follow explicitly. When a hook
1308− handler is run, a client message (``MPV_EVENT_CLIENT_MESSAGE``) is sent to
1309− the client which registered the hook. This message has the following
1310− arguments:
1311−
1312− 1. the string ``hook_run``
1313− 2. the ``id`` argument the hook was registered with as string (this can be
1314− used to correctly handle multiple hooks registered by the same client,
1315− as long as the ``id`` argument is unique in the client)
1316− 3. something undefined, used by the hook mechanism to track hook execution
1317−
1318− Upon receiving this message, the client can handle the event. While doing
1319− this, the player core will still react to requests, but playback will
1320− typically be stopped.
1321−
1322− When the client is done, it must continue the core's hook execution by
1323− running the ``hook-ack`` command.
1324−
1325−``hook-ack <string>``
1326− Run the next hook in the global chain of hooks. The argument is the 3rd
1327− argument of the client message that starts hook execution for the
1328− current client.
1329−
13301289 Input Command Prefixes
13311290 ----------------------
13321291
player/client.c+1−1
@@ -1728,7 +1728,7 @@ int mpv_hook_add(mpv_handle *ctx, uint64_t reply_userdata, · 1727 unmodified lines
17281728 const char *name, int priority)
17291729 {
17301730 lock_core(ctx);
1731− mp_hook_add(ctx->mpctx, ctx->name, name, reply_userdata, priority, false);
1731+ mp_hook_add(ctx->mpctx, ctx->name, name, reply_userdata, priority);
17321732 unlock_core(ctx);
17331733 return 0;
17341734 }
player/command.c+8−61
@@ -123,7 +123,6 @@ struct hook_handler { · 122 unmodified lines
123123 uint64_t user_id; // user-chosen ID
124124 int priority; // priority for global hook order
125125 int64_t seq; // unique ID, != 0, also for fixed order on equal priorities
126− bool legacy; // old cmd based hook API
127126 bool active; // hook is currently in progress (only 1 at a time for now)
128127 };
129128
@@ -178,29 +177,13 @@ static int invoke_hook_handler(struct MPContext *mpctx, struct hook_handler *h) · 48 unmodified lines
178177 h->active = true;
179178
180179 uint64_t reply_id = 0;
181− void *data;
182− int msg;
183− if (h->legacy) {
184− mpv_event_client_message *m = talloc_ptrtype(NULL, m);
185− *m = (mpv_event_client_message){0};
186− MP_TARRAY_APPEND(m, m->args, m->num_args, "hook_run");
187− MP_TARRAY_APPEND(m, m->args, m->num_args,
188− talloc_asprintf(m, "%llu", (long long)h->user_id));
189− MP_TARRAY_APPEND(m, m->args, m->num_args,
190− talloc_asprintf(m, "%llu", (long long)h->seq));
191− data = m;
192− msg = MPV_EVENT_CLIENT_MESSAGE;
193− } else {
194− mpv_event_hook *m = talloc_ptrtype(NULL, m);
195− *m = (mpv_event_hook){
196− .name = talloc_strdup(m, h->type),
197− .id = h->seq,
198− },
199− reply_id = h->user_id;
200− data = m;
201− msg = MPV_EVENT_HOOK;
202− }
203− int r = mp_client_send_event(mpctx, h->client, reply_id, msg, data);
180+ mpv_event_hook *m = talloc_ptrtype(NULL, m);
181+ *m = (mpv_event_hook){
182+ .name = talloc_strdup(m, h->type),
183+ .id = h->seq,
184+ },
185+ reply_id = h->user_id;
186+ int r = mp_client_send_event(mpctx, h->client, reply_id, MPV_EVENT_HOOK, m);
204187 if (r < 0) {
205188 MP_WARN(mpctx, "Sending hook command failed. Removing hook.\n");
206189 hook_remove(mpctx, h);
@@ -261,11 +244,8 @@ static int compare_hook(const void *pa, const void *pb) · 54 unmodified lines
261244 }
262245
263246 void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name,
264− uint64_t user_id, int pri, bool legacy)
247+ uint64_t user_id, int pri)
265248 {
266− if (legacy)
267− MP_WARN(mpctx, "The old hook API is deprecated! Use the libmpv API.\n");
268−
269249 struct command_ctx *cmd = mpctx->command_ctx;
270250 struct hook_handler *h = talloc_ptrtype(cmd, h);
271251 int64_t seq = ++cmd->hook_seq;
@@ -275,7 +255,6 @@ void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name, · 3 unmodified lines
275255 .user_id = user_id,
276256 .priority = pri,
277257 .seq = seq,
278− .legacy = legacy,
279258 };
280259 MP_TARRAY_APPEND(cmd, cmd->hooks, cmd->num_hooks, h);
281260 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) · 5129 unmodified lines
54115390 mp_write_watch_later_conf(mpctx);
54125391 }
54135392
5414−static void cmd_hook_add(void *p)
5415−{
5416− struct mp_cmd_ctx *cmd = p;
5417− struct MPContext *mpctx = cmd->mpctx;
5418−
5419− if (!cmd->cmd->sender) {
5420− MP_ERR(mpctx, "Can be used from client API only.\n");
5421− cmd->success = false;
5422− return;
5423− }
5424− mp_hook_add(mpctx, cmd->cmd->sender, cmd->args[0].v.s, cmd->args[1].v.i,
5425− cmd->args[2].v.i, true);
5426−}
5427−
5428−static void cmd_hook_ack(void *p)
5429−{
5430− struct mp_cmd_ctx *cmd = p;
5431− struct MPContext *mpctx = cmd->mpctx;
5432−
5433− if (!cmd->cmd->sender) {
5434− MP_ERR(mpctx, "Can be used from client API only.\n");
5435− cmd->success = false;
5436− return;
5437− }
5438− mp_hook_continue(mpctx, cmd->cmd->sender, cmd->args[0].v.i);
5439−}
5440−
54415393 static void cmd_mouse(void *p)
54425394 {
54435395 struct mp_cmd_ctx *cmd = p;
@@ -5950,11 +5902,6 @@ const struct mp_cmd_def mp_cmds[] = { · 506 unmodified lines
59505902
59515903 { "write-watch-later-config", cmd_write_watch_later_config },
59525904
5953− { "hook-add", cmd_hook_add, { OPT_STRING("arg0", v.s, 0),
5954− OPT_INT("arg1", v.i, 0),
5955− OPT_INT("arg2", v.i, 0) }},
5956− { "hook-ack", cmd_hook_ack, { OPT_INT("arg0", v.i, 0) }},
5957−
59585905 { "mouse", cmd_mouse, { OPT_INT("x", v.i, 0),
59595906 OPT_INT("y", v.i, 0),
59605907 OPT_INT("button", v.i, 0, OPTDEF_INT(-1)),
player/command.h+1−1
@@ -107,7 +107,7 @@ bool mp_hook_test_completion(struct MPContext *mpctx, char *type); · 106 unmodified lines
107107 void mp_hook_start(struct MPContext *mpctx, char *type);
108108 int mp_hook_continue(struct MPContext *mpctx, char *client, uint64_t id);
109109 void mp_hook_add(struct MPContext *mpctx, const char *client, const char *name,
110− uint64_t user_id, int pri, bool legacy);
110+ uint64_t user_id, int pri);
111111
112112 void mark_seek(struct MPContext *mpctx);
113113

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t