Commit Graph

49025 Commits

Author SHA1 Message Date
Chris Varenhorst 4989ccbe7a docs: fix leftover reference to the now defunct --video-sync-adrop-size option 2021-06-04 16:42:45 +00:00
Retusthese fd8c673cfc ytdl_hook: improve handling of json parsing errors
This moves the JSON parsing above the main youtube-dl error-handling
block and integrates parsing errors into that block. Now, if a parsing
error occurs, youtube-dl's stderr will be logged as it is with other
errors. This also catches errors that cause youtube-dl to output
"null", which would previously be mishandled as a parsing error and
crash ytdl_hook when it attempted to concatenate the error string from
parse_json.
2021-05-29 19:54:03 +03:00
Dudemanguy d7f3d1fff7 wayland: refactor dispatching events
This was originally just a bugfix for a race condition, but the scope
expanded a bit. Currently, the wayland code does a prepare_read ->
dispatch_pending -> display_flush -> read_events -> dispatch_pending
routine that's basically straight from the wayland client API
documentation. This essentially just queues up all the wayland events
mpv has and dispatches them to the compositor. We do this for blocking
purposes on every frame we render. A very similar thing is done for
wait_events from the VO.

This code can pretty easily be unified and split off into a separate
function, vo_wayland_dispatch_events. vo_wayland_wait_frame will call
this function in a while loop (which will break either on timeout or if
we receive frame callback from the compositor). wait_events needs to
just check this in case we get some state change on the wakeup_pipe
(i.e. waking up from the paused state).

As for the actual bugfix part of this, it's a slight regression from
c26d833. The toplevel config event always forced a redraw when a surface
became activated again. This is for something like displaying cover art
on a music file. If the window was originally out of view and then later
brought back into focus, no picture would be rendered (i.e. the window
is just black). That's because something like cover art is just 1 frame
and the VO stops doing any other additional rendering. If you miss that
1 frame, nothing would show up ever again. The fix in this case is to
always just force a redraw when the mpv window comes back into view.

Well with the aforementioned commit, we stopped doing
wl_display_roundtrip calls on every frame. That means we no longer do
roundtrip blocking calls. We just be sure to queue up all of the events
we have and then dispatch them. Because wayland is fundamentally an
asynchronous protocol, there's no guarantee what order these events
would be processed in. This meant that on occasion, a
vo_wayland_wait_frame call (this could occur multiple times depending on
the exact situation) would occur before the compositor would send back
frame callback. That would result in the aforementioned bug of having
just a black window. The fix, in this case, is to just do a
vo_wayland_wait_frame call directly before we force the VO to do a
redraw. Note that merely dispatching events isn't enough because we
specifically need to wait for the compositor to give us frame callback
before doing a new render.

P.S. fix a typo too.
2021-05-28 16:11:01 +00:00
Guido Cella 151b039879 manpage: mention cover-art-auto
--cover-art-auto affects rescan-external-files, and --autoload-files
affects cover art.
2021-05-28 16:10:48 +00:00
Guilherme ce0eb9b1e1 README: fix link to feature-request issues 2021-05-28 16:16:40 +02:00
Guido Cella 029ff1049b player: load cover art with the media filename
Closes #8666.
2021-05-27 18:19:16 +00:00
Avi Halachmi (:avih) 89684976ac win32: support the property 'focused'
And also change the existing WM_KILLFOCUS handler to return 0 instead
of 'break' (which later calls DefWindowProcW), as MSDN says we should
do for WM_{KILL,SET}FOCUS.

It seems that the 'focused' property is now supported by all main VOs:
x11, macOS, wayland, Windows.

TCT/sixel/caca probably don't support it, and unknown with SDL.

