Commit Graph

1197 Commits

Author SHA1 Message Date
nanahi 1d82932cce various: use fopen wrapper for cloexec handling 2026-06-04 04:58:16 +02:00
nanahi 1f150567ac osdep/io: fix fdopen mode flag
In both C11 standard and Microsoft documentation, '+' must be placed
immediately after mode, so placing 'b' between them is incorrect.
2026-06-04 04:58:16 +02:00
nanahi f1a42eff01 osdep/io: use mp_fopen on all platforms
Currently, all fopen uses in mpv do not set cloexec flag, resulting
in fd leak whenever mpv creates a process.

This makes mpv use mp_fopen on all platforms, and always set O_CLOEXEC
on the opened fd. This is required because the "e" flag for fopen is
nonstandard and UB in C11, and unsupported on macOS.

This had been done similarly in other projects. e.g.
https://gitlab.com/graphviz/graphviz/-/merge_requests/3797
2026-06-04 04:58:16 +02:00
Chainik 44a9b03f24 vf_vapoursynth: improve backward compatibility
The previous commit to dynamically load VapourSynth R74 would fail to work
for VapourSynth R73 and before on Linux due to load mode RTLD_LOCAL. To
make it work on all VapourSynth version, switch to use RTLD_GLOBAL mode.
2026-05-31 18:16:18 +02:00
Chainik 3650c67b6d Revert "vf_vapoursynth: improve backward compatibility"
This reverts commit 8aabba933b.
2026-05-31 18:16:18 +02:00
nanahi 5e847889b3 osdep/win32/smtc: fix client handle leak 2026-05-01 13:42:57 +02:00
nanahi 675fb1229b input/dnd: move --drag-and-drop handling to dnd client
This unifies --drag-and-drop handling to a single place. All platforms
currently only support normal drop (mapped to "replace") and shift click
drop (mapped to "append").
2026-05-01 13:42:57 +02:00
nanahi 5e0932e785 input: rename mp_event_drop_files to mp_input_drop_files
Move it to input.c. Will be used in next commit.
2026-05-01 13:42:57 +02:00
Crend King 8aabba933b vf_vapoursynth: improve backward compatibility
The previous commit to dynamically load VapourSynth R74 would fail to work
for VapourSynth R73 and before on Linux due to load mode RTLD_LOCAL. To
make it work on all VapourSynth version, switch to use RTLD_GLOBAL mode.

Add library handle closing in drv_vss_uninit for completeness.
2026-04-25 07:14:56 +02:00
Crend King 75b2ccfeb1 vf_vapoursynth: update for VapourSynth R74
VapourSynth R74 changed two things relevant to mpv build process:

1) VSScript no longer has static library to link to, and only support runtime loading.
This is reflected on the new VSScript example in VapourSynth SDK.
2) The VSScript library name is changed from libvapoursynth-script to libvsscript for Linux
and MacOS.

The new VSScript initialization code is modified from their SDK example to utilize
mpv's mechanisms. Build dependency is also updated accordingly.
2026-04-23 01:38:48 +02:00
Kacper Michajłow 17d12f83ad osdep/io: expand relative path only if it contains directory separator
For anything else, respact default load library search logic.
2026-04-17 03:56:13 +02:00
Kacper Michajłow c3231fa1ee osdep/io: use static string for dlopen errors
The dynamic allocation of this strings is completelly pointless. It adds
complexity with mp_exec_once to init aexit() to free the string, which
was leaked anyway, because the structure is thread_local and atexit only
data from the main thread was freed.

Remove all this, and just use static buffer.
2026-04-17 03:56:13 +02:00
NRK aef3793e92 osdep/io: make getenv case insensitive on windows
env vars are case insensitive on windows so getenv should
compare them as such.

Fixes: https://github.com/mpv-player/mpv/pull/17577#issuecomment-4167125610
2026-04-08 20:24:07 +02:00
NRK 1aee4637f2 osdep/io: add mp_dup_cloexec()
will be used in the next commit
2026-03-12 15:58:53 +01:00
NRK 7e9fa0dee4 osdep/io: remove redundant errno setting
according to the docs _get_osfhandle() sets errno to EBADF upon
failure already:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/get-osfhandle?view=msvc-170
2026-03-12 15:58:53 +01:00
NRK a2ddcdf67b osdep/io: fix error check
_get_osfhandle returns INVALID_HANDLE_VALUE on failure, not 0.
2026-03-12 15:58:53 +01:00
Kacper Michajłow 97867450ba osdep/w32_register: fix EstimatedSize
Move PathCchRemoveFileSpec after actually getting the file size. It must
have been swapped at some point by accident.

Also use correct unit for the size.

Fixes: #17375
2026-02-05 23:23:38 +01:00
Kacper Michajłow f4db102a2e osdep/language-win: remove use of GetSystemPreferredUILanguages
The system preferred language is the language used during Windows
install. It doesn't have much purpose except that it is the backend
language for core Windows internals. All user facing dialogs and text
should follow the user preferred language, as this is what the user
selected and uses on daily basis.

