190 Commits

Author SHA1 Message Date
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 0961a77a5a
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: 3305767560
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):
a7e47b711a/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
Kacper Michajłow
7746942a55 win32: remove pathcch compatibility code
No longer needed after 9f8b4b38c9.
2024-09-24 00:21:19 +02:00
Kacper Michajłow
ad7976c33e input: fix use of bstr like null terminated one
It has been changed in one of the iterations of the patch during review,
but bstr doesn't have to be null terminated. Fix it by adding dedicated
node_map helper.

Fixes: 1a27f3c
2024-09-04 03:52:09 +02:00
Kacper Michajłow
5fed12e025 win32: add Media Control support
Add support for SystemMediaTransportControls interface. This allows to
control mpv from Windows media control ui.
2024-07-29 21:38:19 +02:00
Kacper Michajłow
607ad8943b player/command: don't return ill-formed node if there is no default val
option-info/<name>/default-value would be initialized with zeroed
object, which is not valid for string typed options, as the would be set
to NULL.

Found by OSS-Fuzz.
2024-07-16 22:59:23 +02:00
nanahi
ea03451d1e misc/natural_sort: avoid implementation-defined behavior in comparison
Before a7158ceec0, string comparision was
done with strcmp, which does unsigned comparison. The natural sort
implementation instead compares on char values.
This causes implementation-defined behavior in comparison, depending on
the signedness of char type.

Fix this by using unsigned comparison instead.
2024-06-27 19:45:21 +03:00
Kacper Michajłow
22fc2e6af3 bstr: change memcpy to memmove to allow aliased copies
mp_property_expand_escaped_string() needs this.

Found by OSS-Fuzz.
2024-06-26 01:28:55 +02:00
Kacper Michajłow
7fb7e1dd73 various: add more format specifiers checks 2024-06-25 05:29:46 +02:00
Kacper Michajłow
a949e0c2d5 misc/random: set constant seed for fuzzing
Fuzzing expect deterministic behavior. While we don't use this random
generator for anything significant, still good to set the seed, in case
of future usage.
2024-06-24 03:05:09 +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
a8d95fd51a bstr: use memchr and memrchr for bstrchr and bstrrchr
May be faster to use optimized variants instead of simple loop.
2024-06-06 21:42:58 +02:00
Kacper Michajłow
7258ca3247 misc/thread_tools: fix incorrect win32 check 2024-06-05 19:16:35 +02:00
Guido Cella
20b8fe05bf misc/language: move mp_guess_lang_from_filename() here 2024-05-10 01:22:31 +02:00
Kacper Michajłow
4fe67933c2 misc/language: store string length instead of null terminator
Allows to construct bstr directly without strlen, while keeping language
table the same size.
2024-05-09 17:12:55 +02:00
Kacper Michajłow
5009e13431 player/loadfile: match language and subcodes 2024-05-09 17:12:55 +02:00
Kacper Michajłow
40ba63405f Revert "misc: add language-matching utilities"
This reverts commit 8c8d97c26c.
2024-05-09 17:12:55 +02:00
nanahi
9f5edd4eed various: fix indentation 2024-05-07 11:23:08 +02:00
Kacper Michajłow
86abbb89a7 win32: fix platform checks 2024-05-06 22:01:17 +02:00
Kacper Michajłow
5c2918b4f3 io_utils: use mp_mkostemps instead of mkstemp 2024-05-06 22:01:17 +02:00