Fixes #8868
2021-05-27 13:49:07 +03:00
Retusthese 6abb7e385f osc: re-initialize when chapter list changes
When the OSC initializes, it checks whether the current video has
chapters, and if it does not, it disables its chapter functionality
(chapter buttons are grayed out and unusable, chapter indicators don't
show on the seek bar). If another script changed the chapter list
after the video has loaded, those changes would be ignored by the OSC
until some other event causes it to re-initialize, because it did not
observe the chapter list property. This is fixed by adding
observation of chapter-list alongside the other properties that
trigger re-initialization.
2021-05-27 09:12:38 +03:00
TheAMM c68b9424d6 recorder: fix codec_tag / codec_id confusion 2021-05-26 17:57:24 +02:00
TheAMM 643c699f26 recorder: clear codec_tag if no target format support
Avoiding blindly copying the codec_tag between different formats allows
us to mux packets from, say, mpegts streams to matroska, making the
recorder (dump-cache) much more usable as unsupported codec_tags can
make the muxer reject the streams.
2021-05-26 17:36:22 +02:00
Niklas Haas ec0006bfa1 af_scaletempo2: use gcc vectors to speed up inner loop
This brings my scaletempo2 benchmark down from ~22s to ~7s on my machine
(-march=native), and down to ~11s with a generic compile.

Guarded behind an appropriate #ifdef to avoid being ableist against
people who have the clinical need to run obscure platforms.

Closes #8848
2021-05-26 17:35:55 +02:00
Niklas Haas 353cccfa8c vo_gpu: replace --icc-contrast by --icc-force-contrast
Not only does this have semantics that make far more sense, it also has
a default that makes far more sense. (Equivalent to the old
`icc-contrast=inf`)

This removes the weird 1000:1 contrast default assumption which
especially broke perceptual profiles and also screws things up for
OLED/CRT/etc.

Should probably close some issues but I honestly can't be bothered to
figure out which of the thousands colorimetry-related issues are
affected.
2021-05-26 17:35:29 +02:00
Dudemanguy c26d83348b wayland: shuffle around the render loop again
Take two. f4e89dd went wrong by moving vo_wayland_wait_frame before
start_frame was called. Whether or not this matters depends on the
compositor, but some weird things can happen. Basically, it's a
scheduling issue. vo_wayland_wait_frame queues all events and sends them
to the server to process (with no blocking if presentation time is
available). If mpv changes state while rendering (and this function is
called before every frame is drawn), then that event also gets
dispatched and sent to the compositor. This, in some cases, can cause
some funny behavior because the next frame gets attached to the surface
while the old buffer is getting released. It's safer to call this
function after the swap already happens and well before mpv calls its
next draw. There's no weird scheduling of events, and the compositor log
is more normal.

The second part of this is to fix some stuttering issues. This is mostly
just conjecture, but probably what was happening was this thing called
"composition". The easiest way to see this is to play a video on the
default audio sync mode (probably easiest to see on a typical 23.976
video). Have that in a window and float it over firefox (floating
windows are bloat on a tiling wm anyway). Then in firefox, do some short
bursts of smooth scrolling (likely uses egl). Some stutter in video
rendering could be observed, particularly in panning shots.

Compositors are supposed to prevent tearing so what likely was happening
was that the compositor was simply holding the buffer a wee bit longer
to make sure it happened in sync with the smooth scrolling. Because the
mpv code waits precisely on presentation time, the loop would timeout on
occasion instead of receiving the frame callback. This would then lead
to a skipped frame when rendering and thus causing stuttering.

