Commit Graph

6340 Commits

Author SHA1 Message Date
nanahi c890635634 video/out/gpu/video: use video rectangle for video-target-params
This makes the reported sizes the same as how stats.lua calculates
sizes for VOs witout video-target-params while in dumb mode.
2024-08-30 00:34:05 +02:00
nanahi e8d14cd314 video/out/wayland_common: don't pass mouse inputs on resizing edges
Since a6683ea3c9 it is possible to bind
MBTN_LEFT to something useful without conflicting with VO dragging.
However, currently wayland edge resizing is an exception and trying to
resize still triggers MBTN_LEFT. This is not a problem on win32 which
does not pass these inputs to the input system.

Fix this on wayland to do the same.
2024-08-28 03:30:46 +02:00
Kacper Michajłow bb0a852f56 vf_d3d11vpp: skip conversion mode selection if not requested 2024-08-27 01:27:48 +02:00
Kacper Michajłow 1c34b72aeb vf_d3d11vpp: don't force nv12 output 2024-08-27 01:27:48 +02:00
Kacper Michajłow a341b128de vf_d3d11vpp: alloc output frames through AVHWFramesContext
This fixes d3d11 frame download further in filtering chain.

Fixes: #14732
2024-08-27 01:27:48 +02:00
Kacper Michajłow 421df7564a vulkan/context_display: don't fake avalibity of callbacks
There are generic fallback paths for those and it shouldn't be replaced
by noop.
2024-08-27 01:27:39 +02:00
llyyr cb4fdb530a video/csputils: remove space from choice option for chroma loc
Also document the field
2024-08-24 17:11:39 +02:00
Kacper Michajłow f44c29b223 vf_d3d11vpp: ensure width and height is even
Fixes: bbb3d5ba78
2024-08-20 20:27:03 +02:00
Kacper Michajłow 2848af5618 vf_d3d11vpp: add support for Intel VSR and NVIDIA RTX scaling modes
Adds `--vf=d3d11vpp=scaling-mode` to control which extensions should be
enabled.

Fixes: #11390
Co-authored-by: xc <wxc9312@gmail.com>
2024-08-20 03:34:08 +02:00
Kacper Michajłow bbb3d5ba78 vf_d3d11vpp: add support for scaling
Adds `--vf=d3d11vpp=scale` to scale video using d3d11 video processor.

Co-authored-by: xc <wxc9312@gmail.com>
2024-08-20 03:34:08 +02:00
Lynne a3baf94ab9 hwdec_vulkan: allow using multiple decoding family queues
Some devices may only support a single codec type on a single
queue family. The new libavutil API allows this.
2024-08-17 02:01:05 +02:00
Lynne 678ad90bf4 hwdec_vulkan: update to new libavutil queue family API
The new API allows duplicates to easily port any old API users.
It does require users to check and fill in video decode capabilities.
2024-08-17 02:01:05 +02:00
Mike Will acc69e082f img_format: prevent an offset >= MP_MAX_PLANES into bpp
Addresses the warning: "writing 1 byte into a region of size 0"
2024-08-13 12:35:27 +02:00
Jonas Karlman ea01b042c2 context_drm_egl: always use drmModeAddFB2WithModifiers
Change to always use drmModeAddFB2WithModifiers for all formats and fall
back on using drmModeAddFB2 if drmModeAddFB2WithModifiers fail.

With the DRM_MODE_FB_MODIFIERS-flag now only being used for formats with
modifiers all formats without modifiers should also work.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
2024-08-11 08:22:59 -07:00
Jonas Karlman 84c18f6b96 drm_prime: fix use of formats with modifiers
Similar to handles the modifiers must be supplied for each plane of the
format or a framebuffer cannot be created.

Use the format_modifier tied to the object used for the plane to fix use
of formats with modifiers.

Also fix the improper use of the DRM_MODE_FB_MODIFIERS-flag for formats
without modifiers.

This fixes playback of videos decoded by e.g. rpivid into a NV12 format
using SAND128 modifer on RPi using the drmprime-overlay interop.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
2024-08-11 08:22:59 -07:00
nanahi f3a00ea131 various: handle numpad add/subtract/multiply/divide keycodes 2024-08-11 15:08:42 +02:00
Philip Langdale 4b97c23dac video: hwdec: extend look up of hwdecs to consider device type as well
Now that we have identified the device types associated with each hwdec, we
can take advantage of this to ensure that get the right hwdec is chosen when
decoding frames and there are multiple choices available with different device
types.

This is also plumbed into the filter initialisation logic, although in practice
the decision on the hwdec has already been made at this point - still it's
easier than retaining the ambiguous look up logic and worrying that it might
lead to an inconsistent result.
2024-08-10 14:24:36 -07:00
Philip Langdale 7bbf132e20 vo: hwdec: add AVHWDeviceType property to hwdecs
As the first step towards handling scenarios where the are multiple hwdecs for
a given image format but backed by different AVHWDeviceTypes, let us annotate
the hwdecs with their corresponding device types.

From this, we can also see how all the existing hwdecs which match the same
image format also match the same device type.
2024-08-10 14:24:36 -07:00
Kacper Michajłow 6f619d5ef4 vo_libmpv: don't steal pointer provided by the API user
It won't be TA allocated and would fail on header check. Also
documentation doesn't mention that ownership is transfered to mpv, so it
is unexpected.

This will cause existing clients of this API leak this memory, but I
doubt anyone really used it in this broken state.

Fixes: #14633
2024-08-06 20:17:35 +02:00
Brad Smith a36f8ad162 build: detect VT_GETMODE on OpenBSD 2024-07-29 15:09:49 +00:00
Dudemanguy 3c7b6db205 options: move all wayland specific options to vo_opts
Unlike most other platforming backends, wayland has its own specific
sub_options struct. 027ca4fb85 originally
introduced this and some more options were added later, but in
retrospect it's an unneccesary complication. There are already x11,
and windows-specific options within vo_opts. In fact, there actually is
a wayland one in there already as well (wayland-content-type) so it's
split btween two places. The wayland code already has to handle vo_opts
and it is already handles callbacks if needed. There is no advantage to
having a separate wayland-specific sub_options struct which is stuck
with whatever you set at init time.

