Commit Graph

448 Commits

Author SHA1 Message Date
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
Avi Halachmi (:avih)
1c3eecd821 common/stats: improve accuracy of quick timed measurements
Previously stats_time_start first sampled cpu-time and then real-time,
while stats_time_end sampled them in reverse order.

This resulted in real-time delta values being possibly a bit smaller
than the respective cpu-time deltas, which could become meaningful if
the start/end durations are consistently very short and very frequent.

In one test case (measuging the time spent at the event loop of
a script which spins on zero timeouts), this resulted in accumulated
real-time value of ~230ms per second, with a respective cpu-time
values of ~500ms. This should not be possible with single thread load.

Now start and end sample the values at the same order, so that it
balances on average. Each start/end delta now includes overhead of one
of each sample type, and excludes one of each sample type on average.

With the test case above, it's now 490 +-1 ms for both.
(the other 510ms real-time are at the excluded mpv_wait_event calls
and the unmeasured-overhead-parts of stats_time_start/end).
2025-02-17 22:50:03 +01:00
Avi Halachmi (:avih)
be68ca94ad common/stats: fix incorrect cpu-time value reset
This fixes a bug where if stats reset happened after stats_time_start
and before stats_time_end, then the next reported cpu-time value of
that measurement was from the thread startup.

The long version:

stats resets the time-accumulated values if more than two seconds
ellapsed since last poll.

The reset keeps the elements, but makes them as if no measurement was
yet taken, so that they don't show up at new reports until a new
measurement is taken.

While the events and (untimed) cpu are reset, the timed-cpu value
was only partially reset - the values are reset but the indication
that the element is empty was not enough for stats_time_end.

So when reset happened between start/end calls, stats_time_end was
entered eventhough it shouldn't have, but with reset cpu-time value
it calculated the time since the thread's startup, hence this bug.

Further polls were ok, because they are of the delta since the
previous poll. But at the next reset it happened again.

Now the cpu-value is reset correctly, which fixes this bug.
2025-02-17 22:50:03 +01:00
Avi Halachmi (:avih)
7162c960e7 common/stats: report: account for ongoing timed-measuremets
stats_time_start and stats_time_end accumulate real-time and cpu-time
between these calls, but the total was only updated on stats_time_end.

This resulted in two issues:
- Inaccurate measured value if a report (read the perf-info property)
  happened between start/end. No biggie because it's OK on average and
  typically each start/end duration is quite smaller than the interval.
- If the start/end duration is bigger than the interval, then one or
  more intervals had a report value (delta) of 0, and then one report
  with a value bigger than the interval - which shouldn't be possible.

This commit effectively does end+start at the report time for ongoing
timed measurements, so that the report accounts for them too.

Doing end+start at the report required two more changes:

Store the element type (VAL_TIME) at stats_time_start rather than at
the end. Otherwise if the report happens after the first start but
before the first end, then the type is not yet set and the element
is skipped at the report (bypassing the end+start).

Store the thread id at the element. start/end measure the cpu-time at
the current thread so they used pthread_self(), but with the report
usually running on a different thread, it needs the thread id for the
measurement. Measuring cpu-time from a different thread is OK, and
already happens with VAL_THREAD_CPU_TIME elements during the report.

While at it, stats_time_end now uses the thread id which was stored on
start instead of using pthread_self(). This also serves as a general
protection against measuring start/end from different threads, which
would yield generally meaningless results anyway. In mpv all the
start/end calls for the same element are at the same thread.
2025-02-17 22:50:03 +01:00
Avi Halachmi (:avih)
40fb226cc2 common/stats: don't report cpu-time on unsupported platforms
On Windows and any other platform where cpu-time is unsuported,
previously the cpu-time was reported as 0, and now it's omitted
(at the perf-info property native value).

Code which process this report, like stats.lua, could not distinguish
between 0 which was due to unsupported platform, and "real" 0 which
indicates zero cpu activity in this poll-period.

In stats.lua this resulted in a whole lot of empty cpu graphs,
including one for every loaded script.

Now cpu-time is excluded from the report on unsupported platforms.
Real-time is obviously still being reported where requested.

Implementation wise, this is slightly hacky, by literally only
excluding the cpu-time nodes from the report itself, while keeping
all the other cpu-tinme code intact.

A more correct solution might be to identify support at compile
(configure) time, and no-op the relevant code if needed.

However, stats.c is already hacky in parts, and there's no real cost
to keeping the code active even if the result is excluded at the
report, and it's also way simpler and less bug prone. So be it.
2025-02-17 22:50:03 +01:00
Kacper Michajłow
17db9bdc50 build: add early exit if git is not found
Also fallback to `--always` only if first `git describe` returned
errors, but were called successfully.
2025-02-06 02:16:51 +01:00
Kacper Michajłow
05ff82e153 build: use a more user-friendly version string for shallow clones
If the cloned repo is shallow (e.g. like the default github actions
settings), the git describe command won't actually be able to fetch any
tags and will instead just get a hash. The resulting binary version
string will end up being that git hash. While it does tell you the exact
commit, it's not exactly helpful when wanting to know the general
version at a glance. For the case where we do have a git directory but
no available tags, build a version string using the mpv version + the
commit hash.

