Commit Graph

3954 Commits

Author SHA1 Message Date
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
Nikolai Vavilov
c0366cfa42 loadfile: unescape display filenames
This makes OSD more usable when the filename contains non-ASCII characters.
2025-02-05 05:04:33 +01:00
Guido Cella
b0364f8761 osc.lua: bind right clicking the title to show history
And move show-text ${path} to middle click. This is more useful than the
replaced show-text ${filename} binding since the left click stats
binding already shows the filename, and it matches how right clicking
other buttons shows menus. Alternatively middle click could also be
bound to select-watch-later.
2025-02-05 04:55:37 +01:00
Dudemanguy
38ad1ed03b command: normalize paths for path and track-list/N/external-filename
It's better for API users to actually get predictable results.
2025-02-01 16:12:03 +00:00
Dudemanguy
02c0b346eb command: simplify find_track_with_url handling
Now that mp_normalize_path can accept NULL and we have a shorthand for
expand + normalize, now is a good chance to simplify this to make it
less awkward.
2025-02-01 16:12:03 +00:00
Dudemanguy
956cb2c49f various: simplify mp_normalize_path usage
If a talloc_ctx was being made solely for a onetime usage of getting a
normalized string, we can now just pass NULL instead and free the string
directly to make things easier.
2025-02-01 16:12:03 +00:00
Guido Cella
b2404e16dd console.lua: stop expanding ~/ in file completion
It is not needed to expand ~ in file completion as you type after
62c3aeb9c made commands themselves interpret it. We only need to call
expand-path on the directory before passing it to utils.readdir in order
to find files in it when it contains ~ placeholders. As a bonus this
will now also complete files in directories like ~~/ and ~state/.

This simplifies command completion, and was also the blocker for
splitting running commands out of console.lua, since I didn't know how
to replicate it through mp.input.
2025-02-01 16:11:30 +00:00
Guido Cella
cada717416 Revert "console.lua: add pause_on_open script-opt"
This reverts commit 850e03d29f.

The previous commit solved this in a more general way. You can do:

[open-console]
profile-cond=p['user-data/mpv/console/open'] and p['current-tracks/video/albumart'] == false
profile-restore=copy
pause

Thankfully pause_on_open was just added and has not been in a release so
we can remove it.
2025-01-31 06:04:54 +01:00
Guido Cella
8669205d92 console.lua: add user-data/mpv/console/open
Fixes #15762.
2025-01-31 06:04:54 +01:00
Dudemanguy
62c3aeb9cb command: expand paths for all commands with path arguments
Follow up to be15be3a83 with the same
reasoning.
2025-01-30 21:57:31 +00:00
Dudemanguy
814316fb2a command: add metadata sub-property for track-list
Requires a little bit of massaging for the key/value access to work
correctly, it's not terribly intrusive all things considered.
2025-01-30 15:24:38 +00:00
Dudemanguy
5c3262628e command: prefix all property functions with mp
This weird inconsistency was annoying.
2025-01-30 15:24:38 +00:00
Dudemanguy
d5cb5740cc player: print secondary subtitles on the terminal
Fixes #10118.
2025-01-30 15:20:29 +00:00
Kacper Michajłow
90631b9e90 player/misc: check codec values for overflow
Found by OSS-Fuzz.
2025-01-29 20:15:47 +01:00
Dudemanguy
694817121a command: don't run UPDATE_{AD,VD} if the {ao,vo}_chain doesn't exist
As described in 544240c829, the callbacks
are all run on init so UPDATE_AD and UPDATE_VD both executed. While this
is probably not harmful, it is completely pointless work and results in
extra event notifications being sent. Just skip these if there is no
matching chain.
2025-01-29 15:07:42 +00: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
Dudemanguy
c7c09fdb8b command: fix spammy events when frame stepping forward with seek
The frame-step command also signals on up events. This is only useful
when using the default "play" mode. For seek mode, it triggers another
frame step which is not what you want. Rearrange the logic so the up
event is ignored for the seek flag. The frames check is also not needed
since add_step_frame already handles it.

