Commit Graph

49691 Commits

Author SHA1 Message Date
Jan Ekström 083ae8e736 vd_lavc: hide a deprecation warning in already handled compatible code
The field has been deprecated, yet the upcoming new default is not yet
the default. Thus, until lavc major hits 60 and the default behavior
finally gets changed, we have to explicitly set the field's value.

The deprecation had already been handled by adding the required
version limitation for this code in bbbf3571ed ,
this change merely just removes the warning which would otherwise
appear until lavc major version gets bumped to 60.
2022-04-03 00:23:58 +03:00
Aman Karmani fb7b66ecf1 sub/osd: use atomic for osd_state.force_video_pts
this field is used only in a special vo draining edge case.

switching to an atomic reduces osd->lock contention
between the mpv core (in write_video) and vo threads
which are managing osd rendering manually (such as vo_rpi).

Signed-off-by: Aman Karmani <aman@tmm1.net>
2022-04-02 21:41:58 +03:00
Aman Karmani 76b9254b8b osdep/atomic: add mp_atomic_double
Signed-off-by: Aman Karmani <aman@tmm1.net>
2022-04-02 21:41:58 +03:00
Niklas Haas a76b1f4abd Revert "vo_gpu_next: remove unnecessary dependency"
This reverts commit 1c2dde91d3.

Fixes #10037
2022-04-01 23:43:47 +02:00
Thomas Weißschuh deedc3d418 ao_pipewire: Do not hold thread lock during loop stop
Stopping the thread is done using pw_thread_loop_stop(),
*which must be called without the lock held.*

Fixes #10033
2022-03-31 14:40:21 -07:00
Thomas Weißschuh 84dc9b1a02 ao_pipewire: fix resource lifetimes
We have to destroy the core before destroying the loop.
Also we have to lock the mainloop for operations on its objects.

Fixes #10003
2022-03-30 13:06:33 -07:00
Niklas Haas 1c2dde91d3 vo_gpu_next: remove unnecessary dependency
Pulling in <libplacebo/utils/libav.h> in particular triggers the
notorious _av_vkfmt_from_pixfmt linking issue when FFmpeg is built
without Vulkan support.
2022-03-29 15:42:09 +02:00
sfan5 84821dbcb6 lua: use correct chunkname when loading script files
This was brought up in #10007 and it turned out mpv did not follow Lua conventions.
2022-03-23 21:09:53 +01:00
Philip Langdale fcc81cd940 vo_gpu[_next]: hwdec: fix logging regression when probing
When I introduced the concept of lazy loading of hwdecs by img format,
I did not propagate the probing flag correctly, leading to the new
normal loading path not runnng with probing set, meaning that any
errors would show up, creating unnecessary noise.

This change fixes this regression.
2022-03-21 09:53:37 -07:00
Leo Izen f871294204 common/av_log: explicitly include version.h for required libraries
FFmpeg recently split version.h into version.h and
version_major.h, and no longer automatically includes
version.h in avcodec.h (and the other libraries). This
should allow mpv to build against ffmpeg git master. See
FFmpeg/ffmpeg@f2da2e1458

These headers are not new, so their inclusion should not affect
backwards compatibility.
2022-03-17 20:07:55 +02:00
Niklas Haas 5ef7bf7a20 vo_gpu_next: also include stride alignment in DR size
Fixes #9976
2022-03-14 15:45:36 +01:00
Niklas Haas 23e3be80dc vulkan: correctly inherit proc_addr pointer
As found out by @philipl, failing to pass this from the VkInstance to
the VkDevice is bad style. We might want to override the get_proc_addr
pointer in the future.
2022-03-13 23:39:31 +01:00
LaserEyess 7ac4b7dfe7 ao_sndio: fix parentheses warning
No change in logic, but wrap the LT operator and the && in parentheses
to silence the compiler warning.
2022-03-11 16:43:31 +01:00
Dudemanguy 199a7ebcd9 client API: also export mpv_stream_cb_add_ro
20c4036daa switched to hiding all symbols
by default and exporting the ones we want with MPV_EXPORT.
However, the mpv_stream_cb_add_ro function was missed and it is part of
the client API. Export it too. Fixes #9971.
2022-03-11 08:07:13 -06:00
Philip Langdale 919de742a4 vo_gpu: hwdec_vaapi: Improve logging when probing surface formats
Our logging here today is very poor. We don't make it clear what
formats we are probing, or even that a certain format failed in most
cases. In the case where we do log the error, we don't make it clear
which format it was that failed.

