283 Commits
Author SHA1 Message Date
Kacper Michajłow 1a42c69d26 demux_disc: land seeks on the picture shown at the target
A seek into a slideshow title lands in a VOBU without video and nothing
would show until the next picture. The stream moves back to the VOBU
holding the picture valid at the landing, using the NAV packet's
prev_video pointer, and answers skip_until, the demuxer drops the audio
before the target.
2026-10-24 15:40:31 +02:00
Kacper Michajłow d39127851e demux_disc: describe disc data as declared streams and segments
The disc streams declare the presentation streams of what they play
(STREAM_CTRL_GET_STREAMS) and hand out segments (STREAM_CTRL_GET_SEGMENTS):
where a run of data starts in the byte stream, which in-stream timestamp
plays at which playback time, and which declared streams have data in it.
stream_dvdnav records one per VOBU from its NAV packet, stream_bluray one
per clip, stream_dvda one per track at the IFO's first PTS of the track,
since a title's tracks do not share one PTS timeline and the sector to
time interpolation of a VBR track drifts by seconds. demux_disc registers
the declared streams before their data arrives, maps every packet by its
byte position and marks streams absent or present as the segment says.
This replaces the timeline generations and their tolerances, the slideshow
detection, the reselect position filter, the subpicture deferral, the
timeline offset push and the DVD-Audio seek time hack.
2026-10-24 15:40:31 +02:00
Kacper Michajłow 909f05142a stream_bluray: feed the presentation time and rate to the disc VM
BD-J applets schedule menu loops and timed transitions against the
presentation clock. Libbluray derives it from the read position, which
runs ahead by the whole demuxer readahead. Set the presentation time of
the clip as much as we can, undo the demuxer rebase offset, which
hopefully should be the timeline that libbluray expects.
2026-10-21 05:53:03 +02:00
Kacper Michajłow 791b70086a stream_dvda: describe each title's audio and mark alternate mixes
A DVD-Audio disc commonly carries multiple variants of the same track.
Read the pairing from atsi_index_rows, and the format from the ATSI
audio record that the title's programs select through ATRN. Editions now
read "5.1, 88.2 kHz, 24 bit" and "alternate mix, stereo, 88.2 kHz, 24
bit".
2026-10-21 05:53:03 +02:00
Kacper Michajłow 1c0db815cd stream_dvdnav: push the user's audio choice into the VM registers
The disc could tell mpv what to play, but a track picked in mpv never
reached SPRM1, so the disc's own selection commands kept acting on their
previous choice. Feed it back through dvdnav_set_active_stream().

Only a change the user made is pushed. Whatever the disc last selected
is kept as the baseline, so nothing is echoed back at it during
transitions.
2026-10-21 05:53:03 +02:00
Kacper Michajłow 6559a80f3a stream_bluray: use the disc's chapter names when it has them
libbluray resolves the META_DL title itself, use it when available.
2026-10-21 05:53:03 +02:00
Kacper Michajłow 6779a3ab4a player/command: add more disc navigation actions
Wire more actions, but without default keybindings this time. May be
added later if needed, but most actions are arrows+select in practice.
2026-10-21 05:53:03 +02:00
Kacper Michajłow 899049d89c stream_dvdnav: expose the track flags the IFO declares
The IFO says things about track metadata, use it.
2026-10-21 05:53:03 +02:00
Kacper Michajłow a6ba614e68 stream: add effective_url, the url after redirects
stream_lavf takes it from the location option of the protocol and
stream_curl from CURLINFO_EFFECTIVE_URL.
2026-10-14 18:05:24 +02:00
Kacper Michajłow 87b8d352d2 stream_curl: use the Content-Disposition file name as the filename
Only stream_curl sets it for now.
2026-09-07 15:53:31 +02:00
Kacper Michajłow 02ec593037 stream: auto-detect .iso DVD-Video, DVD-Audio and Blu-ray images
Passing a disc image directly (e.g. `mpv disc.iso`) previously fell
through to FFmpeg. Route it to the matching disc backend instead,
like the VIDEO_TS.IFO/AUDIO_TS.IFO/BDMV redirectors already do.
2026-08-26 01:47:41 +02:00
Kacper Michajłow c855d13170 stream_dvdnav: resync disc-initiated jumps through the seek path
When the disc VM jumps (menu activation, end of title), the demuxer
and player have to flush and reinitialize exactly at the boundary.

Hold an EOF at the boundary until the demuxer acks it, and resync
the player with a regular seek, which already orders flush, decoder
reset and restart. d_seek recognizes the held boundary and releases
it instead of repositioning the VM.

