Commit Graph

49184 Commits

Author SHA1 Message Date
Avi Halachmi (:avih) 1e1b5a6e14 Revert "stats.lua: page 4 (keys): fix "excluding stats keys""
This reverts commit 0f1654811bda0dfdd337734ec33c59b67522234a.

It was an incorrect fix, because the key names do get used - to remove
the forced bindings once stats exits the interactive mode.

And without names - the interactive keys remained active even after
stats exited interactive mode.
2021-07-20 01:00:03 +03:00
Avi Halachmi (:avih) fab25ac004 stats.lua: page 4 (keys): fix "excluding stats keys"
The page 4 keybinding list tries to skip the interactive bindings of
stats itself (because they would hide the normal bindings of these
keys when stats is not visible), and to do that it excludes commands
containing "script-binding stats/__key" - which is how script-added
bindings usually look like.

However, keys which are added with a "name" bind stats/name rather
than stats/__key... - and that's what stats.lua did till now with its
interactive force-bindings.

Now the interactive forced bindings are added without a name, and so
they do end up using the automatic stats/__key... and get excluded.
2021-07-20 00:13:35 +03:00
Avi Halachmi (:avih) 0c6ea0c0b0 DOCS/mpv.rst: add cross references to --input-test and stats 2021-07-19 22:06:50 +03:00
Avi Halachmi (:avih) 2335ee5514 stats.lua: page 4 (keys): support help-like terminal printout
While --input-test is useful, and so is page 4 of stats, until now
there was no way to simply print the list in a help-like fashion.

This commit adds such printout, invoked by the script opt
stats-bindlist=yes, which uses the existing page 4 code. This prints
the list on startup and quits immediately - like any help page.

It's awkward to invoke compared to other help pages, and it does
require the stats page to be enabled (it is by default), however
it is a script-generated output, and currently there's no other
method to print a help page generated by a script.

The printout itself is performed using lua's io.write. While reliable,
it's not the standard way for mpv to print to the terminal.

Other possible printout methods are mp.msg.info - which also prints
"[stats]" prefix on each line (ugly), or forcing term-osd and setting
an osd-message which mpv will then print at the terminal - however
that's printed to stderr, and could also be subject to timing concerns
since we quit right afterwards.

In the future we can consider changing/integrating the invocation so
that mpv itself could print a help page generated by a script, thus
solving both the awkward invocation and printout-method issues.
2021-07-19 22:06:50 +03:00
Avi Halachmi (:avih) 9fb200b641 stats.lua: add page 4: active key-bindings list
This is a scrollable page which also works nicely with the terminal
OSD. Typically there are more than 100 bound keys.

It groups the binding using fuzzy property/command/script name after
simple analysis of the command string, and then further sorts the
binding in each group according to the "complexity" of the key itself
(plain keys -> keys with modifiers, alphabetically, etc).

The alignment/grouping style is heavily inspired by @medhefgo's #8924
but otherwise it's an independent implementation.
2021-07-19 22:06:50 +03:00
Avi Halachmi (:avih) 59c10274b4 stats.lua: scroll: allow throttling page-rebuild (no-op)
Typically the current page is rebuilt and rendered once per second,
howeve, scrolling can invoke the rebuild function very frequently,
even at a rate which is too fast for the rebuild function to keep
up. This can result in high CPU usage and input lag.

This commit adds an argument to the page-rebuild function, letting it
know whether or not it's called following a scroll keypress, thus
allowing it to cache intermediate data so that it doesn't have to
re-calculate the whole page from scratch.

This additional argument is unused currently, but it could be useful
for the internal performance page - which can be relatively heavy.
2021-07-19 22:06:50 +03:00
Avi Halachmi (:avih) 50280197e2 stats.lua: move internal performance from page 4 to page 0
This allows adding more pages without the internal performance page
getting stuck at the middle of the list.
2021-07-19 22:06:50 +03:00
sfan5 3e28c8e983 player: fix missed pause state update during reset in some cases
When playing a new file, if paused_for_cache was true before being reset
the AO would never be unpaused because that state was thrown away, leaving it stuck.
Fix this by updating the pause state before resetting that variable. Note that this
does not make the second update_internal_pause_state() call redundant.
This fixes the same bug fb5d976cb0 was supposed to.
2021-07-18 12:22:55 +02:00
sfan5 d2a56227df Revert "audio: fix ao_reset() not clearing paused state leading to stuck AO"
In hindsight this is obviously broken.
This reverts commit fb5d976cb0.
2021-07-18 12:21:15 +02:00
Kiracus 1e90ec647c osxbundle: use python3 2021-07-17 00:08:54 +02:00
sfan5 fb5d976cb0 audio: fix ao_reset() not clearing paused state leading to stuck AO
This would happen when switching from playback stuck in cache wait
(underrun) to another file.
2021-07-16 20:58:54 +02:00
Guido Cella 075154175d TOOLS/autocrop.lua: improve enable/disable condition
The previous code tried to disable autocrop for cover-art by testing
that track-list/$vid/albumart is false, however, $vid is completely
unrelated to the track-list index.

