Commit Graph

5527 Commits

Author SHA1 Message Date
Dudemanguy 828dd65ef8 wayland: use xdg_surface_set_window_geometry
mpv has never used this because we never really seemed to need it, but
it actually has a purpose. This informs the compositor of the actual
dimensions of the mpv window and avoids errors with sizes not matching
(particularly with weston). It's a better way to fix the "maximizing
causing an error on weston" issue since it also works for dmabuf-wayland
(which always had this problem).
2023-07-13 12:12:37 +00:00
Dudemanguy 4ff27d5220 Revert "wayland_gl: wait until resize to create egl_window"
The original reason for this commit was to prevent a compositor error on
weston when going into the maximized state. The configured dimensions of
mpv didn't match its actual size and Weston is super strict about this
so it threw a compositor error which is fatal. It only happened in
opengl and this seemed like an OK workaround, so I went with this.
However, there's actually a far easier way to solve this problem and we
don't need this anymore. This has the benefit of avoiding a harmless
warning message that appears with gpu-next on opengl. The next commit is
the proper solution. Closes #10324.

This reverts commit 661b5542de.
2023-07-13 12:12:37 +00:00
Dudemanguy 33130741f4 vo_dmabuf_wayland: guard in destroy_osd_buffers
*sigh*
2023-07-12 22:20:20 -05:00
Dudemanguy 7409f4a6c9 vo_dmabuf_wayland: stop lazy loading hwdec
The implementation was copied from vo_gpu/vo_gpu_next but fundamentally
it doesn't make sense for this VO. Hardware decoding is not optional in
vo_dmabuf_wayland. We should be sure to request and load all supported
formats in the preinit and fail if there are any problems. There should
be no functional change from before, but it's more conceptually correct
this way.
2023-07-12 16:59:59 -05:00
Dudemanguy b57cf110c9 vo_dmabuf_wayland: don't try to get pts without frame->current
Fixes a segfault with --force-window=immediate.
2023-07-12 16:59:47 -05:00
Dudemanguy c958990833 vo_dmabuf_wayland: add osd support
This adds osd support via shm buffers using a similar approach that the
normal buffers do, but it differs in a few key areas. One thing to note
is that sway and weston actually handle this extremely differently which
required all the abstractions here. In particular, weston does not cope
well with destroying the wl_buffer from shm outside of the release
handler at all (i.e. it segfaults). The workaround here is to simply
attach a NULL to the osd surface and do a surface commit before we
destroy the buffers. This is reasonable enough and seems to work well
although it's pretty weird. Sway is more straightforward although it
actually releases the osd buffer when the window goes out of sight.
Also, I found that it doesn't always release every buffer before you
close it unlike weston seems to do which is part of the reason all this
bookkeeping is required. I don't know if there's any other compositor
out there that can possibly handle vo_dmabuf_wayland right now, but
suffering through these two is good enough for now I think.
2023-07-12 19:19:54 +00:00
Dudemanguy 180a3df1f1 vo_dmabuf_wayland: init wl_list at the top of preinit
Otherwise, we could fail and skip to uninit without initalizing this
which then will segfault because the list is null and accessed while
trying to destroy buffers.
2023-07-12 19:19:54 +00:00
Dudemanguy a890d7be2a vo_dmabuf_wayland: stop guarding viewport interfaces
It's entirely pointless. Not having viewport is already a fatal error
for this VO as it cannot possibly work without that protocol. Just drop
all these redundant if's.
2023-07-12 19:19:54 +00:00
NRK dc06dec1ee video/image_writer: check for write errors
make sure that fwrite is error checked. and if any data was still
remaining on the buffer, it will be flushed - and errors checked - via
the fclose() call below.
2023-07-11 19:55:28 +02:00
NRK 6b76000f0b video/image_writer: fix file leak in error path
regression from de7f4fb1e
2023-07-11 19:55:28 +02:00
llyyr a0f1bbddff wayland: add xdg_toplevel.wm_capabilities handler
Fixes crash when compositors advertise xdg_toplevel version >= 5
2023-07-10 13:37:23 +00:00
Dudemanguy 7beae9ac86 wayland: add support for suspended toplevel state
mpv already guesses when the window is hidden so plugging in a proper
event that actually tells us this is really trivial. Note that there's
some redundancy with setting wl->hidden in a few spots, but nothing can
really be done about that as long as the crappy hack is still in place.
2023-07-09 19:22:53 +00:00
Dudemanguy 589da09e5a wayland: add cursor-shape-v1 support
This protocol no longer requires us to draw a separate cursor surface
and all of that horrible stuff. We can just ask the compositor for the
default cursor instead since that's literally all mpv cares about.
2023-07-09 18:10:19 +00:00
Kacper Michajłow fc3e28f1e9 vd_lavc: fix delay_queue for videos with frames < max_delay_queue
In case there are no packets from demuxer we cannot send EAGAIN, because
we will not proceed and get stuck with one frame in queue and never
output it. Just respect avcodec_receive_frame ret code and act
accordingly. The only case to care about is EOF when we have to drain
already queued frames.