So solve everything by deleting the old sub_options struct, moving it to
vo_opts and make some minor option naming changes for clarity (i.e.
adding a 'wl_' in front of the name). This simplifies the wayland common
code and also makes it have more functionality since you get runtime
updates for free.
2024-07-24 18:46:04 +00:00
Guido Cella bde7cac447 various: allow changing GPU API options at runtime
Set UPDATE_VO to GPU API options that are only set on init.

To change multiple options without multiple reinits, use
set vo null; set opengl-foo 1; set opengl-bar 1; set vo gpu
2024-07-24 18:44:41 +00:00
Guido Cella a5937ac7e3 m_option: add UPDATE_VO flag
This will allow reiniting the VO when more options are changed without
hardcoding them in options.c

Also reinit the VO when changing --gpu-debug and --gpu-sw.
2024-07-24 18:44:41 +00:00
Dudemanguy e3682f7f2b vo_gpu_next: support --gamma-factor
There's broad agreement that this option will be undeprecated, so just
factor in the multiplier for vo_gpu_next.
2024-07-17 14:09:00 +00:00
der richter 8fc557cc6e mac/vulkan: error out on context creation without an NSApplication
if no NSApplication has been initialized, applications using Appkit
functionality are not supposed to work properly or just deadlock
indefinitely. properly error out on macvk context creation in that case.
2024-07-16 11:20:40 +02:00
Dudemanguy d15660f4ed wayland: avoid potential floating point errors while scaling
Described in more detail in the upstream MR*. mpv naively rounds which
makes us susceptible to the mentioned error. Fix this by keeping
wl->scaling and wl->pending_scaling in the base 120 units. Use the
simple rounding algorithm when needed for calculating widths/heights.
Create a wl->scaling_factor as convenient shorthand for scale / 120
which is what wl->scaling used to previously be.

*: https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/309
2024-07-12 20:48:51 +00:00
nanahi fea6adbc97 x11_common: handle runtime keepaspect/keepaspect-window change
On X11, aspect ratio constraint is applied on the window manager side,
so whenever keepaspect and keepaspect-window change, mpv should update
the size hint immediately, otherwise the new constraint isn't applied.
2024-07-12 20:19:11 +00:00
Kacper Michajłow 6c56a413ab win32: unregister window class on dll detach
Window classes are global per process, but they are associated with the
module that registered them. Documentation is clear that it is the DLL's
responsibility to unregister its own classes:

No window classes registered by a DLL are unregistered when the DLL is
unloaded. A DLL must explicitly unregister its classes when it is
unloaded.

See: https://learn.microsoft.com/windows/win32/api/winuser/nf-winuser-registerclassw

Using a window class after the DLL is unloaded would result in access
violation errors. This is not that important for libmpv, where it is
unlikely someone would use the "mpv" window class externally. The real
issue comes from the fact that reloading libmpv would fail to register
the class (as it still exists) and consequently fail to create a window.

This commit fixes the operability of libmpv after reloading it.

Fixes: #11638
2024-07-11 21:55:21 +02:00
Kacper Michajłow d448598588 vo/opengl/context_win: fix crash on init failure
Don't try to access window context if it failed to create.
2024-07-11 21:55:21 +02:00
llyyr 14571f0f77 vo_dmabuf_wayland: don't use -ve margins in window size calculation
This happens with a positive --video-zoom value. We send invalid
toplevel size and get killed by the compositor.
2024-07-10 19:22:24 +00:00
llyyr 6c59b0272b wayland: use wl_list_empty instead of wl_list_length 2024-07-08 13:33:32 +00:00
llyyr 9d7d861202 wayland: bump wayland-protocol requirement to 1.31
And wayland-client/cursor to 1.21

Debian Stable has these
2024-07-08 13:33:32 +00:00
Dudemanguy 00f43e0916 wayland: fix missed int -> double conversion for cursor scaling
Client side cursors have always had some issues with fractional scaling.
However since we changed to using viewporter for cursor scaling, most
(or all?) of the problems can be fixed. Unfortunately, a scaling factor
was being truncated to int instead of kept as a double. This matched the
old behavior with buffer_scale, but it's better to use double so the
viewport is actually set to the correct size. Of course, none of this is
relevant if the compositor is using cursor shape.

Fixes f0a6578259
Fixes #14001
2024-07-06 09:03:40 -05:00
Guido Cella dc523b137f video/out/gpu/context: convert --gpu-api to object settings list
This follows up 96e1f1dfa5 which converted --gpu-context, and has the
same advantages as listed there.

Unlike with --gpu-context auto can be used anywhere in the list, e.g.
--gpu-api=d3d11,auto works.

I wanted to use the list of GPU contexts as the description in
get_type_desc(), but there is no talloc context to allocate it to, so I
set a print_help_list to print them. The APIs go before the contexts so
that etc/_mpv.zsh doesn't try to complete the contexts.
2024-07-04 22:23:17 +00:00
Guido Cella 3f43999bd6 video/out/gpu/context: simplify --gpu-context's check_unknown_entry
This function is used to reject invalid context names early, and without
it the context fails to create and only audio is played, but it doesn't
need to check for known entries again.
2024-07-04 22:23:17 +00:00
Dudemanguy 68a1a3879c wayland: add a --wayland-present option
Mainly for debugging. It might be handy to disable presentation feedback
on wayland to make sure something isn't going wrong with the
calculations somewhere.
2024-06-28 03:33:16 +00:00
Dudemanguy 111571bd05 options: remove some options with .deprecation_message
In both cases, setting these options did nothing other than give you a
warning that they may be removed in the future. Remove them now.
2024-06-25 02:18:58 +00:00
Dudemanguy 4d7e440533 options: remove various OPT_REMOVED usage
Most of these are pretty obscure things that were replaced a long time
ago. The special messages they were printing are also not really useful
at all so just remove them.
2024-06-25 02:18:58 +00:00
Dudemanguy 6e3d90d72a options: remove some deprecated OPT_REPLACED option mapping
These were all deprecated in mpv 0.37.0 or earlier and are not
considered common enough options to warrant keeping the deprecated
mapping longer. Since demux_cue had only a single option in it, the
entire option substract is removed. This can be readded later if someone
wants to introduce a specific option to it again.
2024-06-25 02:18:58 +00:00
nanahi 265056fa54 vo_gpu: optimize pass_info_reset
No need to reset mp_pass_perf which is only read when desc.len > 0.
This avoids zeroing >16384 uint64_t's every time it's called.
Profiling shows that this reduces CPU usage for frame rendering by ~4%.
2024-06-22 22:48:40 +02:00
Kacper Michajłow 687eb4c875 various: remove no longer needed availability checks
image_writer: remove jpegxl availability check