The end result is that we have no idea what the possible and final
format spaces are, which makes it very hard to debug whether things are
working correctly, or to work on supporting additional formats.
2022-03-10 15:12:12 -08:00
Philip Langdale d598ab2b24 DOCS/options.rst DOCS/vo.rst: Update discussion of hwdec usage
The documentation's current discussion of hwdec usage is out of date,
and unnecessarily pessemistic when applied to modern hardware. The
reality is that modern APIs on modern hardware produce reasonable
results and there's no need to pretend otherwise. The current language
that tries to drive people away from using hwdecs at all leads to them
making bad choices when they do try to use it.

Let's also make it clearer that users should use vo=gpu with hwdecs
rather than vo=vaapi or vo=vdpau. Even the existing admonitions have
proven insufficient, so let's strengthen that language.
2022-03-09 10:51:35 -08:00
Niklas Haas d936293c41 vo_gpu_next: fix crash when disabling DR at runtime
This code fails if we have DR buffers, but none of them correspond to
the current frame. Normally only happens if e.g. changing the decoder at
runtime, since DR buffers are not properly reinit in that case.
(Arguably a separate bug)
2022-03-08 13:49:03 +01:00
Niklas Haas 803bcaa12b vo_gpu_next: don't leak mpi on failed upload
The current map_frame() code fails to clean up after itself on the
failure paths. But if map_frame returns false, no cleanup code is ever
attempted. Add the relevant calls to clean up state manually,
throughout.
2022-03-08 13:42:13 +01:00
Niklas Haas 124dd4270d vo_gpu_next: properly keep track of DR allocations
So, turns out the approach in 7f67a553f doesn't work for all codecs. In
particular, sometimes lavc will internally allocate a new AVBuffer that
just points at the old AVBuffer but has a different opaque field for
some reason. In these cases, the DR metadata doesn't survive the
round-trip through libavcodec.

I explored several alternative ways of solving this problem, including
adding new mp_image fields, but in the end none of them survived the
round-trip through AVFrame and back. The `priv` and `opaque` fields
in respectively `mp_image` and `AVFrame` are also too heavily overloaded
to be of much help.

In the end, bite the bullet and use the same approach as done in
`vo_gpu`, which is to just keep track of a list of all allocations. This
is a really ugly way of doing things IMO, but ultimately, completely
safe.
2022-03-07 11:52:00 +01:00
Avi Halachmi (:avih) 836e87e6d4 hwdec: warn on unsupported hwdec option value
Previously, when mpv was invoked with unsupported hwdec value, such
as --hwdec=foobar, there was no indication that it doesn't exist.

The reason it's not validated during options parsing is that the name
is only evaluated when selecting hwdec for actual decoding, by
matching it against runtime list of names from ffmpeg.

Additionally, when selecting hwdec for decoding, matching the name
came after filtering by codec, hence overall never-matched-name did
not necessarily indicate it's unsupported (doesn't exist at all).

Now we check the name before filtering by codec, and when done,
warn if no hwdec with that name exists at all.

This means that an unsupported name will now generate such warning
whenever we try to choose a hwdec, i.e. possibly more than once.

It's much better than no notification at all, and arguably adequate
for a sort of configuration error (linked ffmpeg has no such hwdec
name) which we don't validate during option parsing.
2022-03-07 01:05:20 +02:00
Niklas Haas 7f67a553f6 vo_gpu_next: don't allocate dr_buf as part of the AVBufferRef
Some decoders, notably hevcdec, will unconditionally memset() the entire
AVBufferRef based on the AVBufferRef size. This is bad news for us,
since it also overwrites our `struct dr_buf`.

Rewrite this code to make it more robust - keep track of the DR buf
metadata in a separate allocation instead. Has the unfortunate downside
of technically being undefined behavior if `opaque` is not at least 64
bits in size, though, but avoids this issue.

