0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 20:03:10 +02:00
Commit Graph

5430 Commits

Author SHA1 Message Date
Dudemanguy
e4e0e7dfcf vo: change vo_platform_init to bool
There's several functions that are used for initializing mpv on a
certain platform (x11, wayland, etc.). These currently are all int, but
they actually return 1 and 0 like a boolean. This gets a bit confusing
because actual vo preinit functions return 0 and -1 instead. Just make
these all bool instead and return true/false to make it clearer.
2023-01-08 20:42:42 +00:00
Dudemanguy
e43393c4da vo_wlshm: cleanup on failure
If failure occurs during preinit, vo_wlshm should goto an error and
cleaup itself like the other VOs.
2023-01-08 12:39:50 -06:00
Dudemanguy
c5af54eb35 vo_dmabuf_wayland: goto err instead of returning
Returning early is clearly wrong. It should use to goto to cleanup after
itself. Also renamed from error_out to err for purely comestic reasons.
2023-01-08 12:19:14 -06:00
Christoph Reiter
96773f39e1 vulkan: fix build error for 32bit builds with clang
vk->surface is a handle and not a pointer, so assign VK_NULL_HANDLE.
This fixes the following build error on 32bit Windows when using clang for example,
which errors out when assigning a 32bit pointer to a 64bit integer:

  ../mpv-0.35.0/video/out/vulkan/utils.c:37:21:
    error: incompatible pointer to integer conversion assigning to 'VkSurfaceKHR' (aka 'unsigned long long') from 'void *' [-Wint-conversion]
          vk->surface = NULL;
                      ^ ~~~~
2023-01-08 16:09:01 +01:00
Dudemanguy
aa8ddfcdf3 wayland: dispatch and wait for compositor events in uninit
Similar to some other issues we've had with unprocessed compositor
events. When quitting mpv, there's two things we should be doing:
dispatching any last minute wayland events and then waiting for a
compositor reply. Luckily, there's already an internal helper for this
(renamed to wayland_dispatch_events for consistency) that we can use.
All of the special casing of wl->feedback becomes unneccesary and we can
remove this from vo_wayland_state with this method. Fixes #110022.
2023-01-03 20:45:39 +00:00
Dudemanguy
4bbb1ccfd7 wayland: initalize display_fd as -1
In the event of a failed wayland initalization, the display_fd is
actually 0 instead of -1 which would correctly indicate it doesn't
exist. Also move the fd check inside vo_wayland_dispatch_events since
that function shouldn't ever do anything if we don't actually have a
display fd.
2023-01-03 20:45:39 +00:00
Dudemanguy
24e2251b73 wayland: consistently employ use_present
We have a use_present bool that keeps track of whether or not to use
presentation time. However, the creation of the feedback listener
actually wasn't checking this and was instead checking for the existence
of wl->presentation. There's no point in always creating the
listener and feedback if mpv isn't actually going to use it. Just change
it to use_present instead.
2023-01-03 20:45:39 +00:00
repojohnray
fee6847aa7 vo: hwdec: fix drmGetDeviceNameFromFd2() related memory leak
This commit fixes a minor memory leak related to drmGetDeviceNameFromFd2().
This function returns a string allocated with strdup().
2023-01-02 16:48:24 -08:00
repojohnray
2e9c43f931 hwdec_drmprime: fix memory leak 2023-01-02 19:46:07 +01:00
Kacper Michajłow
ad65c8855b vo_opengl: do not blindly reject all Microsoft's OpenGL implementations
This change enables mpv to work in the WSL2 (WSLg) environment where
OpenGL is implemented on top of D3D12.

This reverts commit 149d98d244.

Mentioned OpenGL implementation (GDI Generic) in the original change
will be rejected by version check, so there is no need to handle it
manually.

Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2022-12-30 11:02:52 -05:00
Sultan Alsawaf
4a2aa36674 x11: add modesetting to the xpresent whitelist
Since the modesetting driver now has TearFree support with integration into
xpresent, it's important that xpresent is used with the modesetting driver
to get the correct vsync timing when a frame is delayed by one vblank
interval due to a pending page-flip enqueued by a different entity. The
modesetting driver ensures that the xpresent extension reports the correct
presentation timing when TearFree is used; mpv just needs to listen to it.

Add the modesetting driver to the xpresent whitelist so mpv can get the
correct presentation completion timing when modesetting TearFree is used.

This is also helpful for when xpresent performs page flips directly in the
modesetting driver and a natural delay in the display pipeline causes a
page flip to be delayed by one vblank interval or more.
2022-12-27 13:07:33 +01:00
sfan5
d8ae14653a build: add configure test for POSIX shm for the sake of vo_kitty
Android's POSIX coverage is pretty sketchy but not like we have a choice.
2022-12-26 15:08:07 +01:00
Mia Herkt
874e28f4a4
vo_kitty: Introduce modern sixel alternative
See https://sw.kovidgoyal.net/kitty/graphics-protocol/

This makes no attempt at querying terminal features or handling
terminal errors, as it would require mpv to pass the response codes
from the terminal to the vo instead of interpreting them as
keystrokes made by the user and acting very unpredictably.

Tested with kitty and konsole.

Fixes #9605
2022-12-21 19:39:30 +01:00
chen70
3447463008 hwdec/d3d11va: fix a possible memory leak 2022-12-21 19:03:38 +01:00
garamond13
27dab30209 filter_kernels: fix kaiser
Seems to me that params[1] is set to NAN and here should be the same value as in params[0].
2022-12-20 13:53:25 +01:00
Mia Herkt
56f0ba22f1
vo_sixel: Implement write() loop
Not all systems are Linux. Also update the comment to better reflect
POSIX documentation.
2022-12-20 10:45:36 +01:00
Mia Herkt
125fd4c2f9
vo_sixel: Rename draw-clear -> config-clear 2022-12-20 10:29:49 +01:00
Mia Herkt
08747c4965
osdep/terminal.h: Rename screen buffer controls
SAVE/RESTORE were a bit misleading.
2022-12-20 10:26:53 +01:00
Mia Herkt
a4cac2ddc6
vo_sixel: Alias/deprecate exit-clear -> alt-screen
Also update documentation to reflect actual behavior.
2022-12-20 10:22:51 +01:00
Mia Herkt
12c3203e98
vo_sixel: Make buffering optional
It can be slower than unbuffered.
2022-12-20 10:06:49 +01:00
Mia Herkt
fe21553637 vo_sixel: Buffer full output sequence
This allows the VO to write its output without interference from other
processes or threads.
2022-12-19 13:48:49 +01:00
Mia Herkt
3ca31b6cf4 vo_sixel: Use write(2) on POSIX platforms 2022-12-19 13:48:49 +01:00
Mia Herkt
0f721ab51c vo_tct: Use newer options API 2022-12-19 13:48:49 +01:00
Mia Herkt
85f1fa0715 vo_sixel: Move user options to struct 2022-12-19 13:48:49 +01:00
Mia Herkt
68ae603e75 vo_sixel: Add option to skip clear while drawing 2022-12-19 13:48:49 +01:00
Mia Herkt
f1957ce911 osdep/terminal: Move common esc codes to terminal.h 2022-12-19 13:48:49 +01:00
Mia Herkt
4e1626a21c vo_sixel: Use the alternate buffer to restore term 2022-12-19 13:48:49 +01:00
Mia Herkt
1564e4f29f vo_tct: Use the alternate buffer to restore term 2022-12-19 13:48:49 +01:00
Philip Langdale
eeefa8aec0 vd_lavc: Set AV_HWACCEL_FLAG_UNSAFE_OUTPUT flag
This new hwaccel flag was added to allow us to request that an hwaccel
decode not implicitly copy output frames before passing them out. The
only hwaccel that would implicitly copy frames is nvdec due to how it
has a small output pool that cannot be grown very much. However, we
already copy frames as soon as we get our hands on them (in our hwdec)
so we're already safe from pool exhaustion, and the extra copy doesn't
help us.
2022-12-12 10:07:43 -08:00
EmperorPenguin18
cf349d68e3 hwdec_drmprime: support yuv420p format
H264 hardware decode with v4l2m2m wasn't working on the RPi 4. Mpv would
report the image format (yuv420p) wasn't supported. The change to
hwdec_drmprime.c is to explicitly say that the format now is supported.
The change to dmabuf_interop_gl.c is to specify the colour format of the
planes before generating egl images. 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>
2022-12-10 15:57:09 -08:00
NRK
25b66256d7 player: add window-id property
currently only supported on x11.