It only sometimes succeeded to disable for albumart, by accident,
e.g. with one audio track and one video track where $vid==1 and
track-list/1 happens to be the video (cover art) track.

The new code detects the currently-used video track by finding a track
with type=="video" and selected==true. Unlike the previous code, it
also works in scenarios with many audio/video/sub tracks.

Additionally, autocrop is now enabled also with lavfi-complex, which
should be considered an improvement. The previous code implicitly
disabled it with lavfi-complex because $vid is nil on such case.
2021-07-14 11:58:29 +03:00
Shreesh Adiga 8ace8e8790 demux: acquire lock before calling update_bytes_read
in->byte_level_seeks field is written and modified inside
update_bytes_read at the same time when demux_get_reader_state
is executing, which locks the demux thread mutex.  This results
in a data race, reported by Thread Sanitizer when playing mp3 file
of sufficient long length.
2021-07-13 15:16:59 +00:00
Shreesh Adiga be81470f54 audio: check ao driver init failure to avoid use after free
reinit_audio_filters_and_output function will free mpctx->ao_chain
when there is a failure during audio initialization. So modify it
to return -1 in case of init failure. The return value is checked
to avoid use after free. Reported by Address Sanitizer when manually
specifying --ao which triggers "Failed to initialize audio driver" error.
2021-07-13 15:16:59 +00:00
Avi Halachmi (:avih) d828652f24 lua: fix timers comment (no-op)
process_timers() doesn't return an absolute time. It returned delta>0
or nil before f73814b1 , and since f73814b1 it can also return 0.
2021-07-13 13:11:34 +03:00
Martin Tournoij 854404a639 terminal-unix: fix ^Z identification
When using "stty susp ''" to disable sending the TSTP signal with ^Z,
mpv didn't recognize ^Z correctly in the terminal:

  [input] No key binding found for key 'Ctrl+2'.

Because ASCII 26 (^Z) and above were incorrectly considered ^<NUMBER>.

This commit moves the cutoff between letters/numbers from 25 to 26 so
that ^Z is now detected correctly as ^<LETTER>.

Additionally, it rephrases the ^<NUMBER> formula for clarity.
2021-07-13 12:12:56 +03:00
Ripose f223edb616 DOCS/options: adds documentation for secondary-sub-visibility
The --secondary-sub-visibility options was previously undocumented in
the pull request that added it. This commit adds documentation for it
and clarifies its behavior.
2021-07-12 21:07:37 +00:00
Ripose c4f982637f command: adds support for secondary subs to sub-seek and sub-step
Modifies the sub-seek and sub-step commands with a second <flags>
argument to specify whether to seek/step on the primary or secondary
subtitles. The flag is used to index into the current_track array in
cmd_sub_step_seek.
2021-07-12 21:07:37 +00:00
Ripose 34cfe9d89b command: add secondary-sub-start and secondary-sub-end properties
Adds secondary-sub-start and secondary-sub-end properties by setting
the current_track index in the m_property's priv variable which later
gets accessed in get_times. Also adds a test of the secondary subtitle
time properties in tests/subtimes.js bound to 'T'.
2021-07-12 21:07:37 +00:00
Guido Cella 383acd41a8 manpage: DEL key: clarify it refers to the osc 2021-07-12 13:16:10 +03:00
Guido Cella f049acfd43 manpage: fix typo 2021-07-08 13:22:38 +00:00
TheAMM 4d3df1c842 recorder: add support for attachments (fonts)
Though, only when the output format is matroska, to avoid muxing errors.
This is quite useful when the input has ASS subtitles, as they tend to
rely on embedded fonts.
2021-07-08 12:44:06 +03:00
TheAMM f9527497c6 recorder: ignore packet queue in mux_packets()
I've looked and studied the flow in the recorder, and to my
understanding, the packet queue is moot after the initial sync, maybe
even then - but that's beyond me right now.
With the previous choice to mux trailing packets whatever the case, this
doesn't result in any new ill effects (and some missing packets at the
end is no big deal).
Notably, since we don't have to hold onto the packets after we get
muxing, we'll never run into any issues with veeery long GOPs filling up
our queue (resulting in dropped packets and much user chagrin).
2021-07-08 12:44:06 +03:00
TheAMM b0386fc543 av_common: trim FLAC extradata when copying codec params
For muxing, FFmpeg expects the FLAC extradata to be just the bare STREAMINFO,
and passing the full FLAC extradata (fLaC header and block size, with any
additional channel layout metadata) will result in malformed output, as
ffmpeg will simply prefix another fLaC header in front.
This can be considered to be a bug.

