Commit Graph

2875 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
sfan5 6ebac1f794 player: allow vo to be switched at runtime 2020-11-27 17:28:59 +01:00
Avi Halachmi (:avih) 24d6961833 command: mouse: generate MOUSE_{ENTER,LEAVE} if required
Previously the mouse command never ended up in enter/leave keypresses
for the default section even when logically required, because input.c
does not know the area of the default section and relies on something
feeding it ENTER/LEAVE presses - which the VO typically does but the
mouse command didn't.

Now the mouse command feeds it ENTER/LEAVE if required.

It's possible to handle it differently and more consistently by:
1. reverting this commit.
2. Updating the default section area whenever the osd dimensions change.
3. Always ignore MOUSE_ENTER keys because the position is not known yet
   (but MOSE_MOVE typically follows right away).
4. On mouse move: first generate ENTER/LEAVE if required.

That would guarantee consistency between mouse position and enter/leave
events but could be more sensitive to manage (the default section has
"infinite" area which is used to capture any event outside of specific
section areas), while this commit keeps consistency same as before and
depending on correct external feeding - which we now do better, even if
still not optimally (like before, it's still technically possible that
a script recieves MOUSE_ENTER and then reads the position before it got
updated after the ENTER).
2020-11-16 20:29:58 +02:00
Avi Halachmi (:avih) 58004ea2ef command: mouse-pos property: add field "hover"
Add a third field: "hover", which is updated from input.c after input
keys MP_KEY_MOUSE_LEAVE and MP_KEY_MOUSE_ENTER - which are typically
sent by the VO.

It's part of mouse-pos and not a new property because it's highly tied
to mouse-pos - it makes x/y invalid while the cursor doesn't hover the
window.

Unike mouse-move, no dummy command was generated, so we add dummy
command in order for observer notification to work even while nothing
is bound.

Like mouse-pos, clients could not detect whether the mouse pointer
hovers the window because the OSC force-binds the MOUSE_LEAVE key, and
now they can using the hover field.

The lua mp.get_mouse_pos() wrapper still returns only x, y because
that's what osc.lua needs. Other clients can simply read the property.
2020-11-16 20:29:58 +02: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
Avi Halachmi (:avih) a768667956 command: new property: mouse-pos
This is a read-only MPV_NODE value with integer fields: x, y.
The values are unmodified from mp_input_get_mouse_pos(...).

Observer notification of this property is tied to the INPUT_PROCESSED
event, which fires after mouse move even if no command is bound
(dummy commands are generated if nothing is bound to ensure that
mp_input_get_mouse_pos returns the latest values - see ac927e39 ).

This allows clients such as JSON IPC to observe mouse position even
while the OSC is enabled - the OSC force-binds mouse move for most
of the window area, making it impossible for other clients to bind
mouse move without breaking the OSC.
2020-11-16 20:29:58 +02:00
Avi Halachmi (:avih) 799d3d4557 command: add internal INPUT_PROCESSED event
Fires after a non-empty input queue was processed.

Currently yet unused, but the next commit will use it.
2020-11-16 20:29:58 +02:00
Avi Halachmi (:avih) 932c1ada0f js: report scripts CPU/memory usage statistics
This can be viewed at page 4 of the internal stats display (i or I).

CPU time report is the same as at lua.c, but untested - doesn't seem
to work on windows - also not for lua.

TL;DR: Set env MPV_LEAK_REPORT=1 to enable js memory reporting stats.
       This also almost doubles the memory usage by js scripts.

For memory reporting, we don't have enough info by default, because
even when using a custom allocator, mujs doesn't report the old size
(on free or realloc) because it doesn't track this value, and as
a result we can't track the overall size.

Our option are either to track the size of each allocation on our own,
or use talloc which tracks this value.

However, using talloc for mujs allocations adds a considerable
overhead, and almost doubles(!) the overall memory used, because each
individual allocation includes a considerable talloc header, and mujs
does many small allocations.