meson: remove check for lavu vulkan support

image_writer: remove avif availability check

ad_spdif: remove no longer needed definitions

demux_lavf: remove side data extraction compatibility code

demux/packet: remove ITU T.35 availability check

filters/f_lavfi: remove avfilter_filter_pad_count availability check

image_writer: remove PNG cICP support check

mp_image: remove AV_FRAME_DATA_DOVI_METADATA availability check

mp_image: remove AV_FRAME_FLAG_INTERLACED availability check

vd_lavc: remove ctx->pic->duration availability check

sws_utils: remove av_chroma_location_enum_to_pos availability check

vd_lavc: remove AV_CODEC_EXPORT_DATA_FILM_GRAIN availability check

demux_lavf: always use io_close2
2024-06-22 16:12:14 +02:00
Kacper Michajłow 0d8f74231f misc/uuid: remove no longer needed vendored implementation 2024-06-22 16:12:14 +02:00
Kacper Michajłow 4ec060f946 vo_tct: clear backbuffer on reconfig
We were drawing garbage data after reconfig, if there is no video
frame ready or with --force-window without video track.

Found by OSS-Fuzz.
2024-06-22 00:50:38 +02:00
der richter 55241da4ad cocoa-cb: guard color spaces that are only available on 10.15.4 upwards 2024-06-18 19:30:07 +02:00
Kacper Michajłow ab0a50874b d3d11: return minimum bitdepth for display output and swapchain
If the output display reports high bitdepth, 12-bit and 10-bit swapchain
is used the value returned from d3d11_color_depth needs to take it into
account.
2024-06-15 01:18:44 +02:00
Crend King 6031a0e173 vf_vapoursynth: upgrade to VapourSynth API v4
VapourSynth introduced their version 4 API in R55, 3 years ago. mpv is
still using the deprecated version 3. I think it is good to migrate
before VapourSynth completely removes it.

The most impacted area is the video format. Previously we have a fixed
table of supported formats, each represented by an integer. In v4, the
integer is replaced by pointer to the full struct of the format.

Second, the way to create video filter is changed. Previously caller
needs to supply a "initialization" callback to `createFilter()`, which
sets up video info etc. In v4, video info is prepared first, passed to
the `createVideoFilter2()` and we get back the node.

Also, previously mpv was using the `fmSerial` filter mode, which means
VapourSynth 1) can only request one frame from mpv at a time, and 2) the
order of frames requested must be sequential. I propose to change it to
the parallel request mode, which requests multiple frames at a time in
semi random order. The reasons are, for 1), the get frame function,
`infiltGetFrame()`, unlocks the mutex during output image generation,
thus can benefit from parallel requests. For 2) thanks to the frame
buffer, unordered frame requests are acceptable. Just make sure the
buffer is large enough.

Third, the way VapourSynth scripting environment works change. In v4,
the scripting API is operated through struct pointer, much like the
exist `vsapi` pointer. The "finalize" function is also no longer needed.
2024-06-14 00:25:18 +02:00
Kacper Michajłow b4bbc27d9c input: map Num 5 to distinct value when numlock is off
Until now both numlock on and off were mapped to KP5.
2024-06-13 20:42:24 +02:00
Misaki Kasumi c55ff4176c opengl: add --egl-output-format 2024-06-08 10:23:32 +02:00
Misaki Kasumi cd74f8f7c5 opengl: add --egl-config-id 2024-06-08 10:23:32 +02:00
Crend King fe709c986b vf_vapoursynth: add parameter to pass arbitrary string to script
Currently the vapoursynth video filter does not accept any argument for
passing arbitrary user data. This limits what the VS script can do.

Ideally, the vapoursynth filter has an user-data parameter that contain
string value. mpv passes that value to the VS script just like
container_fps and others. Once the VS script gets the data, it can do
all sorts of data extraction and transformation.

Another benefit is that instead of mpv always have to catch up to user
needs for this filter, with this users can just pass whatever needed
themselves, thus becomes more future-proof.

Fixes #14214
2024-06-08 03:13:41 +02:00
Kacper Michajłow dea176a7bf hwdec_vaapi: suppress comparision warning
comparison of unsigned expression in '< 0' is always false
2024-06-07 21:12:38 +02:00
nanahi b2a4c0ce91 wayland_common: properly handle modifiers for keyboard enter keys
Wayland protocol only guarantees the delivery of modifier information after
the enter event. To handle it properly for keys pressed in the enter
event, save those keys for later processing in the modifier event.
2024-06-07 18:57:35 +00:00
Kacper Michajłow 8dd262ffa5 ra_d3d11: make cache header constant size regardless of the build
This makes cache entries compatible between 32-bit and 64-bit builds and
avoids issues with loading cache wrong.
2024-06-07 19:41:50 +02:00
Kacper Michajłow 965809f108 w32_common: stop IME initialization timer after first try
It will be set again on first key press, but no need to call IME api
every 250ms until any key is pressed.
2024-06-07 19:41:15 +02:00
Kacper Michajłow b4683fd3d8 {x11_common,context_x11egl}: suppress Wundef warning 2024-06-05 19:07:58 +02:00
Kacper Michajłow 37127276cc win32: quantize taskbar playback position into uint8 range
Also, if the position is valid, set it to 1 / INF. Windows interprets 0
as non-progress.

Progress is quantized into uint8 range, it is good enough for this
use-case. This avoids unnecessary vo_control and
ITaskbarList3::SetProgressValue calls and should be visually
indistinguishable in practice.