The fix is simple: just only count consecutive timeouts as not receiving
frame callback. If a compositor holds the mpv buffer slightly longer to
avoid tearing, then we will definitely receive frame callback on the
next round of the render loop. This logic also appears to be sound for
plasma (funfact: Plasma always returns frame callback even when the
window is hidden. Not sure what's up with that, but luckily it doesn't
matter to us.), so get rid of the goofy 1/vblank_time thing and just
keep it a simple > 1 check.
2021-05-24 19:20:31 +00:00
Dudemanguy 193814497b wayland: send VO_EVENT_DPI on output event as well
The display scaling might change here, so we need to signal mpv's core.
2021-05-23 16:59:30 -05:00
Dudemanguy cbd87ddb93 command: add a missing comma to MP_EVENT_WIN_STATE
In my defense, it still compiled.
2021-05-23 16:47:25 -05:00
Niklas Haas 6c1dd02f32 vo_gpu: fix extreme clipping with --gamut-clipping for HDR outputs
Checking against 1.0 is wrong for this code, because it's in an absolute
luminance scale relative to reference white. We should be normalizing
this by `dst.sig_peak`.
2021-05-22 21:18:51 +02:00
Dudemanguy f4e89dde36 wayland: simplify render loop
This is actually a very nice simplification that should have been
thought of years ago (sue me). In a nutshell, the story with the
wayland code is that the frame callback and swap buffer behavior doesn't
fit very well with mpv's rendering loop. It's been refactored/changed
quite a few times over the years and works well enough but things could
be better. The current iteration works with an external swapchain to
check if we have frame callback before deciding whether or not to
render. This logic was implemented in both egl and vulkan.

This does have its warts however. There's some hidden state detection
logic which works but is kind of ugly. Since wayland doesn't allow
clients to know if they are actually visible (questionable but
whatever), you can just reasonably assume that if a bunch of callbacks
are missed in a row, you're probably not visible. That's fine, but it is
indeed less than ideal since the threshold is basically entirely
arbitrary and mpv does do a few wasteful renders before it decides that
the window is actually hidden.

