0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-20 03:52:22 +02:00
Commit Graph

585 Commits

Author SHA1 Message Date
Kacper Michajłow
4e50da3ddc demux_playlist: use --directory-filter-types for --autocreate-playlist 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
bb9b862f0c demux: add --autocreate-playlist 2024-08-10 23:27:40 +02:00
nanahi
33e414fa5d demux: avoid seeking video streams for refresh seek
940854c86f added this logic, but when the
demuxer contains a selected video stream, it causes a seek for the video
stream. This is unnecessary since the problems that commit fixed are only
relevant for external audio streams. For a demuxer with a video stream
selected, the synchronization is done by the demuxer implementation.
Add a check to prevent this.
2024-07-04 22:23:27 +00:00
nanahi
c461ea6cd1 demux: don't log if track isn't refreshed
Also use demux_internal type for the refresh_track in style of other
internal functions.
2024-07-04 22:23:27 +00:00
nanahi
940854c86f demux: allow refresh seek for non-video streams
Since d41f0a54b0, enabling a stream will
no longer perform a refresh seek, to fix issues with switching video
tracks. Additionally, 62e9a0c5f6 also
prevents refresh seek on track switching when it happens right after a
seek.

Unfortunately, when external audio files are loaded, preventing refresh
seeks can cause A-V sync issues. Since external tracks have separate demuxer
instances from the internal tracks, the demuxer instances from both
internal and external tracks are explicitly sought to the same pts when
seeking is performed. When enabling an external audio track for the first
time, the existing logic prevents refresh seek because no packets have ever
been read, so the track ends up not being sought. This means that switching
the track in the middle of playback results in a huge A-V desync.

To make it worse, unlike one demuxer instance with multiple tracks,
tracks from multiple demuxer instances are not synced in any meaningful
way beyond the separate explicit seeking. The only thing which keeps these
tracks synced is the generic A-V sync logic, which is unfit for such large
desync above. This means the audio is at the start position after the track
is switched, behind the video, so the audio is not considered ready, and
audio is continuously filtered sequentially until it is synced to the video.
While this is happening, the audio filtering exhausts all CPU resources.

There is also a case with cache enabled: if a seek causes some new data to
be cached, the demuxer is sought to the end of joined cache range.
If track is switched after this, the existing logic prevents a refresh seek,
so the demuxer is at a wrong position after the track is switched.

Fix this by allowing refresh seek for non-video streams, even when no packets
have been read yet or immediately after a seek.
2024-06-22 18:21:28 +00:00
Kacper Michajłow
18ef834ef4 various: move unistd.h inclusion to common.h 2024-05-06 22:01:17 +02:00
Aman Karmani
abe8f3f9df demux: keep track of ts information per stream type
Signed-off-by: Aman Karmani <aman@tmm1.net>
2024-05-05 14:11:47 +02:00
Florian Albrechtskirchinger
56b3bcaaf2 demux: also read "CUESHEET" tag from stream metadata
Read embedded cue sheets from stream-level metadata, in addition to
format-level metadata.

Fixes missing chapters in opus files with "CUESHEET" tags.
2024-04-19 03:10:48 +02:00
Guido Cella
8d85627aad demux: fix seek ranges of images
When a video-reconfig occurs with an image, the cache is not used
because find_cache_seek_range() checks if the start time was
initialized, but for images it stays at MP_NOPTS_VALUE. This makes
rotating large network images slow because they are re-downloaded on
every rotation.

Fix this by setting the timestamps of image cache ranges by altering a
condition.
2024-04-03 14:47:07 +02:00
Guido Cella
a039cfce00 demux: clarify the meaning of still_image
Clarify that ffmpeg sets AV_DISPOSITION_STILL_IMAGE for sparse videos
like https://s3.amazonaws.com/tmm1/music-choice.ts, not for images.
2024-02-11 04:01:04 +00:00
Kacper Michajłow
9456b2f6e9 demux: add missing NULL check
It is assigned to NULL above is !stream.
2023-11-18 23:55:28 +00:00
Dudemanguy
0286e7f206 demux: always update the cache on init
cd59ea8afa removed an arbitrary start
offset added to the timer. However, it turns out that demux secretly
depends on this. When updating cache to actually read bytes from the
stream, there's a diff >= MP_TIME_S_TO_NS(1) check to make it only
update once every second. With the old MP_START_TIME macro, the initial
time value would always be at least 1e10, so this would also be true.
Since we don't have that offset anymore, now the initial time is less
than that so it is not updated and properties like file-size are 0. Just
be sure to always update if the last_speed_query is 0 (i.e. we just
started the player). Fixes #12869.
2023-11-12 11:47:16 +01:00
Kacper Michajłow
174df99ffa ALL: use new mp_thread abstraction 2023-11-05 17:36:17 +00:00
NRK
3789f1a387 demux: make hysteresis-secs respect cache-secs
currently hysteresis-secs only works when the demuxer-max-bytes fills
up. but it's possible for the cache-secs/demuxer-readahead-secs to be
reached first.