Fixes #14282
2024-06-03 19:16:35 +02:00
Kacper Michajłow d3b251bb99 Revert "d3d11: calc vsync interval on real stats, not just last interval"
The values provided since last disjoint event may include significant
error in case there are periods of slower presentation. We should look
at more localized/current values of presentation.

For more accurate approximation of vsync rate I plan to add better
algorithm to calculate it.

Revert this commit alone as it is not neccessary and gives as separation
from other changes for better regression testing.

This reverts commit f27767f59e.
2024-06-03 19:16:01 +02:00
Dudemanguy 52bdeb07a1 x11: correct position coordinates if mpv was launched with --fs
If mpv is launched with --fs, the x11 code tries to reset the size and
position of the window when the fullscreen exits. This has bad behavior
with multiple monitors because the saved nofsrc is not reliable in many
situations. Particularly if the window manager moves the fullscreen
window somewhere else while mpv is fullscreen. The result will be that
exiting fullscreen always goes back to screen 0.

Fix this by translating the rc coordinates of the nofsrc rc to the new
monitor when we're leaving fullscreen from an initial --fs case. By
giving get_current_display a specific rc, we can return what xrandr
display the coordinates are associated with and decide if the nofsrc
should be translated to its new location. After that bit of math, the
usual move/resize logic takes care of the rest but this time it actually
works off of the correct position. Fixes #14226.
2024-05-29 13:39:20 +00:00
llyyr 7ff6cf807c vo_vaapi: remove redundant function call
we already free video specifics when reconfiguring
2024-05-28 21:29:07 +02:00
llyyr 0aec73d1bf vo_vaapi: fix use-after-free when quitting
p->output_surfaces gets freed by destroy_frame when quitting
2024-05-28 21:29:07 +02:00
llyyr ff73aeb5c3 vo_vaapi: fix use-after-free of current frame
This was forgotten when switching vo_vaapi from using draw_image to
draw_frame API

Fixes: 0b70598358 ("vo: fully replace draw_image with draw_frame")
2024-05-28 21:29:07 +02:00
nanahi 2fa66b850d wayland_common: ignore unknown key states
Once https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/368
is merged and we upgrade wl_seat version to 10, compositors will also
generate "repeated" events, which mpv treats as key up right now.
Change the check so that unknown key states are ignored.
2024-05-24 17:57:55 +00:00
nanahi 0fcfbab9af wayland_common: handle pressed keys in keyboard_enter event
This is required by the wayland protocol to keep the logical keyboard
state consistent.
Quoting 9e4f256927:

> In the wl_keyboard logical state, this event sets the active surface to
> the surface argument and the keys currently logically down to the keys
> in the keys argument.
2024-05-24 17:57:55 +00:00
Dudemanguy 1e1e365c18 wayland: use wl->callback_surface for idle inhibitor creation
The idle inhibit protocol specifies that the compositor may ignore the
idle inhibitor if the surface is occluded. In the case of
vo_dmabuf_wayland, wl->surface corresponds to typical black bars when
the video aspect ratio is different than the display's. So in many
cases, wl->surface is actually occluded by wl->video_surface which sits
above it. Change this so that the idle inhibitor is created on
wl->callback_surface instead which is either wl->surface for the gpu VOs
or wl->video_surface for vo_dmabuf_wayland. Fixes #14206.
2024-05-22 14:08:01 +00:00
Kacper Michajłow 072d0ac836 mp_image: remove unneeded PL_HAVE_LIBDOVI check
This function is always available, if libplacebo is compiled without
libdovi it is no-op.
2024-05-21 11:23:29 +02:00
Dudemanguy 2c68e6cb1f wayland: also log version numbers with protocol interface names
Might be useful for debugging.
2024-05-19 00:05:48 +00:00
Dudemanguy 47f60d1c52 wayland: cap xdg_wm_base at 4 if wm_capabilities aren't supported
Fixes #13986.
2024-05-16 16:23:18 +00:00
Kacper Michajłow 21e167cc6a vf_vapoursynth: pass image properties from input
This might not always be correct depending on filtering done in VS. But
unless VS send us all the metadata we have to get it from somewhere.

Fixes dynamic frame metadata, which was copied from fmt_in, initialized
only upon reinitialization.

Fixes crashes caused by the use of stale pointers.

Fixes: #13956
2024-05-12 17:56:53 +02:00
Kacper Michajłow 83e51a82e6 vf_vapoursynth: fix _ChromaLocation 2024-05-12 17:56:53 +02:00
Kacper Michajłow 3874145248 hwdec_cuda_vk: add missing io.h include
Fixes compilation on Windows with cuda enabled.
2024-05-11 21:34:24 +02:00
Kacper Michajłow f17ad792c6 vo_gpu_next: check if existing cache file has correct size 2024-05-10 22:54:25 +02:00
Kacper Michajłow e175b3f685 lcms: check for null arg in gl_parse_3dlut_size
This fixes `icc-3dlut-size` validation in config which would crash if
set without argument.