one practical use-case of this is wanting to embed something (such as
dmenu) into the mpv window to use as a menu/selection. there might be
other use-cases as well (e.g doing some shenanigans with `xdotool` or
whatnot).

it's currently possible to:

* listen for 'current-window-scale' change (to check if the
  window has been created or not)
* call an external tool like `xdo` or `xdotool` and grab the xid
  from mpv's pid.

however it adds unnecessary dependency on external tools when mpv is
fully capable of easily providing this information.

closes: #10918
2022-12-05 02:03:25 +00:00
Philip Langdale
4574dd5dc6 ffmpeg: update to handle deprecation of av_init_packet
This has been a long standing annoyance - ffmpeg is removing
sizeof(AVPacket) from the API which means you cannot stack-allocate
AVPacket anymore. However, that is something we take advantage of
because we use short-lived AVPackets to bridge from native mpv packets
in our main decoding paths.

We don't think that switching these to `av_packet_alloc` is desirable,
given the cost of heap allocation, so this change takes a different
approach - allocating a single packet in the relevant context and
reusing it over and over.

That's fairly straight-forward, with the main caveat being that
re-initialising the packet is unintuitive. There is no function that
does exactly what we need (what `av_init_packet` did). The closest is
`av_packet_unref`, which additionally frees buffers and side-data.
However, we don't copy those things - we just assign them in from our
own packet, so we have to explicitly clear the pointers before calling
`av_packet_unref`. But at least we can make a wrapper function for
that.

The weirdest part of the change is the handling of the vtt subtitle
conversion. This requires two packets, so I had to pre-allocate two in
the context struct. That sounds excessive, but if allocating the
primary packet is too expensive, then allocating the secondary one for
vtt subtitles must also be too expensive.

This change is not conditional as heap allocated AVPackets were
available for years and years before the deprecation.
2022-12-03 14:44:18 -08:00
Philip Langdale
77e7f5de2c sws_utils: update to handle deprecation of avcodec_enum_to_chroma_pos
This has been replaced by `av_chroma_location_enum_to_pos`.
2022-12-01 10:45:47 -08:00
Philip Langdale
83257be693 vd_lavc: update to handle deprecation of pkt_duration
This has been replaced by `duration`.
2022-12-01 10:45:47 -08:00
Philip Langdale
70683b8916 ffmpeg: increase minimum required version to 4.4
Now that 0.35 has been released, we can consider increasing our minimum
required ffmpeg version. Currently, we think 4.4 is the most recent
version we can move to (from the current requirement of 4.0).

This allows us to remove a few conditionals. There are more that we
won't be able to remove unless we move further up to 5.1.
2022-12-01 10:45:47 -08:00
Dudemanguy
11229e7f71 wayland: check for resize/move in touch event first
8300830951 rearranged/simplified some of
the wayland touch code mainly because what was there before was
completely broken on my machine in those days (dragging was unreliable,
resizing was really buggy, etc.). However, one user said that touch
input no longer worked for him after that change. I could not ever
reproduce it, but it seems the issue was putting down the key before
testing for resize/move in the code. Now who knows why this actually
matters, but apparently it works for the user in question and I don't
observe any unexpected behavior on my end when swapping the order. Like
the mouse/pointer code, we also now do a test for dragging before
actually trying a resize/move which is a little more consistent than
before. Fixes #9771.
2022-12-01 11:14:03 -06:00
Niklas Haas
e97e0e4d92 vo_gpu_next: don't flush cache on OSD update
Flushing the cache is a hammer-for-a-screw operation, because it nukes
*all* renderer state, including the HDR peak detection state. When
enabling e.g. --hdr-compute-peak, or any other future methods of dynamic
tone mapping, this would lead to bad results (e.g. brightness
fluctuations) whenever the OSD state is updated.

Instead of flushing the cache to force an OSD re-render, instead just
update the frame signature directly whenever its osd_sync value changes.
This accomplishes effectively the same thing but without touching the
HDR state.

This is slightly violating the libplacebo abstraction in a way that
isn't publicly documented. To be on the safe side we could make a carbon
copy of the array before modifying it, but given that this is unlikely
to change upstream I'll probably just end up explicitly documenting it
instead of forcing the copy in mpv.
2022-11-25 02:15:05 +01:00
Niklas Haas
e1a04cd8ac lcms: fix validate_3dlut_size_opt
Not only was this function needlessly convoluted, it was also broken -
since it returned a bool value where an error code was expected.
2022-11-21 17:39:37 +01:00
Niklas Haas
b9b3342369 lcms: always parse lcms2-related options
Currently, the lcms-related options are only defined when lcms2 is
enabled at build time. However, this causes issues (e.g. segfault) for
vo_gpu_next, which relies on the presence of these options (to forward
them to libplacebo).

(That libplacebo internally depends on lcms2 as well is an
implementation detail - compiling mpv *without* lcms against libplacebo
*with* lcms should be possible in principle)

Fixes: #10891
Closes: #10856
2022-11-21 17:39:37 +01:00
LaserEyess
a62f71bfbe vo_dmabuf_wayland: use single-pixel-buffer-v1
The new single-pixel-buffer protocol is designed to optimize the case
for using a solid color as an underlay wl_surface. It works the same as
the wl_shm 1x1 pixel trick currently used, but it allows the compositor
to make optimizations with more certainty than the wl_shm trick.
2022-11-20 19:13:59 +00:00
LaserEyess
303178e645 wlbuf_pool.h: add headers for forward declarations
This was previously implicitly included by the order of headers in
vo_dmabuf_wayland.c, but it is better to make it an explicit and reorder
the headers properly.
2022-11-20 19:13:59 +00:00
Niklas Haas
8327ac3e6d vo_gpu_next: fix undefined behavior on alpha-first formats
When the alpha channel is the first component, this code block gets
skipped by the continue, meaning the check for c==0 never passes.

Fix it by explicitly keeping track of whether bits have been set.
2022-11-19 14:12:24 +01:00
Dudemanguy
d3a61cfe98 wayland: also log refresh rate on surface entrance
Never bothered to log this for some reason, but it's pretty convenient
when debugging.
2022-11-18 16:36:21 -06:00
LaserEyess
ba20f60add drm: remove legacy API
The legacy DRM API adds some complexity to the DRM code. There
are only 4 drivers that do not support the DRM Atomic API:

1. radeon (early GCN amd cards)
2. gma500 (ancient intel GPUs)
3. ast (ASPEED SoCs)
4. nouveau

Going forward, new DRM drivers will be guaranteed to support the atomic
API so this is a safe removal.
2022-11-16 09:32:55 +01:00
Dudemanguy
6623efb142 wayland: add support for content-type protocol
The content-type protocol allows mpv to send compositor a hint about the
type of content being displayed on its surface so it could potentially
make some sort of optimization. Fundamentally, this is pretty simple but
since this requires a very new wayland-protocols version (1.27), we have
to mess with the build to add a new define and add a bunch of if's in
here. The protocol itself exposes 4 different types of content: none,
photo, video, and game.