Fixes playback of 1-2 frame videos.
2023-07-09 11:59:32 +02:00
Kacper Michajłow bf77f1ae74 vd_lavc: prefer d3d11va-copy over dxva2-copy
There is no reason to prefer dxva2. I believe it was mistake from
initial commit that added the hwdec list that has been propagated
through years.
2023-07-09 11:59:32 +02:00
Dudemanguy ab3002851e vo_wlshm: bail out of resize if width/height is 0
It can happen during initialization and of course nothing good will
happen if we let this go through (i.e. segfault). Return and wait for
geometry to finish setting up in the wayland stuff before doing the
initial resize.
2023-07-08 20:47:35 -05:00
Dudemanguy 0242055564 wayland: fix memory leak with multiple monitors
Very dumb. I can't remember if it was always like this or if I broke it
at some point, but clearly each wl_output should just be freed in
remove_output. Freeing it if it happens to be wl->current_output only
works for that one monitor, so remove that whole line. This has to
happen before we close the wayland connection so reorder the uninit a
little bit.
2023-07-08 20:31:09 -05:00
Dudemanguy ee69d99bd4 various: correctly ignore cache files with --no-config
--no-config should prevent loading user files of any type: configs,
cache, etc. For cache files, this case wasn't properly handled and it
was assumed they would always get something. vo_gpu's shader cache
actually already handles this, so it was left untouched. In theory,
demuxer cache should never have this issue because saving it to disk is
disabled by default (and likely that will never change), but go ahead
and change it for consistency's sake. Fixes some segfaults with
--no-config and various combinations of settings (particularly
--vo=gpu-next).
2023-07-06 13:08:23 +00:00
Dudemanguy 48e0ee9979 vo_gpu/vo_gpu_next: enable gpu shader and icc cache by default
4502522a7a changed the way mpv handled and
saved cached files. In particular, it made a separate boolean option for
actually enabling cache and left the *-dir options as purely just a path
(i.e. having a dir set didn't mean you save cache). This technically
regressed people's configs, so let's just turn the cache on by default.
Linux users already expect random stuff in ~/.cache and well everyone
else can just live with some files possibly appearing in their config
directory.
2023-07-04 22:14:43 +00:00
Dudemanguy d6a6901090 vo_gpu: fix some cache related memory leaks
I goofed this up.
2023-07-04 22:14:43 +00:00
Dudemanguy dbc0fcea1b player: add --input-cursor-passthrough option
Add an option for allowing pointer events to pass through the mpv
window. This could be useful in cases where a user wants to display
transparent images/video with mpv and interact with applications beneath
the window. This commit implements this functionality for x11 and
wayland. Note that whether or not this actually works likely depends on
your window manager and/or compositor. E.g. sway ignores pointer events
but the entire window becomes draggable when you float it (nothing under
the mpv window receives events). Weston behaves as expected however so
that is a compositor bug. Excuse the couple of completely unrelated
style fixes (both were originally done by me).
2023-07-04 19:16:43 +00:00
Kacper Michajłow d2c28bc4df vo_gpu_next: remove synchronization from info_callback
VOCTRL is processed on VO thread.
2023-07-02 16:20:48 +02:00
Kacper Michajłow b73d96776c vo_gpu_next: use pl_dispatch_info_move to avoid useless data copy
Instead copy the data on-demand when VOCTRL_PERFORMANCE_DATA is
requested.
2023-07-02 16:20:48 +02:00
NRK b616a6cef1 vo_x11: don't rely on XFree to free calloc-ed data 2023-07-02 12:47:31 +02:00
NRK fa7503989f vo_x11: check for calloc() failure 2023-07-02 12:47:31 +02:00
Dudemanguy f76c441ba2 win32: add support for drag-and-drop option 2023-07-01 02:06:02 +00:00
Dudemanguy 6625a94608 options: add no to drag-and-drop
Suggested by @sfan5. Naturally, "no" disables all drag and drop
behavior.
2023-07-01 02:06:02 +00:00
cloud11665 de7f4fb1ee video/image_writer: add avif screenshot support
Notes:
- converts the (image) write() api to filenames, because using avio
with FILE* is a pain.
- adds more debug logs for screenshots.

build: rename av1 dependency to avif_muxer
wscript: unify lavf dependency with meson
2023-07-01 02:05:23 +00:00
Philip Langdale 40a1b0066e vd_lavc: do inline string array initialisation for hwdec_api
I couldn't work out the correct syntax, but NRK0 pointed out an example
of where we'd done it elsewhere in the codebase.
2023-06-29 15:03:05 -07:00
Philip Langdale 9ff8c9e780 vd_lavc: let the user provide a priority list of hwdecs to consider
Today, the only way to make mpv consider multiple hwdecs and pick the
first one that works is to use one of the `auto` modes. But the list
that is considered in those cases is hard-coded. If the user wants to
provide their own list, they are out of luck.

And I think that there is now a significant reason to support this -
the new Vulkan hwdec is definitely not ready to be in the auto list,
but if you want to use it by default, it will not work with many codecs
that are normally hardware decodable (only h.264, hevc and av1 if you
are very lucky). Everything else will fall back to software decoding.

Instead, what you really want to say is: use Vulkan for whatever it
supports, and fall back to my old hwdec for everything else.

One side-effect of this implementation is that you can freely mix
hwdec names and special values like `auto` and `no`. The behaviour will
be correct, so I didn't try and prohibit any combinations. However,
some combinations will be silly - eg: sticking any further values after
`no` will result in them being ignored. On the other hand, a
combination like `vulkan,auto` could be very useful as that will use
Vulkan if possible, and if not, run the normal auto routine.

Fixes #11797
2023-06-29 11:58:51 -07:00
NRK 7ad7609541 wayland: remove erroneous POLLERR usage
POLLERR is only returned in `.revents` and is ignored in `.events`
2023-06-29 13:17:56 +02:00
sfan5 76589a5b34 image_writer: respect jpeg-quality when using ffmpeg for writing 2023-06-29 12:42:15 +02:00
sfan5 eac6a82e01 image_writer: remove unused struct fields 2023-06-29 11:33:19 +02:00
NRK d70b859084 mp_image: abort on av_buffer_ref() failure
this changes mp_image_new_ref() to handle allocation failure itself
instead of doing it at its many call-sites (some of which never checked
for failure at all).

also remove MP_HANDLE_OOM() from the call sites since this is not
necessary anymore.

not all the call-sites have been touched, since some of the caller might
be relying on `mp_image_new_ref(NULL)` returning NULL.

Fixes: https://github.com/mpv-player/mpv/issues/11840
2023-06-28 20:56:23 -07:00
syphyr f8cb539e6f hwdec: fix undeclared identifier in mediacodec_embed
mediacodec_embed is a `vo` and not a `hwdec`.
2023-06-28 10:29:24 -07:00
NRK c3781b2d68 vo_drm: fix null dereference and using closed fd
when vo_drm_init() fails inside of preinit(), uninit() will be called as
part of cleanup with vo->drm being NULL and thus `drm->fd` would lead to
null dereference.

and since vo_drm_uninit() closes drm->fd, destroy_framebuffer() ends up
using a closed fd.

according to the drm-gem manpage [0]:

> If you close the DRM file-descriptor, all open dumb-buffers are
> automatically destroyed.

so remove the destroy_framebuffer() loop entirely, which fixes both the
issues.

[0]: https://www.systutorials.com/docs/linux/man/7-drm-gem/
2023-06-28 02:10:14 +00:00
Kacper Michajłow 4dfc2c50c1 hwdec: do not add hwdec device if it failed to create 2023-06-26 19:07:29 +02:00
Kacper Michajłow a5b9290261 vd_lavc: check if av_device_ref is available
Fixes crashes when hwdevice failed to create.

Fixes: #11769
2023-06-26 19:07:29 +02:00
Philip Langdale 78285e98f1 vo: hwdec: prioritise `drmprime` over `drmprime_overlay`
I originally left `drmprime_overlay` as higher priority because
`drmprime` was new, and because I didn't have any hardware where both
worked (only one or the other) so I couldn't compare relative
performance, and if only one worked, the priority didn't matter.

But with time and more usage, we've reached a point where we can say we
would recommend using `drmprime` in situations where both work, and
we've also been able to identify hardware where both do indeed work and
it seems that `drmprime` is more reliable.

So, let's flip them.
2023-06-22 12:46:21 -07:00
Niklas Haas 0af81b16d8 vo_gpu_next: add --corner-rounding option
For better or worse.
2023-06-21 23:52:35 +02:00
Niklas Haas f1600ea9cf vo_gpu_next: add missing --gamut-mapping-mode options
Adds the missing upstream values that were exposed by the new gamut
mapping API.
2023-06-21 23:52:35 +02:00
Dudemanguy 650c53df50 vo_dmabuf_wayland: drop linux-dmabuf-v2 (again)
It was done once before but later reverted for testing reasons. This
time it's permanent though since I can test this VO on ARM and with an
up to date system.
2023-06-16 14:46:59 +00:00
Dudemanguy ca08bf599f wayland: bump wayland-protocols to 1.25
1.27 would have been nicer but ubuntu 22.04 is on 1.25 so we'll just
compromise.
2023-06-16 14:46:59 +00:00
Dudemanguy 45e2ca5411 wayland: bump required version to 1.20
This lets us remove some ifdefs.
2023-06-16 14:46:59 +00:00
Dudemanguy f5e828ac25 vo_dmabuf_wayland: update the image of pending buffers
When using a display-* video-sync mode, it is possible for buffers with
a matching id to already have an image associated with them (i.e. the
compositor hasn't released it yet). Previously, it was thought that we
could just unref, return null, and make a new buffer but this eventually
leads to a fatal error that originates from libwayland itself which
stops playback. Admittedly, the reason for the error is a bit nebulous
but likely it seems to be some kind of mismatch between dmabuf params
and the associated image with the buffer.

However, we can simplify this process greatly. Instead when the
previously mentioned edge case happens, the old image can simply be
freed and we give the buffer the new image. This saves creating a new
buffer and also avoids that nasty libwayland error. A nice win-win all
around. Fixes #11773.
2023-06-14 12:21:10 -05:00
Dudemanguy 4d4837b84e vo_dmabuf_wayland: use a minimum of 15 buffers
vo_dmabuf_wayland has a pool of wl_buffers that it cycles through when
drawing frame. There needs to be at least some minimum number otherwise
a flickering artifact occurs where old frames are mistakenly repeated.
When using display-resample and other similar modes, it seems more
buffers are required (more drawing happens so it makes sense) and the
current minimum of 8 isn't good enough. Let's just bump this to 15. It's
also a random ad hoc number, but as far as I know there's not really a
way to predict how many buffers a random video may need. From testing,
it works fine and overall 15 is still a tiny amount of objects to create
considering the lifetime of a video, so we'll just go with this.
2023-06-14 12:00:23 -05:00
Dudemanguy 8ecf2d37eb player: add drag-and-drop option
Some platforms (wayland) apparently have a lot of trouble with drag and
drop. The default behavior is still the same which is basically obeying
what we get from the window manager/compositor, but the --drag-and-drop
option allows forcibly overriding the drag and drop behavior. i.e. you
can force it to always replace the playlist or append at the end. This
only implements this in X11 and Wayland but in theory windows and macos
could find this option useful (both hardcode the shift key for
appending). Patches welcome.
2023-06-12 20:50:08 +00:00
Dudemanguy 2f8d9322fd wayland: avoid misleading log messages on drag/drop
In data_offer_actions, it's possible to get the
WL_DATA_DEVICE_MANAGER_DND_ACTION_NONE action which would set
wl->dnd_action to DND_APPEND (did nothing in practice) but also log a
message which is confusing and misleading. Instead, just ignore and
don't do anything when we get this case.
2023-06-12 20:50:08 +00:00
Philip Langdale 3a6738ed8c hwdec_cuda: clear vulkan semaphore fd after passing ownership to cuda
This is not technically necessary, because we never touch the fd again
after passing to cuda, but having it there could lead to future code
accidentally using it.
2023-06-04 13:24:52 -07:00
Philip Langdale 7918545caf hwdec_vulkan: respect probing flag when logging during init
All hwdecs should respect the probing flag and demote their lgoging to
verbose level, so that initialisation failures during probing do not
spam the user. I forgot to do this for the Vulkan hwdec.
2023-06-03 18:37:43 -07:00