Found by OSS-Fuzz.
2024-05-09 21:21:40 +02:00
Kacper Michajłow 325abfeed7 dmabuf: fix warnings on 320-bit build 2024-05-08 18:52:40 +02:00
Kacper Michajłow aa9cc72199 filter/vf_gpu_vulkan: fix Vulkan handle type 2024-05-08 18:52:40 +02:00
Kacper Michajłow 43b702d707 drm_prime: remove off by one when allocating new ref counter 2024-05-07 21:05:18 +02:00
repojohnray d1e55a0e87 drm_prime: fix issue detected by valgrind
Conditional jump or move depends on uninitialised value(s)
   at 0x10FE22: drm_prime_remove_handle_ref (drm_prime.c:144)
   by 0x10FCCD: drm_prime_destroy_framebuffer (drm_prime.c:107)
   by 0x10FEB1: set_current_frame (hwdec_drmprime_drm.c:73)
   by 0x11054F: overlay_frame (hwdec_drmprime_drm.c:223)
   by 0xF1311: gl_video_render_frame (video.c:3315)
   by 0xFA015: draw_frame (vo_gpu.c:85)
   by 0xF8FDB: render_frame (vo.c:961)
   by 0xF943F: vo_thread (vo.c:1099)
   by 0x5EBE89B: start_thread (in /lib/libpthread-2.31.so)
 Uninitialised value was created by a heap allocation
   at 0x484713C: realloc (vg_replace_malloc.c:1437)
   by 0x10258B: ta_realloc_size (ta.c:195)
   by 0x10325D: ta_xrealloc_size (ta_utils.c:298)
   by 0x10FDBF: drm_prime_add_handle_ref (drm_prime.c:133)
   by 0x10FC57: drm_prime_create_framebuffer (drm_prime.c:87)
   by 0x1102FF: overlay_frame (hwdec_drmprime_drm.c:188)
   by 0xF1311: gl_video_render_frame (video.c:3315)
   by 0xFA015: draw_frame (vo_gpu.c:85)
   by 0xF8FDB: render_frame (vo.c:961)
   by 0xF943F: vo_thread (vo.c:1099)
   by 0x5EBE89B: start_thread (in /lib/libpthread-2.31.so)

Conditional jump or move depends on uninitialised value(s)
   at 0x10FCE4: drm_prime_destroy_framebuffer (drm_prime.c:109)
   by 0x10FEB1: set_current_frame (hwdec_drmprime_drm.c:73)
   by 0x11054F: overlay_frame (hwdec_drmprime_drm.c:223)
   by 0xF1311: gl_video_render_frame (video.c:3315)
   by 0xFA015: draw_frame (vo_gpu.c:85)
   by 0xF8FDB: render_frame (vo.c:961)
   by 0xF943F: vo_thread (vo.c:1099)
   by 0x5EBE89B: start_thread (in /lib/libpthread-2.31.so)
 Uninitialised value was created by a heap allocation
   at 0x484713C: realloc (vg_replace_malloc.c:1437)
   by 0x10258B: ta_realloc_size (ta.c:195)
   by 0x10325D: ta_xrealloc_size (ta_utils.c:298)
   by 0x10FDBF: drm_prime_add_handle_ref (drm_prime.c:133)
   by 0x10FC57: drm_prime_create_framebuffer (drm_prime.c:87)
   by 0x1102FF: overlay_frame (hwdec_drmprime_drm.c:188)
   by 0xF1311: gl_video_render_frame (video.c:3315)
   by 0xFA015: draw_frame (vo_gpu.c:85)
   by 0xF8FDB: render_frame (vo.c:961)
   by 0xF943F: vo_thread (vo.c:1099)
   by 0x5EBE89B: start_thread (in /lib/libpthread-2.31.so)
2024-05-07 21:05:18 +02:00
nanahi 4e59a56896 various: fix comma style 2024-05-07 11:23:08 +02:00
nanahi 9f5edd4eed various: fix indentation 2024-05-07 11:23:08 +02:00
nanahi bb88e4aeb5 various: fix trailing whitespace 2024-05-07 11:23:08 +02:00
Jrelvas 1759d73c83 hwdec_cuda: reduce nesting in check functions
This simplifies the code and makes it easier to read.
2024-05-07 00:34:46 +02:00
Jrelvas 58f50c8e49 hwdec_cuda: avoid gpu wakeup by deferring cuInit
`cuInit` wakes up the nvidia dgpu on nvidia laptops. This is bad news because the wake up process
is blocking and takes a few seconds. It also needlessly increases power consumption.

Sometimes, a VO loads several hwdecs (like `dmabuf_wayland`). When `cuda` is loaded, it calls
`cuInit` before running all interop inits. However, the first checks in the interops do not
require cuda initialization, so we only need to call `cuInit` after those checks.

This commit splits the interop `init` function into `check` and `init`. `check` can be called without
initializing the Cuda backend, so cuInit is only called *after* the first interop check.

With these changes, there's no cuda initialization if no OpenGL/Vulkan backend is available. This prevents
`dmabuf_wayland` and other VOs which automatically load cuda from waking up the nvidia dgpu unnecessarily,
making them start faster and decreasing power consumption on laptops.

Fixes: https://github.com/mpv-player/mpv/issues/13668
2024-05-07 00:34:46 +02:00
Kacper Michajłow b647201795 osdep/dirent: add implementation for Windows SDK build 2024-05-06 22:01:17 +02:00
Kacper Michajłow fffe723fc4 various: move strings.h inclusion to common.h 2024-05-06 22:01:17 +02:00
Kacper Michajłow 18ef834ef4 various: move unistd.h inclusion to common.h 2024-05-06 22:01:17 +02:00
der richter 8a61929eb8 cocoa-cb: add support for macOS color space transformation (EDR/HDR)
by default utilises the color space of the screen on which the window is
located. if a specific value is defined, it will instead be utilised.

depending on the chosen color space the macOS EDR (HDR) support is
activated and that OS's transformation (tone mapping) is used.

Fixes #7341
2024-05-05 19:02:50 +02:00
Kacper Michajłow 4cc9e6f999 win32: fix maximize state with --border=no
WS_POPUP windows cannot be maximized, so instead of forcing it with
unavoidable side-effects, change the window style before maximizing to
make it work correctly.
2024-05-05 14:02:57 +02:00
nanahi 861908c70f win32: make context menu items accessible from the window menu
This makes the context menu items accessible from the window menu,
which can be opened by either right-clicking on the title bar or
left-clicking on the mpv icon on the title bar.
2024-05-03 16:36:02 +02:00
nanahi ee2e14015d win32: move context menu init/uninit to GUI thread
Currently if VO init fails, the context menu is leaked. Additionally,
init/uninit are in the VO thread, while other accesses are in the GUI
thread.

