Commit Graph

50397 Commits

Author SHA1 Message Date
sfan5 a0d8962be8 zimg: fix broken sig_peak handling
In sum there were three issues:
1. nominal_peak_luminance is an output parameter, not input
2. mpv internally uses MP_REF_WHITE which we need to scale by
3. the value should be left at its default for SDR

Together with the last change this means mpv can sucessfully
take HDR screenshots with --screenshot-sw without resulting
in a brightly colored mess. Though note that zimg does not
perform proper tonemapping.
2023-07-19 13:01:08 +02:00
sfan5 a960b75604 image_writer: move tag_csp check into image_writer_flexible_csp()
This ensures the sRGB fallback to happen in all situations involving
the image writer code, notably --screenshot-sw.

fixes: cbbe2e5221
2023-07-19 13:01:08 +02:00
sfan5 157ef77427 image_writer: replace sprintf usage
also fixes the buffer being cut off (?!)
2023-07-19 13:01:08 +02:00
sfan5 f95339c02a image_writer: share some code between write_lavc and write_avif
As a consequence:
- write_avif now respects tag-colorspace=no
- write_lavc additionally sets colorspace and chroma_location
  (of no consequence for png or jpeg)
2023-07-19 13:01:08 +02:00
sfan5 8f26d99fbd image_writer: error check avif-pixfmt option 2023-07-19 13:01:08 +02:00
sfan5 8aa8e21da9 image_writer: fix still-picture option for AVIF
Gets rid of validation warnings on the produced files.
2023-07-19 13:01:08 +02:00
sfan5 d7ef91fecd image_writer: remove duplicate packet writing code 2023-07-19 13:01:08 +02:00
sfan5 608b430b56 TOOLS: remove obsolete travisCI-related scripts 2023-07-19 13:01:08 +02:00
sfan5 d46a31317f wayland_common: remove questionable gcd impl and global state 2023-07-19 13:01:08 +02:00
Dudemanguy e399266400 wayland: don't treat tiled and maximized windows the same
mpv has historically always treated the various tiled states in
xdg-shell as maximized (probably because it was easier). Well it turns
out that there are some tiling compositors (hyprland) that allow tiled
windows to maximize themselves. This can lead to some scenarios where
mpv ends up doing a maximize on hyprland which actually works since it's
not a no-op like on sway. Fix this by separating out the tiled state
from maximize. It works mostly the same, but the main difference is that
there's no request to tile yourself like there is with maximize. Should
fix #11954.
2023-07-19 01:14:32 +00:00
Dudemanguy 949e1f0dcc wayland: add locked_size convenience shorthand
There's a lot of checks that are along the lines of !maximized &&
!minimized or vice versa. Make a locked_size boolean and store the
value of this in here to avoid writing long lines since the next commit
will add yet another condition to this.
2023-07-19 01:14:32 +00:00
Niklas Haas dbbcd9ec9c builtin.conf: add --hdr-contrast-recovery to gpu-hq
The first change to the gpu-hq profile in aeons.
2023-07-18 15:22:18 +02:00
Niklas Haas 02595011eb vo_gpu_next: add --hdr-contrast-recovery/smoothness
New upstream feature. Disabled by default.
2023-07-18 15:22:18 +02:00
rcombs ac725764ec builtin.conf: unset default languages in libmpv and encode profiles
The `auto` behavior doesn't really make sense in these contexts.
2023-07-18 00:42:56 -07:00
Philip Langdale fbd0be1cf4 vd_lavc: repeatedly attempt to fallback if hwdec fails in receive_frame
There is an additional failure path I didn't account for in my previous
work. While I ensured that a late hwdec failure in receive_frame can be
recovered from by trying the next hwdec, there is a specific
combination where if an hwdec fails in receive_frame, and the next
hwdec is a full decoder (eg: v4l2m2m), and that also fails, we are left
with no decoder and so the entire decoding process ends and playback is
stopped.

Basically, we must keep re-attempting the fallback in receive_frame
until we get a valid decoder (software or hardware). This edge case
will rarely be encountered as there are only a couple of decoder based
hwdecs.