Also log the VM domain in nav event messages.
2026-08-26 01:47:41 +02:00
Kacper Michajłow a2448f3b81 stream_dvda: expose DVD-Audio still images as a cover-art video track
DVD-Audio discs carry an Audio Still Video Set (ASVS). An MPEG-2 still
images (cover art, booklet/lyric pages) that the disc associates with
tracks.

A new STREAM_CTRL_GET_STILL returns the still for a given playback time.
demux_disc exposes it as a selectable mpeg2video track and injects the
still as a keyframe at the track's playback time. It changes as playback
crosses track boundaries (and follows onset times when a disc encodes
them).

--dvda-page (with the new STREAM_CTRL_SET_STILL_PAGE) forces a specific
still page instead of the scheduled one. The still state is guarded by
a mutex, runtime page changes arrive from the player thread while the
demuxer thread extracts stills.
2026-08-26 01:47:41 +02:00
Kacper Michajłow bb19b0fc36 stream_bluray: remove BD_EVENT_POPUP and menu-event tracking
BD_EVENT_POPUP was tracked into has_popup, which never grew a
consumer. BD_EVENT_MENU's menu_event_active only fed the menu_active
condition, where it was subsumed by the visible-overlay check. Remove
all three.
2026-08-26 01:47:41 +02:00
Kacper Michajłow c9422ff88f stream: turn the highlight fields into mp_dvdnav_highlight
The highlight rectangle and palette were passed around as loose fields
in three places. Bundle them into a struct, pass the whole nav state to
the sd_lavc control.
2026-08-26 01:47:41 +02:00
Kacper Michajłow 3897b3a579 stream_dvdnav: add support for still frames
DVDNAV_STILL_FRAME means the VM is holding a frame indefinitely (menu
pages, some logos) or for a timed duration. Report the indefinite case
via nav state so the player holds playback at EOF instead of ending
the file, and skip timed stills, which would otherwise stall playback.
2026-08-26 01:47:41 +02:00
Kacper Michajłow f0bc30aaf1 demux: adapt caching to interactive disc navigation
The disc VM advances when the stream is read, so in nav mode the cache
must not run ahead of what the user is seeing. Never read ahead (a
looping menu is endless). Never satisfy seeks from the cache either.

This applies to the whole disc session, not only while a menu is on
screen. The VM can jump at any time (BD-J timers, end of title), so
the cache must never run ahead of playback.

Activations still must be able to drive the VM while nothing is
consumed. demux_drive_nav() forces a single read for them.
2026-08-26 01:47:41 +02:00
Kacper Michajłow 70174945a4 discnav: sync track selection state with VM
The disc VM selects audio and subpicture streams itself (menu SPU
highlights, title-authored stream changes on jumps). Follow the VM's
selection on every hop, and turn subtitles on/off with the disc's
sub_visible flag.

The sync only applies while the corresponding track selection is on
auto. An explicitly chosen track (--aid/--sid or runtime cycling) is
never overridden.
2026-08-26 01:47:41 +02:00
Kacper Michajłow af9a11a8e5 demux_disc: reopen slave demuxer on disc-nav hops
Playing a disc through the menu means crossing playlist boundaries at
runtime: menu -> title (and back), sub-menu -> sub-menu, title -> title.
Each new playlist can have a different stream count and/or a different
codec mix. The previous slave demuxer was probed once at open and never
refreshed, so after a hop the player either kept decoding stale streams
or saw nothing at all. Tear down and re-open the slave on every nav
discontinuity.
2026-08-26 01:47:41 +02:00
Kacper Michajłow e2b7a983fa stream: add disc-nav actions and states
Define three new stream controls so disc backends (libdvdnav, libbluray)
can expose their in-disc menu/highlight state to the player.

Not used yet, the next commits add the backends and the player side.
2026-08-26 01:47:41 +02:00
Thomas Weißschuh 1c467ad4f9 stream: drop unneeded include fcntl.h 2026-07-02 17:36:31 +00:00
NRK e2180e581e demux_playlist: only autocreate on regular file
trying to autocreate playlist when the file is a fifo breaks
playback. the bug report is a special case of `/dev/fd/*` but
even for named fifos, opening and closing them can cause the
other end to stop writing.

Closes: https://github.com/mpv-player/mpv/issues/17682
2026-04-06 18:50:28 +02: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
Kacper Michajłow 9bc3aee6fb stream/stream: mark mf:// and edl:// as unsafe protocols 2025-03-07 00:15:23 +01:00
Kacper Michajłow 3717a530ca player/loadfile: we shouldn't unescape inplace
I got mesmerized by the simplicity of the original commit, but in fact
it was not a correct thing to do.