Fix this by moving them to the GUI thread, similar to other resources.
This also lets init function take the mpv HWND in the next commit.
2024-05-03 16:36:02 +02:00
Dudemanguy cb613ba916 wayland: set wl->scaling if there is no wl->current_output yet
If we get either preferred_scale or preferred_buffer_scale this early
during initialization the wl->scaling value should be immediately
updated instead of being deferred until later for correct geometry.
Fixes #14019.
2024-05-03 16:18:35 +02:00
nanahi e20ca15b66 win32: support multitouch
Use the multitouch API. To disable system's defualt mouse emulation,
set --native-touch=yes.
2024-05-03 16:14:03 +02:00
nanahi f0e163bab5 wayland_common: support multitouch
Use the multitouch API. No need to emulate mouse input as it's already
done by the input system.
2024-05-03 16:14:03 +02:00
Dudemanguy d61d294665 wayland: log if cursor shape support is missing
This is done for the other protocol interfaces already but was
accidentally omitted.
2024-05-02 13:46:20 +02:00
der richter 4a686dac6f mac: properly handle regular expressions without force unwrap 2024-04-28 20:21:18 +02:00
der richter 8f1189341f mac: code cleanup and consistency changes, fix linting issues 2024-04-28 20:21:18 +02:00
der richter 984c890661 mac/helper: make wakeup callback declaration consistent 2024-04-28 20:21:18 +02:00
nanahi 93708a9d38 w32_common: fix show-in-taskbar toggling after explorer is restarted
After explorer is restarted while show-in-taskbar is false, toggling
show-in-taskbar no longer puts mpv back to the taskbar until it's
unfocused and refocused.

My guess of how this works is that the HWND of the taskbar is cached,
and setting the WS_EX_TOOLWINDOW style internally uses this value to
show/hide the taskbar button. But after explorer is restarted it no
longer works until its taskbar state needs to change (such as focusing).
Only then it realizes the HWND is no longer valid and refreshes it.

Fix this by following MS documentation on this: the window needs to be
hidden before changing the style, and be shown after that. This
unfortunately can sometimes introduce a brief window flash, but it
fixes the problem.
2024-04-27 03:02:00 +02:00
Shreesh Adiga d9c5aef98d vf_gpu: vulkan and egl implementations
Abstract out EGL, and allow choosing between EGL and vulkan at runtime.
vf_gpu_egl.c contains GL specific context and creation/destroy code,
vf_gpu_vulkan.c contains Vulkan specific. This allows vf_gpu being
built in systems where EGL is not available and where Vulkan is
available.
2024-04-27 01:08:22 +02:00
der richter f7a32b5f29 mac: make display-names unique to allow specific selection
the Screen property localizedName returns a none unique dynamic name
that doesn't allow a specific selection of a Screen on every OS boot.
the name consists of the vendor name and model name (eg DELL U2723QE).
if the same model display is connected to the system several times,
macOS starts to add numbers to the localizedName (eg DELL U2723QE (1)),
that may not be associated to the same Screen on every OS boot or
connecting the display. it also changes the name of the first connected
display by adding that numeration. this makes it impossible specify the
proper screen with the screen-name option every time.

to circumvent this we remove the enumeration from the name and instead
add the serial number to the display-names property. this makes the
actual Screen unique and none dynamic. furthermore the selection of a
screen by name will check for equality for the old localizedName, simple
name without enumeration, serial number and the combined name with
serial number. this makes it possible to select the screen by either of
those names and identifiers, and keeps backwards compatibility with the
old behaviour.

Examples:
localized name (System Settings name): DELL U2723QE, DELL U2723QE (1)
simple name: DELL U2723QE
serial number: 123456789
combined name: DELL U2723QE (123456789)
2024-04-24 20:35:38 +02:00
Dudemanguy d255f31f98 vo_dmabuf_wayland: use wl_fixed_from_int when setting viewport source
When this was originally implemented, the fixed conversion factor was
accidentally reverse engineered. It was left as is though. Instead, use
the wl_fixed_from_int helper, so it's more obvious what is going on
here.
2024-04-21 13:42:49 -05:00
Dudemanguy 8db1902ae9 vo_dmabuf_wayland: fix scaling for subsurface positioning
It's off if the video aspect ratio doesn't match the monitor aspect
ratio. Fixes c243946338.
2024-04-21 13:42:49 -05:00
Kacper Michajłow 1a495451ab d3d11: disable IDXGIInfoQueue usage if dxgidebug.h is incomplete
Older MinGW-w64 doesn't define IDXGIInfoQueue in dxgidebug.h.
2024-04-19 03:32:29 +02:00
Kacper Michajłow 19a9164e24 d3d11: use IDXGIInfoQueue instead ID3D11InfoQueue
DXGI debug interface encapsulate multiple message queues, which allows
to get validation not only for D3D11 calls, but also DXGI ones.

Also this makes leak detector not report self debug interface as alive
like it was before. And same as with validation, it has ability to
detect more alive objects, not being limited to D3D11.
2024-04-19 03:32:29 +02:00
Dudemanguy e5d683e187 context_drm_egl: guard gbm_device on uninit
Not all cards support gbm which means the creation of the gbm device
will fail. However during the uninit process, the destruction of the
device was unconditionally done which leads to a segfault. Guard it
instead. Fixes #13929.
2024-04-18 14:57:01 -05:00
Dudemanguy 4d80e7b72c x11: always do a reset_size if geometry/autofit is updated at runtime
Previously, the code required a check against the old saved geometry to
make sure the size and/or position was different before updating. The
doesn't work with the previous changes that allow a geometry value to be
set again with the same value as before. It would probably be nicer to
check against something that always keeps track of the actual window
size in real time, but it seems geometry in x11 doesn't quite work that
way so we'll do it the easier way instead.
2024-04-18 17:40:16 +00:00
nanahi 2533ea764f various: add GPU context description
Now that obj_settings_list is used for GPU contexts, detailed
descriptions can be added so that --gpu-context=help can print
the descriptions of the GPU contexts using standard
obj_settings_list help printing.
2024-04-18 16:28:21 +02:00
nanahi a6ff33425d video/out/gpu/context: add auto dummy context
This adds a dummy context at the start of the context lists, which
serves three purposes:

- The "auto" option is listed for --gpu-context=help.
- Some special handlings of "auto" string are removed.
- Make sure that lists have at least one element, so MP_ARRAY_SIZE()
  works as intended.