in those cases, hysteresis-secs doesn't work and keeps buffering
non-stop. but the goal of this option was to save power by avoiding
non-stop buffering so go ahead and make it respect cache-secs as well.

additionally remove some redundant repetition from the docs.
2023-10-30 17:16:38 +00:00
NRK
20fff1e509 demux: cosmetics
- brace goes to next line for multi-line conditional
- sort standard headers some more
2023-10-30 17:16:38 +00:00
NRK
d05ef7fdc4 various: sort some standard headers
since i was going to fix the include order of stdatomic, might as well
sort the surrouding includes in accordance with the project's coding
style.

some headers can sometime require specific include order. standard
library headers usually don't. but mpv might "hack into" the standard
headers (e.g pthreads) so that complicates things a bit more.

hopefully nothing breaks. if it does, the style guide is to blame.
2023-10-20 21:31:09 +02:00
NRK
2070331f64 osdep: remove atomic.h
replace it with <stdatomic.h> and replace the mp_atomic_* typedefs with
explicit _Atomic qualified types.

also add missing config.h includes on some files.
2023-10-20 21:31:09 +02:00
Dudemanguy
5cda1a5deb demux: convert cache updates to nanoseconds
As a bonus, we can remove the awkward and horribly named MP_SECOND_US.
2023-10-16 15:38:59 +00:00
Dudemanguy
da4f11803f demux: change the default of metadata-codepage to auto
There's really no reason not to do this especially since sub-codepage
already defaults to auto. Also change logging in charset_conv since
telling us that the data is UTF-8 if the passed codepage value is "auto"
or "utf-8" is really not useful information (that's the expectation).
2023-10-07 02:41:27 +00:00
Dudemanguy
0a1e3d8685 demux: move parent_stream_info before the goto
Previously if the demuxer didn't exist, then it could jump down and try
to free sinfo.filename before it was ever set thus segfaulting. Just
always set the struct unconditionally so we're always sure to free it.
2023-10-01 16:11:53 -05:00
Dudemanguy
d50de74c1e Revert "demux: constify a struct member"
Some demuxers actually close the stream right after they are finished
opening like cue. Since the stream->url is no longer copied with this
commit, that means it gets thrown away after the stream closes. This
leads to a use after free. We still need to allocate stream->url so fix
this another way.

This reverts commit 3e85df3b2d.
2023-10-01 16:11:06 -05:00
Dudemanguy
9d9e986e06 demux: fix erroneous condition in lazy_stream_needs_wait
Yeah another try at this. So when inspecting lazy_stream_needs_wait, I
realized it had a curious !ds->reader_head condition. Actually, this is
what is messing everything up. This was originally added in
cf2b7a4997 for showing large negative sub
delay values correctly. It worked because the packet will eventually be
discarded during playback causing ds->reader_head not exist and thus the
next one will correctly be read ahead as needed.

But for the "switching subtitle tracks while paused" case, this is
actually bad. As the stream is read, eventually you'll find a packet and
set the reader_head. But it's not going to be the correct packet (unless
you're looking for the very first one), so you need to read more. This
won't happen because of the !ds->reader_head check and unlike the sub
delay case, nothing will eventually discard that packet since playback
isn't occuring. So read_packet exits earlier than it should and isn't
tried again, so the subtitle that you want won't show since the
returned packet has the wrong pts. All that needs to be done here is to
delete this one condition. There's already checks in place to make sure
that it's not read past the desired timestamp and for the sub delay case
(the only other time this logic is used), it makes no difference since
you won't read past the specified pts in the first place.
2023-10-01 14:06:45 +00:00
Dudemanguy
3a572c7a88 Revert "demux: improve stream selection state"
The stream selection state wasn't improved. I didn't realize this messed
with caches. All in all, just not a good idea. Back to drawing board I
guess.

This reverts commit f40bbfec4f.
2023-09-30 09:02:57 -05:00
Kacper Michajłow
da4c4d2ebd timer: rename mp_time_us_to_timespec to reflect what it actually does 2023-09-29 20:48:58 +00:00
Dudemanguy
f40bbfec4f demux: improve stream selection state
This replaces the previous commit and makes more sense. The internal
demux marked tracks as eager depending on their type and for subtitles
it would always lazily read them unless there happened to be no
available av stream. However, we want the sub stream to be eager if the
player is paused. The existing subtitle is still preserved on the
screen, but if the user changes tracks that's when the problem occurs.
So to handle this case, propagate the mpctx->paused down to the stream
selection logic. This modifies both demuxer_refresh_track and
demuxer_select_track to take that boolean value. A few other parts of
the player use this, but we can just assume false there (no change in
behavior from before) since they should never be related to subtitles.
The core player code is aware of its own state naturally, and can always
pass the appropriate value so go ahead and do so. When we change the
pause state, a refresh seek is done on all existing subtitle tracks to
make sure their eager state is the appropriate value (i.e. so it's not
still set to eager after a pause and a track switch). Slightly invasive
change, but it works with the existing logic instead of going around it
so ultimately it should be a better approach. We can additionally remove
the old force boolean from sub_read_packets since it is no longer
needed.
2023-09-27 22:38:13 -05:00
Dudemanguy
09b04fbf09 Revert "demux: eagerly read subtitle streams when switching tracks while paused"
Actually, I thought of a better way of handling this shortly after
merging this. Revert it and redo it in the next commit.

This reverts commit c2c157ebec.
2023-09-27 21:51:49 -05:00
Dudemanguy
c2c157ebec demux: eagerly read subtitle streams when switching tracks while paused
a323dfae42 almost fixed subtitle tracks
disappearing when paused but it actually missed one part: the behavior
of demux_read_packet_async_until. It's a bit unintuitive, but for
subtitle streams, that function would only return the very first packet
regardless of whatever pts you pass to it. So the previous commit worked
on the very first subtitle, but not actually any of the others (oops).
This is because subtitle streams never marked as eager and thus never
actually read farther ahead. While the video is playing, this is OK, but
if we're paused and switching subtitle tracks then the stream should be
eagerly read. Luckily, the logic is already there in the function for
this. All we have to do add an extra argument to
demux_read_packet_async_until to force the stream to be read eagerly and
then it just works. Be sure to unset the eager flag when we're done.
Actually fixes the bug for real this time.
2023-09-27 23:10:20 +00:00
Dudemanguy
a343666ab5 demux: make demux opts public
Several parts of the code need to access options here. There's no point
in hiding it demux.c so just expose it in the demux.h header. This means
pulling it out of demux_internal and putting it in the demuxer struct
instead.
2023-09-22 14:20:38 +00:00
Dudemanguy
a703dc10c8 options: move some demux-specific opts to demux opts
These options are only ever accessed by the demuxer and have no need to
be in MPOpts. Move them to demux.c instead.
2023-09-22 14:20:38 +00:00
Dudemanguy
36ea5d7b5c options: remove a few options marked with .deprecation_message
A bit different from the OPT_REPLACED/OPT_REMOVED ones in that the
options still possibly do something but they have a deprecation
message. Most of these are old and have no real usage. The only
potentially controversial ones are the removal of --oaffset and
--ovoffset which were deprecated years ago and seemingly have no real
replacement. There's a cryptic message about --audio-delay but who
knows. The less encoding mode code we have, the better so just chuck
it.
2023-09-21 16:06:29 +00:00
Alexander Seiler
bdf7b5c3b8 various: fix various typos in the code base
Signed-off-by: Alexander Seiler <seileralex@gmail.com>
2023-03-28 19:29:44 +00:00
rcombs
ad60753bce demux: propagate hls_bitrate and program_id in generated caption tracks 2023-03-03 23:54:46 -06:00
rcombs
c39e332e50 demux_lavf: report program_id
This can be useful in stream selection.
2023-03-03 23:54:46 -06:00
sfan5
3e85df3b2d demux: constify a struct member
Fixes a segfault when an invalid demuxer is given due to
uninitialized use of `filename` after goto.
2023-02-24 13:22:03 +01:00
Christoph Heinrich
91cc0d8cf6 options: transition options from OPT_FLAG to OPT_BOOL
c784820454 introduced a bool option type
as a replacement for the flag type, but didn't actually transition and
remove the flag type because it would have been too much mundane work.
2023-02-21 17:15:17 +00:00
Kacper Michajłow
ebf34ffad3 demux: remove unused code 2023-02-02 14:23:02 +00:00
sfan5
1201d59f0b various: replace abort() with MP_ASSERT_UNREACHABLE() where appropriate
In debug mode the macro causes an assertion failure.
In release mode it works differently and tells the compiler that it can
assume the codepath will never execute. For this reason I was conversative
in replacing it, e.g. in mpv-internal code that exhausts all valid values
of an enum or when a condition is clear from directly preceding code.
2023-01-12 22:02:07 +01:00
sfan5
7b03cd367d various: replace if + abort() with MP_HANDLE_OOM()
MP_HANDLE_OOM also aborts but calls assert() first, which
will result in an useful message if compiled in debug mode.
2023-01-12 22:02:07 +01:00
Simon Ruderich
c153eb7d01 demux: boost read EBU R128 gain values to ReplayGain's reference level
Without this change the same track encoded as Opus - which requires R128
tagging - and e.g. Vorbis with ReplayGain tagging have different volumes.
This is caused by ReplayGain 2 having a higher reference level of -18 dB
LUFS, while EBU R128 has a lower reference level of -23 dB LUFS.

For the results of gain application to match, the read EBU R128
values need to be boosted according to the difference in reference
levels.

Patch inspired by mpd's source code.
2023-01-04 14:05:22 +02:00
Sultan Alsawaf
eb29aa4839 demux: add --demuxer-hysteresis-secs option to save power with caching
Buffering ahead nonstop into the cache results in nonstop disk or network
activity to read stream data from wherever it may originate. Currently,
there's no way to configure the demuxer to back off once it's buffered
ahead enough data, since the cache limit will be perpetually not-reached as
a stream continues to play, until the entire stream is eventually buffered.

On a laptop with an i9-12900H with decoding performed by the iGPU,
watching a locally-saved 1080p video which hasn't been buffered into the
page cache consumes approximately 15 W even with caching enabled. When
configuring a hysteresis to make the demuxer back off, power consumption
drops to 9 W when watching the same video, resulting in a whopping 6 W of
power savings.

To make it possible to attain significant power savings via caching, add
a --demuxer-hysteresis-secs option to configure a hysteresis to make the
demuxer back off until there's only the configured number of seconds
remaining in the cache from the current playback position.

This feature is disabled by default.
2022-12-30 10:30:22 +01:00
Emanuele Torre
9022b1b51d demux: stop iterating over demuxers as soon as a match is found 2022-05-21 23:32:40 +03:00
datasone
ee62a1a56e demux: add support for r128 replaygain tags 2022-04-28 20:13:36 +00:00
Cœur
bb5b4b1ba6 various: fix typos 2022-04-25 09:07:18 -04:00
Niklas Haas
8bd0dee531 osdep: rename MP_UNREACHABLE
It was pointed out on IRC that the name is misleading, since the actual
semantics of the macro is to assert first.
2021-11-03 15:15:20 +01:00
Niklas Haas
c704824b45 osdep: add MP_UNREACHABLE
This seems to work on gcc, clang and mingw as-is, but I made it
conditional on __GNUC__ just in case, even though I can't figure out
which compilers we care about that don't export this define.

Also replace all instances of assert(0) in the code by MP_UNREACHABLE(),
which is a strict improvement.
2021-11-03 14:09:27 +01:00
Shreesh Adiga
8ace8e8790 demux: acquire lock before calling update_bytes_read
in->byte_level_seeks field is written and modified inside
update_bytes_read at the same time when demux_get_reader_state
is executing, which locks the demux thread mutex.  This results
in a data race, reported by Thread Sanitizer when playing mp3 file
of sufficient long length.
2021-07-13 15:16:59 +00:00
TheAMM
4d3df1c842 recorder: add support for attachments (fonts)
Though, only when the output format is matroska, to avoid muxing errors.
This is quite useful when the input has ASS subtitles, as they tend to
rely on embedded fonts.
2021-07-08 12:44:06 +03:00
TheAMM
dd9ed47c99 demux, dump-cache: fix demux cache range sorting
dump_cache() calls qsort() to order an array of pointers, while the
comparator forgets it's receiving pointers to pointers.
Since cache-dumping over multiple cache ranges is fairly rare, this
seems to have gone unnoticed.
2021-07-08 12:44:06 +03:00