It makes no sense to include system language in track selection.
2026-01-21 04:39:54 +01:00
Kacper Michajłow a339fe58b5 osdep/language-win: fix use of GetUserPreferredUILanguages()
Commit baf2fd2f28 fixed this for 2nd call
to GetSystemPreferredUILanguages(), but apparently regressed the 1st
call, duh.

To retrieve the size both buffer has to be NULL and size 0.

Memory has a lot of zeros, because it has been working quite
consistently on CI.
2026-01-18 11:09:00 +01:00
llyyr 0035bb7cbd path-unix: check fopen value, and also call fclose 2026-01-04 21:50:04 +01:00
der richter 80155c3dc9 mac/touchbar: remove manual 1 second rate limit of position property
duration and position properties were observed as double which lead to a
lot of updates per second (high granularity). it is recommended to not
update the position of the touchbar too frequently, why we had a manual
1 second rate limit.

instead of manually rate limiting the property, just observe it as int64
which only updates every second. it also causes a bit less pressure for
our core.
2025-12-22 10:19:29 +01:00
der richter dc6886ebb5 mac/remote: remove manual 1 second rate limit of position property
duration and position properties were observed as double which lead to
a lot of updates per second (high granularity). it is recommended to not
update the position of the remote command center to frequently, why we
had a manual 1 second rate limit.

instead of manually rate limiting the property, just observe it as int64
which only updates every second. it also causes a bit less pressure for
our core.
2025-12-22 10:19:29 +01:00
der richter f1ad9dfdf0 mac/event: add MPV_FORMAT_INT64 handler 2025-12-22 10:19:29 +01:00
der richter bf9ddf1db2 mac/type: add Int64 type conversion helper 2025-12-22 10:19:29 +01:00
der richter 83d9de42bc mac/vulkan: log colorspace changes of metal layer
since we have a mapping layer between vulkan and metal (MoltenVK) we
don't actually know which colorspace is used/mapped to.

log colorspace changes to actually see which colorspace was chosen.
2025-12-08 19:13:32 +01:00
der richter 5cfdbc24d9 mac/vulkan: log pixel format changes of metal layer
since we have a mapping layer between vulkan and metal (MoltenVK) we
don't actually know which pixel format is used/mapped to.

log pixel format changes to actually see which format was chosen. only
those 9 formats are valid for a CAMetalLayer.
https://developer.apple.com/documentation/quartzcore/cametallayer/pixelformat
2025-12-08 19:13:32 +01:00
Kacper Michajłow 0f5fafdaad osdep/compiler: fix typo in MP_ASSERT_UNREACHABLE 2025-11-15 01:25:37 +01:00
LordMZTE df939d4fe8 osdep/linux-als: support ambient-light on Linux
This implements the ambient-light property on Linux using the sysfs
interface.
2025-10-15 21:59:42 +02:00
Kacper Michajłow 6c047794dd osdep/compiler: use __MINGW_{PRINTF,SCANF}_FORMAT for attribute format
This ensures that we test format string for the actual impl that is
being used. Depending if UCRT is used and if __USE_MINGW_ANSI_STDIO is
defined the implementation capabilities may differ.

Note that we don't explicitly define __USE_MINGW_ANSI_STDIO anymore,
this is defined implicitly in mingw headers, if needed. We don't support
ancient mingw versions that does not define it correctly for c11.
2025-10-05 21:34:29 +02:00
Kacper Michajłow 883db51ad0 osdep/compiler: refactor MP_ASSERT_UNREACHABLE 2025-10-05 21:34:29 +02:00
Kacper Michajłow 4338880560 various: add MP prefix for {PRINTF,SCANF}_ATTRIBUTE 2025-10-05 21:34:29 +02:00
nanahi 9422a6dc52 osdep/terminal-unix: use numpad keycodes
Use the dedicated numpad keycodes for +-*/.
2025-09-29 01:45:37 +02:00
Kacper Michajłow f65a61e488 osdep/w32_register: register url protocols if they don't exist yet
Some protocols may not exist, add them so the mapping to url handler
works correctly. Note that protocols are not removed, only the handler
is. They will remain unassociated, after unregister.

Fixes: #16832
2025-09-27 22:16:36 +02:00
Kacper Michajłow 4499f16215 osdep/w32_register: don't mark io.mpv.url as url protocol 2025-09-27 22:16:36 +02:00
der richter 065af28bc2 mac/dialog: fix build for macOS older than 11
UniformTypeIdentifiers is only available since macOS 11.
added in 6b0e4f7 and #15859.

guard the allowedContentTypes UTType property of the NSOpenPanel and
add a dummy struct UTType and dummy allowedContentTypes property on
macOS versions that don't have those available.
2025-09-15 03:59:32 +02:00
der richter a4d818b4f9 mac/compat: fix building with swift version lower than 5.7
currently we use the withLock function with NSCondition and NSLock,
which are not available on swift versions lower than 5.7. we only added
compatibility fallbacks for NSCondition though. introduced in 1364c80
and #14334.

