Commit Graph

522 Commits

Author SHA1 Message Date
Guido Cella 7ca14d646c console: use wl-paste on Wayland 2020-12-14 22:43:34 +00:00
Philip Sequeira df805cfc84 auto_profiles: fix compile_cond on lua 5.1
5.1's load() doesn't accept strings; loadstring must be used instead.

In 5.2, loadstring is deprecated and setfenv is gone.
2020-12-08 17:29:19 +00:00
Avi Halachmi (:avih) 0d5055fe93 lua/js: mp.get_mouse_pos: use the mouse-pos property
mp.get_mouse_pos() is undocumented and is no longer required - the
property can be used officially by any client now, however, osc.lua
uses it, and also some user scripts learnt to rely on it, so we keep
it - as a trivial wrapper around the new mouse-pos property.
2020-11-16 20:29:58 +02:00
Guido Cella e49404cba9 console: let type set the cursor position
This allows keybindings such as:

a script-message-to console type "seek :0 absolute" 6
% script-message-to console type "seek  absolute-percent" 6

The cursor position 0 isn't allowed because it has the weird effect of
filling the console with the text twice, leaving the cursor in the
middle.
Negative positions would put the cursor n characters before the end, and
positions greater than the text's length at the end. They seem to work
at first, but the console breaks when you move the cursor, so they
aren't allowed.
It seems that float values don't cause issues, but I'm using the
argument's floor anyway to be safe. Using >= 1 instead of > 0 ignores
values like 0.5.
2020-10-27 17:10:50 +00:00
Ricardo Constantino ad1ecd4350
ytdl_hook: if ytdl not found in config dirs, use ytdl_path as is 2020-10-27 15:42:39 +00:00
Ricardo Constantino 93f84b514a
ytdl_hook: support alternative youtube-dl path
Allows using a youtube-dl not in PATH or a compatible fork of
youtube-dl.
2020-10-27 15:42:39 +00:00
sfan5 cbbdb3fae4 stats: display hw pixel format too 2020-10-16 17:48:05 +02:00
wm4 5dcfe32ff2 ytdl_hook: sort subtitle list by language
The subtitle list is returned in randomized order, because a table (i.e.
JSON object) is used. To make the order stable across repeated
invocations, sort it by language.
2020-08-12 20:16:13 +02:00
wm4 4c72202eb1 auto_profiles: unapply conditional profiles if declared
Uses the mechanism introduced in the previous commit. The hope was to
make auto-profiles easier to use, and to get rid of the need for
manually created inverse profiles. Not sure if the end result is useful.
2020-08-07 19:41:56 +02:00
wm4 53ee1ae417 auto_profiles: register hooks for more synchronous profile application
The property observation mechanism is fairly asynchronous to the player
core, and Lua scripts also are (they run in a separate thread). This may
sometimes lead to profiles being applied when it's too load.

For example, you may want to change network options depending on the
input URL - but most of these options would have to be set before the
HTTP access is made. But it could happen that the profile, and thus the
option, was applied at an slightly but arbitrary later time.

This is generally not fixable. But for the most important use-cases,
such as applying changes before media opening or playback
initialization, we can use some of the defined hooks.

Hooks make it synchronous again, by allowing API users (such as scripts)
to block the core because it continues with loading.

For this we simply don't continue a given hook, until we receive an idle
event, and have applied all changes. The idle event is in general used
to wait for property change notifications to settle down. Some of this
relies on the subtle ways guarantees are (maybe) given. See commit
ba70b150fb for the messy details. I'm not quite sure whether it
actually works, because I can't be bothered to read and understand my
bullshit from half a year ago. Should provide at least some improvement,
though.
2020-08-05 23:28:24 +02:00
wm4 d0ab562b1f lua: make hook processing more flexible
This can now opt to not continue a hook after the hook callback returns.
This makes it easier for scripts, and may make it unnecessary to run
reentrant event loops etc. for scripts that want to wait before
continuing while still running the event loop.
2020-08-05 23:19:41 +02:00
wm4 13d354e46d auto_profiles: add this script
This is taken from a somewhat older proof-of-concept script. The basic
idea, and most of the implementation, is still the same. The way the
profiles are actually defined changed.

I still feel bad about this being a Lua script, and running user
expressions as Lua code in a vaguely defined environment, but I guess as
far as balance of effort/maintenance/results goes, this is fine.

It's a bit bloated (the Lua scripting state is at least 150KB or so in
total), so in order to enable this by default, I decided it should
unload itself by default if no auto-profiles are used. (And currently,
it does not actually rescan the profile list if a new config file is
loaded some time later, so the script would do nothing anyway if no auto
profiles were defined.)

