Commit Graph

5373 Commits

Author SHA1 Message Date
Thomas Weißschuh c7c92240a9 image_pool: properly free frames
av_frame_unref() only frees the buffers, not the frame data itself.
2023-02-03 09:23:09 -08:00
Kacper Michajłow bc7a126237 sws_utils: add check for HAVE_ZIMG to suppress warnings 2023-02-02 14:23:02 +00:00
Kacper Michajłow 87fb254deb vo_gpu_next: add check for PL_HAVE_LCMS 2023-02-02 14:23:02 +00:00
Kacper Michajłow a97dd423c8 hwdec_cuda: fix enum type for semaphore 2023-02-02 14:23:02 +00:00
Kacper Michajłow 68c1338d56 vo_d3d11: do not call MAKEINTRESOURCEW twice 2023-02-02 14:23:02 +00:00
Kacper Michajłow 0a4b139ddf osdep: add MP_FALLTHROUGH 2023-02-02 14:23:02 +00:00
Kacper Michajłow 08cd7c1e29 libplacebo: fix enum type cast 2023-02-02 14:23:02 +00:00
Leo Izen 7990dd8f3f video/image_writer: avoid stripping colorspace info when writing image
Writing an image either with vo_image or with a screenshot will strip
the colorspace info because it allocates a new mp_image that contains
the same data as the old image after calling mp_image_params_guess_csp.
However, mp_image_params_guess_csp cannot always guess the appropriate
colorspace, so it picks a "sane default." Since this function also
changes parameters so the space always makes sense, this extra info
isn't harmful and allows screenshots and vo_image outs to be properly
tagged with the correct colorspace.

Fixes #10988.
2023-01-31 12:39:04 -05:00
Dudemanguy 9659555d45 hwdec/vaapi: zero-initialize VADRMPRIMESurfaceDescriptor
Otherwise, desc can contain garbage values and segfault trying to close
file descriptors that aren't actually there. Fixes #11239.
2023-01-30 10:41:32 -06:00
rcombs 4bcefa5be3 vo_lavc: set frame rate on encoder; fixes #11215
ffmpeg was internally defaulting to 24000fps, which resulted in encoders selecting inappropriate levels and making poor ratecontrol decisions.
2023-01-29 22:14:27 -06:00
Dudemanguy da81a6d532 wayland: add auto choice to wayland-configure-bounds
Previously, this defaulted to yes and configure-bounds from the
compositor would always apply. In the case where the user explicitly set
autofit or geometry, this could be confusing because configure-bounds
would take precedence over it. Instead, let's add an auto choice and
make that the default. If we detect that the option is on auto and that
there is autofit/geometry being set, then ignore the event. This should
be more intuitive since someone who bothers to explicitly set mpv's
geometry would naturally expect that geometry to actually apply.
2023-01-30 03:59:40 +00:00
Dudemanguy adc04dbba0 wayland: handle runtime hidpi-window-scale changes correctly
Semi-regression although this option never really did what the manual
said until recently. In the past, this option also controlled whether or
not mpv set the wayland buffer_scale to the value of the wl_output or
force it 1. This had varying effects depending on the exact compositor
configuration. That logic has now all been removed and this option now
only controls whether or not to scale the window with the hidpi scale
factor we get from the compositor. i.e. it actually does what the
manual says now.
2023-01-30 03:59:40 +00:00
Dudemanguy e6a42f7afc wayland: unbreak runtime geometry/autofit changes
Regressed from 879824a47f. The geometry
needs to be explictly recalculated now. Change up this function a little
bit also give it the ability to directly perform a resize after the
fact. This is a common workflow and we'll be using it in the next
commit.
2023-01-30 03:59:40 +00:00
Aaron Boxer 588d66fb25 hwdec_vaapi: close file descriptors even if surface export fails
otherwise they can leak
2023-01-28 16:54:48 +01:00
Aaron Boxer 881f820fdf vo_dmabuf_wayland: close file handles when surface export fails
file handles may still be opened despite failure
2023-01-28 16:54:48 +01:00
Aaron Boxer e3618002e3 vo_dmabuf_wayland: plug leaking file descriptor from solid buffer pool 2023-01-28 16:54:48 +01:00
Kacper Michajłow af537eff06 vo_opengl/angle_dynamic: simplify symbol renaming to make it more straightforward 2023-01-28 01:03:12 +00:00
Sultan Alsawaf 0d44ae319d x11: remove PresentNotifyMSC from egl/glx/vulkan to fix xpresent timing
PresentNotifyMSC turns out to be not only redundant, but also harmful with
mesa-backed egl/glx/vulkan VOs because for all of them, mesa uses
PresentPixmap behind the scenes when DRI3 is available, which already
spawns a PresentCompleteNotify event when the buffer swap actually
finishes. This is important because without using the timing information
from these PresentCompleteKindPixmap events, there's no way for mpv to know
exactly when a frame becomes visible on the display.