To do that, let's add a new option (wayland-content-type) that lets
users control what hint to send to the compossitor. Since the previous
commit adds a VOCTRL that notifies us about the content being displayed,
we can also add an auto value to this option. As you'd expect, the
compositor hint would be set to photo if mpv's core detects an image,
video for other things, and it is set to none for the special case of
forcing a window when there is not a video track. For completion's sake,
game is also allowed as a value for this option, but in practice there
shouldn't be a reason to use that.
2022-11-15 23:18:55 +00:00
Dudemanguy
bab85944df player/video: add VOCTRL_CONTENT_TYPE
mpv's core already keeps track of whether or not it thinks a track is an
image. Some VOs (i.e. wayland) would benefit from knowing if what is
currently being displayed is an image or not so add a new VOCTRL that
signals this anytime we load a new file with a VO. Additionally, let's
add a helper enum for signaling the kind of content that is being
displayed. There is now MP_CONTENT_NONE (strictly for force window being
used on a track with no image/video), MP_CONTENT_IMAGE, and
MP_CONTENT_VIDEO. See the next commit for the actual usage of this (with
wayland).
2022-11-15 23:18:55 +00:00
Philip Langdale
25fa52d237 vo: hwdec: remove legacy_names
These were introduced for configuration compatibility in 0.35 but we
don't want to retain them past that point.
2022-11-15 16:33:12 +01:00
Dudemanguy
38a626650a player: add --force-render option
mpv has an internal optimization on a couple of platforms where it will
not render any frames if the window is minimized or hidden. There's at
least once possible use case for wanting to force a render anyway
(screensharing with pipeware) so let's just add a simple switch for
this that always forces mpv to render. Closes #10846.
2022-11-15 15:31:21 +00:00
Dudemanguy
295ceab382 wayland: error out if essential protocol support is missing
Related issue: #10868. While most protocols are in theory optional, a
small amount of them are absolutely essential and nothing will work
without them. We should make sure to error out in those cases and not
try to actually do anything. For wayland support in general,
wl_compositor support is obviously required. If there is no wl_surface,
you can't do anything. Additionally, vo_wlshm quite obviously requires
wl_shm so mark that one as well. vo_dmabuf_wayland needs linux_dmabuf,
viewporter, wl_shm, and wl_subcompositor. In practice, these are all
very standard protocols and shouldn't be missing but the linked issue
above is at least one example where a compositor was stuck on an ancient
version of a wayland interface.
2022-11-15 14:42:02 +00:00
Niklas Haas
33136c276c vo_gpu_next: add tunable shader parameters
This is a very simple but easy way of doing it. Ideally, it would be
nice if we could also add some sort of introspection about shader
parameters at runtime, ideally exposing the entire list of parameters as
a custom property dict. But that is a lot of effort for dubious gain.