Maybe there's a better way for us to unconditionally keep track of DR
allocation metadata. I could try adding it into the `mp_image` itself.
Maybe on a rainy day. For now, this works.

Fixes #9949
Might fix #9526
2022-03-06 15:53:47 +01:00
Niklas Haas 1c49d5735d hwdec: fix out-of-date preprocessor variable name
This was renamed to HAVE_VAAPI_LIBPLACEBO.
2022-03-04 14:33:26 +01:00
Avi Halachmi (:avih) b15b3f6711 ytdl_hook.lua: consider any subprocess status != 0 as error
Previously only status<0 was considered as error, but status>0 is
also an error (the process exit code). Change to status != 0.

This likely makes little to no difference in practice, because if
stdout is empty or can't be parsed as JSON then it's considered
an error anyway, but still, this is more correct.

Also, on error, add the complete subprocess result to the verbose log.
2022-03-03 15:01:40 +02:00
James Ross-Gowan 11f0947d46 vo_gpu_next: add D3D11 RA texture wrapping/unwrapping for hwdec
This mostly copies the API used in the GL backend.
2022-03-03 13:06:05 +01:00
Niklas Haas dfe846f9de vo_gpu_next: add support for hardware decoding
There are two major ways of going about this:

1. Expose the native ra_gl/ra_pl/ra_d3d11 objects to the pre-existing
   hwdec mappers, and then add code in vo_gpu_next to rewrap those
   ra_tex objects into pl_tex.

2. Wrap the underlying pl_opengl/pl_d3d11 into a ra_pl object and expose
   it to the hwdec mappers, then directly use the resulting pl_tex.

I ultimately opted for approach 1 because it enables compatibility with
more hardware decoders, specifically including ones that use native
OpenGL calls currently. The second approach only really works with
cuda_vk and vaapi_pl.
2022-03-03 13:06:05 +01:00
Niklas Haas c13f5f24cd manpage: add vo_gpu_next wiki link to manpage
I was initially hesitant to link to an external article from the manpage
but a lot of other places in the man page already do something like
this, and it really makes more sense to have this as a wiki article
rather than trying to keep the manpage up-to-date by hand, since this
evolves quickly and the two are expected to converge over time.
2022-03-03 13:06:05 +01:00
Niklas Haas a71baf7c63 vo_gpu_next: configure the VO queue size dynamically
This avoids decoding/caching more frames in advance than necessary. In
particular, this is very important for hwdec, which generally can't have
too many decoded frames in a pool at the same time.
2022-03-03 13:06:05 +01:00
Niklas Haas 4b7671cf36 vo_gpu_next: expose EGLDisplay to pl_gpu
Straightforward and enables the import/export of dmabufs.
2022-03-03 13:06:05 +01:00
Niklas Haas d4fc44e711 vo_gpu: move hwdec loading code to common helper
So I can reuse it in vo_gpu_next without having to reinvent the wheel.
In theory, a lot of the stuff could be made more private inside the
hwdec code itself, but for the time being I don't care about refactoring
this code, merely sharing it.
2022-03-03 13:06:05 +01:00
Niklas Haas bb434a60ed hwdec: release images as soon as possible after mapping
We don't need to hold on to buffers longer than necessary. Doesn't
matter for vo_gpu but greatly matters for vo_gpu_next, since it persists
hwdec mapped textures for longer periods.

Unfortunately, only provides benefits for hwdecs which do explicit
copies in their decode path, which currently just means cuda and
d3d11va.
2022-03-03 13:06:05 +01:00
Niklas Haas e2c02a4ce3 hwdec_vaapi_vk: rename to vaapi_pl
There's really nothing vulkan-specific about this hwdec wrapper, and it
actually works perfectly fine with an OpenGL-based ra_pl. This is not
hugely important at the time, but I still think it makes sense in case
we ever decide to make vo_gpu_next wrap OpenGL contexts to ra_pl instead
of exposing the underlying ra_gl.
2022-03-03 13:06:05 +01:00
Niklas Haas 4387f3bcd0 hwdec_vaapi_gl: properly zero initialize priv struct
Easiest way is by just using a designated struct initializer. If we
don't, `p->images` ends up inheriting random data, which leaks into e.g.
eglDestroyImageKHR.

