208 Commits

Author SHA1 Message Date
Guido Cella 9dbf5d681d misc/path_utils: rename bstr_strip_ext() to mp_strip_ext() 2026-06-27 21:43:18 +02:00
Guido Cella 089c172dff misc/path_utils: rename bstr_get_ext() to mp_get_ext() 2026-06-27 21:43:18 +02:00
Guido Cella 4fa3c38983 misc/path_utils: remove mp_splitext()
It is no longer used.
2026-06-27 21:43:18 +02:00
Guido Cella 9ffc0cd861 misc/path_utils: remove mp_strip_ext()
It is no longer used.
2026-06-27 21:43:18 +02:00
Guido Cella 2057e34f45 misc/path_utils: make bstr_strip_ext() and bstr_get_ext() accurate
Move bstr_strip_ext() and bstr_get_ext() to path_utils.c making them use
split_ext(), which is better than the previous bstr.c implementation
because it doesn't consider . in the dirname or at the start of
basenames.
2026-06-27 21:43:18 +02:00
Guido Cella 381e7eb155 misc/path_utils: add split_ext()
This will be used by bstr_get_ext() and bstr_strip_ext() without
allocating memory.
2026-06-27 21:43:18 +02:00
Guido Cella 4eaef66f4c bstr: don't make bstr_splice() add to NULL
If str.start is NULL, don't error on FreeBSD + ASan with "applying zero
offset to null pointer" in bstr_splice().

This will avoid an error in split_ext() in the language test with NULL
as argument.
2026-06-27 21:43:18 +02:00
Guido Cella 29c26b5bc5 misc/path_utils: add mp_basename_bstr()
This will be used by bstr_get_ext() and bstr_split_ext() without
allocating memory.
2026-06-27 21:43:18 +02:00
Hubert Głuchowski 7ec11ad67a misc/codepoint_width: handle partially ill-formed UTF-8
Previously the function just bailed on invalid input, this instead makes
it count how many replacement characters would be shown by a terminal
complying with the Unicode specification's recommendation here:
https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/#G66453

Fixes https://github.com/mpv-player/mpv/pull/17773#issuecomment-4277538534
2026-04-22 00:06:59 +02:00
nanahi 3d568495fc misc/bstr: move str_in_list to this file
Rename it to bstr_in_list0 and implement it in bstr_find_in_list0.
2026-04-17 04:09:23 +02:00
nanahi ac8d69e6fc misc/bstr: add bstr_find_in_list0 function
This will be used to unify several find in list handlings.
2026-04-17 04:09:23 +02:00
nanahi ae6728a7c0 misc/io_utils: allow mp_save_to_file writing empty files 2026-03-25 01:41:05 +01:00
nanahi 58ee11c58a misc/hash: add mp_hash_to_bstr function
This util function uses the generic libavutil hash API to hash any data
with the specified algorithm to a bstr. It deduplicates multiple hash
routines used in mpv.
2026-03-23 15:03:38 +01:00
nanahi edc8534d0b misc/io_utils: rename cache
The function is used for various purposes so rename cache to something
generic.
2026-03-21 20:14:09 +01:00
Rudi Heitbaum 8ace278cbe various: fix Wdiscarded-qualifiers warnings
Signed-off-by: Rudi Heitbaum <rudi@heitbaum.com>
2026-03-15 14:49:00 +01:00
WhitePeter 648fc933b1 misc/path_utils: new mp_strip_ext shorthand
There are at least two users of this functionality, the filename/no-ext
property and the screenshot template %F specifier. The latter uses a
buggy private version. So split out what the former does, so it can be
reused.

Co-authored-by: Guido Cella <guido@guidocella.xyz>
2026-03-03 03:06:39 +01:00
WhitePeter 5dba9c52c0 misc/path_utils: fix mp_splitext bugs
The detection for leading dots was in the wrong place, in case path was
not already a basename. Fixed by acting on basename. Also all leading
dots are now getting skipped, otherwise the root of `path/to/...ext`
could end up as `path/to/..` which in the wrong place/context would mean
directory traversal.