2024-04-18 16:28:21 +02:00
nanahi 96e1f1dfa5 video/out/gpu/context: convert --gpu-context to use obj_settings_list
Since the list of available GPU contexts is a compile time constant,
use obj_settings_list instead of opt_string_validate for GPU contexts.
This has several advantages:

- Aligns with the existing usage of vo, ao, and filter lists.
- Allows custom probing order.
- Allows list option suffixes. (--gpu-context-append, etc.)
- Allows autocomplete in console.lua.
- Uses the standard obj_settings_list help printing, so the custom
  help printing function is no longer needed.

This also deduplicates some context creation code for ra_ctx_create
and ra_ctx_create_by_name.
2024-04-18 16:28:21 +02:00
nanahi d5ec069829 video/out/gpu/context: don't use hidden flag for contexts
For contexts that have no API, just use a separate list for them.
This keeps validate func for the main contexts simpler.
2024-04-18 16:28:21 +02:00
Kacper Michajłow 2f8038c598 vo_gpu_next: invalidate cache object if requested by libplacebo
See: https://code.videolan.org/videolan/libplacebo/-/merge_requests/659
2024-04-18 02:25:12 +02:00
nanahi c2ed2e7bc8 terminal: add terminal_set_mouse_input function
This function is used to enable/disable mouse input for win32 and unix.
2024-04-18 01:03:33 +02:00
nanahi 7c6bb9c37b vo_{tct,sixel,kitty}: implement mouse support 2024-04-18 01:03:33 +02:00
nanahi 8c614e0df5 w32_common: implement --show-in-taskbar option
When the window style changes, use WS_EX_TOOLWINDOW style to exclude
the window from the taskbar and Alt+Tab switching.
2024-04-18 00:09:09 +02:00
nanahi dcd1034529 x11_common: implement --show-in-taskbar option
This adds a new option --show-in-taskbar, which controls whether
mpv appears in taskbars. This is useful for picture-in-picture
setups where the video window should not appear in taskbars.

On X11, this can be controled by setting the
_NET_WM_STATE_SKIP_TASKBAR window state.
2024-04-18 00:09:09 +02:00
nanahi 3a92d7ba3b x11_common: detect wm support for _NET_WM_STATE_SKIP_TASKBAR 2024-04-18 00:09:09 +02:00
Kacper Michajłow e720159f72 player/command: add video-codec-info and audio-codec-info
Adds support for extracting codec profile. Old properties are redirected
to new one and removed from docs. Likely will stay like that forever as
there is no reason to remove them.

As a effect of unification of properties between audio and video,
video-codec will now print codec (format) descriptive name, not decoder
long name as it were before. In practice this change fixes what docs
says. If you really need decoder name, use the `track-list/N/decoder-desc`.
2024-04-15 19:34:40 +02:00
llyyr 3995cd3714 wayland: fix segfault in surface_handle_enter due to memory read
Fixes: 895f40e150 ("wayland: only perform a rescale if window is on one output")
2024-04-15 16:41:01 +00:00
Dudemanguy cb6e7c7a55 wayland: check if scale actually changes in scaling events
The protocol strongly implies that this only happens when the value
changes, and it's also what you would naturally expect. But maybe it's
worth guarding this in cause for some reason the same value twice in a
row happens.
2024-04-14 17:09:31 +00:00
Dudemanguy 895f40e150 wayland: only perform a rescale if window is on one output
The mpv window overlapping multiple outputs with different scale values
can result in some weird behavior when dragging it from one monitor to
another one. This is due to the way some compositors implement
preferred_scale or preferred_buffer_scale (integer scale equivalent).
Depending on the scale values, mpv window has to be resized to match the
new scaling value (due to fractional scaling requiring a viewport). This
can cause the window to become smaller and no longer overlap the monitor
you were just trying to drag it to. Repeat this and the window will
become smaller and smaller. Depending on the layout, the reverse can
also happen (the window becomes larger). This can cause additional
events to fire as the preferred_scale value may change again which does
more weird things.