FFmpeg's own demuxers only store the STREAMINFO, hence the naivety, while
our common source of FLAC streams, the matroska demuxer, holds onto the
full extradata. It has been deemed preferable to adjust the extradata upon
muxing, instead of in the demuxer (ffmpeg's FLAC decoder knows to read
the full fLaC extradata).

This fixes muxing FLAC streams, meaning recorder.c or dump-cache.
2021-07-08 12:44:06 +03:00
TheAMM dd9ed47c99 demux, dump-cache: fix demux cache range sorting
dump_cache() calls qsort() to order an array of pointers, while the
comparator forgets it's receiving pointers to pointers.
Since cache-dumping over multiple cache ranges is fairly rare, this
seems to have gone unnoticed.
2021-07-08 12:44:06 +03:00
TheAMM 27db175ab6 recorder: clear packet queue after they've been muxed
In commit f7678575a5, wm4 chooses to mux
all remaining packets when mp_recorder_mark_discontinuity() is called and
adds a call to mux_packets(). However, it is called only after flush_packets(),
which clears the packets before they can be muxed out. This has no ill
effects per se  - recordings end on keyframes, as before - but judging from
his commit message, the intention explicitly was to output the inter
frames, since long GOPs can mean several seconds of missing content from
the output. So, clear the stream packet queues only after the final mux.

Also, flushing can mean both discarding and committing. What a country!
2021-07-08 12:44:06 +03:00
Guido Cella b3fccf0803 player: add append-play flag to loadlist
Closes #5664.
2021-07-06 15:46:45 +00:00
Avi Halachmi (:avih) d2dd4cacb8 osc: expose osc-visibility via shared-script-properties
osc-visibility can already be changed at runtime via script-message
or other means, but until now there was no way to tell what the
current state is.

Now shared-script-properties/osc-visibility reflects this state.
It's output-only by the osc - changing it does not affect the osc.

Useful if a script wants to change osc-visibility temporarily, and
later restore to its original state.