Fixes 9661a3839b
2025-01-29 14:48:55 +00:00
Attila Fidan
3544728991 clipboard-wayland: initialize offer fd
Fixes: https://github.com/mpv-player/mpv/issues/15763
2025-01-29 13:19:04 +01:00
Dudemanguy
0e03fdf0f7 f_decoder_wrapper: allow changing --ad and --vd at runtime 2025-01-28 15:48:15 +00:00
Dudemanguy
8d665ac2df osc.lua: add visibility_modes script opt
This allows users to choose what visibility modes they want to cycle
through when calling the osc-visibilty cycle script binding.
2025-01-28 15:47:47 +00:00
Dudemanguy
fd4aa9b533 osc.lua: deprecate pointless script-messages
1a558bf5c2 effectively aliased the custom
OSC printing to actual mpv properties instead. These only exist for
backwards compatibility which hopefully will get removed one day so
instead deprecate them and warn users of what they should be using.
2025-01-28 15:47:47 +00:00
Kacper Michajłow
1d352f8527 stream_file: allow to open only our fd in case of fuzzing
This ensures that we don't open some other fd, for example when loading
playlist. Also filters out loading any local files.

This also allows to remove custom filtering from fuzzer itself.
2025-01-28 07:59:04 +01:00
Dudemanguy
9661a3839b command: allow frame-step to go through multiple frames and/or seek
Previously, the default behavior of frame-step and frame-back-step is to
play forward 1 frame or seek back 1 frame. We keep this behavior but
introduce additional flags to control the exact behavior of the frame
stepping. The first argument simply specifies how many frames to go
through. The second argument specifies whether to play video to step
through frames or to seek to step through frames. Playing through the
video to step through frames only works going forwards (otherwise it
will always seek). In theory we could use backwards playback for this,
but that can be decided later.

As a minor note, MPSEEK_BACKSTEP is renamed to MPSEEK_FRAMESTEP since
forward seeks can use this as well. Fixes #10128.
2025-01-28 04:20:16 +00:00
Guido Cella
1f6bba19d7 osc.lua: add an icon for the miscellaneous menu
Add the generic menu to bar layouts to provide discoverability for the
select menus to users who don't realize you can right click OSC buttons.

There's no space to add it in box layout.
2025-01-27 21:06:50 +01:00
Guido Cella
3e0b3373df select.lua: add a miscellaneous menu 2025-01-27 21:06:50 +01:00
Guido Cella
24db17d10f loadfile: discard prefetched files if demuxer options changed
When using --prefetch-playlist, if demuxer options are changed in the
time window between the start of prefetching and the playback of the
next file, the old values are used. This includes setting demuxer
options in legacy extension auto profiles.

Fix this by setting a flag when demuxer options change and not using the
prefetched data when that flag is true.

UPDATE_DEMUXER is not added to demux.c's options because those already
support updates while playing.
2025-01-27 19:32:52 +00:00
Guido Cella
130128762b command: group flag updates together 2025-01-27 19:32:52 +00:00
Guido Cella
e2090533cf select.lua: select from the watch history with g-h
Implement selection of the entries in the watch history.

The last entry in the selector deletes the history file.
2025-01-27 18:53:28 +01:00
Guido Cella
b75ed73f4f loadfile: optionally save the watch history
The history could be formatted as CSV, but this requires escaping the
separator in the fields and doesn't work with paths and titles with
newlines. Or as JSON, but it is inefficient to reread and rewrite the
whole history on each new file, and doing so overwrites the history with
an empty file when writing without disk space left. So this uses a
hybrid of one JSON object per line to get the best of both worlds. This
is called NDJSON or JSONL.

Co-authored-by: Kacper Michajłow <kasper93@gmail.com>
2025-01-27 18:53:28 +01:00
Guido Cella
908dc02eb9 misc: extract mp_find_non_filename_media_title() from command.c
This will be used to write the title in the watch history.
2025-01-27 18:53:28 +01:00
nanahi
ab461e0209 console.lua: use clipboard property for native Wayland backend
This backend does not require the window focus quirk handling,
and also supports primary selection.
2025-01-27 18:51:31 +01:00
nanahi
3be195e616 console.lua: autocomplete clipboard/text-primary property 2025-01-27 18:51:31 +01:00
nanahi
481646da37 command: add current-clipboard-backend property
Useful to know which clipboard backend is active.
2025-01-27 18:51:31 +01:00
nanahi
b2165c263a clipboard: add function to get clipboard backend name
Some platforms like Wayland may have support for multiple backends,
so add this function to make it possible to determine the current
active backend.
2025-01-27 18:51:31 +01:00
nanahi
46e2f55338 command: add clipboard/text-primary property
This property contains the text in the primary selection.
2025-01-27 18:51:31 +01:00
nanahi
9f2ac08851 clipboard-wayland: add Wayland clipboard backend
This adds a "native" Wayland clipboard backend based on the
ext-data-control-v1 protocol.
This backend overcomes the limitation of the VO (Wayland core protocol)
backend, and does not require the presence of the VO window to receive clipboard
updates.
This backend also supports primary selection if supported by the compositor.

