0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 12:02:23 +02:00
mpv/DOCS/man
wm4 11c573fda0 scripting: change when/how player waits for scripts being loaded
Fundamentally, scripts are loaded asynchronously, but as a feature,
there was code to wait until a script is loaded (for a certain arbitrary
definition of "loaded"). This was done in scripting.c with the
wait_loaded() function.

This called mp_idle(), and since there are commands to load/unload
scripts, it meant the player core loop could be entered recursively. I
think this is a major complication and has some problems. For example,
if you had a script that does 'os.execute("sleep inf")', then every time
you ran a command to load an instance of the script would add a new
stack frame of mp_idle(). This would lead to some sort of reentrancy
horror that is hard to debug. Also misc/dispatch.c contains a somewhat
tricky mess to support such recursive invocations. There were also some
bugs due to this and due to unforeseen interactions with other messes.

This scripting stuff was the only thing making use of that reentrancy,
and future commands that have "logical" waiting for something should be
implemented differently. So get rid of it.

Change the code to wait only in the player initialization phase: the
only place where it really has to wait is before playback is started,
because scripts might want to set options or hooks that interact with
playback initialization. Unloading of builtin scripts (can happen with
e.g. "set osc no") is left asynchronous; the unloading wasn't too robust
anyway, and this change won't make a difference if someone is trying to
break it intentionally. Note that this is not in mp_initialize(),
because mpv_initialize() uses this by locking the core, which would have
the same problem.

In the future, commands which logically wait should use different
mechanisms. Originally I thought the current approach (that is removed
with this commit) should be used, but it's too much of a mess and can't
even be used in some cases. Examples are:
- "loadfile" should be made blocking (needs to run the normal player
  code and manually unblock the thread issuing the command)
- "add-sub" should not freeze the player until the URL is opened (needs
  to run opening on a separate thread)
Possibly the current scripting behavior could be restored once new
mechanisms exist, and if it turns out that anyone needs it.

With this commit there should be no further instances of recursive
playloop invocations (other than the case in the following commit),
since all mp_idle()/mp_wait_events() calls are done strictly from the
main thread (and not commands/properties or libmpv client API that
"lock" the main thread).
2018-04-18 01:17:41 +03:00
..
af.rst f_lavfi: add an option to use old audio PTS handling for af_lavfi 2018-04-15 23:11:33 +03:00
ao.rst ao_pulse: reduce requested device buffer size 2018-04-15 23:11:33 +03:00
changes.rst manpage: mention the client API/interface change logs 2016-09-02 09:48:35 +02:00
encode.rst encode: implement --oset-metadata, and --oremove-metadata 2017-12-26 03:33:19 -07:00
input.rst scripting: change when/how player waits for scripts being loaded 2018-04-18 01:17:41 +03:00
ipc.rst manpage: document tricky issue with IPC observe_property command 2017-05-16 12:20:39 +02:00
javascript.rst js: implement mp.register_idle 2018-04-07 16:02:19 -07:00
libmpv.rst manpage: define stricter rules for C plugin return values 2017-01-14 17:41:04 +01:00
lua.rst scripting: change when/how player waits for scripts being loaded 2018-04-18 01:17:41 +03:00
mpv.rst config: replace config dir lua-settings/ with dir script-opts/ 2018-04-07 16:02:16 -07:00
options.rst audio: don't recreate AO if a filter changes the output format 2018-04-15 23:11:33 +03:00
osc.rst config: replace config dir lua-settings/ with dir script-opts/ 2018-04-07 16:02:16 -07:00
stats.rst config: replace config dir lua-settings/ with dir script-opts/ 2018-04-07 16:02:16 -07:00
vf.rst vf_vavpp: select best quality deinterlacing algorithm by default 2018-02-13 17:45:29 -08:00
vo.rst client API: deprecate opengl-cb API and introduce a replacement API 2018-02-28 00:55:06 -08:00