This still requires defining inverse profiles for "unapplying" a
profile. Also this is still somewhat racy. Both will probably be
alleviated to some degree in the future.
2020-08-05 22:37:47 +02:00
Eva 359261c50c stats: fix crash when aspect ratio is unavailable
When switching between files it's possible that r["aspect"] returns nil, resulting in a crash.
2020-08-03 00:50:57 +03:00
Derek Guenther b238897614 ytdl_hook: fix typo in unexpected error message 2020-08-01 15:02:39 +03:00
sfan5 b67c7a23b8 stats: fix single invocation keybindings 2020-07-21 19:34:41 +02:00
wm4 1b03970d79 lua: windows got what users crave
It's got '\r's.

Fixes: #7733
2020-05-27 15:01:39 +02:00
Julian c7b94c03f1 stats: UP/DOWN scrolling on page 2 (frame stats)
Code contributed by @avih with only minor modifications to comments by
me.
Fixes #7727.
2020-05-17 20:11:50 +02:00
wm4 152b0e2a8c osc: fix hovering timestamp sticking around when moving mouse away
The OSC calls this "tooltip" (and although a general mechanism, there's
only one instance using it). One particular problem was that with the
default OSC layout, moving the mouse down and out of the window, the
tooltip stuck around, because the returned mouse position was the last
pixel row in the window, which still overlaps with the seek bar.

Instead of introducing mouse_in_window, you could check last_mouse_X for
nil, but I think this is clearer.

This returns (-1, -1) to the caller if the mouse is outside. Kind of
random, but works.
2020-05-16 13:45:16 +02:00
wm4 ccbb8b1c9b lua: restore change detection with legacy OSD function
mp.set_osd_ass() (which was undocumented, or in other words, was not
supposed to be used by external scripts) used to do change detection in
the mpv C code. If the resolution or payload did not change, it was not
re-rendered on the lower levels.