It seems kwin is not affected by this because their implementation of
preferred_scale sends the event only if the window is fully on the new
monitor. Honestly, this is probably more logical anyway but we should at
least deal with the other implementations better. Try to deal with it by
reworking scaling changes so they only occur when the mpv window is
fully on one monitor. If we get a preferred_scale event and there is an
overlap, save it as a pending change to be performed on the next
surface_enter or surface_leave event (whichever results in there being
only one monitor. Some weird rendering glitches can still happen during
overlap but this makes it usable again.
2024-04-14 17:09:31 +00:00
Kacper Michajłow 078da37d5c vo_gpu_next: rotate target crop
Turns out libplacebo uses unrotated target crop in relation to source.
Use dst rect from VO, instead of extracting it from pl_frame, to avoid
another unrotating operation.

Fixes: a9354b36ca
2024-04-13 23:07:16 +02:00
Dudemanguy 1172c4ead9 wayland: apply keepaspect options to wayland configure bounds
Previously if mpv's size was constrained by the compositor's configure
bounds event, there was no attempt to preserve the aspect ratio of the
given coordinates if --keepaspect (the default) was used. Be sure to
apply keepaspect to the bounded widths and heights if we are using this
event.
2024-04-13 14:33:58 +00:00
Dudemanguy 307255d00d wayland: avoid unneeded calls to xdg_toplevel state functions
The reconfigure event handles setting fullscreen, maximize, etc. We were
implictly relying on the compositor to just ignore mpv if we set a
redundant state (e.g. setting fullscreen when we're already fullscreen),
but kwin actually doesn't and operates again. This causes some subtle
issues when handling geometry on state changes. Rework the state change
calls so they are only executed if wl->geometry_configured isn't set yet
(i.e. the window just opened up for the first time). It's the only time
this is actually needed.
2024-04-13 14:33:58 +00:00
Dudemanguy 4023146a04 wayland: enforce a state change after a reconfigure
If mpv is coming out of some locked size state (fullscreen, maximized,
tiled), the window size given by the reconfigure event should be used
assuming the --auto-window-size option is set.

Fixes 8a9749b8a5
2024-04-13 14:33:58 +00:00
Kacper Michajłow a9354b36ca vo_gpu_next: set target resolution to crop value
Use rect of the actual image instead of FBO size which includes
margins.
2024-04-13 13:37:12 +02:00
der richter ee6794225d mac/vulkan: add support for frame timing via presentation feedback 2024-04-10 19:14:20 +02:00
der richter 6df07ce90c mac/window: fix window pinch gesture and modify current-window-scale
this will prevent jumping of the window size in the case the window size
was 'externally' modified and not via the window-scale property, when
using the pinch gesture.

Fixes #11594
Fixes #13799
2024-04-10 19:13:00 +02:00
nanahi 9bb7d96bf9 various: make filter internal function names more descriptive
Lots of filters have generic internal function names like "process".
On a stack trace, all of the different filters use this name,
which causes confusion of the actual filter being processed.

This renames these internal function names to carry the filter names.
This matches what had already been done for some filters.
2024-04-10 19:00:22 +02:00
Kacper Michajłow 89cc477ef1 vo_gpu_next: keep target params in priv instead of alocating it 2024-04-10 18:35:47 +02:00
Dudemanguy 0d250892ba Revert "vo_dmabuf_wayland: assume counter-clockwise rotations"
This commit was originally sparked by a change in sway. When looking at
the wording of the spec, it was believed that the rotation should be
counter-clockwise. But that was interpreted incorrectly. The rotation
direction in the spec is meant for compositors not clients. Clients
should be rotating clockwise and compositors rotate it the opposite
direction. Also see the discussion in upstream wayland*.

*: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/369

This reverts commit 27ef1725e7.
2024-04-09 13:48:08 +00:00
Kacper Michajłow d3941f235a bstr: change bstr0_s to bstr0_lit, restrict it only for string literals
Allows to avoid non-portable strlen usage. Also avoid "initializer
element is not constant" warnings on older GCC that doesn't like
explicit type specification in aggregate initialization.

Co-authored-by: NRK <nrk@disroot.org>
Co-authored-by: nanahi <130121847+na-na-hi@users.noreply.github.com>
2024-04-08 02:06:06 +02:00
Kacper Michajłow 2d4fae4f70 vo_tct: reduce lut_item size and generate it without snprintf 2024-04-07 20:23:04 +02:00
Kacper Michajłow 7d2b7fa019 vo_tct: use fwrite when appropriate 2024-04-07 20:23:04 +02:00
Kacper Michajłow 6177aa7616 vo_tct: add synchronized output support
See-Also: https://gist.github.com/christianparpart/d8a62cc1ab659194337d73e399004036
2024-04-07 20:23:04 +02:00
Kacper Michajłow 5a53fa7cad vo_tct: add --vo-tct-buffering option 2024-04-07 20:23:04 +02:00
Kacper Michajłow fbc5e47e00 misc/bstr: add bstr0_s for static initialization 2024-04-07 20:23:04 +02:00
Kacper Michajłow 39d560676f vo_tct: write frame fully instead of every pixel
This is multiple times faster than just writing every pixel sequence
separately. Especially on slower terminal emulators. In general no need
to stress I/O, while we can just prepare the frame to print and do it
once.
2024-04-07 20:23:04 +02:00
Kacper Michajłow 2f76536f62 vulkan: use pl_vk_inst_create
This change is mostly motivated by missing
VK_KHR_portability_enumeration instance extension when enumerating the
devices. Which causes issues with MoltenVK which does not advertise full
Vulkan conformance.

To avoid duplicating code use pl_vk_inst_create() which correctly query
availability and enables the mentioned extension.

While at it fix the VkInstance leaking in vk_validate_dev().
2024-04-07 20:16:50 +02:00
Shuanglei Tao 3c1e983351 vo: add win32 context menu support 2024-04-06 08:24:06 +02:00
der richter c555cfccfe mac/common: reuse hidpi window scale frame calculation helper 2024-04-04 19:39:27 +02:00
der richter 5178c5b7d1 mac/window: cleanup unfsContentFrame usage and make it none optional 2024-04-04 19:39:27 +02:00
der richter fc36e5d71e mac/window: fix unfs window size retrieval
the unfsContentFrame wasn't updated when externally resized leading to
a wrong unfs window size afterwards. update it on windowDidResize event
when not in fs, not animating and not live resizing.
2024-04-04 19:39:27 +02:00
nanahi a140d2788c wayland_common: set mouse position on pointer enter
At least on some compositors, when the pointer enters a surface,
only a wl_pointer_enter event is generated, but not wl_pointer_motion.
This results in the initial mouse position being lost, which is
especially problematic when input simulation is used.

Fix this by setting the mouse position on pointer enter event.
2024-04-01 01:17:22 +00:00
der richter 92cb47338f mac/view: fix cursor visibility when toggling fullscreen
this broke with the recent refactor of the input handling. one of the
edge cases was not considered, where not every mouse down event has a
corresponding mouse up event, eg all double clicks or more only have one
up event after the first down event.

this was handled correctly previously.

Fixes #13777
2024-03-29 14:20:40 +01:00
der richter ba45f2004f mac: cleanup swift bridge header imports and unify them 2024-03-29 14:20:40 +01:00
der richter ed0587692f mac/log: rename log functions and cleanup class 2024-03-29 14:20:40 +01:00
der richter ceaabb7b98 mac: use LogHelper directly instead of mp_log 2024-03-29 14:20:40 +01:00
der richter e7df95b10d mac: rename mpvHandle to mpv 2024-03-29 14:20:40 +01:00
der richter e71e340b77 mac: remove now unnecessary objective-c forwarding 2024-03-29 14:20:40 +01:00
der richter 1bc680d32a mac/apphub: move menu bar into AppHub 2024-03-29 14:20:40 +01:00
der richter 1acca1d3c4 mac/apphub: move app icon into AppHub
split up AppHub header in obj-c and c parts and make it a bidirectional
bridging.
2024-03-29 14:20:40 +01:00
nanahi 6fed2f8e58 win32: fix native key repeat support
win32 does not respect --native-keyrepeat option, and native key
repeat has been broken since 0ab3482f73.

This lets mpv respect the --native-keyrepeat option on win32.
2024-03-29 14:07:37 +01:00