It's a small miracle this never blew up before. Or maybe it did. Who
knows.
2022-03-03 13:06:05 +01:00
Philip Langdale 7d08201a8f filters: Re-add vavpp deinterlacing auto-filter
A few years ago, in 25e70f4743, we
disabled the vavpp deinterlacing auto-filter on the basis that it
caused crashes on _some_ hardware with _some_ driver version(s). But
since then, the situation has improved. There is still a limitation
where you can't turn deinterlacing on on the fly with AMD, but it
doesn't crash anymore (That is #7388).

So, given that AMD users have to set up the deinterlacing filter
manually either way, let's re-add the auto-filter for Intel users.
2022-03-02 16:21:04 -08:00
George Brooke 1a3e85ec33 ytdl_hook: fix url_is_safe to match URL protocols properly
Some youtube_dl extractors retrieve URLs which contain other URLs
inside of them, for example Funimation, like this:
https://example.com/video?parameter=https://example.net/something

The url_is_safe function uses a pattern to match the protocol at the
start of the URL. Before this commit, this pattern was not compliant
with the URL spec (see the definition of "A URL-scheme string"):
https://url.spec.whatwg.org/#url-writing
Therefore it would match any characters, including "://", until the
last occurence of "://" in the string. Thus the above URL would match
https://example.com/video?parameter=https
which is not in safe_protos so the video will not play.

Now the protocol can only start with a letter and only contain
alphanumerics, "." "+" or "-" as the spec says, so it will only match
the first protocol in the URL ("https" in the above example.)
Previously the URL also had to contain "//" after the ":". Data URLs
do not contain "//": https://datatracker.ietf.org/doc/html/rfc2397
so now the pattern does not look for "//", only ":".
2022-03-02 20:59:33 +02:00
Niklas Haas b1fb4b783b vo_gpu_next: remove/simplify plane flipping hacks
libplacebo v198 fixed this properly by adding the ability to flip planes
directly, which is done automatically by the swapchain helpers.

As such, we no longer need to concern ourselves with hacky logic to flip
planes using the crop. This also removes the need for the OSD coordinate
hack on OpenGL.
2022-02-25 22:13:20 +01:00
Niklas Haas 626fa506d5 vo_gpu_next: avoid rendering subtitles as HDR/wide gamut
Fixes #9911
2022-02-25 14:22:03 +01:00
Niklas Haas e6c18641bd mp_image: fix mp_image_plane_w/h
These helpers, for some reason, decided to round the returned values up
to multiples of the nearest plane alignment. This logic makes no sense
to me, and completely breaks any sort of oddly-sized mp_image.

This logic was introduced, presumably in error and without real
justification, as part of a major refactor commit (caee8748), As far as
I can tell, removing it again doesn't regress anything.

Fixes several serious bugs including buffer underflows and GPU crashes
in vo_gpu and vo_gpu_next.
2022-02-24 18:36:28 +01:00
Avi Halachmi (:avih) 57f42cee84 stats.lua: page 2 - frame timing: use fixed display order
Page 2 displays the frame timing info for each type (currently "Fresh"
and "Redraw"), but since they're unordered keys of a map, their
iteration order and hence their order on screen could (and did) change
depending on $things, which was annoying.

haasn thinks none of them should be considered more important (and
therefore maybe worthy of being displayed on top), so we go with
lexicographic order, which currently means that "Fresh" is first.

Fixes #9901
2022-02-23 02:20:49 +02:00
Avi Halachmi (:avih) 37927b65f7 stats.lua: graphs: fix bad rendering due to division by 0
This fixes two potential divisions by 0 at generate_graph(...):
- If v_avg is (given and) 0.
- if v_max is 0.

The former doesn't seem to happen in practice because v_avg is only
used at one generate_gpah call, where it's apparently not 0.

The latter triggers if all the graph values are 0 (hence v_max is
also 0).

The implication of these divisions by 0 is an invalid y-value which
ends up at the ASS coordinates string for the graph inner content.

On linux the value ends as "nan" (luajit) or "-nan" (lua 5.1/5.2), and
on Windows it's "nan" (luajit) or "-1.#IND00" (lua 5.1/5.2), maybe due
to msvcrt's snprintf.