Fixes: c0366cfa42
2025-02-05 18:04:11 +01:00
Kacper Michajłow a1424d5fe0 demux/ebml: fix ebml_read_length()
Fixes reading EMBL sizes in some files and makes this function readable
while at it.

Would be good to inline mp_log2(), but should be good enough.

Fixes: #15691
2025-01-27 18:50:59 +01:00
Kacper Michajłow e9b5773bf9 stream_bluray: add STREAM_CTRL_GET_TITLE_PLAYLIST 2024-12-04 14:51:53 +01:00
nanahi dc0d99eaff stream: add STREAM_READ_FILE_FLAGS_DEFAULT
This is the default set of flags used by stream_read_file().
Useful for doing flag customization for stream_read_file2().
2024-10-22 03:16:51 +03:00
nanahi c2e71ceb07 stream: add STREAM_ALLOW_PARTIAL_READ flag
This allows stream_read_complete() to return partial result
instead of error if the file size is larger than the limit.
2024-10-22 03:16:51 +03:00
nanahi 7673c4e34a stream: add stream_read_file2
This is stream_read_file with the ability to specify flags.
2024-10-20 19:31:49 +02:00
llyyr d84a7c5112 stream: don't mark stdin as a filesystem file
Also rename the field to appropriately reflect what it is supposed to be
used for. The only other use of this was to search for ordered chapter
sources, and that makes no sense for mkv files from stdin.

This also fixes autocreate-playlist loading in the current directory
when the input file is stdin.
2024-09-14 16:17:44 +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
Kacper Michajłow a59b8edb96 stream: increase max_size to INT_MAX minus padding
No need to magic number limit, we can support up to INT_MAX with current
code. Which should be more than enough.
2024-01-31 15:38:21 +00:00
sfan5 5117fa70af stream: turn stream_info.open2's args argument const
So nobody comes up with the "smart" idea to modify those again.
2021-04-08 23:47:35 +03:00
wm4 06033df715 demux_lavf: workaround reading gif from unseekable streams
FFmpeg, being the pile of trash as usual, recently broke this. Add our
own trash hack to trashily workaround this shit.

Fixes: #7893
2020-07-09 12:29:22 +02:00
wm4 ad9f3bfe96 stream: make stream_read_file() more robust
Change it to strictly accept local paths only. No more http://, no more
$HOME expansion with "~/" or mpv config path expansion with "~~/". This
should behave as if passing a path directly to open().

Reduce annoying log noise to further facilitate it using as open()
replacement.
2020-05-10 16:44:35 +02:00
wm4 217c47ecb2 stream: fix whitespace within comment
arrrrrrrghh
2020-04-10 10:50:54 +02:00
wm4 1cb9e7efb8 stream, demux: redo origin policy thing
mpv has a very weak and very annoying policy that determines whether a
playlist should be used or not. For example, if you play a remote
playlist, you usually don't want it to be able to read local filesystem
entries. (Although for a media player the impact is small I guess.)

It's weak and annoying as in that it does not prevent certain cases
which could be interpreted as bad in some cases, such as allowing
playlists on the local filesystem to reference remote URLs. It probably
barely makes sense, but we just want to exclude some other "definitely
not a good idea" things, all while playlists generally just work, so
whatever.

The policy is:
- from the command line anything is played
- local playlists can reference anything except "unsafe" streams
  ("unsafe" means special stream inputs like libavfilter graphs)
- remote playlists can reference only remote URLs
- things like "memory://" and archives are "transparent" to this

This commit does... something. It replaces the weird stream flags with a
slightly clearer "origin" value, which is now consequently passed down
and used everywhere. It fixes some deviations from the described policy.

I wanted to force archives to reference only content within them, but
this would probably have been more complicated (or required different
abstractions), and I'm too lazy to figure it out, so archives are now
"transparent" (playlists within archives behave the same outside).

There may be a lot of bugs in this.

This is unfortunately a very noisy commit because:
- every stream open call now needs to pass the origin
- so does every demuxer open call (=> params param. gets mandatory)
- most stream were changed to provide the "origin" value
- the origin value needed to be passed along in a lot of places
- I was too lazy to split the commit

Fixes: #7274
2019-12-20 13:00:39 +01:00
wm4 5a99015acf stream_lavf: set --network-timeout to 60 seconds by default
Until now, we've made FFmpeg use the default network timeout - which is
apparently infinite. I don't know if this was changed at some point,
although it seems likely, as I was sure there was a more useful default.

For most use cases, a smaller timeout is more useful (for example
recording something in the background), so force a timeout of 1 minute.