Fixes #15789.
2025-02-05 23:17:06 +00:00
Dudemanguy
8e97f41849 build: prepend version strings with 'v' for release tarball builds
This was an inconsistency with the git tagging since the meson project
version is just a number.
2025-02-05 23:17:06 +00:00
Kacper Michajłow
038d66549d demux: reclaim demux_packets to reduce memory allocator pressure
This update introduces a demux_packet_pool, allowing for the reuse of
previously allocated packets when needed.

sizeof(AVPacket) is not a part of the lavc public ABI, which prevents us
to allocate memory in larger blocks. However, we can substantially
decrease the amount of alloc/free operations during playback by reusing
both mpv's demux_packet and AVPacket.

This adjustment addresses the root cause of issue #12076, which,
although resolved upstream, did not fully tackle the persistent problem
of allocating small blocks of aligned memory. This issue largely stems
from the FFmpeg design of the AVPacket API. After this change memory
will no longer be allocated once cache limits is reached.

The demux_packet_pool is shared as a global pool of packets for a given
MPContext.

This change significantly speeds up the demuxer deinitialization,
benefiting file switching scenarios, especially when a large demuxer
cache is used.

See: #12294
See: #12563
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
2025-02-05 05:09:33 +01:00
Dudemanguy
be15be3a83 various: expand paths for all file/directory related options
There's several path-related options that do not handle common shortcuts
(like ~/). Fix this by using mp_get_user_path where appropriate which
expands the path so users get more intuitive behavior. Fixes #15598.
2025-01-29 14:49:06 +00:00
Kacper Michajłow
59d1dc43b9 various: fix typos 2025-01-04 15:59:49 +02:00
Kacper Michajłow
e01f75e636 version.h.in: bump copyright year 2025-01-03 01:21:15 +01:00
Kacper Michajłow
04eb51246f options: remove old compatibility definitions
This makes things more readable.
2024-12-09 19:19:50 +01:00
Kacper Michajłow
d673356990 common: ensure MP_HANDLE_OOM is used only on pointers
To make it clear it should be used for memory allocation and not generic
error checking.
2024-11-30 17:08:42 +02:00
Kacper Michajłow
51f02679d4 common/playlist: don't allocate duplicated playlist_path
If the playlist is loaded directly from a protocol like memory://, the
playlist_path represents the entire playlist. In cases where we have a
large playlist, this results in the entire playlist being duplicated for
each item. For example, if the input size is 300 kB with 10k items, we
end up using 3 GB of memory just to store the playlist_path strings.
2024-11-18 17:14:38 +01:00
Kacper Michajłow
bc9d982330 encode_lavc: fix memory leak on --ofopts=help
Found by OSS-Fuzz.
2024-11-02 01:40:41 +01:00
Kacper Michajłow
201a39d7fa msg: skip formatting if there is only control char present
This doesn't change behaviour just skips some redundant code early.
2024-10-21 20:06:48 +02:00
Kacper Michajłow
3cf0f8309f msg: add newline conditionally
In idle mode, there is not status line and we sometimes want to have
output without last new line, which were always added after truncation.

Also, make sure we don't overwrite important chars with ellipsis, this
could happen when cut point is near the end.

Fixes: bf025cd289
2024-10-21 20:06:48 +02:00
Kacper Michajłow
6b695ac6e4 msg: use .. instead of … as ellipsis char
There were some concerns about the width of the … glyph, so avoid it and
use two dots.

Fixes: 6aa331289f
2024-10-18 19:57:53 +02:00
Kacper Michajłow
3e499ff3bc msg: fix width with ellipsis
Fixes: 6aa331289f
2024-10-18 00:25:10 +02:00
Kacper Michajłow
b026fded7d msg: fix clipped output to non-tty
Not sure how it got lost.
2024-10-17 23:55:51 +02:00
Kacper Michajłow
6aa331289f msg: use … instead of ... dots 2024-10-17 23:55:51 +02:00
Kacper Michajłow
2df582b839 msg: don't format status line if not printing to terminal 2024-10-17 22:32:10 +02:00
Kacper Michajłow
39d3591bb2 msg: strip control char also when not printing to terminal 2024-10-12 01:26:43 +02: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
4c19df1ded msg: print format string on format errors 2024-09-29 16:06:25 +02:00
Kacper Michajłow
4de6390d25 msg: don't use bold colors and instead use bright ones
Also avoid regular white/black, because it is often the terminal
background and invisible as foreground color.