By using PresentNotifyMSC in conjunction with DRI3-enabled mesa, two
problems are created:
1. mpv assumes that a vblank won't elapse (i.e., it assumes the current MSC
   won't change) between the time when mesa enqueues the buffer swap and
   the time when mpv calls PresentNotifyMSC to ask xorg for a notification
   at the next MSC, relative to the current MSC at the time that xorg reads
   it for the PresentNotifyMSC call. This means that mpv could get a
   notification one or more vblanks later than it expects, since the
   intention here is for mpv to get a notification at the MSC that the
   buffer swap completes.
2. mpv assumes that a buffer swap always takes one vblank to complete,
   which isn't always true. A buffer swap (i.e., a page flip) could take
   longer than that depending on hardware conditions (if the GPU is running
   slowly or needs to exit a low-power state), scheduling delays (under
   heavy system or GPU load), or unfortunate timing (if the raster scan
   line happens to be at one of the last few rows of pixels and a vblank
   elapses just before the buffer swap is enqueued).

This causes mpv to have a faulty assumption of when frames become visible.

Since mpv already receives the PresentCompleteNotify events generated by
mesa's buffer swaps under the hood, the PresentNotifyMSC usage is unneeded
and just throws a wrench in mpv's vsync timing when xpresent is enabled.

Simply removing the PresentNotifyMSC usage from the egl, glx, and vulkan
VOs fixes the xpresent vsync timing.
2023-01-25 03:13:23 +00:00
Dudemanguy 879824a47f wayland: add wp-fractional-scale-v1 support
This protocol is pretty important since it finally lets us solve the
longstanding issue of fractional scaling in wayland (no more mpv doing
rendering over the target resolution and then being scaled down). This
protocol also can completely replace the buffer_scale usage that we are
currently using for integer scaling so hopefully this can be removed
sometime in the future. Note that vo_dmabuf_wayland is omitted from the
fractional scale handling because we want the compositor to handle all
the scaling for that VO.

Fixes #9443.
2023-01-24 00:04:39 +00:00
Dudemanguy 006ec9ce43 wayland: rewrite geometry and scaling handling
This is in preparation for fractional scaling support. Basically, redo
all the coordinates in wayland so that wl->geometry is equal exactly to
what is being put out to the screen (no extra wl->scaling multiplication
required). The wl->vdparams variable is also eliminated for simplicity.
This changes mpv's behavior on wayland with hidpi scaling but that will
be addressed in more detail with the next commit.
2023-01-24 00:04:39 +00:00
sfan5 9b59d39a3a vo_gpu: implement VO_DR_FLAG_HOST_CACHED
For OpenGL, this is based on simply comparing GL_VENDOR strings against
a list of allowed vendors.

Co-authored-by: Nicolas F. <ovdev@fratti.ch>
Co-authored-by: Niklas Haas <git@haasn.dev>
2023-01-23 14:13:34 +01:00
Niklas Haas 2531a89fcb vo_gpu_next: implement VO_DR_FLAG_HOST_CACHED
For sufficiently new versions of libplacebo.
2023-01-23 14:13:34 +01:00
sfan5 c7ea0cd68f vd_lavc: add "auto" choice for vd-lavc-dr
--vd-lavc-dr defaulted to "yes", which caused issues on certain
hardware. Instead of disabling it, add a new "auto" value and
make it the default.

The "auto" choice will enable DR only when we can request host-cached
buffers (as signalled by the new VO_DR_FLAG_HOST_CACHED).

Co-authored-by: Nicolas F. <ovdev@fratti.ch>
Co-authored-by: Niklas Haas <git@haasn.dev>
2023-01-23 14:13:34 +01:00
Niklas Haas f8c17f55f9 vo: add `int flags` to the get_image signature
This is a huge disgusting mess to thread through everywhere. Maybe I'm
stupid for attempting to solve the problem this way.
2023-01-23 14:13:34 +01:00
Dudemanguy 92a6f2d687 drm: rewrite based around vo_drm_state
A longstanding pain point of the drm VOs is the relative lack of state
sharing. While drm_common does provide some sharing, it's far less than
other platforms like x11 or wayland. What we do here is essentially copy
them by creating a new vo_drm_state struct and using it in vo_drm and
context_drm_egl. Much of the functionality that was essentially
duplicated in both VOs/contexts is now reduced simple functions in
drm_common. The usage of the term 'kms' was also mostly eliminated since
this is libdrm nowadays from a userspace perspective.
2023-01-21 17:08:29 +00:00
Niklas Haas 8c617765fe mp_image: fix XYZ primaries default
This was incorrectly set to BT.2020, when it should be DCI-P3 for pretty
much all real-world XYZ content (which is digital cinema content).
2023-01-21 13:03:33 +01:00
Niklas Haas b091dfda71 hwdec_cuda: drop support for PL_HANDLE_WIN32_KMT
This handle type was only needed for backwards compatibility with
windows 7. Dropping it allows us to simplify the code: there is no
longer a need for runtime checks, as the handle type can now be
statically assigned based on the platform.