The backend runs in a separate thread, so clipboard reading
does not stall the player like the VO backend.
2025-01-27 18:51:31 +01:00
nanahi
589e34cebd clipboard-vo: use clipboard parent log context
This adds clipboard backend names to backend-specific logs,
e.g. clipboard/vo.
2025-01-27 18:51:31 +01:00
nanahi
dc5c857f7b clipboard: don't store mpv_global context
It's only used for logging, and further creation of log contexts
can use the parenting feature instead, so there is no need to
store it.
2025-01-27 18:51:31 +01:00
Guido Cella
04c328f784 console.lua: use the same blur amount as --osd-blur
I have no idea why, but console's blur is smaller than in OSD messages
and stats (regardless of persistent_overlay). It's smaller regardless of
scale_with_window, or if using 0 PlayRes like stats with
persistent_overlay=yes.

With scale_with_window=yes, multiplying the blur by 2.5 seems to make it
the same. This is probably because 2.5 is 720 / 288, which are the base
height sizes scale from and the OSD's PlayResY. With
scale_with_window=no, we need to multiply by osd_h, which is always 720
with scale_with_window=yes.
2025-01-25 03:14:59 +00:00
Guido Cella
20375d1133 select.lua: show the ID of editions without title
MKV editions can have no title. Print "Edition" and their IDs instead of
showing an empty selection.
2025-01-24 04:35:36 +00:00
Guido Cella
5bbeabf450 console.lua: sort completions
With the previous commit, this sorts completions with the same score
alphabetically.
2025-01-24 04:35:27 +00:00
Guido Cella
8ae3beeb98 console.lua: preserve the order of items with equal score
table.sort() is unstable, meaning that it randomly reorders items with
the same score, so currently fuzzy_find() checks if the line is empty to
not change the original order of the unsorted items. But actually filled
lines have the same problem: e.g. searching foo with filenames like
foo_{1..99}, they are returned in random order.

To fix this sort by score only when 2 items have different score, else
sort by the original position.
2025-01-24 04:35:27 +00:00
Guido Cella
7ded290e2c console.lua: rename format_table() to format_grid()
Since there is no table header or predetermined columns.
2025-01-24 04:34:49 +00:00
Guido Cella
0c5d966f47 console.lua: always say completions instead of suggestions
Both completions and suggestions were being used inconsistently. Just
always use completions which is much more common.
2025-01-24 04:34:49 +00:00
Guido Cella
a2ce811b28 console.lua: rename update() to render()
It is not clear what update() updates, in fact this rename allows
removing the comment explaining it. render() is clearer and is the same
term used by the OSC.
2025-01-24 04:34:49 +00:00
Guido Cella
df3872e318 loadfile: fix --loop-playlist + --shuffle + --prefetch-playlist
With this combination of options, the playlist is shuffled every time
the last playlist is reached, instead of when restarting from the first
playlist entry. Abort prefetching in this case, as we can't predict
which file to prefetch until the playlist is shuffled when actually
going to the first file again.
2025-01-22 14:01:11 +00:00
Guido Cella
304a620b0b loadfile: return earlier if prefetch already started
There is no need to call mp_next_file() if prefetching already started,
so return earlier.
2025-01-22 14:01:11 +00:00
Guido Cella
e7a253614c loadfile: fix --loop-playlist=N with --prefetch-playlist
With --prefetch-playlist and --loop-playlist, mp_next_file() is called
continously since the last second of playback or when viewing an image,
which decreases --loop-playlist=N to 1.

Fix this by adding a flag to mp_next_file() to specify whether to
decrement --loop-playlist=N. The first playlist entry is still
prefetched when it's the next one, but without decrementing
--loop-playlist=N.
2025-01-22 14:01:11 +00:00
Guido Cella
effa81eb6e console.lua: set a high z in select mode
Give console's overlay a high z only in select mode, since in this case
you want to click it so it should be above other overlays. In particular
console should be above the OSC's box layout with visibility=always when
you show it by clicking its buttons.

Keep using z=0 otherwise when it doesn't handle clicks, to avoid
unintuitive behavior of overlays handling clicks like the OSC being
drawn below console.

Since the legacy mp.set_osd_ass() doesn't accept z, we need to repeat
its caching logic, like 490b3ba007 and 86d24b069b did for the OSC.
2025-01-22 12:55:24 +02:00
Guido Cella
2ecfe3ecf7 Revert "osc.lua: draw box layout below console"
This reverts commit 2dd5bd4cd1.

Instead of drawing the box layout below any other overlay with z >= 0
which may not be wanted, the next commit will increase console's z only
in select mode instead.
2025-01-22 12:55:24 +02:00