Change debug messages to blue while at it to differentiate them from
trace ones.
2024-09-14 17:11:07 +02:00
llyyr
92f052c14e playlist: fix setting current item with autocreate-playlist
when the current directory isn't the playlist directory.
2024-08-23 00:56:17 +02:00
Kacper Michajłow
e3f426aa4a common/playlist: add missing playlist_dir clear
Fixes: https://github.com/mpv-player/mpv/pull/14555#issuecomment-2282759582
2024-08-11 21:06:13 +02:00
Kacper Michajłow
ff1f8baecd common/playlist: add playlist_set_current() 2024-08-10 23:27:40 +02:00
Kacper Michajłow
4f1e9e34c3 demux_playlist: add --directory-filter-types 2024-08-10 23:27:40 +02:00
Kacper Michajłow
c54ad6933b demux_playlist: add --autocreate-playlist-{video,audio,image}-exts 2024-08-10 23:27:40 +02:00
Kacper Michajłow
7fb7e1dd73 various: add more format specifiers checks 2024-06-25 05:29:46 +02:00
Dudemanguy
0db6abadd4 playlist: let playlist-next go to first item if player is idle
Similar to the previous commit but the other way around. If you start
mpv as idle, load up a playlist without immediately hitting play and
then try to go to the next item, nothing happens. Naturally, you would
expect this to go to the first item. Fix this detecting if the playlist
has not started yet, the direction, and going to the first item in the
list.
2024-06-25 02:19:08 +00:00
Dudemanguy
0f76848e5f playlist: let playlist-prev go to last item in playlist
Previously, playlist-prev didn't work if you played a playlist to
completion using --idle and tried to go back. Naturally, one would
expect this to bring up the last item in the playlist, but nothing
happens. This is just because playlist_get_next is stupid and doesn't
take this into account since pl->current is NULL and thus returns NULL.
Fix this by considering the direction, checking if the playlist was
played to completion and grabbing the last entry in the index.
2024-06-25 02:19:08 +00:00
Kacper Michajłow
5534e0e1d9 common: validate parsed unicode codepoints value
Fixes UB when converting out of expected range values.

Found by OSS-Fuzz.
2024-06-23 02:33:04 +02:00
Kacper Michajłow
e5d85704a3 av_log: sort library version print and add missing libavdevice
Incidentally sorted list put more important libs to the top.
2024-06-22 16:12:14 +02:00
Kacper Michajłow
3c5a79300c various: remove av channel layout check 2024-06-22 16:12:14 +02:00
Kacper Michajłow
00cfe1e1fd common: clang supports __builtin_clz also in non-GNU modes 2024-06-05 19:16:35 +02:00
Dudemanguy
f921b64ed7 stream: implement get_protocols method for stream_lavf
Previously, all stream protocols were a static list in mpv. This is okay
for own builtin stuff, but for protocols that depend on ffmpeg it's not
so great. Support for certain protocols may or may not be enabled in a
user's ffmpeg and the protocol list that mpv generates should ideally
match this. Fix this by implementing a get_protocols method for
stream_lavf that will have different results depending on the ffmpeg mpv
is built against. We keep the safe and unsafe protocols separation. The
former is essentially a whitelist. Any protocol that is found in ffmpeg
but is not in the safe whitelist is considered unsafe. In the stream
list, ffmpeg is moved to the bottom so any possible protocols that are
added in the future don't automatically take precedence over any builtin
mpv ones.
2024-05-22 20:10:52 +00:00
Dudemanguy
406301f23d av_common: parent mp_get_lavf_demuxer contents to the list
The only usage of this function is freed in mpv's generic property code,
so no other changes are needed.
2024-05-22 20:10:52 +00:00
Kacper Michajłow
a16f653eb5 msg: clear status line only if needed 2024-05-19 19:10:58 +02:00
Kacper Michajłow
895dd9e4e2 msg: split mp_msg_flush_status_line into private and public variant 2024-05-19 19:10:58 +02:00
Kacper Michajłow
243c1d6d91 msg: check target stream before printing
After f18ce7eca0 status is not always
printed to stderr.
2024-05-19 19:10:58 +02:00
Kacper Michajłow
1f7c223749 av_common: fix integer overflow when adjusting timebase
Found by OSS-Fuzz.
2024-05-15 01:25:18 +02:00
Kacper Michajłow
f18ce7eca0 msg: print all messages to one stream
This reverts commit 4939570e17 and makes
it more strict about the output stream. Status message is also on the
same stream now.
2024-05-06 22:21:46 +02:00
Kacper Michajłow
414c47d1d8 player/main: select msg output stream early
This avoids printing any stray messages in encode output stream.

--o is already pre-parse cli option which is designed to be parsed
before anything else is printed to output. So we can use that to force
stderr output if needed for encode mode.
2024-05-06 22:21:46 +02:00
Kacper Michajłow
9fc2343512 osdep/mpv.rc: fix encoding of MPVCOPYRIGHT
llvm-rc doesn't allow multi-byte codes in narrow utf-8.
2024-05-06 22:01:17 +02:00