There's no way to coordinate if more than one script wants to change
it, but that would be a hard problem to solve anyway, even if the
osc itself tried to coordinate such requests from different sources.
2021-07-06 16:12:36 +03:00
Dudemanguy f2afae55e9 wayland: refactor surface scaling
Another day, another wayland refactor. Way back when, dcc3c2e added
support for the hidpi-window-scale option (something you probably should
never set to no but whatever) to wayland. Well technically, it never had
any runtime toggling support (don't remember if detecting when vo_opts
changed was possible or not then; maybe not). Anyways in the process of
fixing that, I went ahead and refactored how this is all handled. The
key difference is that when hidpi-window-scale is disabled, wl->scaling
is directly set to 1 instead of forcibly setting
wl->current_output->scale to 1. Note that scaling operations don't
always require a geometry reset/resize so set_surface_scaling needs to
be separate from set_geometry. The logic here is kind of complicated but
it (should) be correct.
2021-06-30 16:37:36 +00:00
rcombs 0c1544e66c sub: fix subs/lyrics on music files with sub-past-video-end=no
Regressed in 11423acf3
2021-06-27 21:02:39 -04:00
Dudemanguy a02901cae7 wayland: fix wl_surface_set_buffer_scale usage
The wl_surface lives for the entire lifetime of the vo. It's only
neccesary to set the scale initially and when the output scaling changes
(the surface moves to a different output with a different scale or the
output itself changes it scale). All of the calls that were being made
in the egl/vulkan resize functions are not needed. vo_wlshm wasn't
correctly rescaling itself before this commit since it had no logic to
handle scale changes. This should all be shared, common code in the
surface/output listeners.
2021-06-27 10:58:59 -05:00
Dudemanguy 76bddaccd6 wayland: always be sure to initially try to render
A subtle regression from c26d833. On sway if mpv was set to be a
floating window in the config, set_buffer_scale would actually get
applied twice according to the wayland log. That meant a 1920x1080
window would appear as a 960x540 window if the scale of the wl_output
was set to 2. This only affected egl on sway (didn't occur on weston and
was too lazy to try anything else; probably they were fine). Since
wl->render is initially false, that meant that the very first run
through the render loop returns false. This probably caused something
weird to happen with the set_buffer_scale calls (the egl window gets
created and everything but mpv doesn't write to it just yet) which makes
the set_buffer_scale call happen an extra time. Since it was always
intended for mpv to initally render, this is worth fixing. Just chnage
wl->render to wl->hidden (again) and flip the bools around. That way,
the initial false value results in render == true and mpv tries to draw
on the first pass. This fixes the weird scaling behavior because
reasons.
2021-06-27 10:58:42 -05:00
Dudemanguy 573f696077 wayland: remove unused includes
Presentation time only lives in in wayland_common.
2021-06-27 10:20:05 -05:00
Dudemanguy a1c6762156 wayland: handle app id option less stupidly
Not sure what I was on when I wrote this. wayland-app-id is supposed to
default to "mpv". Just set that in the vo_sub_opts and don't do this
weird m_config_cache_write_opt thing. Also make the doc entry nicer.
2021-06-26 17:28:01 -05:00
Dudemanguy 488581912d wayland: reorganize wayland common code
Mostly a cosmetic change that (hopefully) makes things look better. Some
functions and structs that were previously being exported in the wayland
header were made static to the wayland_common.c file (these shouldn't be
accessed by anyone else).
2021-06-26 17:24:44 -05:00
Dudemanguy 76a53f9de3 stats.lua: add scaled resolution
Calculate the actual scaled size of the video from osd-dimensions and
display it on the stats page.
2021-06-25 17:54:36 +00:00
hooke007 5f76744c61 DOCS: fix typo on seekbarkeyframes 2021-06-24 14:34:33 +00:00
LaserEyess ee27629244 TOOLS/lua/autoload: load files even if current file is hidden
When the current file is hidden and `ignore_hidden` is true,
autoload will skip loading other files in the current directory. Make
sure that the current file is always counted for autoloading even if it
is hidden.
2021-06-24 13:13:53 +00:00
LaserEyess 28c53dbfa0 TOOLS/lua/autoload: add ignore_hidden option
In 8a7614a0fb files that start with a '.'
were blacklisted from autoload.lua. Since then
35e8710b86 was introduced and explicitly
whitelisted file extensions. With this change, there is no longer a
reason to blacklist all files starting with '.', because it is valid to
have a file called '.hidden.mkv', and there is no chance of hidden files
such as '.bashrc', '.DS_STORE', '.gitignore', etc. being autoloaded by
mpv.

This commit tries to keep the same behavior as before, which is to by
default not load hidden files, but allows the user to optionally allow
hidden files to be autoloaded.
2021-06-24 13:13:53 +00:00
Guido Cella 5e23e81485 player: fix property name
Commits 4d1ffec and 6e481d0 renamed sub-ass-style-override to
sub-ass-override. But in commit bd603c2, when renaming it in
quit-watch-later's backup_properties, which determines which properties
are saved by quit-watch-later/write-watch-later-config, it was
incorrectly renamed to sub-style-override instead, and thus never got
saved even if modified at runtime. Instead mpv attempted to save the
non-existing property "sub-style-override", but since no error is raised
when saving non-existing properties with quit-watch-later, no one
noticed it. This commit renames the saved property to the correct new
name "sub-ass-override" so that it does get saved.
2021-06-24 12:01:22 +03:00
Avi Halachmi (:avih) 5b40db385a lua: idle observers: ensure timers are up-to-date
This fixes two issues, both of which resulted from the timers-wait
period not being re-calculated after idle-observers were executed:

- If timers were added from an idle observer then they could fire long
  after they were due (only when/if the next mpv event arrives).

- Idle observers don't execute in zero time, and the wait period for
  the next timer was implicitly extended by the idle observers
  execution time (because it was calculated before the idle observers).

This commit ensures that if idle-observers were executed, then the
timers wait period is re-calculated, which solves both issues.
2021-06-23 23:47:08 +03:00
Avi Halachmi (:avih) f73814b180 lua: timers: don't block forever with slow callbacks
Previously, process_timers() kept going as long as there were due
timers, which could be for extended periods of time or even forever
if there were slow timer callbacks with either periodic timers or if
timers were added repeatedly.

This prevented dequeuing mpv events, and subsequently, among others,
prevented mpv from quitting until process_timers() completed.

For instance, this caused process_timers() to never return:

  function render() <longer than 1/60 s on a slow system> end
  mp.add_periodic_timer(1/60, render)

Similarly, it never returned if a timer callback always added a new
one-shot which was already due by the time the callback completed.

This commit ensures that process_timers() only executes callbacks which
were due when it started, so that timers which are added (or repeated)
during process_timers() will wait for the next iteration - after mpv
events are dequeued.

This has no performance impact under normal conditions (when callbacks
complete before the next timer is due).

Additionally, previously idle-observers were executed unconditionally
after the timers because indeed there was nothing due when (if...)
process_timers() completed. However, now process_timers() can return
even if there are due timers, so skip idle-observers on such case.
2021-06-23 23:47:08 +03:00
rcombs 11423acf30 sub: by default, don't render timestamps after video EOF
This fixes a long-standing apparent issue where mpv would display the last
frame with no subtitles at EOF. This is caused by sub rendering switching from
video timestamps to audio timestamps when the video ends, and audio streams
often running past the timestamp of the last video frame. However, authoring
tools (most notably Aegisub) don't tend to provide easy ways to add meaningful
subtitles after the end of the video, so this is rarely actually useful.
2021-06-23 16:10:29 -04:00
Guido Cella cb56c2f888 player: change cover-art-auto behavior
This makes cover-art-auto behave more like sub-auto and audio-file-auto:

- load cover art with a language, e.g. if playing foo.mp3, foo.en.jpg
will be loaded with lang=en
- load cover art containing the media filename with fuzzy and all, e.g.
'foo (large).jpg'
- make all/2 load all images in the directory, and make fuzzy/1 the
default

These are all uncommon use cases, but synchronizing the behavior of the
external file options simplifies the code.
2021-06-23 16:23:50 +00:00
Avi Halachmi (:avih) 0427fe97e1 js: idle-observers: minor performance improvement
The idle-observers block has at least 3 function calls, and it was
entered every time the script went into idle, however, we can save these
calls by checking first that there are indeed such observers.
2021-06-22 18:17:11 +03:00
Avi Halachmi (:avih) 76b1ac57a4 osc: seekbar hover/drag: display target chapter at the title
Fixes #8925
2021-06-22 18:12:29 +03:00
Guido Cella a17d79907a manpage: add article in fuzzy explanation 2021-06-21 15:37:18 +00:00
Guido Cella 9eb126a798 player: remove unnecessary check
Remove the check that the external filename is not the same as the
currently playing one, which prevents mpv from loading images again as
external cover art, but this isn't necessary because cover art is only
added when playing standalone audio. I had only added this check because
I would otherwise get a segfault only when compiling with gcc 10.2 with
optimize and changing position within a playlist of multiple images (and
this couldn't even be reproduced by Dudemanguy on the same gcc version),
but this was caused by the uninitialized lang variable which is now
fixed.
2021-06-21 15:36:30 +00:00
Guido Cella f70995cc9b player: fix segfault
Commit 029ff10 added a goto statement which skipped initializing the
`lang' variable. This could crash depending on compiler optimizations
and other factors: if the lang bstr pointer happened to end up NULL
(which is apparently the case with most compilers) then it's validly
empty, but if it pointed to a random and incorrect memory address then
it crashed.

The crash was observed when mpv was compiled using gcc 10.2 with
optimizations enabled, and affected some third party Windows builds.

This commit ensures the goto doesn't skip the initialization.

Thanks to votemp for figuring this out.

Fixes #8922.
2021-06-21 15:36:30 +00:00
Avi Halachmi (:avih) 48f3a26746 osc: ensure tick after any mouse-event
Previously tick() was ensured unconditionally only after mouse-move,
but there are other mouse-events which need re-rendering (tick), like
mouse-down (icons may get grayed-out) or mouse-up (icons may change).

For instance: mpv --pause --myclip.mkv

then move the mouse over the volume/mute OSC button, then - without
moving the mouse - press and release the left mouse button.

The osc was not re-rendered because it's paused and the mouse didn't
move, so the volume icon didn't get grayed-out when held down, and the
icon doesn't change on mouse-up (to reflect the new mute state).

Now both these changes are rendered correctly.
2021-06-20 17:37:47 +03:00