Additionally, since we act on the basename there is no longer a need to
test for trailing path separators. The previous check also did not
account for Windows paths with \ separators.

Co-authored-by: Guido Cella <guido@guidocella.xyz>
2026-03-03 03:06:39 +01:00
Guido Cella 616149744a misc/path_utils: ensure mp_normalize_path never returns NULL
If the current working directory or the realpath could not be retrieved,
return the path as it was passed to mp_normalize_path() to avoid
guarding the return value. This is also makes it consistent with what
the Windows code was doing.
2026-01-12 15:10:37 +00:00
Guido Cella e6885cb926 misc/path_utils: don't normalize -
This fixes options like --audio-file=- and avoids returning $PWD/- as
path and stream-open-filename when playing from standard input.

It will also allow storing playlist filenames as normalized without
checking for - at the caller.

Fixes 23b57e9f7f.
2025-11-18 20:23:08 +00:00
Kacper Michajłow 4338880560 various: add MP prefix for {PRINTF,SCANF}_ATTRIBUTE 2025-10-05 21:34:29 +02:00
Louis Pate 86e12929aa various: fix Wpedantic warnings 2025-08-01 11:56:38 +02:00
dyphire 2d149e007f misc/language: parse default tag from external subtitle tracks 2025-07-06 12:52:22 +02:00
sfan5 6b178e4f5a misc/path_utils: create folders with 0777 mode
This better matches other Unix tools.
Note that in practice the umask downgrades this to 0755 or 0775, so folders don't actually end up world-readable.
2025-06-02 15:59:05 +02:00
sfan5 9db49973f2 misc/path_utils: check existence first in mp_mkdirp() 2025-06-02 15:59:05 +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 22f4ff44c5 misc/random: add mp_rand_in_range32()
removes awkward back-and-forth int -> double -> int conversion.
the last step also broke uniformity, though it likely doesn't
matter much in mpv's playlist shuffle context.
2025-04-02 17:28:49 +02:00
NRK b968dec77d misc/random: improve the fallback case
c365e2f7 added av_random_bytes() to avoid multiple
threads/processes getting the same seed. but the fallback case
still suffers from it.

also mix in a function pointer, which hopefully is randomized
per process due to ASLR (20+ years old technology) along with
the stack position which will be different on different threads.
2025-04-02 17:28:49 +02:00
NRK b3d461e3aa misc/random: use av_random_bytes() for the whole seed
splitmix was used since it's recommended by the official xoshiro
site [0] as a "radically different" PRNG to avoid correlation of
similar seeds. av_random_bytes() is cryptographically secure
and so we don't have to worry about that. so just use it to
initialize the whole state.

[0]: https://prng.di.unimi.it/
2025-04-02 17:28:49 +02:00
NRK dd29542f6f misc/random: eliminate mutex
mutex itself was probably more costly than the PRNG itself. and
locking PRNGs is almost universally not recommended. simply add
a state parameter that the caller can hold to avoid locks.
2025-04-02 17:28:49 +02:00
Tom Grimwood-Taylor f608780032 misc/language: parse forced tag from external subtitle tracks
Fixes: mpv-player#16060
2025-03-31 11:47:52 +02:00
Kacper Michajłow 7df3f442ea misc/language: parse hi/sdh/cc tags from external subtitle tracks
This also adds `hearing-impaired` argument to `sub-add` command.

Fixes: #14805
2025-03-08 00:21:06 +01:00
Kacper Michajłow 415b70dc7b misc/mp_assert: important fix forgotten before merge 2025-03-07 22:11:05 +01:00
Kacper Michajłow 1c49cfdb97 various: use mp_assert macro 2025-03-04 20:07:29 +01:00
Kacper Michajłow c0dbdcf7ad misc/mp_assert: add mp_assert and mp_require macros 2025-03-04 20:07:29 +01:00
Kacper Michajłow 2542a7824c misc/codepoint_width: update tables after clustering fix
Updates tables after https://github.com/microsoft/terminal/commit/0961a77a5aec003e9f79d388f8e7bffb9a550cdb
2025-03-03 23:48:40 +01:00
Kacper Michajłow d759e26fd0 libmpv: use correct header directory name
libmpv headers are installed to `mpv/`, so why are we pretending it is
`libmpv`?