See: #5793
2019-11-14 13:46:03 +01:00
wm4 ac7f67b3f2 demux_mkv, stream: attempt to improve behavior in unseekable streams
stream_skip() semantics were kind of bad, especially after the recent
change to the stream code. Forward stream_skip() calls could still
trigger a seek and fail, even if it was supposed to actually skip data.
(Maybe the idea that stream_skip() should try to seek is worthless in
the first place.)

Rename it to stream_seek_skip() (takes absolute position now because I
think that's better), and make it always skip if the stream is marked as
forward.

While we're at it, make EOF detection more robust. I guess s->eof
shouldn't exist at all, since it's valid only "sometimes". It should be
removed... but not today. A 1-byte stream_read_peek() call is good to
get the s->eof flag set to a correct value.
2019-11-14 12:59:14 +01:00
wm4 19becc8ea9 stats, demux: log byte level stream seeks 2019-11-07 22:53:13 +01:00
wm4 6487abde79 stream: remove unused read_chunk field
It was set, but its value was never used. The stream cache used to use
it, but it was removed. It controlled how much data it tried to read
from the underlying stream at once.

The user can now control the buffer size with --stream-buffer-size,
which achieves a similar effect, because the stream will in the common
case read half of the buffer size at once. In fact, the new default size
is 128KB, i.e. 64KB read size, which is as much as stream_file and
stream_cb requested by default. stream_memory requested more, but it
doesn't matter anyway. Only stream_smb set a larger size with 128KB.
2019-11-07 22:53:13 +01:00
wm4 e5a9b792ec stream: replace STREAM_CTRL_GET_SIZE with a proper entrypoint
This is overlay convoluted as a stream control, and important enough to
warrant "first class" functionality.
2019-11-07 22:53:13 +01:00
wm4 d3479018db stream: change buffer argument types from char* to void*
This is slightly better, although not much, and ultimately doesn't
matter.

The public API in stream_cb.h also uses char*, but can't change that.
2019-11-07 22:53:13 +01:00
wm4 53f17a71f4 stream: fix typos in a comments 2019-11-07 22:53:13 +01:00
wm4 12d1761064 stream: remove eof getter
demux_mkv was the only thing using this, and everything else accessed it
directly. No need to keep the indirection wrapper around.

(Funny how this getter was in the initial commit of MPlayer.)
2019-11-07 22:53:10 +01:00
wm4 b4466cf0d4 stream: remove inline buffer optimization
Was probably worthless, and I can't measure a difference anymore (I used
to be able and it still seemed worth doing so back then).

When the default buffer size is enlarged in the next commit, the inline
buffer probably won't even be useful in theory, because the data will
rarely be on the same page as the other stream fields. It surely makes
the inline buffer seem like a ridiculous micro-optimization. Farewell...
2019-11-06 21:54:41 +01:00
wm4 f37f4de849 stream: turn into a ring buffer, make size configurable
In some corner cases (see #6802), it can be beneficial to use a larger
stream buffer size. Use this as argument to rewrite everything for no
reason.

Turn stream.c itself into a ring buffer, with configurable size. The
latter would have been easily achievable with minimal changes, and the
ring buffer is the hard part. There is no reason to have a ring buffer
at all, except possibly if ffmpeg don't fix their awful mp4 demuxer, and
some subtle issues with demux_mkv.c wanting to seek back by small
offsets (the latter was handled with small stream_peek() calls, which
are unneeded now).

In addition, this turns small forward seeks into reads (where data is
simply skipped). Before this commit, only stream_skip() did this (which
also mean that stream_skip() simply calls stream_seek() now).

Replace all stream_peek() calls with something else (usually
stream_read_peek()). The function was a problem, because it returned a
pointer to the internal buffer, which is now a ring buffer with
wrapping. The new function just copies the data into a buffer, and in
some cases requires callers to dynamically allocate memory. (The most
common case, demux_lavf.c, required a separate buffer allocation anyway
due to FFmpeg "idiosyncrasies".) This is the bulk of the demuxer_*
changes.

I'm not happy with this. There still isn't a good reason why there
should be a ring buffer, that is complex, and most of the time just
wastes half of the available memory. Maybe another rewrite soon.

It also contains bugs; you're an alpha tester now.
2019-11-06 21:36:02 +01:00
wm4 a267452b00 stream: move stream_read_line to demux_playlist.c
demux_playlist.c is the only remaining user of this. Not sure if it
should stay this way, but for now I'll say yes.
2019-10-31 11:05:48 +01:00
wm4 c6b08d222f stream: stop accessing buffer internals in stream_read_line()
Getting this out of the way in preparation for reworking stream
internals.
2019-10-31 11:05:45 +01:00