Fixes #11947
2023-07-17 18:37:41 -07:00
Dudemanguy 1f8013ff3f wayland: handle modifier keys correctly
I don't know why we've been doing this wrong for so long or how I didn't
notice until now. Wayland specifically has an event for handling
modifiers. We even named it "keyboard_handle_modifiers" in the code.
What we should do is just get the modifier and save it after the xkb
state is updated. Then later if the user does something else (press
another key or clicks the mouse button), the saved modifier key is
applied. If you let go of the modifier at any point, the xkb will just
update its state again and we save a 0 again here (i.e. no modifier).

There is one bit of an edge case however. If a key is pressed BEFORE the
modifier, then we have to handle the mp_input_put_key in the modifier
event instead since the ordering is not guarenteed. What we do here is
keep track of the mpkey as well as the mpmod. However if we are unable
to find a matching mpkey and the key state is pressed down, assume it's
a modifery key that was pressed and don't update mpkey. That way
whenever the modifier event does happen, it can correctly handle this
and we know that the keys must be pressed down if we end up there in the
code path.

As another fun historical note, the xkb_keysym_to_utf8 line was actually
written by wm4 himself in 460ef9c7a4
nearly 10 years ago. As the commit shows, it was clearly intended to
handle modifiers (if lookupkey finds nothing, then try to find a mod
instead). Of course, this is extremely dated and wayland hasn't worked
like that in ages. This branch never actually did anything, and thus
we'll remove it here along with modifier lookup changes.

