Commit Graph

50245 Commits

Author SHA1 Message Date
Philip Langdale 872b068cb7 f_hwtransfer: disable vulkan multiplane images when uploading from cuda
Although we can support vulkan multiplane images, cuda lacks any such
support, and so cannot natively import such images for interop. It's
possible that we can do separate exports for each plane in the image
and have it work, but for now, we can selectively disable multiplane
when we know that we'll be consuming cuda frames.

As a reminder, even though cuda is the frame source, interop is one way
so the vulkan images have to be imported to cuda before we copy the
frame contents over.

This logic here is slightly more complex than I'd like but you can't
just set the flag blindly, as it will cause hwframes ctx creation to
fail if the format is packed or if it's planar rgb. Oh well.
2023-05-28 15:46:05 -07:00
Philip Langdale 642dae1a6e hwdec_vulkan: use bwdif_vulkan as deinterlacing auto filter
This is currently the only vulkan deinterlacing filter in ffmpeg and
it's a very high quality algorithm.
2023-05-28 15:46:05 -07:00
Philip Langdale 45a2d8c670 vo: vulkan: request additional extensions and features for ffmpeg
Vulkan hwdec interop with the ffmpeg 6.1 vulkan code will require
additional features beyond those activated by libplacebo by default.

Enabling these features requires both requesting the features'
extensions and then explicitly turning on the features. libplacebo
handles detecting unsupported features and dropping them, to avoid
failing to create the vulkan device.

We then leave it to ffmpeg to decide if any missing features are
required for functionality, and error out if necessary.

As ffmpeg requires at least one bleeding edge extension (descriptor
buffers), all of this logic is gated on the presence of sufficiently
new Vulkan headers.
2023-05-28 15:46:05 -07:00
Philip Langdale 61e685594d hwdec_vulkan: add Vulkan HW Interop
Vulkan Video Decoding has finally become a reality, as it's now
showing up in shipping drivers, and the ffmpeg support has been
merged.

With that in mind, this change introduces HW interop support for
ffmpeg Vulkan frames. The implementation is functionally complete - it
can display frames produced by hardware decoding, and it can work with
ffmpeg vulkan filters. There are still various caveats due to gaps and
bugs in drivers, so YMMV, as always.

Primary testing has been done on Intel, AMD, and nvidia hardware on
Linux with basic Windows testing on nvidia.

Notable caveats:
* Due to driver bugs, video decoding on nvidia does not work right now,
  unless you use the Vulkan Beta driver. It can be worked around, but
  requires ffmpeg changes that are not considered acceptable to merge.
* Even if those work-arounds are applied, Vulkan filters will not work
  on video that was decoded by Vulkan, due to additional bugs in the
  nvidia drivers. The filters do work correctly on content decoded some
  other way, and then uploaded to Vulkan (eg: Decode with nvdec, upload
  with --vf=format=vulkan)
* Vulkan filters can only be used with drivers that support
  VK_EXT_descriptor_buffer which doesn't include Intel ANV as yet.
  There is an MR outstanding for this.
* When dealing with 1080p content, there may be some visual distortion
  in the bottom lines of frames due to chroma scaling incorporating the
  extra hidden lines at the bottom of the frame (1080p content is
  actually stored as 1088 lines), depending on the hardware/driver
  combination and the scaling algorithm. This cannot be easily
  addressed as the mechanical fix for it violates the Vulkan spec, and
  probably requires a spec change to resolve properly.

All of these caveats will be fixed in either drivers or ffmpeg, and so
will not require mpv changes (unless something unexpected happens)

If you want to run on nvidia with the non-beta drivers, you can this
ffmpeg tree with the work-around patches:

* https://github.com/philipl/FFmpeg/tree/vulkan-nvidia-workarounds
2023-05-28 15:46:05 -07:00
Philip Langdale 085f3e31a0 vo: hwdec: Pass the ra_ctx to hwdecs instead of just the ra
We will need the full ra_ctx to be able to look up all the state
required to initialise an ffmpeg vulkan hwcontext, so pass let's
pass the ra_ctx instead of just the ra.
2023-05-28 15:46:05 -07:00
Kacper Michajłow 959ef843d2 vo_gpu_next: fix to allow using dllimport
Address of variables can't be used for constant initialization in C
language modes.
2023-05-27 14:54:59 +02:00
Niklas Haas 7595ea7c7c vo_gpu_next: respect `gl->flipped`
This fixes flipped rendering on angle/dxinterop instances.
2023-05-27 11:37:48 +02:00
Niklas Haas b216c09ade opengl: move `ra_gl_ctx_params.flipped` to `struct GL`
This is motivated by a need to access it from vo_gpu_next's opengl
wrapping code, and justified by it being an inherent property of the GL
context itself,
2023-05-27 11:37:48 +02:00
Kacper Michajłow 9fd4ae9529 vo: make mp_frame_perf thread safe
It was unsafe to return pointer to memory that was freed on another
thread, just copy the string to caller owned sturcture.

Fixes crashes when displaying passes stats with gpu-next.
2023-05-25 16:25:33 +02:00
Kacper Michajłow 19c5cd92b2 vo_gpu_next: add size guard for pass->num_samples
This shouldn't happen as the array sizes are the same, but guard against
it in case libplacebo do something naughty.
2023-05-25 16:25:33 +02:00
Kacper Michajłow 3b89a58af7 vo_gpu_next: synchronize voctrl_performance_data access
info_callback is fired quite often and from different thread than any
accesses to this structure.
2023-05-25 16:25:33 +02:00
Kacper Michajłow 695b3c51d1 vo_gpu_next: fix off by one in info_callback
Fixes invalid memory writes.
2023-05-25 16:25:33 +02:00
Dudemanguy c1de4bb745 vo_dmabuf_wayland: rewrite around wl_list
vo_dmabuf_wayland worked by allocating entries to a pool and then having
a lot of complex logic dealing with releasing buffers, pending entries,
etc. along with some other not so nice things. Instead, we can rewrite
this logic so that the wl_buffers created by the imported dmabuf is
instead stored in a linked list, wl_list. We can simply append our
buffers to the list when needed and destroy everything at the end. On
every frame, we can check the ids of our surfaces and reuse existing
buffers, so in practice there will only ever be a handful at a time.
Some other small changes were made in an attempt to organize the
vaapi/drmprime code a little better as well.

An important change is to always enforce at least a minimum number of
buffers. Certain formats would not make enough unique buffers, and this
results in flickering/artifacts occuring. The old way to attempt to deal
with this was to clear out all the existing buffers and remake them, but
this gets complicated and also didn't always work. An easy solution to
this is just create more buffers which appears to solve this problem.
The actual number needed is not really based on anything solid, but 8
is a reasonable number to create for the lifetime of a file and it seems
to do the trick.

Additionally, seeking/loading new files can result in flicker artificts
due to buffers being reused when they shouldn't. When that happens, we
flip a bool so all the buffers get destroyed in draw_frame to avoid any
visual glitches.
2023-05-24 21:53:17 +00:00
Niklas Haas b9a5583f17 vo_gpu_next: fix build on older libplacebo
Introduced by, of all things, a rebase...

Fixes: a5da8b2c87
2023-05-24 22:06:03 +02:00
Niklas Haas a5da8b2c87 vo_gpu_next: update to new libplacebo gamut mapping API
This just replaces the API calls to get rid of deprecation warnings, it
doesn't yet expand the enum, nor replace them by the proper options.

The translation from tone map modes to hybrid mix parameters is taken
from the libplacebo source code.
2023-05-24 21:32:23 +02:00
Niklas Haas dc13d47c73 vo_gpu_next: remove --tone-mapping-crosstalk
Removed upstream, to be replaced by constant 0.04.
2023-05-24 21:32:00 +02:00
Matthew Lindner a1a2e27f84 context_drm_egl: check for non-existant drm in uninit
Previously, if vo_drm_init failed at the start of drm_egl_init it
caused a use-after-free in drm_egl_uninit when it tried to access the
non-existant drm context. At that point vo_drm_uninit had already been
called resulting in two different null pointer dereference. In this
situation the DRM private context had also not been allocated.
2023-05-22 21:47:24 -05:00
sfan5 2a2cb6a49e player: improve diagnostics around writing watch_later files 2023-05-21 20:11:24 +02:00
sfan5 576e86bfa1 path: let configdir also override "cache" and "state" paths
This matches the behaviour that libmpv API clients expect better and
prevents silent regressons with watch_later suddenly appearing in
an entirely different path (or none at all in case of weird platforms*).