instead of only adding the fallback to a specific class add it to the
whole protocol all the locking classes use, similar to the actual
implementation.
2025-09-15 03:59:32 +02:00
der richter 00415f1457 osdep/mac/meson: fallback to swift build for old swift versions
with commit 8d20b72 and PR #15442 we switched to the recommended swiftc
compiler for building our swift code. this lead to some
incompatibilities with swift versions prior to 5.8, where a new linker
was introduced.

work around that problem by using the old swift frontend build for older
swift versions. this can be removed when we remove the support for those
old versions.

Fixes #15591
2025-09-15 03:59:32 +02:00
Kacper Michajłow 0d03e0565f osdep/win32-console-wrapper: remove stray include 2025-09-15 03:47:35 +02:00
Kacper Michajłow 4f08802ff1 osdep/w32_register: add register/unregister options for Windows
On Linux, we have `mpv.desktop`, and on macOS, we have `osxbundle`, both
of which handle file associations and protocol registration in the
system environment.

On Windows, this information is stored in the registry, so this commit
adds support for it.

It registers the application, supported file types, and supported
protocols, and adds an uninstall entry so users can remove all
registrations via the control panel. Note that this does not remove the
binary itself.

The implementation is fully portable. There are no external installers,
as mpv handles everything automatically. This should improve usability
when moving binaries and so on.

- `mpv --register` registers mpv (see verbose output for a list of actions).
- `mpv --unregister` reverts all changes made during installation.
- `mpv --register-rpath <string>` allows specifying a string to be
  prepended to `PATH` before running mpv. This is useful when using
external dependencies that shouldn't be added globally to `PATH`.
2025-09-15 03:47:35 +02:00
Andarwinux 42fd091e47 osdep/win32/meson: use files() instead current_source_dir()
In reproducible builds, meson.current_source_dir() also leaks absolute paths, so it's better to use files() instead

ref: https://mesonbuild.com/Reference-manual_builtin_meson.html#mesoncurrent_source_dir

> You do not need to use this function!
> When passing files from the current source directory to a function since that is the default. Also, you can use the files() function to refer to files in the current or any other source directory instead of constructing paths manually with meson.current_source_dir().
2025-08-29 19:07:46 +02:00
Dudemanguy ce7ea3d8ea path-unix: support ~~desktop path expansion
xdg-user-dirs is basically the standard for defining user desktop
directories on linux/bsd. To account for locales and languages, we
basically have to parse the config file (~/.config/user-dirs.dirs)
directly. That or call xdg-user-dir. Either way, it's a little more
complicated than the others, but still doable enough.
2025-08-17 16:58:00 +00:00
Kacper Michajłow cf3e332abb osdep/win32/smtc: workaround GCC 15 bogus template warning
Drop it to warning, even if -Werror is in effect. Interesting part is
that this makes this warning disappear completely. GCC diagnostics at
its finest.
2025-04-28 15:54:12 +02:00
Kacper Michajłow 22aacb4008 misc/language: mark arrays as nonstring for GCC 15
Fixes unterminated-string-initialization warnings.
2025-04-28 15:54:12 +02:00
NRK b09e06a920 osdep/threads: prefer using thread_local
C11 uses _Thread_local as the keyword, which thread_local macro
is defined to (inside of <threads.h>, which mpv doesn't use):
https://port70.net/~nsz/c/c11/n1570.html#7.26.1p3

C23 promotes thread_local to a keyword and marks _Thread_local
as obsolete and to be avoided in new code:
https://www.iso-9899.info/n3220.html#6.4.1p3

so just use thread_local directly, which is future-proof while
having a fallback define in osdep/threads.h for pre-C23 cases.
2025-04-06 17:01:33 +02:00
Kacper Michajłow baf2fd2f28 osdep/language-win: fix use of GetSystemPreferredUILanguages()
The buffer size were never set to 0, after first call. To retrive the
size both buffer has to be NULL and size 0. Otherwise it fails.

While at it refactor whole thing and use returned count as sanity limit.
2025-04-01 21:27:45 +02:00
Kacper Michajłow 38439dd531 threads: remove unused recursive mutex support
After removal of `MP_MUTEX_RECURSIVE` from vdpau.c there are no more
clients of recursive mutex. Remove all the code related to it. This
commit can be reverted if in the future it is needed again. For now
let's not keep dead code.
2025-03-26 19:16:21 +01:00
Kacper Michajłow 2799d8b130 mac/apphub: remove mpv:// protocol handling
It has been moved to the mpv core with additional security
considerations, including filtering unsafe protocols from being opened
via the URL handler.

While we are not aware of any active exploitation, naive protocol
handling could allow the use of niche protocols in FFmpeg, which, in
turn, might load native code. How such native code would be dropped on
the local machine is another question.

This remains theoretical, but it's better to be safe than sorry.

Fixes: 494d408583
2025-03-07 00:15:23 +01:00
Kacper Michajłow 1c49cfdb97 various: use mp_assert macro 2025-03-04 20:07:29 +01:00
Kacper Michajłow 16bbfbf992 osdep/compiler: use C23 attributes if available 2025-03-04 20:07:29 +01:00
Kacper Michajłow 7f1e26831e osdep/compiler: add MP_UNUSED macro 2025-03-04 20:07:29 +01:00