Skip to content

Commit

Permalink
player/client: clear hooks when a client is destroyed
Browse files Browse the repository at this point in the history
Clear any registered hook when a client is destroyed like it is already
done for OSD overlays and input sections. This is necessary both if a
client exists intentionally or by error. e.g. the script:

mp.add_hook("on_load", 0)
error()

logs the warning "Sending hook command failed. Removing hook." before
this commit.
  • Loading branch information
guidocella committed Nov 2, 2024
1 parent d09145a commit 446825f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions player/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ static void mp_destroy_client(mpv_handle *ctx, bool terminate)

osd_set_external_remove_owner(mpctx->osd, ctx);
mp_input_remove_sections_by_owner(mpctx->input, ctx->name);
mp_remove_client_hooks(mpctx, ctx->id);

mp_mutex_lock(&clients->lock);

Expand Down
11 changes: 11 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ static void hook_remove(struct MPContext *mpctx, struct hook_handler *h)
MP_ASSERT_UNREACHABLE();
}

void mp_remove_client_hooks(struct MPContext *mpctx, int64_t client_id)
{
struct command_ctx *cmd = mpctx->command_ctx;
for (int n = 0; n < cmd->num_hooks; n++) {
if (cmd->hooks[n]->client_id == client_id) {
talloc_free(cmd->hooks[n]);
MP_TARRAY_REMOVE_AT(cmd->hooks, cmd->num_hooks, n);
}
}
}

bool mp_hook_test_completion(struct MPContext *mpctx, char *type)
{
struct command_ctx *cmd = mpctx->command_ctx;
Expand Down
1 change: 1 addition & 0 deletions player/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ void mp_hook_start(struct MPContext *mpctx, char *type);
int mp_hook_continue(struct MPContext *mpctx, int64_t client_id, uint64_t id);
void mp_hook_add(struct MPContext *mpctx, char *client, int64_t client_id,
const char *name, uint64_t user_id, int pri);
void mp_remove_client_hooks(struct MPContext *mpctx, int64_t client_id);

void mark_seek(struct MPContext *mpctx);

Expand Down

0 comments on commit 446825f

Please sign in to comment.