Also added some comments for easier understanding.

* Android
2023-05-21 20:11:24 +02:00
sfan5 d8d0c853c0 path: simplify "cache" and "state" fallback
Instead of having more global state just do it on-the-fly.
2023-05-21 20:11:24 +02:00
Arthur Williams 519e56f80f player: always try to detect subtitle language from file name
Previously, we'd only attempt to call guess_lang_from_filename if the
external file name matched the video name ignoring the extensions. So if
they didn't match, we'd just report the language as "unknown". And since
the name will never match for urls, the language would always be treated
as unknown.

Now we'll always try to guess the language from the filename regardless
of its similarity to the video file name.

Closes #10348
2023-05-21 10:02:03 -04:00
Kacper Michajłow ec58670a0d ra_d3d11: change how messages are ignored during texture size lookup
Filtering globally D3D11_MESSAGE_ID_CREATETEXTURE2D_INVALIDDIMENSIONS is
suboptimal, because can also hide other invalid usages. In the same time
it is not enough, because not only this message is emitted, but also one
about E_INVALIDARG. Just flush queue before and clear messages after to
ignore this part of code.

As a side note, I don't believe this texture size lookup is in fact
useful, but since it is there and is relatively harmless, let's leave
it as is.
2023-05-18 21:56:54 +02:00
Dudemanguy f677f8a5a7 wayland: improve guessing when mpv is focused
The current implementation is order dependent and assumes that getting
keyboard input happens before the toplevel is activated. This isn't
necessarily the case and indeed mutter activates the toplevel first.
Improve this by simply spinning off the check to a function and calling
it in the three places where it would be needed: the toplevel
configuration event, keyboard entering, and keyboard leaving. This
fixes #11694.
2023-05-17 16:13:04 -05:00
Kacper Michajłow 1237bf0d73
demux/demux_lavf: pass-through mime_type
This fixes HLS playback. After FFmpeg@954d16f check is strict as per
RFC8216 requirement and demuxer need to have this information to work
properly.
2023-05-16 10:46:35 -04:00
Kacper Michajłow fe4f03f42c
demux/demux_lavf: pass-through filename for HLS
Fixes local HLS playback.

After FFmpeg@6b1f68c commit HLS is only processed if file extension
matches RFC8216 requirement.
2023-05-16 10:46:35 -04:00
Kacper Michajłow 1a649df00a
Revert "demux/demux_lavf: pass dummy filename when an HLS mimetype is detected"
This reverts commit acababec20.

Now it has been fixed upstream FFmpeg@6b1f68c.
2023-05-16 10:46:33 -04:00
Leo Izen acababec20 demux/demux_lavf: pass dummy filename when an HLS mimetype is detected
Pass "dummy.m3u8" filename to work around FFmpeg commit
6b1f68ccb04d791f0250e05687c346a99ff47ea1 which broke their HLS demuxer
and its ability to probe.

Since the above commit, libavformat will check the filename of the file
to be probed and reject it if it doesn't end with a valid HLS extension
i.e. m3u8,hls,m3u (never mind that .hls is not a valid HLS extension).
In addition to a bug with query strings, this also breaks mpv
functionality as mpv explicitly doesn't tell libavformat the filename
when probing, in order to properly detect the file based only on their
contents.