It's worth noting that, as currently implemented, re-setting
`glsl-shader-opts` to a new value doesn't reset back previously mutated
values to their defaults.
2022-11-11 13:58:35 +01:00
sfan5
ac3966184b vo_gpu: mark --gamma-factor and --gamma-auto with deprecation warnings
This was forgotten in commit 2207236aaa.
2022-11-10 16:19:37 +01:00
sfan5
175e250038 wayland, x11: fix possibly unsafe bstr usage
In practice this never led to any issues due to implementation
details of bstr_sanitize_utf8_latin1, but there's no guarantee that
a bstr is correctly null-terminated.
2022-11-10 16:19:37 +01:00
Aaron Boxer
00e3c90fb1 vo_dmabuf_wayland: improve error handling exporting VA surface
1. check for all error conditions when calling vaExportSurfaceHandle
2. only clean up valid descriptors
2022-11-07 16:42:01 +00:00
Aaron Boxer
259eda4e2f hwdec_vaapi: only set VADisplay resource if entire init process has succeeded
This resource is used by dmabuf_waland to decide if it should manage
vaapi buffers, so it should not be set if vaapi init has failed
2022-11-07 16:42:01 +00:00
Dudemanguy
2c53fb6a2b gpu/context: properly guard wldmabuf context
This should only be added if the build has dmabuf-wayland enabled. This
fixes #10828.
2022-11-03 17:24:09 -05:00
Niklas Haas
6acb7db9fa vo_gpu_next: set background transparency
Fixes: https://github.com/mpv-player/mpv/issues/10815
2022-11-01 19:09:40 +01:00
Lynne
d555ae9571 wayland_common: always zero out presentation context when destroying it
A desync between the feedback and the feedback in the context
still happens when closing a hidden surface.
2022-10-31 20:46:29 -05:00
Dudemanguy
5fa3bca863 wayland: correct braindead comment (no-op)
I was confused in d3a28f12c9 why it
actually even worked, but after not being stupid, it's quite obviously
just a dangling pointer. The reason it only happens with
wp_presentation_feedback is because the object and listener actually
created in frame_callback not the presentation events itself (for vsync
timing reasons). So it is possible to free the object, but not
immediately recreate it again before quitting (unlike with the frame
callback). The actual comment is moved into feedback_presented (which is
first) but as of this commit it doesn't have the NULL setting logic
(that's the next one).
2022-10-31 20:45:56 -05:00
Dudemanguy
d3a28f12c9 wayland: hack around presentation_feedback weirdness
964692ad4c added some code to destroy
presentation_feedback we get in the presentation_discarded event. This
is the correct thing to do since the compositor could send us this
instead of feedback_presented. Without that change, mutter could
potentially leak memory on every frame.

Unfortunately, life is not so simple and wlroots and weston act
differently. These compositors only send one presentation_discarded
event if the mpv window is hidden. Not on every single missed frame like
mutter. Now in theory this shouldn't matter, but it also turns out that
mpv attempts to free the presentation feedback twice if you quit it
while it is hidden away (on weston and wlroots compositors only). The
inital wp_presentation_feedback_destroy in feedback_discarded fires, but
then the function goes off again in vo_wayland_uninit because
wl->feedback is apparently not NULL for some reason. Possibly, this is
some race condition but we can't just get rid of what's in
feedback_discarded since mutter needs this line. Instead, just hack it
by explicitly setting wl->feedback to NULL in feedback_discarded after we
destroy the presentation feedback. Some valgrind testing in mutter,
sway, and weston shows that this works correctly on all of those
compositors with various combinations of mpv being visible or not while
quitting. feedback_presented doesn't appear to exhibit this behavior so
we just leave that as-is.
2022-10-30 14:23:55 +00:00
Dudemanguy
667222dffa wayland: free dmabuf_feedback object
666cb91cf1 added dmabuf_feedback, but it
was never actually free'd on uninit. Because this function requires
wayland protocols 1.24, we have to wrap it in an #if. Also throw in some
minor cosmetic changes in here.
2022-10-30 14:23:55 +00:00
Philip Langdale
48bb17549c filters/f_hwtransfer: remove VAAPI <-> Vulkan mapping for now
This mapping isn't actually relevant until we have the Vulkan interop
merged, and it requires a newer version of libavutil than our minimum
requirement. So I'm going to remove it from master and put it in the
interop PR.

Fixes #10813
2022-10-29 18:49:46 -07:00
Dudemanguy
f594482451 build: add an additional check for wayland-protocols 1.24
666cb91cf1 added support for v4 of the
dmabuf protocol. This was meant to be optional and the fallback support
for the old v2 (dates back to 2017[0] well before the 1.15
wayland-protocol version we depend on) was maintained. However, v4 added
several new functions and structs that of course aren't defined in old
protocol versions so naturally this breaks the build on those systems.
Since this is just a niche feature and not really critical to overall
wayland support in mpv, just give in and add another check in the build
system and #if out the newer stuff in wayland_common. v4 of linux-dmabuf
depends on wayland protocols 1-24[1], so go ahead and make that our new
check. Fixes #10807.

[0]: a840b3634a
[1]: 8a5cd28a0e
2022-10-29 20:41:20 +00:00
Dudemanguy
adb556bf15 vo_dmabuf_wayland: use special ra_ctx_create_by_name
vo_dmabuf_wayland has its own ra and context so it can handle all the
different hwdec correctly. Unfortunately, this API was pretty clearly
designed with vo_gpu/vo_gpu_next in mind and has a lot of concepts that
don't make sense for vo_dmabuf_wayland. We still want to bolt on a
ra_ctx, but instead let's rework the ra_ctx logic a little bit. First,
this introduces a hidden bool within the ra_ctx_fns that is used to hide
the wldmabuf context from users as an option (unlike the other usual
contexts). We also want to make sure that hidden contexts wouldn't be
autoprobed in the usual ra_ctx_create, so we be sure to skip those in
that function. Additionally, let's create a new ra_ctx_create_by_name
function which does exactly what says. It specifically selects a context
based on a passed string. This function has no probing or option logic
is simplified just for what vo_dmabuf_wayland needs. The api/context
validations functions are modified just a little bit to make sure hidden
contexts are skipped and the documentation is updated to remove this
entries. Fixes #10793.
2022-10-28 02:36:46 +00:00
Dudemanguy
31af37f877 vo_dmabuf_wayland: load all hwdecs in preinit
vo_gpu and vo_gpu_next typically load hwdec interops on demand and
vo_dmabuf_wayland naively copied this logic. This is actually wrong
however since draw_frame in the VO always inherently relies on hwdec
being fully loaded. This can lead to a race condition during startup
which happens with --force-window=immediate. Avoid this by simply always
loading all the interops. In the case of vo_dmabuf_wayland, this is not
really a big deal since there's only vaapi and drmprime to load. Also
fixes #10791 (the other half).
2022-10-28 02:36:46 +00:00
Dudemanguy
99699cd7ba wayland: always do a display_roundtrip at the end of init
We really need two roundtrips in the init function. The first one is for
running the registry and then second one is for ensuring the xdg_surface
and other potential wayland objects are configured at least once before
mpv does anything. We've been getting away with only doing the first for
a while via luck, but really we should do at least one more wait on the
compositor. Fixes #10791 (half of it).
2022-10-28 02:36:46 +00:00
Dave Craig
6e274dc8d8 vo_dmabuf_wayland: fix DRM builds with no VAAPI
Building on DRM platform without VAAPI broke because of misuse of
HAVE_VAAPI with #ifdef in place of #if. Also, the hwcontext_drm.h
header is not required for VAAPI builds, only DRM builds.
2022-10-27 18:41:37 +00:00
Jan Ekström
bc3e96098d video/out/wayland_common: adjust decoration disagreement log level
Originally, I considered warning once to be useful for figuring
out whether the change in logic regarding resetting requested
mode actually fixed the reported issue or not, but alas not everyone
was happy with that decision. Thus the log level will always be
debug. This enables us to lose one level of indent as well as a
variable, which is always positive.

Additionally, make the message more explicit regarding what could
possibly be implied by the mismatch, as it seems like this was
not always clear.
2022-10-27 19:07:05 +03:00
Jan Ekström
e0c4193ee5 video/out/wayland_common: clear decoration request even if compositor disagrees
Otherwise mpv and the compositor can end up in an eternal loop where
mpv requests one mode, and compositor tells that the mode is not
that (and will most likely not change).

Additionally, log these mismatches - first time as a warning, and
later as debug logging.
2022-10-26 22:20:31 +03:00
Jan Ekström
f39e56bf5e video/out/wayland_common: don't pass a negative of border flag into ternary
Make it clear that we are passing the original requested border mode
on.
2022-10-26 22:20:31 +03:00
Jan Ekström
2c58ab481b video/out/wayland_common: make decoration state usage explicit
It is verbose, but makes it more explicit that requested_decoration
takes in three values:

* 0: no specific mode requested by mpv
* ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE: (!border)
* ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE: (border)
2022-10-26 22:20:31 +03:00
Emmanuel Gil Peyrot
666cb91cf1 wayland: bump dmabuf protocol to version 4
Pulled from https://github.com/mpv-player/mpv/pull/10382

The zwp_linux_dmabuf_v1 protocol version 4 provides a file descriptor
containing both formats and modifiers, which makes it possible for the
compositor to import the buffers onto planes using explicit modifiers.

This is an extremely important efficiency improvement, as the 3D
hardware can be left powered off altogether, the vaapi buffer being sent
directly from the video hardware to the display controller.

It could be possible to support zwp_linux_dmabuf_v1 version 3 as well,
but there is no reason beyond compatibility with old stacks.  I would
recommend to ditch version 2 as well, as modifier-less formats aren’t
very useful nowadays.
2022-10-26 18:41:47 +00:00
Aaron Boxer
aeb4792cb6 vo_vaapi_wayland: remove, as it is superceded by vo_dmabuf_wayland 2022-10-26 18:41:47 +00:00
Aaron Boxer
7358b9d371 vo_dmabuf_wayland: wayland VO displaying dmabuf buffers
Wayland VO that can display images from either vaapi or drm hwdec

The PR adds the following changes:

1. a context_wldmabuf context with no gl dependencies
2. no-op ra_wldmabuf and dmabuf_interop_wldmabuf objects
   no-op because there is no need to map/unmap the drmprime buffer,
    and there is no need to manage any textures.

Tested on both x86_64 and rk3399 AArch64
2022-10-26 18:41:47 +00:00
Aaron Boxer
964692ad4c wayland: clean wp_presentation_feedback in discard callback to avoid leak 2022-10-26 18:41:47 +00:00
Aaron Boxer
fbcd9c140f mp_imgfmt: move DRMPRIME format to end of enum
dmabuf-wayland vo supports both DRMPRIME and VAAPI formats.
If upload filter is needed, we want to try VAAPI hwdec first
since most users will be using VAAPI, and there is a several second
delay when DRMPRIME hwdec is tried and fails.
2022-10-26 18:41:47 +00:00
Philip Langdale
395b37b005 vo_gpu/hwdec: add NULL check for legacy_name 2022-10-22 12:56:18 -07:00
sfan5
42cfed002f hwdec_aimagereader: fix incorrect return values 2022-10-22 15:34:37 +02:00
Philip Langdale
345342f50a hwdec/dmabuf_interop_gl: work-around implicit rgba swizzling
This has been a long standing problem that I think was the root cause
for wm4's vaapi shitlist. As DRM explicit supports all possible rgba
orderings, but OpenGL only guarantees support for 'rgba8', something
has to happen to support import of dmabufs with non-native ordering.

Although undocumented, it appears that somewhere in the import on the
GL side, the ordering is swizzled to rgba - which makes sense as that's
the only way to be able to support importing all the different formats.

But we didn't know this, and we do our own swizzling based on the
original imgfmt - which matches the drm format. So we get double
swizzling and messed up colours.

As there is no way for us to express that the GL swizzle happened to
the rest of mpv, the easiest thing to do is fudge the format to the
natural ordering so the GL doesn't change anything, then our swizzling
will do the right thing in the end.

Note that this change doesn't handle 0rgb and 0bgr because they seem to
be affected by some additional feature/bug that is mangling the
ordering somewhere that equally affects Vulkan interop. That could be a
vaapi driver bug or something going on in ffmpeg.
2022-10-15 09:30:46 -07:00
Philip Langdale
66e30e7f2f hwdec/vaapi: improve probing of supported sw formats
The logic around trying to establish what formats are supported by
vaapi is confusing, and it turns out that we've been doing it wrong.

Up until now, we've been going through the list of decoding profile
endpoints and checking the formats declared in those profiles to build
our list.

However, the set of formats that the vaapi driver can actually support
is potentially a superset of those supported by any given profile
endpoint. This master list is exposed by libavutil via the
av_hwframe_transfer_get_formats() function, and so we should use that
list as our starting point.

Perhaps surprisingly, this change actually removes no code, because we
still want the logic that enumerates endpoints and finds supported
formats for endpoints. We need this because we must have at least one
known sw format to initialise the hwframe_ctx with.

Additionally, while in the general case,
av_hwframe_transfer_get_formats can return different formats depending
on what format you initialise the hwframe_ctx with, I happen to have
read the libavutil code, and it doesn't care, so we just need to call
it once, we know we'll get back all known formats.

In practice, with an Intel vaapi driver, this will result in us
supporting a handful of extra formats for hwuploads - particularly
yuv420p (so no need to convert to nv12 first) and various orderings
of rgb(a).
2022-10-15 09:30:46 -07:00
rcombs
dfb5b0c55f vo_gpu_next: fix crash on uninit after startup failure 2022-10-14 15:37:49 +02:00
Philip Langdale
064059e6c3 vo_gpu/hwdec: rename and introduce legacy names for some interops
We've had some annoying names for interops, which we can't simply
rename because that would break config files and command lines. So we
need to put a little more effort in and add a concept of legacy names
that allow us to continue loading them, but with a warning.

The two I'm renaming here are:
* vaapi-egl -> vaapi (vaapi works with Vulkan too)
* drmprime-drm -> drmprime-overlay (actually describes what it does)
* cuda-nvdec -> cuda (cuda interop is not nvdec specific)
2022-10-11 10:07:48 -07:00
odnar-dev
d050e350fe x11: fix --on-all-workspaces option
mpv set _NET_WM_DESKTOP to 0xFFFFFFFF, which behaves differently with each window manager.
Instead, set the window property to STICKY, and let the window managers deal with it.
2022-10-11 09:25:26 +02:00
Niklas Haas
c96cee2940 vo_gpu_next: vulkan: libplacebo: unify log prefix
The new status quo is simple: all messages coming from libplacebo are
marked "vo/gpu{-next}/libplacebo", regardless of the backend API (vulkan
vs opengl/d3d11).

Messages coming from mpv's internal vulkan code will continue to come
from "vo/gpu{-next}/vulkan", and messages coming from the vo module
itself will be marked "vo/gpu{-next}".

This is significantly better than the old status quo of vulkan messages
coming from "vo/gpu{-next}/vulkan/libplacebo" whereas opengl/d3d11
messages simply came from "vo/gpu{-next}", even when those messages
originated from libplacebo.

(It's worth noting that the the destructor for the log is redundant
because it's attached to the ctx which is freed on uninit anyway)
2022-10-09 21:47:35 +02:00
Dudemanguy
bb56554a62 x11: fix a couple of memory leaks
Managed to go completely unnoticed for months (who was the bad person
that introduced these*). Fairly self-explanatory. After getting
ProviderInfo from randr, we need to free it. The other one is pretty bad
because it leaked every frame (ouch). It turns out that you're supposed
to free any event data after you cast a generic event to an
XGenericEventCookie. Free that as well.

*: It was me.
2022-10-08 23:50:55 -05:00
Dudemanguy
d2a0791fe8 wayland: correctly handle non-CLOCK_MONOTONIC clocks
The wayland presentation time code currently always assumes that only
CLOCK_MONOTONIC can be used. There is a naive attempt to ignore clocks
other than CLOCK_MONOTONIC, but the logic is actually totally wrong and
the timestamps would be used anyway. Fix this by checking a use_present
bool (similar to use_present in xorg) which is set to true if we receive
a valid clock in the clockid event. Additionally, allow
CLOCK_MONOTONIC_RAW as a valid clockid. In practice, it should be the
same as CLOCK_MONOTONIC for us (ntp/adjustime difference wouldn't
matter). Since this is a linux-specific clock, add a define for it if it
is not found.
2022-10-06 18:08:51 +00:00
Niklas Haas
7f5541fc3c vulkan: remove --vulkan-disable-events
This has had no effect since libplacebo v4.192.0, and was deprecated
upstream a year ago. No deprecation period in mpv is justified by this
being a debug / work-around option.
2022-10-05 16:35:14 +02:00
sfan5
a2de6524ff vo: hwdec_aimagereader: add missing image format specifier
This is required since e50db42927, but was missed during the merge.
2022-10-03 20:34:25 +02:00
sfan5
5463d3eeff vo_gpu: hwdec: add Android hwdec utilizing AImageReader 2022-10-02 14:12:26 +02:00
Niklas Haas
98e6fb26a3 vo_gpu_next: respect --blend-subtitles=<yes/no>
This brings vo_gpu_next's behavior more in line with vo_gpu. Currently,
the status quo was that `vo_gpu_next` generated subtitles with the full
resolution of the dst crop, even though practical limitations of
libplacebo meant that such subtitles inevitably got cut off at the video
boundaries. This was actually a worse status quo than `vo_gpu`, which
simply constrained subtitles to the video dimensions to prevent these
issues.

With this change, the behavior is the same as `vo_gpu`, which has the
exact same problem w.r.t interpolation. Users are back to choosing
between --blend-subtitles=yes and not having subtitles in margins,
and using --blend-subtitles=no and not having subtitle interpolation.

There are different pros and cons to each approach, and I still
ultimately plan on allowing libplacebo to interpolate subtitles even in
the black bars, to solve this issue once and for all. But for now, let's
not let perfect be the enemy of good.

No attempt is made to implement `--blend-subs=video`, which I consider
deprecated.

Fixes: https://github.com/mpv-player/mpv/issues/10272
2022-09-29 22:02:00 +02:00
Niklas Haas
eba4ce5c2d mp_image: strip DoVi metadata that requires an EL
We can't support this. Better strip it than partially apply.

Fixes: #9831
2022-09-28 02:28:37 +02:00
Niklas Haas
3376f775e3 vo_gpu_next: fix screenshots of rotated sources
I actually don't quite understand why this is needed, since in theory we
should already be doing the rotation as part of applying the crop. But I
guess that code doesn't quite work. This is the only way it works, so
it's probably correct. (And note that `vo_gpu` does the same internally)
2022-09-27 21:32:46 +02:00
Niklas Haas
1c8fdf6992 vo_gpu_next: use static assert for array size
This is used in other places in the code, so it should be fine.
2022-09-27 01:35:53 +02:00
Niklas Haas
6b9b032d51 vo_gpu_next: update render_info for upstream API change
This fixes an issue where blend stages with multiple passes got
overwritten by later passes, with only the final pass (typically the
overlayp pass) actually being shown.
2022-09-26 21:14:34 +02:00
Niklas Haas
2b0736ed83 vo_gpu_next: implement --video-output-levels
This was ignored as an oversight.
2022-09-25 20:31:22 +02:00
Philip Langdale
f221666ade f_hwtransfer: mp_image_pool: support HW -> HW mapping
Certain combinations of hardware formats require the use of hwmap to
transfer frames between the formats, rather than hwupload, which will
fail if attempted.

To keep the usage of vf_format for HW -> HW transfers as intuitive as
possible, we should detect these cases and do the map operation instead
of uploading.

For now, the relevant cases are moving between VAAPI and Vulkan, and
VAAPI and DRM Prime, in both directions. I have introduced the IMGFMT
entry for Vulkan here so that I can put in the complete mapping table.
It's actually not useless, as you can map to Vulkan, use a Vulkan
filter and then map back to VAAPI for display output.
2022-09-21 09:39:34 -07:00
Philip Langdale
7b84e6fa89 f_autoconvert: f_hwtransfer: support HW -> HW uploads
Historically, HW -> HW uploads did not exist, so the current code
assumes they will never happen. But as part of introducing Vulkan
support into ffmpeg, we added HW -> HW support to enable transfers
between Vulkan and CUDA.

Today, that means you can use the lavfi hwupload filter with the
correct configuration (and previous changes in this series) but it
would be more convenient to enable HW -> HW in the format filter so
that the transfers can be done more intuitively:

```
--vf=format=fmt=cuda
```

and

```
--vf=format=fmt=vulkan
```

Most of the work here is skipping logic that is specific to SW -> HW
uploads doing format conversion. There is no ability to do inline
conversion when moving between HW formats, so the format must be
mutually understood to begin with.

Additional work needs to be done to enable transfers between VAAPI
and Vulkan which uses mapping, rather than uploads. I'll tackle that
in the next change.
2022-09-21 09:39:34 -07:00
Philip Langdale
989d873d6e filters: lavfi: allow hwdec_interop selection for filters
Today, lavfi filters are provided a hw_device from the first
hwdec_interop that was loaded, regardless of whether it's the right one
or not. In most situations where a hardware based filter is used, we
need more control over the device.

In this change, a `hwdec_interop` option is added to the lavfi wrapper
filter configuration and this is used to pick the correct hw_device to
inject into the filter or graph (in the case of a graph, all filters
get the same device).

Note that this requires the use of the explicit lavfi syntax to allow
for the extra configuration.

eg:

```
mpv --vf=hwupload
```

becomes

```
mpv --vf=lavfi=[hwupload]:hwdec_interop=cuda-nvdec
```

or

```
mpv --vf=lavfi-bridge=[hwupload]:hwdec_interop=cuda-nvdec
```
2022-09-21 09:39:34 -07:00
Philip Langdale
5629ed81ee filters: support loading new hwdec_interops from filters
If we want to be able to handle conversion between hw formats in filter
chains, then we need to be able to load hwdec_interops from filters, as
the VO is only ever going to initialise one interop, based on its
configuration. That means that in almost all situations, only one of
the required interops will be loaded at the time the filter is
initialised.

The existing code has some assumptions that new hwdec_interops will not
be loaded after the vo has picked one to use. This change fixes two
instances:

* Refusing to load a new hwdec_interop if there is at least one
  loaded already.
* Not recalculating the set of formats known to the autoconvert
  filter when a new output format shows up. This leads to autoconvert
  not knowing that a new format is supported when the hwdec interop is
  lazily loaded.
2022-09-21 09:39:34 -07:00
Philip Langdale
e50db42927 vo: hwdec: do hwdec interop lookup by image format
It turns out that it's generally more useful to look up hwdecs by image
format, rather than device type. In the situations where we need to
find one, we generally know the image format we're dealing with. Doing
this avoids us having to create mappings from image format to device
type.

The most significant part of this change is filling in the image format
for the various hw interops. There is a hw_imgfmt field today today, but
only a couple of the interops fill it in, and that seems to be because
we've never actually used this piece of metadata before. Well, now we
have a good use for it.
2022-09-21 09:39:34 -07:00
Niklas Haas
1fb5f06c66 vo_gpu_next: support error diffusion dithering
One step closer to vo_gpu_next feature parity with vo_gpu!
2022-09-20 14:59:00 +02:00
rcombs
588cb9a977 mac: avoid unnecessary unsafe conversions; fixes crash in debug builds
Previously, running a debug build of mpv would crash with this output
when preinit() at vo_libmpv.c:732 calls control(vo, VOCTRL_PREINIT, NULL):

Swift/Optional.swift:247: Fatal error: unsafelyUnwrapped of nil optional

This comes from this line of code:

var data = UnsafeMutableRawPointer.init(bitPattern: 0).unsafelyUnwrapped

Unsafely unwrapping a UnsafeMutableRawPointer.init has always been UB,
but the Swift runtime began asserting on it in debug builds a couple macOS
versions ago.
2022-09-14 16:28:12 -05:00
Niklas Haas
b9c7e5b5ff vo_gpu_next: only require full pixel byte alignment
The current code also rejects e.g. rgb30, even though this format is
perfectly valid, because it only checks for alignment of the used bits.
2022-09-12 16:01:07 +02:00
Niklas Haas
30ca46259e vo_gpu_next: implement ICC 3DLUT caching
Relies on a new upstream API for adding save/load callbacks to the ICC
3DLUT generation parameters.

Closes: https://github.com/mpv-player/mpv/issues/10252
2022-09-12 15:35:17 +02:00
Niklas Haas
7a6dc79e29 vo_gpu_next: use correct pixel size when mapping formats
`total_bits` may be less than the true pixel stride (`bpp`) for formats
which contain extra ignored components (e.g. rgb0).
2022-09-12 15:25:56 +02:00
Philip Langdale
98f02e33ef repack: add repacker for ccc16x16 formats
I'm adding support in ffmpeg for the XV36 format which will be used
by VAAPI for 12bit 4:4:4 content. It's an undefined-alpha channel
variant of Y412 which is itself a 12bit+4bits padding variant of Y416.

We currently have a repacker for full four channel cccc16, and for
three channel ccc16, but nothing for ccc16x16 with the undefined alpha
channel.

It's simple enough to add one using the existing macros.
2022-09-10 12:31:44 -07:00
Tillmann Karras
1800891a1d vo_gpu_next: fix typo affecting --target-trc option 2022-09-02 22:03:33 -04:00
Thomas Weißschuh
103efdd614 x11: add support for F13-F24 keys 2022-09-02 14:05:46 +02:00
Thomas Weißschuh
03e8ed450d wayland: add support for F13-F24 keys 2022-09-02 14:05:46 +02:00
Niklas Haas
04062b6f89 vo_gpu_next: display subtitles without video stream
Fixes https://github.com/mpv-player/mpv/issues/10594
2022-08-31 13:33:05 +02:00
Niklas Haas
37aea112c1 vo_gpu_next: pass GL get_proc_addr pointer to libplacebo
Facing down the multitude of ways to somehow wrangle the get_fn pointer
out of the GL environment and into libplacebo, I decided the easiest is
to just store it inside the GL struct itself.

The lifetime of this get_fn function is a bit murky, since it's not
clear on whether or not it survives the VO init call (especially in the
case of the GL render API, which explicitly states that parameters do
not need to survive the call they're passed to), so just add a
disclaimer.

(It's fine for us to use like this because `gpu_ctx_create` is still
part of VO init)

Closes https://code.videolan.org/videolan/libplacebo/-/issues/216
2022-08-19 13:54:50 +02:00
Dudemanguy
f0011552e7 wayland: add support for configure bounds
In wayland-protocols 1.25, xdg-shell got a version bump which added the
configure_bounds event. The compositor can send this to clients to
indicate that they should not resize past a certain size. For mpv, we'll
choose to only listen to this on reconfig events (i.e. when the window
first appears and if the video resolution changes later in the
playlist). However, this behavior is still exposed as a user option
(default on) because it will neccesarily conflict with a user setting a
specific geometry size and/or window scale. Presumably, if someone is
setting a really large size that goes beyond the bounds of their
monitor, they actually want it like that. The wayland-protocols version
is newer-ish, but we can get around having to poke the build system by
just using a define that exists in the generated xdg-shell header.
2022-08-14 16:04:49 +00:00
Dudemanguy
f781dddabc x11: fix display-{width,height} calculation
Unexpectedly, x11->screenrc actually doesn't update with randr events.
In a multimonitor configuration it could easily be wrong depending on
the user's layout. While it's tempting to modify the logic so screenrc
changes with randr events, this rectangle is currently used everywhere
and as far as we know, this pretty much works fine. Instead, just loop
over the randr displays that we have and select it if it overlaps with
the winrc. This follows the same logic as the fps selection in the case
of the mpv window overlapping multiple monitors (the last one is
selected).
2022-08-14 16:04:23 +00:00
sfan5
f2ef942ef5 drm_common: remove hard dependency on drmIsKMS()
ae768a1e14 forgot to bump the required
libdrm version however Debian 11 just barely misses the requirement,
which is a good reason not to require it unconditionally anyway.
2022-08-11 18:31:04 +02:00
Ho Ming Shun
5f6e8f856c context_drm_egl: skip page flip wait on error
Any error in page flipping caused mpv to wait indefinitely for a page
flip callback.
2022-08-11 09:05:44 +02:00
Philip Langdale
4081f45501 gpu/hwdec: reorder drmprime below drmprime_drm
The older overlay based drmprime hwdec should be preferred to the new
texture mapping one. This is for a few reasons:

1. In any situation where both hwdecs work, it's probably right to use
   the more mature one by default, for now.
2. It seems like the overlay path primarily works on older SoCs
   where the texture path is less performant, and in at least one
   tested case is visually buggy, so you definitely want it to be
   tried first.
3. In situations where the old hwdec doesn't work, it will fall through
   to the new one.
2022-08-09 22:19:45 -07:00
Philip Langdale
6265cbb62a video/drmprime: fix use-after-free
Same thing as in hwdec/drmprime.
2022-08-09 22:19:45 -07:00
Philip Langdale
f87ab4d441 hwdec/drmprime: fix build
I accidentally included an adjustment for a pending change.
2022-08-09 21:21:47 -07:00
Philip Langdale
093db2f565 hwdec/dmabuf_interop: Properly prefix priv struct
Obviously, this should be dmabuf_interop_priv as it's declared in a
header file that could get included anywhere.
2022-08-09 21:02:50 -07:00
Philip Langdale
dbc2d37401 hwdec/drmprime: Fix small issues
sfan5 found a few things after I pushed the change, so this fixes them.

* Use-after-free on drm_device_Path
* Not comparing render_fd against -1
* Not handling dup() errors
2022-08-09 21:01:04 -07:00
Philip Langdale
25fa1b0b45 hwdec/drmprime: add drmprime hwdec-interop
In the confusing landscape of hardware video decoding APIs, we have had
a long standing support gap for the v4l2 based APIs implemented for the
various SoCs from Rockship, Amlogic, Allwinner, etc. While VAAPI is the
defacto default for desktop GPUs, the developers who work on these SoCs
(who are not the vendors!) have preferred to implement kernel APIs
rather than maintain a userspace driver as VAAPI would require.

While there are two v4l2 APIs (m2m and requests), and multiple forks of
ffmpeg where support for those APIs languishes without reaching
upstream, we can at least say that these APIs export frames as DRMPrime
dmabufs, and that they use the ffmpeg drm hwcontext.

With those two constants, it is possible for us to write a
hwdec-interop without worrying about the mess underneath - for the most
part.

Accordingly, this change implements a hwdec-interop for any decoder
that produces frames as DRMPrime dmabufs. The bulk of the heavy
lifting is done by the dmabuf interop code we already had from
supporting vaapi, and which I refactored for reusability in a previous
set of changes.

When we combine that with the fact that we can't probe for supported
formats, the new code in this change is pretty simple.

This change also includes the hwcontext_fns that are required for us to
be able to configure the hwcontext used by `hwdec=drm-copy`. This is
technically unrelated, but it seemed a good time to fill this gap.

From a testing perspective, I have directly tested on a RockPRO64,
while others have tested with different flavours of Rockchip and on
Amlogic, providing m2m coverage.

I have some other SoCs that I need to spin up to test with, but I don't
expect big surprises, and when we inevitably need to account for new
special cases down the line, we can do so - we won't be able to support
every possible configuration blindly.
2022-08-09 10:19:18 -07:00
Philip Langdale
2b34949a7c hwdec/dmabuf_interop_gl: support basic multi-plane formats
I already added the equivalent logic for dmabuf_interop_pl previously
but I skipped the GL support because importing dmabufs into GL requires
explicitly providing the DRM format, and if you are taking a
multi-plane format and trying to treat each plane as a separate layer,
you need to come up with a DRM format for each synthetic layer.

But my initial testing has shown that the RockPRO64 board I've got to
work on drmprime hwdec will only produce NV12 in a single layer multi
plane format, and it doesn't have Vulkan support, so I have had to
tackle the GL multi-plane problem.

To that end, this change introduces the infrastructure to provide new
formats for synthetic layers. We only have lookup code for NV12 and
P010 as these were the only ones I could test.
2022-08-03 16:56:17 -07:00
Philip Langdale
64f4249604 hwdec/dmabuf_interop: use AVDRMFrameDescriptor to describe dmabufs
Annoyingly, libva and libdrm use different structs to describe dmabufs
and if we are going to support drmprime, we must pick one format and do
some shuffling in the other case.

I've decided to use AVDRMFrameDescriptor as our internal format as this
removes the libva dependency from dmabuf_interop. That means that the
future drmprime hwdec will be able to populate it directly and the
existing hwdec_vaapi needs to copy the struct members around, but
that's cheap and not a concern.
2022-08-03 16:56:17 -07:00
Philip Langdale
e9e5059589 hwdec/dmabuf_interop: refactor out hwdec_vaapi dependencies
With the files renamed, we can now disentangle the shared private
struct between the interops and hwdec_vaapi. We need this separation
to allow the future drmprime hwdec to use the interops.
2022-08-03 16:56:17 -07:00
Philip Langdale
06900eef63 hwdec/vaapi: rename interops to reflect more general use
This is the first in a series of changes that will introduce a drmprime
hwdec. As our vaapi hwdec is based around exporting surfaces as
drmprime dmabufs, we've actually got a lot of useful code already in
place in the GL/PL interops. I'm going to reorganise and adjust this
code to make the interops usable with the new hwdec as well.

The first step is to rename the files and functions. There are no
functional or other changes here. They will come next.
2022-08-03 16:56:17 -07:00
sfan5
ae768a1e14 drm_common: skip cards that don't support KMS for autodetection
Avoids another pitfall on systems where the first card has a primary
node but is not capable of KMS. With this change --drm-context=drm
should work correctly out-of-the-box in all cases.
2022-08-03 16:43:08 +02:00
Ho Ming Shun
8b1f978712 drm: avoid drmModeAtomicCommit races by blocking
On S905X (meson) boards drmModeAtomicCommit called from
disable_video_plane in hwdec_drmprime_drm.c might still be running when
another call is made from queue_flip in context_drm_egl.c.

This causes EBUSY error in queue_flip, and causes mpv to hang.
2022-08-03 16:42:49 +02:00
Aaron Boxer
24d10fc998 video: remove unnecessary code
plane_clear[p] is never NULL
2022-08-01 23:11:42 +02:00
Emmanuel Gil Peyrot
d2467f61be wayland: add missing newline in wayland_common 2022-07-23 19:56:48 +00:00
Philip Langdale
89dfcf8286 hwdec_vaapi_pl: support simple multi-plane image formats
This is somewhat academic for now, as we explicitly ask for separate
layers and the scenarios where multi-plane images are required also use
complex formats that cannot be decomposed after the fact, but
nevertheless it is possible for us to consume simple multi-plane
images where there is one layer with n planes instead of n layers with
one plane each.

In these cases, we just treat the planes the same as we would if they
were each in a separate layer and everything works out.

It ought to be possible to make this work for OpenGL but I couldn't
wrap my head around how to provide the right DRM fourcc when
pretending a plane is a layer by itself. So I've left that
unimplemented.
2022-07-23 12:23:30 -07:00
Niklas Haas
6e4dd334fe vo_gpu_next: fix screenshots on single-frame files
This check was wrong/outdated. PL_QUEUE_MORE does not imply an empty
frame mix, it can still contain partial frames.
2022-07-23 14:54:39 +02:00
Graham Booker
99315383f8 vo_gpu/d3d11: fix VRAM leak
A VRAM memory leak was present in d3d11 when `idle=yes` and playback
stops for an item. This patch re-enables some of the code which is
only used during diagnostic which fixes the issue.
2022-07-21 16:13:45 +02:00
Niklas Haas
8ef744d1b7 vo_gpu_next: don't crash on !frame->current
This path incorrectly assumes there is a current frame.
2022-07-18 22:03:06 +02:00
Coelacanthus
70fa9502f3 libplacebo: fix compatibility with libplacebo >= 5
libplacebo 4.157 [1] rename context.h to log.h, and left a compatibility
header. In 5.x, this header has been removed.

Since we require libplacebo 4.157 to build mpv, we can just use log.h to
fix compatibility with 5.x.

[1]: 2459200a13

Signed-off-by: Coelacanthus <coelacanthus@outlook.com>
2022-07-16 13:06:21 +03:00
Niklas Haas
81c5ed5b13 vo_gpu: fix 3DLUT precision
Using cmsFLAGS_HIGHRESPRECALC results in Little-CMS generating an
internal 49x49x49 3DLUT, from which it then samples our own 3DLUT. This
is completely pointless and not only destroys the accuracy of the 3DLUT,
but also results in no additional gain from increasing the 3DLUT
precision further.

The correct flag for us to be using is cmsFLAGS_NOOPTIMIZE, which
suppresses this internal 3DLUT generation and gives us the full
precision. We can also specify cmsFLAGS_NOCACHE, which is negligible but
in theory prevents Little-CMS from unnecessary pixel equality tests.
2022-07-15 16:34:11 +02:00
Ho Ming Shun
80e29d1851 drm_prime: fix newline in error message 2022-07-05 13:55:47 -04:00
Dudemanguy
369168b9be context_x11egl: remove supposed transparency fix
This was introduced in 7fb972fd39 and
later revised in f5a094db04. Transparency
in EGL/X11 has been broken upstream for years in Mesa unfortunately.
However, the first commit claimed to have found a way to preserve
transparency by doing a trick with picking EGLConfigs (the second commit
revises this but keeps the logic in place). However, it doesn't appear
that the first commit actually fixes anything (transparency doesn't work
on my machine) and no one else seems to have reported it working. On the
other hand, if Mesa does ever actually fix this, transparency would
immediately be broken since mpv would always set the EGL_ALPHA_SIZE to
0. Go ahead and remove this since it doesn't seem to have any actual
utility and is technically a bit of a timebomb (not that deleting two
lines is a lot of work but still) if upstream ever does fix this.
2022-07-01 14:13:19 +00:00
Niklas Haas
3a2838c88d vo_gpu_next: implement --cscale
Fixes #9451
2022-06-24 16:11:17 +02:00
Dudemanguy
652f09a7a6 x11: avoid XPresent API calls when it's not needed
This commit kind of mixes several related things together. The main
thing is to avoid calling any XPresent functions or internal functions
related to presentation when the feature is not auto-whitelisted or
enabled by the user. Internally rework this so it all works off of a
use_present bool (have_present is eliminated because having a non-zero
present_code covers exactly the same thing) and make sure it updates on
runtime. Finally, put some actual logging in here whenever XPresent is
enabled/disabled. Fixes #10326.
2022-06-22 18:09:11 +00:00
Dudemanguy
24f4582b6f x11: add --x11-present option
With the recent addition of the libxpresent, it should improve frame
timings for most users. However, there were known cases of bad behavior
(Nvidia) which lead to a construction of a whitelist instead of just
enabling this all the time. Since there's no way to predict whatever
combination of hardware/drivers/etc. may work correctly, just give users
an option to switch the usage of xorg's presentation statistics on/off.
The default value, auto, works like before (basically, Mesa drivers and
no Nvidia are allowed), but now one can force it on/off if needed.
2022-06-22 03:55:49 +00:00
Dudemanguy
d9f7dd7212 x11: add nouveau to the xpresent whitelist
A user noted that this worked correctly (i.e. vsync jitter of 0) so go
ahead and add it here as a safe driver for xpresent to use.
2022-06-22 03:55:49 +00:00
Dudemanguy
230d490eca x11: correct provider detection logic
The old logic always reset the x11->has_mesa/has_nvidia values on every
loop through the provider. This meant that it would always just match
whatever the last provider happened to be. So in the case of a dual GPU
system, if nvidia was the very first provider and the integrated
intel/amd card was the second (in practice, this is probably mostly the
other way around), then mpv would set has_mesa to true and has_nvidia to
false and thus try to use presentation. This is not the intended
behavior. Just rework this by also checking x11->has_mesa/has_nvidia in
the loop so a true value from the previous iteration is preserved.
2022-06-21 18:05:35 +00:00
Aaron Boxer
b29878e3a1 vo_vaapi_wayland: remove vaapi format query as formats are never used
This code was taken from the older vo_vaapi driver, which does
use the vaapi format list, but the new driver has no use for
these formats, as it is only interested in va surfaces that
can be mapped to wl buffers. The format doesn't enter into
it at all.
2022-06-21 14:05:19 +00:00
Dudemanguy
2606d4cc51 x11: replace strcasestr usage with bstr
strcasestr is a GNU extension, but we can just use bstr instead to do
the same thing.
2022-06-19 16:21:07 -05:00
Dudemanguy
3d459832a8 x11: support xorg present extension
This builds off of present_sync which was introduced in a previous
commit to support xorg's present extension in all of the X11 backends
(sans vdpau) in mpv. It turns out there is an Xpresent library that
integrates the xorg present extention with Xlib (which barely anyone
seems to use), so this can be added without too much trouble. The
workflow is to first setup the event by telling Xorg we would like to
receive PresentCompleteNotify (there are others in the extension but
this is the only one we really care about). After that, just call
XPresentNotifyMSC after every buffer swap with a target_msc of 0. Xorg
then returns the last presentation through its usual event loop and we
go ahead and use that information to update mpv's values for vsync
timing purposes. One theoretical weakness of this approach is that the
present event is put on the same queue as the rest of the XEvents. It
would be nicer for it be placed somewhere else so we could just wait
on that queue without having to deal with other possible events in
there. In theory, xcb could do that with special events, but it doesn't
really matter in practice.

Unsurprisingly, this doesn't work on NVIDIA. Well NVIDIA does actually
receive presentation events, but for whatever the calculations used make
timings worse which defeats the purpose. This works perfectly fine on
Mesa however. Utilizing the previous commit that detects Xrandr
providers, we can enable this mechanism for users that have both Mesa
and not NVIDIA (to avoid messing up anyone that has a switchable
graphics system or such). Patches welcome if anyone figures out how to
fix this on NVIDIA.

Unlike the EGL/GLX sync extensions, the present extension works with any
graphics API (good for vulkan since its timing extension has been in
development hell). NVIDIA also happens to have zero support for the
EGL/GLX sync extensions, so we can just remove it with no loss. Only
Xorg ever used it and other backends already have their own present
methods. vo_vdpau VO is a special case that has its own fancying timing
code in its flip_page. This presumably works well, and I have no way of
testing it so just leave it as it is.
2022-06-19 18:13:55 +00:00
Dudemanguy
ceade34930 x11: use xrandr providers for driver detection
Unfortunately there's a certain company that makes graphics drivers that
are harder to deal with. The next commit aims to implement presentation,
but some empirical testing from users show that it's actually broken.
Give up and just tap into Xrandr so we can figure what drivers (or well,
providers by the extension terminology) are driving the screen.
Basically if we find intel, amd, or radeon, assume it's a Mesa driver.
If we find nvidia, then it must be nvidia. This detection requires randr
1.4 (which means using presentation in mpv secretly depends on randr
1.4), but this protocol version is nearly a decade old anyway so
probably 99.9% of users are fine. Do the version query check and all
that anyway just to be on the safe side.
2022-06-19 18:13:55 +00:00
Dudemanguy
7ce26dd324 vo: move wayland presentation to separate files
Wayland had some specific code that it used for implementing the
presentation time protocol. It turns out that xorg's present extension
is extremely similar, so it would be silly to duplicate this whole mess
again. Factor this out to separate, independent code and introduce the
mp_present struct which is used for handling the ust/msc values and some
other associated values. Also, add in some helper functions so all the
dirty details live specifically in present_sync. The only
wayland-specific part is actually obtaining ust/msc values. Since only
wayland or xorg are expected to use this, add a conditional to the build
that only adds this file when either one of those are present.

You may observe that sbc is completely omitted. This field existed in
wayland, but was completely unused (presentation time doesn't return
this). Xorg's present extension also doesn't use this so just get rid of
it all together. The actual calculation is slightly altered so it is
correct for our purposes. We want to get the presentation event of the
last frame that was just occured (this function executes right after the
buffer swap). The adjustment is to just remove the vsync_duration
subtraction. Also, The overly-complicated queue approach is removed.
This has no actual use in practice (on wayland or xorg). Presentation
statistics are only ever used after the immediate preceding swap to
update vsync timings or thrown away.
2022-06-19 18:13:55 +00:00
Aaron Boxer
c961f4d0db vo_vaapi_wayland: only attach solid buffer once to main surface, on creation
There's no need to attach it with each frame.
2022-06-15 20:54:34 +00:00
Aaron Boxer
ccce813a92 vo_vaapi_wayland: remove unnecessary subsurface sync/desync in resize
resize only changes subsurface position, which is always synchronized
with the parent surface.

For reference, see :
https://wayland-book.com/surfaces-in-depth/subsurfaces.html
2022-06-15 20:54:34 +00:00
Dudemanguy
602995fd40 wayland: set appid before initial surface commit
This shouldn't have mattered but apparently qtile is unable to get the
app id if you set it after the initial surface commit. Wayland is a mess
anyway so just shuffle this around so that the frame callback and
surface commit are the last things registered in vo_wayland_init. This
works around qtile and, in theory, doesn't appear to break anything
else. Fixes #10280.
2022-06-11 10:20:06 -05:00
Dudemanguy
b3ef506932 wayland_gl: fix a typo
Somehow in commit 661b5542de, my editor
snuck in a ¥ sign in here. Oops.
2022-06-11 10:07:11 -05:00