The motivating usecase here, apart from code simplification, is a
desired switch to timeline semaphores, which (in the CUDA API) only
supports the non-KMT win32 handles.

It's worth pointing out that we need no runtime check for
IsWindows8OrGreater(), because the `export_caps.sync` check will already
fail on versions of windows not supporting PL_HANDLE_WIN32.
2023-01-17 11:38:46 +01:00
Thomas Weißschuh f52cfdabca wayland: only warn when actually missing idle inhibit support 2023-01-16 19:26:09 +00:00
Thomas Weißschuh 2bbf880d96 vo: make driver list static 2023-01-16 19:25:54 +00:00
Thomas Weißschuh f66c5404f4 vo: remove trailing NULL element from driver array 2023-01-16 19:25:54 +00:00
Dudemanguy 6cdce9e18e wayland: store presentation feedbacks in a pool
Officially, the most cursed part of the wayland code in mpv (third or
fourth try now?) This time, let's allocate a pool during init
(arbitrarily set to the maximum swapchain length mpv allows, 8; don't
even know if this actually works in wayland). Then we add/remove
feedbacks from the pool during the lifecycle of the VO, and clean it up
all at the end. Hopefully, this does the trick for good this time.
2023-01-13 22:24:11 -06:00
Dudemanguy f32c5586d6 Revert "wayland: dispatch and wait for compositor events in uninit"
This ended up being a bad idea. The problem is that it introduces
ordering when destroying events (something we weren't worried about
before) and Lynne pointed out a problem with the callback not also being
destroyed before the surface in IRC. Just undo this and go with a
different approach (next commit). P.S. the wayland_dispatch_events name
change is kept though because I like that better.

This reverts commit aa8ddfcdf3.
2023-01-13 22:23:49 -06:00
sfan5 1201d59f0b various: replace abort() with MP_ASSERT_UNREACHABLE() where appropriate
In debug mode the macro causes an assertion failure.
In release mode it works differently and tells the compiler that it can
assume the codepath will never execute. For this reason I was conversative
in replacing it, e.g. in mpv-internal code that exhausts all valid values
of an enum or when a condition is clear from directly preceding code.
2023-01-12 22:02:07 +01:00
sfan5 7b03cd367d various: replace if + abort() with MP_HANDLE_OOM()
MP_HANDLE_OOM also aborts but calls assert() first, which
will result in an useful message if compiled in debug mode.
2023-01-12 22:02:07 +01:00
sfan5 833bff8738 {video,audio}: adjust unsafe strncpy usages 2023-01-12 22:02:07 +01:00
sfan5 f4280e5238 video/x11: replace sprintf usage 2023-01-12 22:02:07 +01:00
sfan5 2703a2c8ff video: replace sprintf usage 2023-01-12 22:02:07 +01:00
sfan5 356096b954 ra_d3d11: fix incorrect type
As it happens, `SIZE_T` and `size_t` are not the same length on 32-bit Windows
2023-01-12 22:02:07 +01:00
Dudemanguy a5b9d529ee vo_dmabuf_wayland: drop support for linux-dmabuf-v2
The only real reason this was ever supported is because it was
dramatically simpler than v4, so it was put in as an initial
implementation. Later, v4 support was added and we left v2 for
compatibility, but let's just drop it. Compositors all use v4 nowadays,
and v2 is significantly limited (no modifier support for example). It's
better to just remove this dead code for simplicity.
2023-01-12 17:42:35 +00:00
Aaron Boxer 865a159244 vo_dmabuf_wayland: support panscan and panning 2023-01-11 18:10:40 +00:00
Dudemanguy 4beb1bcae7 vo_wlshm: properly support video panscan
Turns out it was already doing this under the hood the entire time. The
only catch is that the vo just needed a resize.
2023-01-09 19:30:26 -06:00
Dudemanguy 8439c084e1 wayland: make vo_wayland_reconfig a bool
This was already returning true/false but the type was int. Also
simplify a few places in the wayland contexts where we can just return
the value of this function instead of doing redundant checks.
2023-01-08 20:42:42 +00:00
Dudemanguy d73fc7912a wayland: cleanup on vo_wayland_init error
Instead of just returning true/false, it's better to have this function
cleanup itself. We can eliminate some redundant uninit calls elsewhere
in the code as well.
2023-01-08 20:42:42 +00:00
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