The [HLS specification](https://www.rfc-editor.org/rfc/rfc8216.txt) aka
RFC 8216, specifies in section 4 that "Each Playlist file MUST be
identifiable either by the path component of its URI or by HTTP
Content-Type." Notably, it does not require both, so this FFmpeg commit
is noncompliant. We work around this noncompliance by checking the MIME
type ourselves. If the mimetype matches one of the valid HLS mimetypes
(and also application/x-mpegurl, a legacy pre-standardization type),
then we pass "dummy.m3u8" to libavformat in order to work around its
overly strict checking of filenames.

Without this patch, we are unable to play many HLS streams, including a
few from the ytdl hook. This patch restores those ability to play those
streams when built against FFmpeg master. Do note that if the server
sends an invalid content-type header then we cannot implement this
workaround so those streams will still fail to play.
2023-05-14 16:28:29 -04:00
Kacper Michajłow 9e716d6303 vo_gpu_next: allow to use ICC profile luminance value
Also while at it respect target-peak option when ICC profile is used.

Fixes #11449
2023-05-13 17:08:37 +02:00
Philip Langdale 8343b3bded mp_image: use the ffmpeg interlaced frame flags where available
The old frame properties are deprecated and have been replaced by frame
flags.
2023-05-11 14:31:17 -07:00
rim 5afc0da530 ao_oss: return actual OSS playing state
fix: https://github.com/mpv-player/mpv/issues/10640
2023-05-11 01:53:55 +00:00
Dudemanguy 4502522a7a player: use XDG_CACHE_HOME by default
This adds cache as a possible path for mpv to internally pick
(~/.cache/mpv for non-darwin unix-like systems, the usual config
directory for everyone else). For gpu shader cache and icc cache,
controlling whether or not to write such files is done with the new
--gpu-shader-cache and --icc-cache options respectively. Additionally,
--cache-on-disk no longer requires explicitly setting the --cache-dir
option. The old options, --cache-dir, --gpu-shader-cache-dir, and
--icc-cache-dir simply set an override for the directory to save cache
files. If unset, then the cache is saved in XDG_CACHE_HOME.
2023-05-09 20:37:17 +00:00
Dudemanguy 7c4c9bc86f player: use XDG_STATE_HOME for watch_later
A pain point for some users is the fact that watch_later is stored in
the ~/.config directory when it's really not configuration data. Roughly
2 years ago, XDG_STATE_DIR was added to the XDG Base Directory
Specification[0] and its description, user-specific state data, actually
perfectly matches what watch_later data is for. Let's go ahead and use
this directory as the default for watch_later. This change only affects
non-darwin unix-like systems (i.e. Linux, BSDs, etc.). The directory
doesn't move for anyone else.

Internally, quite a few things change with regards to the path
selection. If the platform in question does not have a statedir concept,
then the path selection will simply return "home" instead (old
behavior). Fixes #9147.

[0]: 4f2884e16d
2023-05-09 20:37:17 +00:00
Dudemanguy 5158b85b21 path: expand internal path selection API to allow for additional types
Currently, nothing new is actually implemented but the idea is simply to
just pass a type string all the way up from mp_find_user_file down to
actually getting the platform path. This allows for selecting different
directories besides the user's native config directory. See the next
commit for an implementation.
2023-05-09 20:37:17 +00:00
Dudemanguy baa9d56481 osdep: separate out macos paths from path-unix.c
macOS really has completely different path conventions that mpv doesn't
take into account and it treats it just like any other old unix-like
system. This means mpv enforces certain conventions on it (like all the
XDG stuff) that doesn't really apply. Since we'd like to use more of
this but at the same time not distrupt mac users even more, let's just
copy and paste the current code to a new file, update the build and call
it a day. This way, the paths of these two platforms can more freely
diverge.
2023-05-09 20:37:17 +00:00
Nick Hanley a1580b6424 DOCS/options: document required parameter for --x11-name 2023-05-06 21:26:50 +00:00
Dudemanguy a3eb163303 meson: bump required version to 0.62
This lets us use meson's custom dl dependency as well as the version
method when checking rst2pdf's version.
2023-05-02 19:20:50 +00:00
Simon Ser 6234a70920 wayland: add support for wl_surface.preferred_buffer_scale
See [1] for the motivation. Very similar to the fractional scale,
except it's in core and integer-only.

[1]: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/220
2023-04-30 21:20:18 +00:00
Thomas Weißschuh 6d422b3edc options: read config file as stream
This aligns the possible sources of config files other loaded data.
For example `--input-conf`.
2023-04-29 22:34:54 +00:00
Kacper Michajłow 7668361685 ci: switch to lua51 for MSYS build
luajit is currently crashing on 32-bit build:
https://github.com/msys2/MINGW-packages/issues/17042
2023-04-29 19:07:45 +00:00
Kacper Michajłow e836b58050 ci: use auto detection for lua library version for MSYS 2023-04-29 19:07:45 +00:00
low-batt 6d208d38d2 charset_conv: fix memory corruption in mp_iconv_to_utf8
If mp_iconv_to_utf8 was given an empty string to convert in the buf
parameter it would corrupt memory when writing a null into outbuf
before returning it to the caller. This happened when streaming from a
URL that ends in a slash. For such a URL the method mp_basename returns
an empty string. The method append_dir_subtitles passes the result
returned from mp_basename to mp_iconv_to_utf8 which then corrupts
memory. This was detected using Guard Malloc. The fix changes
mp_iconv_to_utf8 check up front if buf is empty and if it is return
buf as the result in compliance with the documented behavior of the
method when no conversion is needed.

Fixes #11626
2023-04-29 01:37:41 +00:00
Lypheo e928bd5fdb sub: fix UPDATE_SUB_HARD for converted and external subtitles
Upon an option update with an UPDATE_SUB_HARD flag,
the ass_track that stores all the decoded
subtitle packets/events is destroyed and recreated, which means
the packets need to be read and decoded again to refill
the ass_track. This caused issues (no subs displayed) in 2 cases:
1. external sub files
  Previously, external sub files were read and decoded only
  once when loaded. Since this meant all decoded events were lost
  forever when recreating the ass_track, we need to change this
  and trigger a new preload during sub reinits.
2. converted subs (non-ASS text subs like srt)
  For converted subs, we maintain a list of previously
  seen packets to avoid decoding and adding duplicate events
  to the ass_track. Previously this list wasn’t synchronized with
  the corresponding ass_track, so the sub decoder would reject
  any previously seen sub packets, usually meaning only subs sometime
  after the current pts would be displayed after sub reinits.
  Fix this by resetting the list upon ass_track recreation.
2023-04-29 00:30:15 +00:00
Guido Cella c5211dbf4a console.lua: add a script-opt for the border size
Because I find the console log easier to read with a thicker border.
2023-04-26 16:30:01 +00:00
Kacper Michajłow 4fd0a39fc8 vo_gpu_next: fixes to allow using dllimport
Address of variables can't be used for constant initialization in C
language modes.

See 0c43d8077e
2023-04-24 13:16:55 +02:00
Thomas Weißschuh 71f9e97fc0 ao_pipewire: clarify --pipewire-buffer=native 2023-04-23 21:03:58 -07:00
Thomas Weißschuh 993553e138 ao_pulse: clarify --pulse-buffer=native 2023-04-23 21:03:58 -07:00
Thomas Weißschuh cb6b4af1d7 ao_pipewire: let sound server determine latency
Fixes #11467
2023-04-23 21:03:58 -07:00
Thomas Weißschuh eafd0e5fad ao_pipewire: give sound server more flexibility for buffers 2023-04-23 21:03:58 -07:00
EmperorPenguin18 c7a8e71578 hwdec_drmprime: support rpi4_8 and rpi4_10 formats
HEVC hardware decode with drm wasn't working on the RPi 4. Mpv would
report the image format (rpi4_8 for 8-bit and rpi4_10 for 10-bit) wasn't
supported. The change to hwdec_drmprime.c identifies these two formats
as NV12 because it functions exactly the same. The change to
dmabuf_interop_gl.c adds support for P030 which rpi4_10 uses. These
changes were tested on a Pi 4 with this fork of ffmpeg:
https://github.com/jc-kynesim/rpi-ffmpeg.

Signed-off-by: EmperorPenguin18 <60635017+EmperorPenguin18@users.noreply.github.com>
2023-04-20 14:37:15 -07:00
Arnold Stanovský c50f536bd1 ytdl_hook: fix clip start and end 2023-04-12 02:14:09 +00:00