All these strings are wrong as ASS numbers, but due to luck in how
libass parses the coordinates, "nan" and "-nan" result in empty graph
(which looks OK for "all values are 0"), while "-1.#IND00" is parsed
as -1, which breaks the graph rendering (affects other graphs too).

One example of "all values are 0" is at page 0 (internal performance
graphs) on Windows - because the cpu metrics don't work.
So this fixes at least page 0 on Windows with lua 5.1/5.2.

While at it, move the scale calculations to one place, which now
avoids division by 0, instead of duplicating this calculation.

In the future, we can consider improving the generate_graph API:
- It needs one peak value, but takes 3 (v_max, v_avg, scale) which
  are meshed into one final value.
- v_avg is only used in 1 of 6 call sites, but at the middle of the
  arguments, so all other call sites need to pass explicit "nil".
- "scale" is arbitrary and used to leave some space at the top of the
  graph. 5 places use 0.8, one uses 0.9. Could probably be unified.
2022-02-21 16:05:02 +02:00
Niklas Haas fbe154831a vo_gpu_next: refactor subtitle rendering
Render subs at the output resolution, rather than the video resolution.
Uses the new APIs found in libplacebo 197+, to allow controlling the OSD
resolution even for image-attached overlays.

Also fixes an issue where the overlay state did not get correctly
updated while paused. To avoid regenerating the OSD / flushing the cache
constantly, we keep track of OSD changes and only regenerate the OSD
when the OSD state is expected to change in some way (e.g. resolution
change). This requires introducing a new VOCTRL to inform the VO when
the UPDATE_OSD-tagged options have changed.

Fixes #9744, #9524, #9399 and #9398.
2022-02-21 12:01:44 +01:00
Dudemanguy 27c38eac10 options: add always to stop-screensaver
The stop-screensaver option is currently limited to a simple yes/no
option. While the no option does always disable mpv trying to stop the
screensaver, yes does not mean the screensaver is always stopped. The
screensaver will be enabled again depending on certain conditions (like
if the player is paused). Simply introduce a new value for this option,
always, which does exactly what the name implies: the screensaver will
always be disabled.
2022-02-18 22:04:08 +00:00
Guido Cella beac97ba07 DOCS/input: document subprocess more clearly
- Make it clearer that playback_only affects subprocess' behavior when
  the playback of the current playlist entry terminates, rather than
  when mpv quits.
- Explain when status is positive and when it is negative.
- Replace "exited gracefully" in status' and error_string's
  documentation with "terminated normally" so it can't be misinterpreted
  as exiting successfully.
- Reword the playback_only warning
2022-02-18 19:39:10 +02:00
Guido Cella b89ca0c552 DOCS/input: fix typo 2022-02-18 19:39:10 +02:00
Philip Langdale 5186651f30 vo_gpu: hwdec: load hwdec interops on-demand by default
Historically, we have treated hwdec interop loading as a completely
separate step from loading the hwdecs themselves. Some hwdecs need an
interop, and some don't, and users generally configure the exact
hwdec they want, so interops that aren't relevant for that hwdec
shouldn't be loaded to save time and avoid warning/error spam.

The basic approach here is to recognise that interops are tied to
hwdecs by imgfmt. The hwdec outputs some format, and an interop is
needed to get that format to the vo without read back.

So, when we try to load an hwdec, instead of just blindly loading all
interops as we do today, let's pass the imgfmt in and only load
interops that work for that format. If more than one interop is
available for the format, the existing logic (whatever it is) will
continue to be used to pick one.

We also have one callsite in filters where we seem to pre-emptively
load all the interops. It's probably possible to trace down a specific
format but for now I'm just letting it keep loading all of them; it's
no worse than before.

You may notice there is no documentation update - and that's because
the current docs say that when the interop mode is `auto`, the interop
is loaded on demand. So reality now reflects the docs. How nice.
2022-02-17 20:02:32 -08:00
Alex B bc9805c71a ao_pipewire: fix ao-volume handling
Pass channel volumes to `pw_stream_set_control` as array.
This is correct calling conventions and prevents
right channel muting every time ao-volume property is changed.