So our solution is that by default we behave like previously - not
using a custom allocator with mujs, and stats does not display memory
usage for js scripts.

However, if the env var MPV_LEAK_REPORT is set to 1, then we use
a custom allocator with talloc and track/report memory usage.

We can't switch allocator at runtime, so an mpv instance either tracks
or doesn't track js scripts memory usage, according to the env var.
(we could use a property and apply it whenever a new script starts,
so that it could change for newly launched scripts, but we don't).
2020-11-15 20:36:04 +02:00
Ben Kerman f85de9e6d6 command: make subtitle time properties observable 2020-11-11 18:21:54 +00:00
sfan5 73be20143e player: fix external cover file prioritization
Array order was ignored entirely instead of being used as intended.
Fixes: c07089a250
2020-10-28 18:15:34 +01: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 c07089a250 player: reorder list of external cover files for optimal results 2020-10-25 22:35:53 +01:00
Vladimir Panteleev a92466c289 command: add delete-watch-later-config
This introduces the delete-watch-later-config command, to complement
write-watch-later-config. This is an alternative to #8141.

The general problem that this change is attempting to help solve has
been described in #336, #3169 and #6574. Though persistent playback
position of a single file is generally a solved problem, this is not
the case for playlists, as described in #8138.

The motivation is facilitating intermittent playback of very large
playlists, consisting of hundreds of entries each many hours
long. Though the current "watch later" mechanism works well - provided
that the files each occur only once in that playlist, and are played
only via that playlist - the biggest issue is that the position is
lost completely should mpv exit uncleanly (e.g. due to a power
failure).  Existing workarounds (in the form of Lua scripts which call
write-watch-later-config periodically) fail in the playlist case, due
to the mechanism used by mpv to determine where within a playlist to
resume playback from.

The missing puzzle piece needed to allow scripts to implement a
complete solution to this problem is simply a way to clean up the
watch-later configuration that the script asked mpv to write using
write-watch-later-config. With that in place, scripts can then
register an end-file event listener, check the stop playback reason,
and in the "eof" and "stop" case, invoke delete-watch-later-config to
delete any saved positions written by write-watch-later-config. The
script can then proceed to immediately write a new one when the next
file is loaded, which altogether allows mpv to resume from the correct
playlist and file position upon next startup.

Because events are delivered and executed asynchronously,
delete-watch-later-config takes an optional filename argument, to
allow scripts to clear watch-later configuration for files after mpv
had already moved on from playing them and proceeded to another file.

A Lua script which makes use of this change can be found here:
https://gist.github.com/CyberShadow/2f71a97fb85ed42146f6d9f522bc34ef
(A modification of the one written by @Hakkin, in that this one takes
advantage of the new command, and also saves the state immediately
when a new file is loaded.)
2020-10-22 19:53:35 +00:00
sfan5 cbbdb3fae4 stats: display hw pixel format too 2020-10-16 17:48:05 +02:00
sfan5 3d9d041a11 command: expose underlying pixfmt for hwdec 2020-10-16 17:48:05 +02:00
wm4 6de25997a1 player: fix another nightmarish corner case
Pretty much fuck this shit.
2020-10-08 00:36:41 +02:00
wm4 39f4fd0dc7 screenshot: add --screenshot-sw option
Probably worthless. As usual, the manpage dumps all the subtle
differences due to implementation details on the user.
2020-10-05 00:16:46 +02:00
wm4 e1536193cb player: cosmetically change around some code
Is this better?
2020-09-28 00:14:54 +02:00
wm4 55d7f9ded1 player: add automatic loading of external cover art files
Picks up files like "cover.jpg". It's made part of normal external file
loading, so I'm adding 3 new options that are direct equivalents for the
options that control loading of external subtitle and audio files. Even
though I bet nobody wants them and they just increase confusion... I
guess the world is actually hell, so this outcome should be fine.

It prefers non-specific external files like "cover.jpg" over embedded
cover art. Not sure if that's wanted or unwanted.

There's some pain over explicitly marking such files as external
pictures. This is basically an optimization: in most cases, a heuristic
would treat an image file loaded with --external-file the same (it's a
heuristic because ffmpeg can't tell us whether something is an image or
a video). However, even with this heuristic, it would decode the cover
art picture again on each seek, which would essentially slow down
seeking in audio files. This bothered me greatly, which is why I'm
adding these additional options at all, and bothered with the previous
commit.

Fixes: #3056
2020-09-28 00:12:52 +02:00
wm4 102a4a8b06 player: let frontend decide whether to use cover-art mode
Essentially, this lets video.c decide whether to consider a video track
cover art, instead of having the decoder wrapper use the lower level
sh_stream flag.

Some pain because of the dumb threading shit. Moving the code further
down to make some of it part of the lock should not change behavior,
although it could (framedrop nonsense).

This commit should not change actual behavior, and is only preparation
for the following commit.
2020-09-28 00:04:21 +02:00
wm4 9ba90b4f6f player: add pause state to playback start message
Now the player tells you that audio or video are playing while paused,
or something.
2020-09-21 19:36:25 +02:00
sfan5 3054bcc62c options: simplify --android-surface-size handling 2020-09-20 12:04:25 +02:00
wm4 9806e9f82b command, demux: make drop-buffers reset state even harder
Leave nothing left when it's executed.
2020-09-17 15:34:40 +02:00
wnoun 49f5c9b482 command: add property track-list/N/main-selection 2020-09-12 13:03:13 +02:00
wm4 eed8b6d47b player: fix inconsistent AO pause state in certain situations
Pause can be changed during a file change, such as with for example
--reset-on-next-file=pause, or in hooks, or by being quick, and in this
case the AO's pause state was not updated correctly. mpctx->ao_chain is
only set if playback is fully initialized, while the AO itself in
mpctx->ao can be reused across files.

Fix this by always running set_pause_state() if the pause option is
changed. Could cause new bugs since running this used to be explicitly
avoided outside of the loaded state. The handling of time_frame is
potentially worrisome.

Regression due to recent audio refactor; before that, the AO didn't have
a separate/persistent pause state.

Fixes: #8079
2020-09-12 00:13:24 +02:00
wm4 98f9d50b30 player: some minor code golf 2020-09-10 23:47:59 +02:00
wm4 09d3a4d39d player: clamp relative seek base time to nominal duration
Since b74c09efbf, audio-only files let you seek to arbitrary points
beyond the end of the file (but still displayed the time clamped to the
nominal file duration). This was confusing and just not wanted. The
reason is probably that the commit removed setting the audio PTS for
data before the seek target, so if you seek past the end of the file,
the audio PTS is never set. This in turn means the logic to determine
the current playback time has no PTS at all, and thus falls back to the
seek PTS.

This happened in the past for other reasons (like efe43d768f). I have
enough of this, so I'm just changing the code to clamp the seek
timestamp to a "known" range. Do this when seeking ends, because in the
fallback case, the playback time shouldn't be stuck at e.g. "end +
seek_argument". Also do it when initiating a new seek (mp_seek), because
if the previous seek hasn't finished yet, it shouldn't add them up and
allow it to go "out of range" either. The latter is especially relevant
for hr-seeks.

Doing this clamping is problematic because the duration is a possibly
invalid value from the demuxer, or just missing. Especially with
timestamp resets, fun sometimes happens, and in these situations it
might be better not to clamp.

One could argue you should just use the last audio timestamp returned by
the decoder or demuxer (even if that directly conflicts with --end), but
that sounds even more hairy.

In summary: what a dumb waste of time, what the fuck.
2020-09-10 23:24:35 +02:00
Guido Cella 9b9ce74afa command: add read-only focused property
Add a property that returns whether the window is focused, currently
only for X11 and Wayland.

My use cause for this is having an equivalent of pause-when-minimize.lua
for tiling window managers: make mpv play only while it's in the current
workspace or is focused (I'm fine with either one but prefer focus).
On X I do this by observing display-names, which is empty when the
rectangles of the display and mpv don't intersect, but on Wayland its
value doesn't change when mpv leaves the current workspace (and the same
check doesn't work since the geometries still intersect).

This could later be made writable as requested in #6252.

Note that on Wayland se shouldn't consider an unactivated window with
keyboard input focused.

The wlroots compositors I tested set activated after changing the
keyboard focus, so if you set wl->focused only in
keyboard_handle_enter() and keyboard_handle_leave() to avoid adding the
"has_keyboard_input" member, focused isn't set to true when first
opening mpv until you focus another window and focus mpv again.

Conversely, if that order can't be assumed for all compositors, we
should toggle wl->focused when necessary in keyboard_handle_enter() and
keyboard_handle_leave() as well as in handle_toplevel_config().
2020-09-08 20:09:17 +02:00
wm4 b5c225382e encode: propagate errors to exit status properly
Don't just let mpv CLI return 0 (success) as exit status if encoding
failed somehow.
2020-09-03 15:44:35 +02:00
wm4 4b3500dd14 client API: inactivate the opengl_cb API
The render API replaced the opengl_cb API over 2 years ago. Since then,
the opengl_cb API was emulated on top of the render API. While it would
probably be reasonable to emulate these APIs until they're removed in an
eventual libmpv 2.0 bump, I have some non-technical reasons to disable
the API now.

The API stubs remain; they're needed for formal ABI compatibility.
2020-09-03 14:52:11 +02:00
wm4 80bf6b26ba encode: disable unsupported media types automatically
If you encode to e.g. an audio-only format, then video is disabled
automatically. This also takes care of the very cryptic error message.
It says "[vo/lavc] codec for video not found". Sort of true, but
obscures the real problem if it's e.g. an audio-only format.
2020-09-03 14:13:17 +02:00
wm4 2761f37fe4 encode: remove early EOF failure handling
I don't see the point of this. Not doing it may defer an error to later.
That's OK? For now, it seems better to reduce the encoding internal API.
If someone can demonstrate that this is needed, I might reimplement it
in a different way.
2020-09-03 12:29:12 +02:00
wm4 b9baa1598a audio: slightly simplify audio_start_ao()
Get rid of an indirection; no behavior change.
2020-09-03 12:22:20 +02:00
wm4 177a88f676 audio: reduce excessive logging of delayed audio start
Since this is a messy and fragile mechanism, I want it logged (even if
it's somewhat in conflict with the verbose logging policy). On the other
hand, it's unconditionally logged on every playloop iteration. So add
some nonsense to log it only on progress.
2020-09-03 12:18:42 +02:00
wm4 2f30d5c060 audio: do not show audio draining message when it does not make sense
Just for the redundant message. The function which is called here,
ao_drain(), does not care in which state it is called, and already
handled this gracefully.
2020-09-01 21:28:13 +02:00
wm4 50c998afab audio: do not wake up player when waiting for audio state and paused
Bullshit.
2020-09-01 21:28:13 +02:00
Leo Izen cdc5932859 player/playloop.c: reorder included headers per contribute.md
This commit sorts the included headers alphabetically and puts
them in sections, as described by DOCS/contribute.md.
2020-08-31 17:01:22 -04:00
wm4 b74c09efbf audio: refactor how data is passed to AO
This replaces the two buffers (ao_chain.ao_buffer in the core, and
buffer_state.buffers in the AO) with a single queue. Instead of having a
byte based buffer, the queue is simply a list of audio frames, as output
by the decoder. This should make dataflow simpler and reduce copying.

It also attempts to simplify fill_audio_out_buffers(), the function I
always hated most, because it's full of subtle and buggy logic.

Unfortunately, I got assaulted by corner cases, dumb features (attempt
at seamless looping, really?), and other crap, so it got pretty
complicated again. fill_audio_out_buffers() is still full of subtle and
buggy logic. Maybe it got worse. On the other hand, maybe there really
is some progress. Who knows.

Originally, the data flow parts was meant to be in f_output_chain, but
due to tricky interactions with the playloop code, it's now in the dummy
filter in audio.c.

At least this improves the way the audio PTS is passed to the encoder in
encoding mode. Now it attempts to pass frames directly, along with the
pts, which should minimize timestamp problems. But to be honest, encoder
mode is one big kludge that shouldn't exist in this way.

This commit should be considered pre-alpha code. There are lots of bugs
still hiding.
2020-08-29 13:12:32 +02:00
wm4 ab6dbf0a29 player: fix video paused condition on VO creation
Doesn't take paused_for_cache into account. For consistency; unlikely to
matter at all in practice.
2020-08-27 11:55:20 +02:00
wm4 2a23105c1b player: fix swapped debug output
Such failure.
2020-08-27 11:55:20 +02:00
wm4 c9c01a07f8 audio: remove delay debug logging
Some absurd useless stuff.
2020-08-23 11:49:11 +02:00
wm4 c06577e291 player: do not loop if there's nothing to loop
This can happen if a file contains headers only, or if decoding of all
data failed, and such. Interestingly, it also happened when doing "mpv
--loop emptyfile.png", because demux_mf still detects file formats by
file extension.

In this situation, the player burned a lot of CPU by restarting playback
after doing nothing. Although such "degenerate" behavior can't be
avoided in all situations (what if you loop a file with 1 audio
sample?), detecting this seems to make sense.

For now, this actually decrements the loop count by 1, and then errors
out with a warning. Works for --loop and --ab-loop, while
--loop-playlist already avoids this situation with an existing
mechanism.
2020-08-22 20:43:15 +02:00
rcombs c9474dc9ed player: add --subs-with-matching-audio option
This allows users to control whether full dialogue subtitles are displayed
with an audio track already in their preferred subtitle language.

Additionally, this improves handling for the forced flag, automatically
selecting between forced and unforced subtitle streams based on the user's
settings and the selected audio.
2020-08-19 23:44:54 -05:00
Avi Halachmi (:avih) 557e9d9531 win32: scripting utils.get_env_list(): use UTF-8
lua/js utils.get_env_list() uses `environ' which was ANSI, thus
it broke any unicode names/values.

mpv already has an internal utf8_environ for win32, but it's used
only at the getenv(..) wrapper and not exposed in itself, and also it
has lazy initialization - on first getenv() call.

Now `environ' maps to a function which ensures initialization while
keeping it an l-value (like posix expects).

The cost of this fuglyness is that files should include osdep/io.h
(which now declares environ as extern) rather than declaring it
themselves, or else the build will break on mingw.
2020-08-16 12:24:19 +03:00
wm4 7f67c5250a lua: pass strings with embedded zeros as byte arrays
This was a vague idea how to handle passing byte arrays from Lua to the
mpv command interface in a somewhat reasonable way. The idea was
cancelled, but leave the Lua part of it, since it might get useful
later, and prevents passing (and silently cutting off) such byte
strings.

Barely tested, let's say not tested at all.
2020-08-16 02:57:26 +02:00
wm4 e27c523a10 command: extend subprocess command stdin, change behavior
Make it possible to feed a string to stdin of a subprocess. Out of
laziness, it can't be an arbitrary byte string. (Would require adding an
option type that takes in a Lua byte string.)

Do not set stdin of a subprocess to fd 0 (i.e. mpv's stdin) anymore,
because it makes things more consistent. Enabling stdin didn't make too
much sense in the first place, so this behavior change seems
justifiable.

win32 support missing.

Fixes: #8003
2020-08-16 02:54:44 +02:00
wm4 112d2a2c50 command: export alpha type in format properties 2020-08-15 12:05:11 +02:00