Apparently this made some people sad, so fix it. (But only after I told
them to fuck off.) (Well I didn't put it this way, but still.)
2020-05-01 00:59:57 +02:00
Avi Halachmi (:avih) 5ff215c4df stats.lua: don't disable terminal escape sequences on windows
When stats.lua is used without a video window then it uses the terminal.
On Windows, however, so far it disabled ansi escape sequences and used
plaintext unless ANSICON env is set.

It's unclear why it's disabled on windows, because at the time it was
added it only used bold by default and mpv ansi emulation on windows
already supported bold at that time.

We can guess that it was disabled because if the same config is used on
both linux and Windows, and it had complex escape sequences for
stats.lue, then it would be emulated incorrectly on Windows.

This shouldn't be an issue anymore, as the last two commits both enhance
the emulation to be quite complete (and graceful where it's not), and
also enable the much-more complete native VT terminal when possible
(Windows 10).

Just remove this windows exception at stats.lua.
2020-04-23 17:02:38 +03:00
LaserEyess 34e7d9c2f4 stats: move chapter/edition info below title
It is more consistent for editions/chapters to go below either
the title or filename. They are all descriptive strings about
the media itself and not file metadata like filesize.

Suggested by Argon-
2020-04-16 23:13:46 +02:00
LaserEyess c364879e9f stats: add edition information to page 1
Edition information is conditional based on there being more than
one edition present. It is printed on the same line as Chapters to
save vertical space.
2020-04-16 23:13:46 +02:00
Avi Halachmi (:avih) 530a0863b8 stats: support UP/DOWN to scroll at page 4 (perf)
Keys and lines-to-scroll are configurabe, and the scroll keys are only
bound on pages which support scrolling (currently only page 4) - also
during oneshot (like the page-switching keys).

Scroll offset is reset for all pages on any key - except scroll keys, so
that entering or switching to a page resets the scroll, as well as when
"re-entering" the same page or "re-activating" the stats oneshot view.

TODO: print_page(..) is highly associated with extending the oneshot
timer if required. The timer handling can probably move into print_page
and removed from all the places which boilerplate its management.
2020-04-11 16:04:46 +03:00
wm4 c2ee7bce4c console: reduce memory usage in default mode
This used 1 MB due to building the complete command and property list
when starting the script. These are needed only for auto-completion, so
build them only on demand. Since building them is fast enough, rebuild
them every time.

The key bindings table is not that much, but saves some KBs. Oddly, the
code to build it uses less memory than the table at runtime (???), so
build it at runtime as well.

Add 2 tactic collectgarbage() calls as well. This frees unused heap when
it is known that the script is going to be completely inactive until
re-enabled by the user.
2020-04-10 13:36:10 +02:00
wm4 73e565dc0f stats: fix crash if both plot_vsync_* options are disabled
In this case, init_buffers() was not called, and the unrelated cache
sample buffers were not initialized. It appears they are indeed
completely unrelated, so move their initialization away. Not sure what
exactly the purpose of calling init_buffers() is, maybe clearing old
data when displaying stats again. The new place for initializing the
cache sample buffers should achieve the same anyway.

Fixes: #7597
2020-04-09 15:03:17 +02:00
wm4 fd3caa264e stats: some more performance graphs
Add an infrastructure for collecting performance-related data, use it in
some places. Add rendering of them to stats.lua.

There were two main goals: minimal impact on the normal code and normal
playback. So all these stats_* function calls either happen only during
initialization, or return immediately if no stats collection is going
on. That's why it does this lazily adding of stats entries etc. (a first
iteration made each stats entry an API thing, instead of just a single
stats_ctx, but I thought that was getting too intrusive in the "normal"
code, even if everything gets worse inside of stats.c).

You could get most of this information from various profilers (including
the extremely primitive --dump-stats thing in mpv), but this makes it
easier to see the most important information at once (at least in
theory), partially because we know best about the context of various
things.

Not very happy with this. It's all pretty primitive and dumb. At this
point I just wanted to get over with it, without necessarily having to
revisit it later, but with having my stupid statistics.

Somehow the code feels terrible. There are a lot of meh decisions in
there that could be better or worse (but mostly could be better), and it
just sucks but it's also trivial and uninteresting and does the job. I
guess I hate programming. It's so tedious and the result is always shit.
Anyway, enjoy.
2020-04-09 00:33:38 +02:00
wm4 f9cc29ec91 stats: fix previous commit
The previous commit included a rendering error of the "Speed:" line,
caused by incorrect copy&paste.
2020-04-03 23:26:51 +02:00
wm4 516934b233 stats: move input speed to cache page, make it a graph
I think that makes more sense.

And also remove the graph from the total cache usage, since that wasn't
very interesting. So there's still a total of 2 graphs.
2020-04-03 14:54:32 +02:00
sfan5 c8e5a615e9 ytdl_hook: enable runtime changes of script options 2020-03-29 17:45:59 +02:00
wm4 37f441d61b lua: restore recent end-file event, and deprecate it
Lua changed behavior for this specific event. I considered the change
minor enough that it would not need to go through deprecation, but
someone hit it immediately and ask on the -dev channel.

It's probably better to restore the behavior. But mark it as deprecated,
since it's problematic (mismatch with the C API). Unfortunately, no
automatic warning is possible. (Or maybe it is, by playing sophisticated
Lua tricks such as setting a metatable and overriding indexing, but
let's not.)
2020-03-22 19:42:59 +01:00
wm4 9815887435 osc: avoid using a deprecated event
The new code is pretty much equivalent.
2020-03-21 19:32:50 +01:00
wm4 cb2b5553bf osc: fix updating message when paused
The message_timeout field was basically polled. But ever since the OSC
was changed to work more event based, this didn't quite work. It was
quite visible when switching subtitle or audio tracks while paused (and
with caching disabled, since the cache update triggered some extra
redrawing).

Fix by using a proper timer.

I noticed that changing tracks with the message call commented didn't
redraw properly either, but, uh, I guess the message is always triggered
anyway, and happens to take care of this.
2020-03-14 15:15:44 +01:00
wm4 7a76b577d8 command: extend osd-overlay command with bounds reporting
This is more or less a minimal hack to make _some_ text measurement
functionality available to scripts. Since libass does not support such a
thing, this simply uses the bounding box of the rendered text.

This is far from ideal. Problems include:
- using a bitmap bounding box
- additional memory waste and/or flushing caches
- dependency on window size
- odd small deviations with different window sizes (run osd-test.lua and
  resize the window after each timer update; the bounding boxes aren't
  adjusted in an overly useful way)
- inability to query the size _after_ actual rendering

But I guess it's a start. Since I'm aware that it's crap, add a threat
to the manpage that this may be changed/removed again. For now, I'm
interested whether anyone will have use for it in its current form, as
it's an often requested feature.
2020-03-06 18:20:11 +01:00
wm4 7e2bb7b439 osc: use default hr-seek when dragging progress bar to seek
The "seekbarkeyframes" option is now interpreted such if it's true, the
player default is used. Too lazy to make this a choice option or
whatever; the Lua option parser doesn't have support for that anyway.
Someone who cares can adjust this.
2020-02-28 17:17:42 +01:00
sfan5 57ecfb4da2 ytdl_hook: fix URL extraction for manifests 2020-02-23 12:04:55 +01:00
wm4 c68b813678 ytdl_hook: prefer "format" over "format_note" field for track titles
Much more verbose, but on the other hand format_note is useless for the
alphabetic site with fragmented DASH streams.
2020-02-21 22:23:17 +01:00
wm4 dc82921012 ytdl_hook: use "format" as fallback for "format_note" for stream titles
"format_note" normally contains a semi-informative description of the
format. But some extractors, confusingly, have it in the "format" field.
2020-02-21 16:38:17 +01:00
wm4 2b9b77fcf3 ytdl_hook: fix audio codec with some extractors
E.g. soundcloud. While it still worked, not having the audio codec was
pretty annoying.
2020-02-21 16:27:56 +01:00
wm4 c1f7b0c535 ytdl_hook: fix Lua escapes
This was obviously nonsense. In Lua 5.1 this appeared to work correctly,
but it really turned "\." into "." (making the pattern accept any
character). The proper way is using "%" for escaping.
2020-02-21 16:23:43 +01:00
wm4 605e1fb766 ytdl_hook, edl: add fps, samplerate codec parameters
Well, didn't help much in the case I was interested it.
2020-02-21 14:48:23 +01:00
wm4 6337c1cc14 ytdl_hook: make codec mapping more declarative 2020-02-21 14:29:55 +01:00
wm4 04118eefb8 ytdl_hook: remove some old playlist redirection hack
Should not be needed anymore. In fact, it's probably dangerous.
2020-02-21 14:19:01 +01:00
wm4 4c32468241 ytdl_hook: enable default selection via --ytdl-format with all_formats
In all_formats mode, we've ignored what --ytdl-format did so far, since
we've converted the full format list, instead of just the formats
selected by youtube-dl.

But we can easily restore --ytdl-format behavior: just mark the selected
tracks as default tracks.
2020-02-21 14:18:35 +01:00
wm4 daa3c11e1b ytdl_hook: add length parameter to delay-loaded tracks only once
This was done for each media type, so muxed tracks had it twice, which
logged a dumb warning. Move it out of the per-media type loop.
2020-02-21 12:06:18 +01:00
wm4 3d225ad275 ytdl_hook: remove bitrate estimation from file size
I think this is unnecessary, and at worst done by youtube-dl itself
(didn't check).
2020-02-21 11:57:57 +01:00
wm4 76aaf74d30 ytdl_hook: use tbr for all tracks if vbr/abr not available
vbr and abr are the video and audio bitrates. Sometimes there is a weird
mix of any of them available, but in these cases, it's not good to fall
back to tbr if a specific track has no vbr/abr.

For example, the alphabetic site provides tbr only for the muxed
fallback stream, but using tbr would make the primitive mpv hls_bitrate
selection pick the compatibility stream for audio, because it appears to
have a higher bitrate than the other audio-only streams (because the
bitrate includes video). So we must not use tbr in this case.

On the other hand, formats coming from youtube-dl HLS master playlist
use will only have tbr set.

So as a heuristic, use the tbr only if it's the only bitrate available
in any track entry.
2020-02-21 11:57:21 +01:00
wm4 6d09a042e6 ytdl_hook: replace skip_muxed with force_all_formats option
I don't think the skip_muxed option was overlay useful. While it was
nice to filter out the low quality muxed versions (as it happens on the
alphabetic site, I suspect it's compatibility stuff), it's not really
necessary, and just makes for another tricky and rarely used
configuration option. (This was different before muxed tracks were also
delay-loaded, and including the muxed versions slowed down loading.)

Add the force_all_formats option instead, which handles the HLS case.
Set it to true because they are also delay-loaded now, and don't slow
down startup as much.
2020-02-21 11:50:58 +01:00
wm4 390e995b6a ytdl_hook: delay-load interleaved files
(Or if it's about HLS, just "muxed"/multiplexed streams.)

This only affects all_formats=yes,skip_muxed=no modes.
2020-02-21 00:20:22 +01:00
wm4 f321d8da99 ytdl_hook: signal duration in all_formats mode
If all streams were delay loaded, there was actually no duration present
at all in the EDL metadata. So the length was considered unknown by the
player frontend.
2020-02-20 14:55:14 +01:00
wm4 89203cc994 ytdl_hook: attempt to filter out muxed streams if all_formats is used
See manpage additions. We would have to extend delay_open to support
multiple sub-tracks (for audio and video), and we'd still don't know (?)
whether it might contain more than one stream each (thinking of HLS
master streams). And if it's a true interleaved file (such as a "normal"
mp4 file provided as fallback for more primitive players), we'd either
have to signal such "bundled" tracks, or waste bandwidth.

This restructures a lot. The if/else tree in add_single_video for format
selection was a bit annoying, so it's split into separate if blocks,
where it checks each time whether a URL was determined yet.
2020-02-20 14:54:09 +01:00