1
0
mirror of https://github.com/mpv-player/mpv synced 2025-04-09 03:02:13 +00:00

client API: send MPV_EVENT_SHUTDOWN only once

Before this change, mpv_wait_event() could inconsistently return
multiple MPV_EVENT_SHUTDOWN events to a single mpv_handle, up to the
point of spamming the event queue under certain circumstances. Change
this and just send it exactly once to each mpv_handle.

Some client API users might have weird requirements about destroying
their state asynchronously (and not reacting immediately to the SHUTDOWN
event). This change will help a bit to make this less weird and
surprising.
This commit is contained in:
wm4 2018-03-09 11:53:48 +01:00 committed by Kevin Mitchell
parent 03791fae16
commit 2edf00fb94
3 changed files with 6 additions and 3 deletions

View File

@ -40,6 +40,8 @@ API changes
- rename mpv_detach_destroy() to mpv_destroy() (the old function will - rename mpv_detach_destroy() to mpv_destroy() (the old function will
remain valid as deprecated alias) remain valid as deprecated alias)
- add mpv_create_weak_client(), which makes use of above changes - add mpv_create_weak_client(), which makes use of above changes
- MPV_EVENT_SHUTDOWN is now returned exactly once if a mpv_handle
should terminate, instead of spamming the event queue with this event
1.28 - deprecate the render opengl_cb API, and replace it with render.h 1.28 - deprecate the render opengl_cb API, and replace it with render.h
and render_gl.h. The goal is allowing support for APIs other than and render_gl.h. The goal is allowing support for APIs other than
OpenGL. The old API is emulated with the new API. OpenGL. The old API is emulated with the new API.

View File

@ -1166,9 +1166,8 @@ typedef enum mpv_event_id {
/** /**
* Happens when the player quits. The player enters a state where it tries * Happens when the player quits. The player enters a state where it tries
* to disconnect all clients. Most requests to the player will fail, and * to disconnect all clients. Most requests to the player will fail, and
* mpv_wait_event() will always return instantly (returning new shutdown * the client should react to this and quit with mpv_destroy() as soon as
* events if no other events are queued). The client should react to this * possible.
* and quit with mpv_destroy() as soon as possible.
*/ */
MPV_EVENT_SHUTDOWN = 1, MPV_EVENT_SHUTDOWN = 1,
/** /**

View File

@ -634,6 +634,8 @@ static int append_event(struct mpv_handle *ctx, struct mpv_event event, bool cop
ctx->events[(ctx->first_event + ctx->num_events) % ctx->max_events] = event; ctx->events[(ctx->first_event + ctx->num_events) % ctx->max_events] = event;
ctx->num_events++; ctx->num_events++;
wakeup_client(ctx); wakeup_client(ctx);
if (event.event_id == MPV_EVENT_SHUTDOWN)
ctx->event_mask &= ctx->event_mask & ~(1ULL << MPV_EVENT_SHUTDOWN);
return 0; return 0;
} }