Fixes documentation, libmpv meson dependency, tests.
2025-02-23 01:40:12 +01:00
Kacper Michajłow 77313f73a2 various: reduce the include scope of some public headers 2025-02-23 01:40:12 +01:00
Dudemanguy 0755edb327 misc/path_utils: allow passing NULL to mp_normalize_path
Instead of requiring the caller to pass an appropriate talloc_ctx,
mp_normalize_path will make its own internal allocations and cleanup as
needed.
2025-02-01 16:12:03 +00:00
Guido Cella a3cc06f754 misc: make json_append() non-static
This will be used to write json with a bstr in the next commit.

Co-authored-by: Kacper Michajłow <kasper93@gmail.com>
2025-01-27 18:53:28 +01:00
nanahi 90a84e97f3 misc/dispatch: remove mention of select
mpv code doesn't use select, only poll.
2025-01-26 22:15:30 +01:00
Guido Cella f7e2a8c1cc bstr: add bstr_xappend0 2024-11-27 15:37:42 +01:00
Kacper Michajłow 4b11f66eb1 various: use avcodec_get_supported_config() to resolve deprecation warn
See: https://github.com/FFmpeg/FFmpeg/commit/3305767560a6303f474fffa3afb10c500059b455
2024-11-20 20:42:33 +01:00
Kacper Michajłow 0c4c2caabf misc/codepoint_width: assume tabstop width to be 8
It has been hardcoded to the same value in stats.lua so keep the current
behaviour. Can be made configurable if requested in the future.
2024-10-21 20:06:48 +02:00
Kacper Michajłow 5fed98e0ee various: use mp_tprintf_buf wrapper to work around mingw garbage
Look it up if you really care but basically z as a format specifier
often doesn't work in mingw because reasons. Our CI was working by
accident because of meson previously ignoring the CFLAGS variable. Use
our wrapper instead for these places.
2024-10-18 14:02:51 +00:00
Kacper Michajłow bf025cd289 msg: allow to truncate the message to terminal width 2024-10-11 15:16:33 +02:00
Kacper Michajłow 95f0046309 misc/codepoint_width: add unicode width detection support
Add 4 stage trie to lookup unicode codepoint width and grapheme join
rules.

Generated by GraphemeTableGen from Microsoft Terminal (MIT Licence):
https://github.com/microsoft/terminal/blob/a7e47b711a2adc7b9e80eddea8168089f7d3b11e/src/tools/GraphemeTableGen/Program.cs

With minor adjustment to use it in C codebase.
- Replaced constexpr with static
- Replaced auto with explicit types

Generated from Unicode 16.0.0:
ucd.nounihan.grouped.xml: sha256(b11c2d23673bae660fff8ddcd3c1de4d54bdf6c60188a07696b010282f515fcf)
2024-10-11 15:06:14 +02:00
Kacper Michajłow 216abbc121 bstr: add missing function docs 2024-10-04 00:45:30 +02:00
Kacper Michajłow 96006fa97b bstr: don't abort on format error in bstr_xappend_vasprintf
Most of the time it is recoverable error, and it makes no sense to
abort here.
2024-09-29 16:06:25 +02:00
Kacper Michajłow 2c2755992d bstr: use vsnprintf with a proper size of 0 instead of a 1-sized buffer
There is no need for that, use of 0 size is well defined.
2024-09-29 16:06:25 +02:00
Andreas Klauer c365e2f7b1 misc/random: seed using libavutil/random_seed
When starting multiple processes of `mpv --shuffle` in parallel,
sometimes the random seed happens to be identical, so files are
played in the same random order.

mp_rand_seed(0) now uses a random seed provided by libavutil,
and only falls back to time in case of failure.
2024-09-28 14:11:56 +02:00