Terminate `pw_stream_set_control` calls with 0.
2022-02-11 11:27:57 -08:00
Niklas Haas ef83498aef vo_gpu_next: don't crash on negative plane strides
This is an annoying special case only really needed because of the
`vflip` filter. mpv handles this by directly adjusting the plane
transform. The libplacebo API, unfortunately, does not allow passing the
required information for this to work smoothly.

Long-term I plan on adding support for plane flipping in libplacebo
directly, but for the meantime, we will have to work-around it by moving
the flipping to the whole-image `crop` instead. Not an ideal solution
but better than crashing.

Fixes #9855
2022-02-11 05:12:09 +01:00
James Ross-Gowan 4629fe577f vo_gpu: d3d11_helpers: don't create UNORDERED_ACCESS backbuffers in Win7
We're getting bug reports that the recent change to add extra usage
flags to swapchain buffers (for gpu-next) breaks mpv on some Windows 7
systems, and it seems like this is only happening with flip-model
swapchains.

Creating swapchains with DXGI_USAGE_UNORDERED_ACCESS should be valid. At
least, it's not specifically disallowed, unlike some other flags[1]. So,
just disable it for flip-model swapchains in Windows 7, rather than
disabling it everywhere.

[1]: https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-usage
2022-02-09 17:20:07 +02:00
Dudemanguy f9bf6a601c meson: remove horrifying macos luajit hack
See the previous commit for the full explanation. Basically, luajit 2.0
has a bad pc file on macos that causes libmpv to fail during build. The
workaround was, if the os was darwin and luajit was found, to save a
full luajit dep and a partial luajit dep with the link args removed. The
partial dep was used for compiling libmpv, and the full dep was used for
the actual mpv executable. This worked and was needed for the CI to pass
but it sucked. Since the previous commit now makes the CI grab lua 5.1,
we don't need all this crap anymore. Just delete it and treat the
dependency normally.

This does effectively mean that building libmpv with luajit 2.0 on macOS
will no longer work with the meson build. However libraries not being
built correctly is not a mpv-specific issue. The waf build will succeed
for some reason, but it has known issues and it would be better if it
just failed honestly. An upstream developer said years ago that that
macOS users should use the 2.1 branch (and there's no release of
course). In any case, no macOS user should be building mpv with luajit
2.0, so we shouldn't be going out of our way to support this.

https://github.com/mpv-player/mpv/issues/7512
https://github.com/LuaJIT/LuaJIT/issues/521#issuecomment-562999247
2022-02-07 21:17:12 +00:00
Dudemanguy 649556b2b6 github/workflows: use lua 5.1 on macos
LuaJIT is still actively developed, but upstream is allergic to making
new releases for whatever reason. The last tagged release was in May of
2017, so we probably shouldn't expect a new release anytime soon. Now
for mpv, this doesn't really matter except in the case of macOS where
2.0.5 is actually a bit broken (and of course the CI uses luajit). More
specifically, the 2.0.5 pc is broken and has a "-pagezero_size 10000"
flag which causes libmpv to fail (only executables are allowed to use
this). This magically works on waf. It's possible that it just happens
to ignore the link arguments. However on the meson build, this is broken
and led to a really ugly hack using a partial dependency so both mpv and
libmpv succeed. Fortunately, the 2.1 luajit branch fixes this.
Unfortunately, there's no actual release.

Instead, just use Lua 5.1. Note that lua 5.1 is technically deprecated
in homebrew, but the chances of this going away is pretty slim since
everyone knows that new lua versions are not backwards compatible.
Anyways, using 5.1 works fine and lets us get rid of a terrible hack in
the meson build. People really shouldn't be using 2.0 LuaJIT anyway.
2022-02-07 21:17:12 +00:00
Guido Cella 25bd428393 DOCS/mpv: improve vf=rotate examples
We have a few examples with vf=rotate=90, but libavfilter's rotate
accepts radians - not degrees, so a value of 90 is valid but misleading
because it's not 90 degrees.

Change the value of 90 at those examples.

Also replace "vf-add=hflip" with "vf add hflip", since that example
lists commands, not options, to run.
2022-02-07 22:14:51 +02:00