diff options
author | wm4 <wm4@nowhere> | 2020-03-07 02:52:10 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-03-07 02:52:10 +0100 |
commit | ba70b150fbe89c00e4ef7dcb975ec695b49dac8d (patch) | |
tree | 0114edb0a97b4c585b77a8496ff9b77eb118c856 /DOCS/man | |
parent | 8a4f812b76befa9529591e274cefdd2f234fb450 (diff) | |
download | mpv-ba70b150fbe89c00e4ef7dcb975ec695b49dac8d.tar.bz2 mpv-ba70b150fbe89c00e4ef7dcb975ec695b49dac8d.tar.xz |
client API: provide ways to finish property changes on file changes
When the current file changes (or rather, when starting/finishing
playback of a playlist entry), clients tend to have the problem that
it's hard to tell whether a property change notification (via
mpv_observe_property() and mechanisms layered on top of it) is from the
previous or new playlist entry. The previous commit probably helps, but
all the asynchronity is still a bit unhelpful.
Try to make this better by adding new hooks, that are run before/after
playback init/deinit. This is similar to the existing hooks, except
they're outside of "initialized" playback, which excludes that you might
accidentally get an overlap between the current and the previous/next
playlist entry.
That still doesn't seem quite enough, since normally, property change
notifications come after the hook event. So basically a client would
have to explicitly "drain" the event queue within the hook, and make the
hook continue only after that is done. Knowing when property
notifications are done is another asynchronous nightmare (how exactly it
works keeps changing within client.c, and an API user probably can't
tell anymore when all pending properties are truly done). So introduce
another guarantee: properties that were changed before the hook happens
will be returned before the hook event is returned. That means the
client will have received all pending property notifications from the
previous playlist entry (or whatever) before the hook is entered.
As another minor complication, we shouldn't just keep the hook pending
until _all_ property notifications are done, since the client's hook
could produce new ones. (Or just consider things like the demuxer thread
hammering the client with cache update events, while the "on_preloaded"
hook is run.) So there is some extra untested, fragile logic in client.c
to handle this (the waiting_for_hook flag).
This probably works, but was barely tested. Not sure if this helps
anyone, but I think it's fine for my own purposes. (I really hated this
aspect of the API whenever I used it myself.)
Diffstat (limited to 'DOCS/man')
-rw-r--r-- | DOCS/man/input.rst | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/DOCS/man/input.rst b/DOCS/man/input.rst index 7c93843619..082776f66d 100644 --- a/DOCS/man/input.rst +++ b/DOCS/man/input.rst @@ -1253,6 +1253,12 @@ the player freeze randomly. Basically, nobody should use this API. The C API is described in the header files. The Lua API is described in the Lua section. +Before a hook is actually invoked on an API clients, it will attempt to return +new values for all observed properties that were changed before the hook. This +may make it easier for an application to set defined "barriers" between property +change notifications by registering hooks. (That means these hooks will have an +effect, even if you do nothing and make them continue immediately.) + The following hooks are currently defined: ``on_load`` @@ -1286,6 +1292,16 @@ 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. +``on_before_start_file`` + Run before a ``start-file`` event is sent. (If any client changes the + current playlist entry, or sends a quit command to the player, the + corresponding event will not actually happen after the hook returns.) + Useful to drain property changes before a new file is loaded. + +``on_after_end_file`` + Run after an ``end-file`` event. Useful to drain property changes after a + file has finished. + Input Command Prefixes ---------------------- |