The biggest urk in the vo_wayland_wait_frame is the use of
wl_display_roundtrip. Wayland developers would probably be offended by
the way mpv abuses that function, but essentially it was a way to have
semi-blocking behavior needed for display-resample to work. Since the
swap interval must be 0 on wayland (otherwise it will block the entire
player's rendering loop), we need some other way to wait on vsync. The
idea here was to dispatch and poll a bunch of wayland events, wait (with
a timeout) until we get frame callback, and then wait for the compositor
to process it. That pretty much perfectly waits on vsync and lets us
keep all the good timings and all that jazz that we want for mpv. The
problem is that wl_display_roundtrip is conceptually a bad function. It
can internally call wl_display_dispatch which in certain instances,
empty event queue, will block forever. Now strictly speaking, this
probably will never, ever happen (once I was able to to trigger it by
hardcoding an error into a compositor), but ideally
vo_wayland_wait_frame should never infinitely block and stall the
player. Unfortunately, removing that function always lead to problems
with timings and unsteady vsync intervals so it survived many refactors.

Until now, of course. In wayland, the ideal is to never do wasteful
rendering (i.e. don't render if the window isn't visible). Instead of
wrestling around with hidden states and possible missed vblanks, let's
rearrange the wayland rendering logic so we only ever draw a frame when
the frame callback is returned to use (within a reasonable timeout to
avoid blocking forever).

This slight rearrangement of the wait allows for several simplifications
to be made. Namely, wl_display_roundtrip stops being needed. Instead, we
can rely entirely on totally nonblocking calls (dispatch_pending, flush,
and so on). We still need to poll the fd here to actually get the frame
callback event from the compositor, but there's no longer any reason to
do extra waiting. As soon as we get the callback, we immediately draw.
This works quite well and has stable vsync (display-resample and audio).
Additionally, all of the logic about hidden states is no longer needed.
If vo_wayland_wait_frame times out, it's okay to assume immediately that
the window is not visible and skip rendering.

Unfortunately, there's one limitation on this new approach. It will only
work correctly if the compositor implements presentation time. That
means a reduced version of the old way still has to be carried around in
vo_wayland_wait_frame. So if the compositor has no presentation time,
then we are forced to use wl_display_roundtrip and juggle some funny
assumptions about whether or not the window is hidden or not. Plasma is
the only real notable compositor without presentation time at this stage
so perhaps this "legacy" mechanism could be removed in the future.
2021-05-22 00:59:56 +00:00
Zsolt Vadasz 83b4bc622a player/command: add secondary-sub-text property 2021-05-19 15:57:01 +00:00
Zsolt Vadasz 62f225ef9d sub/osd: hide secondary subtitles if secondary-sub-visibility is false 2021-05-19 15:56:43 +00:00
Niklas Haas da0c1b8404 vo_gpu: hwdec_vaapi: silence errors while probing
Silences warnings related to DRM format modifiers that can show up while
probing formats.
2021-05-19 04:06:52 +02:00
Dudemanguy 8fc8df3d39 stream_lavf: remove uninitialized http_like array
Serves no purpose and can be a fatal error on certain compiler settings.
Just move the other http_like up here instead.
2021-05-18 13:25:06 -05:00
der richter 9fbe000451 osxbundle: fix slow and wasteful memory allocation
when using the bundle with activated big enough cache, very slow and
wasteful memory allocations lead to jittery playback and lot of dropped
frames. the cache had to have a certain size so it would constantly
allocate new memory to reproduce this. this never happens when started
from the terminal.

the source of the problem is a different malloc allocation policy,
MALLOC_NANO, that allocated a huge amount of virtual memory without
actually using it. the usage was between 0% to 25% of that virtual
memory. the binaries allocation policy on the other hand used >80% of
that allocated virtual memory and was a lot more efficient, it would use
MALLOC_TINY instead.

this is fixed by setting the MallocNanoZone environment variable to 0
to use the V1 of the allocation policy. when started from the bundle via
launchd this is forced to 1 and V2 policy which causes this problem.

some more info can be found in following file and its comments on the
Apple open source site:
https://opensource.apple.com/source/libmalloc/libmalloc-317.40.8/src/nano_malloc_common.c.auto.html

Fixes #7405
2021-05-16 13:50:40 +02:00
der richter f8128f6570 stream_file: disable read ahead for remote files on macOS
this can cause stutter on remote files because in certain cases this
causes a reconnect to the remote that leads to the file not being read
fast enough. VLC had the same problem and fixes it the same way.
b8b8c438f8

Fixes #4434
2021-05-16 13:48:45 +02:00
sfan5 3010588d14 build: move mingw jobs to Github actions 2021-05-16 01:55:37 +03:00
sfan5 10d68d06e6 build: move website rebuild into Linux/clang travis job
The mingw ones will be removed in the next commit.
2021-05-16 01:55:37 +03:00
Your Name ded36a4470 options: add some entries to --display-tags defaults
Useful for the previous commit.
2021-05-11 22:22:33 +02:00
Your Name cbb8f534b0 ytdl_hook: expose some JSON fields as tags
Shows uploader, channel, description fields. This works only if the
media media is constructed as EDL (for youtube it usually does this),
and if the all_formats option is not set to true (does anyone even use
it?). The former usually happens because youtube serves audio and video
separately, though it will not for live HLS/DASH. The latter uses
delayed media opening, which breaks the global_tags mechanism (see
previous commit).
2021-05-11 22:21:46 +02:00
Your Name adcf51dccd edl: add a way to add tags
Add new header which shows up as tags/metadata (associated with
--display-tags). The way this is added means it doesn't always work,
because root->meta (see code) can be NULL for some absurd reason. But it
works for the one case I intended to use it (ytdl_hook, see next
commit), though only in default configurations.
2021-05-11 22:18:40 +02:00
Niklas Haas ea89e813f7 zsh completion: perform globbing on binary path
When trying to use completion for mpv binaries specified with some shell
glob, e.g. ~/dev/mpv/build/mpv, the current code doesn't substitute the
homedir prefix into the path name, resulting in runtime errors about
the file '~/dev/mpv/build/mpv' not being found.

The simple fixed is to use $~var instead of $var whenever expanding the
filename, which performs the same globbing that would otherwise be
performed when executing the command.
2021-05-07 22:18:23 +02:00
Your Name c3ebe7eabd vo_gpu: fix trivial memory leak
Nobody noticed this? Seriously?
2021-05-07 15:01:15 +02:00
Your Name d9008d2aa8 Revert "vo_gpu: revert 8a09299 and conditionally clear framebuffer again"
This reverts commit b8156a9a86.

Apparently there are two problems here. One on Linux (fixed by the
original change and this revert) and one on alternative-medicine-Job's
OS. Since the latter has deprecated OpenGL and OpenGL is a second-class
citizen, I think it's better to prefer the fix for a platform that is
still alive.
2021-05-07 15:01:15 +02:00
Your Name 623b92465f vf_sub: restore OSD if removed
When inserting vf_sub, the VO OSD is directed not to draw itself. But
this flag was never unset, even when removing vf_sub.

The fix is pretty shit, but appears to work.
2021-05-07 15:01:15 +02:00
Your Name f891eefb5c options: extend --replaygain-preamp range
Whether that makes sense or not.
2021-05-07 15:01:15 +02:00
Your Name 3f7d3d5804 audio: fix replaygain being completely broken
Switching to a new file while keeping the AO didn't update the volume.
While there's an explicit audio_update_volume() call in
reinit_audio_chain_src(), it doesn't work, because at that point
ao_chain->ao is still NULL, and it does nothing. That's pretty weird and
might cause other problems (what happens if you try to mute while the AO
is "floating"?). Regarding gapless, trying to use the AO gain for
replaygain is also gross nonsense, because the new replaygain computed
gain would affect audio from the previous file. It looks like replaygain
should be in an af_volume filter maybe. On the other hand, I enjoy
setting ridiculous replaygain-preamp values and compensating with a low
volume setting, which would not work well if both gains were applied to
the audio independently.

For now, just add the missing call. This is orthogonal to fixing
replaygain "properly".
2021-05-07 15:01:15 +02:00
Your Name fce994bdc4 Revert "audio: set audio chain ao on reinit"
This reverts commit 3239e41277.

I'm fairly sure this is wrong, and my next commit should fix it
properly. I'm not really sure, though. Normally, the AO is set again
by reinit_audio_filters_and_output() after the new audio chain has
decoded a frame and knows the new format. The reason replaygain (and
apparently the thing the reverted commit tried to fix) didn't work is
because they work asynchronously to the audio played by the AO (i.e.
buggy and hard to fix).
2021-05-07 15:01:14 +02:00
der richter dd4d239bcb mac: add support for display-width/display-height property
also merge back a helper function that was introduced in commit d3b7732
and for the purpose to be used with the new display res voctrl event.
2021-05-06 17:36:55 +00:00
Dudemanguy a88fdfde0c command: add display-width/display-height property
For some reason, this never existed before. Add VOCTRL_GET_DISPLAY_RES
and use it to obtain the current display's resolution from each
vo/windowing backend if applicable. Users can then access the current
display resolution as display-width and display-height as per the client
api. Note that macOS/cocoa was not attempted in this commit since the
author has no clue how to write swift.
2021-05-06 17:36:55 +00:00
Avi Halachmi (:avih) 8edfe70b83 DOCS/input.rst: clarify --no-input-default-keybindings docs
This commit describes more accurately what currently gets disabled
by this option - specifically also keys from mp.add_key_binding.

It's not necessarily the best behavior because libmpv clients might
want to disable mpv's own builtin keybindings while still allowing
scripts to define keys which `input.conf' can override.

In the future we might exclude mp.add_key_binding from this option,
but for now at least document this option accurately.

Fixes #8809
2021-05-04 17:26:55 +03:00
Niklas Haas f6f9b1e8db filter_kernels: fix quadric window
3909e4cdfc seems to have replaced this 0.5 constant by 0.75, using its
presence in glumpy as justification.

0.75 is clearly a bug in glumpy, as its own source code doesn't even
match the comment immediately above it. Every other implementation of
this window I could find uses 0.5, including e.g. ImageMagick.
2021-05-04 13:18:43 +02:00
Avi Halachmi (:avih) b6aedaa726 DOCS/lua.rst: fix docs for utils.file_info
The ctime member on Windows uses FILE_BASIC_INFO.ChangeTime, which is
pretty much the same as st_ctime on POSIX.

See https://devblogs.microsoft.com/oldnewthing/20100709-00/?p=13463 :

  ... The Last­Write­Time covers writes to the file’s data stream
  (which you accomplish via the Write­File function). On the other
  hand, the Change­Time also includes changes to the file metadata,
  such as changing its file attributes ...

Fixes #8801
2021-05-03 13:25:21 +03:00
sfan5 39630dc8b6 build: address AVCodec, AVInputFormat, AVOutputFormat const warnings
FFmpeg recently changed these to be const on their side.
2021-05-01 22:07:31 +02:00
Avi Halachmi (:avih) 02fbdf8aaf scripting (lua/js): utils.getpid: make wrapper of pid property
We now have at least 3 scripting APIs which are trivial wrappers
around properties: mp.get_mouse_pos, utils.getcwd, utils.getpid.

After some discussion on IRC it was decided that it's easier for us to
maintain them as trivial wrappers than to deprecate them and inflict
pain on users and script authors, so currently no plan to deprecate.
2021-05-01 16:07:05 +03:00
Avi Halachmi (:avih) f3b2ea9de5 command: new property: pid (process id)
Fixes #7562
2021-05-01 16:07:04 +03:00
Dudemanguy 7df9ebda6c DOCS: clarify how client/script names work
This isn't really clearly stated anywhere and could understandably lead
to some confusion.
2021-04-29 15:56:11 -05:00
Dudemanguy 029cd8a813 command: osd-dimensions: return ints and doc fixes
Some subproperties in osd-dimensions were returned as doubles despite
actually being integers. Additionally, correct a highly misleading line
in the osd-width/osd-height documentation.
2021-04-29 15:37:33 +00:00
sfan5 96b68358e3 audio: add two minor log messages
This would have made the problem fixed in the previous
commit a bit more obvious from the log output.
2021-04-29 17:14:51 +02:00
sfan5 aa300f8023 ao/pulse: fix incorrect state reported after reset
fixes #8768
2021-04-29 17:06:29 +02:00
ossifrage 0d384592c5 osc: reset margins when using boxvideo with showfullscreen/showwindowed
This fixes a bug where using boxvideo with showfullscreen=no or
showwindowed=no resulted in the margins not resetting when the OSC
wasn't visible.

For example, using:

script-opts=osc-visibility=always,osc-boxvideo=yes,osc-showfullscreen=no

and then going fullscreen would make the OSC disappear but the video
margins would remain. This is because boxvideo was missing a dependence
on the showfullscreen and showwindowed user options.

This is fixed by adding the corresponding conditions to update_margins()
and setting state.marginsREQ on fullscreen changes. update_margins() is
called on tick() if there's a margins update pending, which guarantees
the boxvideo margins are reset appropriately.
2021-04-27 14:12:05 +03:00
Dudemanguy 61a387ac95 wayland: ignore toplevel listener if geometry is 0
It turns out that if a user specifies fullscreen=yes and a width/height
in an autoprofile, the compositor can execute its toplevel listener
event. This can happen before we have any mpv window rendered at all so
we end up performing a bunch of geometry operations and state checks
when we shouldn't. It subtly messes up a lot of things like state
detection. Just return from this function if the geometry has no width
or height yet.
2021-04-26 00:54:26 +00:00
ossifrage c1568a3a6c osc: display immediately when visibility changes from never to always
Clearing state.osd.data with an empty string at render_wipe() fixes an
issue where changing the OSC visibility from "never" directly to
"always" didn't immediately update the display when the player was
paused. This could be verified by starting the player with
`--script-opts=osc-visibility=always --pause` and then running
`script-message osc-visibility never` followed by
`script-message osc-visibility always`.

Removing the overlay without changing the contents meant the overlay
wouldn't update and display when enabled again until the fields changed
in some way (e.g. seeking, mousing over the OSC area, etc.). Clearing
state.osd.data before removal of the OSC makes sure set_osd doesn't
return on re-enable and instead displays the OSC immediately as the data
is now different.

render_wipe() is now also used when the OSC needs to be cleared at
tick() as using set_osd to clear it with an empty string did not call
state.osd:remove() which can allow cleanups related to bitmap memory
allocations etc.
2021-04-25 19:24:46 +03:00