This solves bizarre issues with modifiers not working with random keys
while working fine with others (don't ask me why). Fixes #10286 and
fixes #11945.
2023-07-17 18:53:50 +00:00
Kacper Michajłow 347fbd6fa3 vo_gpu_next: add --target-contrast option
For better control over target display levels.
2023-07-17 18:50:34 +02:00
llyyr fbd392bcbb loadfile: make get_audio_lang function static
This fixes a build warning about missing prototypes
2023-07-17 18:02:07 +02:00
sfan5 8a6cabce35 DOCS/release-policy.md: add additional advice 2023-07-17 11:55:45 +02:00
rcombs 9e6c6c0897 loadfile: compute audio lang for sub selection when using lavfi-complex
When using lavfi-complex, no single track populates current_track for audio.
We work around this by iterating over the list of tracks and using the first
non-null language from a selected track. If multiple tracks are selected
(i.e. used by the filter) and have conflicting language tags, we'll ignore
them all and maintain the previous behavior (null).
2023-07-16 21:32:50 -07:00
Dudemanguy 9e9abb1a0f wayland: wrap resize requests in prepare_resize
828dd65ef8 started this and put it in the
most common place, but any resize mpv is doing should be accompanied by
that function call to correctly inform the compositor of the window
bounds. Since we also have to set VO_EVENT_RESIZE at the same time, it
makes sense to just put these in the same function. A slight thing to
note is that xdg_surface_set_window_geometry uses surface local
coordinates which means they are divided by the wl->scaling factor. If
possible, we should use surface local coordinates directly if available
(like in the toplevel config) to avoid potential rounding errors.
Otherwise, just calculate it out. The linked commit actually broke
some weston resizes in weird ways (window disappearing or completely
freezing). Don't ask me why and I didn't attempt to find out why either,
but with this it all appears to work normally again (the other
compositors don't appear to be any different, and they shouldn't be), so
we'll go with this since it fixes soemthing and it also is more
conceptually correct.
2023-07-16 21:20:50 -05:00
llyyr 580f36e436 sd_ass: fix converted subtitles having too-wide borders
Libass commit f08f8ea5 (between 0.16 and 0.17) changed how PlayResX
affects some aspects of rendering.

The libass change fixes a VSFilter compatibility issue which existed
for about two decades, and there are no libass plans to support the
previous behavior, so ultimately we have to adjust the mpv code, and
we can't guarantee to restore the old behavior in all cases.

Starting at this commit, vector drawing coords, font spacing, border
and shadow widths are all affected by PlayResX (specifically, by
the aspect), while previously they were unaffected by PlayResX.

This changed converted sub border and shadow widths in mpv, because
ffmpeg generates the ass with fixed PlayResX of 384 (aspect of 4:3),
and with libass 0.17, if this doesn't match the display aspect, then
borders and shadow were too wide - because most clips aspect is more
than 4:3.

The fact that ffmpeg uses fixed PlayResX of 384 could be considered
an issue, but for now we have no control over it, and ffmpeg doesn't
have the video resolution when it converts an srt source to ass.

So here we adjust PlayResX accordingly so that border/shadows are
now rendered with correct width.

However, regardless of that commit, changing PlayResX also affects
the margin value, so to compensate, we adjust sub-margins-x too.

According to libass devs, this should cover basic srt-to-ass
conversion by ffmpeg to work correctly with libass 0.17.

However, there could be srt extensions which use more complex ass,
and/or ffmpeg conversion of other sub formats (such as aribb24,
aribcaption and movtext), where more things need adjustments.
As of now we don't know what these are, and so we don't really know
what else might remain broken or get broken.
2023-07-16 21:02:54 +03:00
Dudemanguy cab544889a sd_ass: don't reconfigure ass on every frame
dbc5d7b7db seems to have originally
introduced this behavior. At the time, wm4 simply reconfigured ass on
every frame in order to accommodate runtime changes in sub options. This
certainly works, but these libass API calls are not free and there is at
least one known performance regression due to a change in libass*.
Regardless of whether or not the libass change is good/bad, there is no
need for mpv to constantly reconfigure this. When wm4 made that commit,
there was no notification mechanism for options changing that could
easily be used so he didn't really have any other choice. But it's
nearly 10 years later now and internally we have all the necessary
pieces to only configure ass again when we need to: on option changes or
resizes. So go ahead and implement that in this commit which simply uses
the already existing SD_CTRL_UPDATE_OPTS and compares osd_res sizes to
determine whether or not an ass configure is needed.

*: https://github.com/libass/libass/issues/698
2023-07-15 23:57:16 +00:00
m154k1 b077cf72df player: set default cache dir on macOS
Use ~/Library/Caches/io.mpv for caches instead of ~~home.
2023-07-15 23:56:57 +00:00
Dudemanguy 031e172cef DOCS/mpv: clarify the location of cache/state files 2023-07-15 15:10:41 +00:00
Dudemanguy d482bf6ef0 path-win: implement cache directories
4502522a7a implemented cache directories
but only on linux which meant other OSes continued to save this stuff in
their config directory. Since we turned on cache by default, people are
getting cache files in there which is understandably causing some
confusion. Let's go ahead and implement a separate cache directory for
windows since there seems to be some established conventions for this
already. For people using the portable_path, the cache is saved in a
subdirectory within the portable_path since the idea is for that to be
completely self contained.
2023-07-15 15:10:41 +00:00
Philip Langdale 93f95f61e9 DOCS/interface-changes: document change in ctrl+h behaviour
We now use `auto-safe` when turning on hardware decoding instead of
`auto`.
2023-07-15 18:58:28 +08:00
Philip Langdale e64ef6089f vd_lavc: map `hwdec=yes` to `hwdec=auto-safe`
To remain consistent with our belief that `auto-safe` should be the
recommended mode when turning on hw decoding, let's remap `yes` from
`auto` to `auto-safe`.
2023-07-14 20:41:24 -07:00
Philip Langdale 7fe2a76621 vd_lavc: add `drm` and `drm-copy` to the `auto-safe` list
We have supported `hwdec=drm` for some time now, and on devices where
this method is present, it is the preferred, and only, method
available. Combine that with the fact that software decoding on
embedded devices will not turn out well, and it's clear that we should
put `drm` and `drm-copy` on the `auto-safe` list to maximise usability
in simple configurations.
2023-07-14 20:41:24 -07:00
Philip Langdale 9f7f9c1614 input: update ctrl+h to toggle `auto-safe` rather than `auto`
It has been odd that ctrl+h toggles `auto` for hwdecs even though we
always recommend people start with `auto-safe`, and `auto` will attempt
various hwdecs that can fail so badly we can't fall back to software
decoding.

With the change to more exhaustively attempt to use hwdecs, it is now
easier to get into situations where these fragile hwdecs will get
attempted in basic scenarios, like pressing ctrl+h.

So it is high time to default to `auto-safe`.
2023-07-14 20:41:24 -07:00
Philip Langdale 4501e07996 vd_lavc: try other hwdecs when falling back after an hwdec failure
Today, if hwdec initialisation succeeds, we move on to attempting
decoding, and if decoding fails, we enter a fallback path that will
only do software decoding.

This is suboptimal because some hwdecs and codec combinations can
pass hwdec init, but then fail at hwaccel init, or even frame decoding.
In these situations, we will never attempt other hwdecs in the `auto`
or manually specified lists which might work.

One good example is someone tries to use `vulkan,auto` and tries to
play av1 content. The vulkan decoding will fail at hwaccel init time,
and then fallback to software instead of going through the auto list
which would allow vaapi, nvdec, etc to play the file.

Instead, let's not give up immediately, and try the next hwdec after
a failure, just like we do if hwdec init fails.

The key part of this change is to keep track of the hwdecs we have
tried, so that each time we run through hwdec selection, we don't try
the same one over and over again. If we really get through the whole
list with no success, we will then fall back to software decoding.

Fixes #11865
2023-07-14 20:41:24 -07:00
Dudemanguy 1f683401aa vo_dmabuf_wayland: error out if compositor doesn't support the format
This was never implemented so in cases where the compositor didn't have
support for the underlying format, the window would just be black and
quite unhelpful. Well it turns out that fixing this is actually really
easy because mpv has reconfig2 which returns the entire mp_image on
every reconfig. We can just use that mp_image to try and obtain the
format and modifier pair and then use that to check against what we know
the compositor supports. If there are any problems, error out
gracefully. Some code duplication with the vaapi/drmprime importers, but
it's probably better to keep these separate. Fixes #11198 and fixes #11664
2023-07-14 14:24:45 +00:00
Dudemanguy 2616b2b11e build: make dmabuf-wayland a build option and require drm
It makes more sense as an option at this point. Also libdrm is not
optional at all. You have to get a drm format and modifier for this to
even work (the VO will just fail without DRM). Just hard require it and
remove the guards. vaapi can remain optional.
2023-07-14 14:24:45 +00:00
Christoph Heinrich cf0373e15b console: sort the output from the `help` command
Closes #11927
2023-07-14 13:06:01 +00:00
Guido Cella fc43faa026 player: delete watch later redirect entries again
6a365b258a broke deleting redirect entries for resuming playback. If you
do mpv dir1 dir2, quit-watch-later on a file in dir1, then later
quit-watch-later on a file in dir2, mpv dir1 dir2 would not resume from
dir2 because the redirect entry for dir1 is never deleted.

Fix this by deleting watch later config files for directory/playlist
entries.
2023-07-14 13:05:40 +00:00
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 f3c1dcf7a1 draw_bmp: ensure last slice is less than total width (again)
Essentially the same as d1d2370d07 except
for clear_rgba_overlay. From some empirical testing, the s->x1 value is
either 0 or SLICE_W (256). In the case where it is 256 and s->x0 is 0,
then it writes memory. For most slices, this is fine. However for the
very last slice in the loop, it is possible for the width here to exceed
the total width of the line (p->w). If that occurs, the memset triggers
a buffer overflow. This last case needs to be guarded in the same way as
the previously mentioned commit (total width - SLICE_W * x) and with
MPMIN in case s->x1 is 0 here to preserve the old behavior. It's unknown
if anything other than dmabuf-wayland can possibly hit this, but it's
definitely a problem within mp_draw_sub_overlay itself.
2023-07-12 19:19:54 +00: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
Adam Sampson 6461fb9c44 wscript: add 1.32 protocols to sources
The patch that added these protocols didn't include them in the list of
sources, which caused build failure with wayland-protocols 1.32.
2023-07-11 17:33:59 +00:00
m154k1 cbb1af64d5 stats.lua: set sans-serif as default font
sans is deprecated and unsupported on some platforms.
2023-07-10 16:58:54 +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