demux: add --demuxer-hysteresis-bytes

Fixes: https://github.com/mpv-player/mpv/discussions/17888#discussioncomment-16852506
This commit is contained in:
Kacper Michajłow committed 2026-05-08 17:27:13 +02:00
1 parent 09900a0ff0
commit e0eb42c303
4 files changed
+26 -2

No files matched your search

@@ -0,0 +1 @@
add `--demuxer-hysteresis-bytes`
+13
View File
@@ -4334,6 +4334,19 @@ Demuxer
The default value is 0 seconds, which disables the caching hysteresis. A
value of 10 seconds probably works well for most usecases.
``--demuxer-hysteresis-bytes=<bytesize>``
Same as ``--demuxer-hysteresis-secs``, but specifies the hysteresis in
bytes of forward buffered data instead of seconds. Once the demuxer limit
is reached, the demuxer will not buffer ahead again until the amount of
forward buffered data drops to this value.
This option is useful for streams with variable or unknown bitrate, where
a byte-based threshold is more meaningful than a time-based one. It can
also be combined with ``--demuxer-hysteresis-secs``. In that case buffering
can resume when either threshold is reached.
The default value is 0, which disables the byte-based caching hysteresis.
``--prefetch-playlist=<yes|no>``
Prefetch next playlist entry while playback of the current entry is ending
(default: no). This merely opens the URL of the next playlist entry as soon
+11 -2
View File
@@ -102,6 +102,8 @@ const struct m_sub_options demux_conf = {
{"cache-on-disk", OPT_BOOL(disk_cache)},
{"demuxer-readahead-secs", OPT_DOUBLE(min_secs), M_RANGE(0, DBL_MAX)},
{"demuxer-hysteresis-secs", OPT_DOUBLE(hyst_secs), M_RANGE(0, DBL_MAX)},
{"demuxer-hysteresis-bytes", OPT_BYTE_SIZE(hyst_bytes),
M_RANGE(0, M_MAX_MEM_BYTES)},
{"demuxer-max-bytes", OPT_BYTE_SIZE(max_bytes),
M_RANGE(0, M_MAX_MEM_BYTES)},
{"demuxer-max-back-bytes", OPT_BYTE_SIZE(max_bytes_bw),
@@ -201,6 +203,7 @@ struct demux_internal {
bool eof; // whether we're in EOF state
double min_secs;
double hyst_secs; // stop reading till there's hyst_secs remaining
size_t hyst_bytes; // stop reading till there's hyst_bytes remaining
bool hyst_active;
size_t max_bytes;
size_t max_bytes_bw;
@@ -2275,12 +2278,17 @@ static bool read_packet(struct demux_internal *in)
total_fw_bytes += get_forward_buffered_bytes(ds);
}
if (in->hyst_bytes > 0 && total_fw_bytes <= in->hyst_bytes) {
in->hyst_active = false;
prefetch_more |= true;
}
MP_TRACE(in, "bytes=%zd, read_more=%d prefetch_more=%d, refresh_more=%d\n",
(size_t)total_fw_bytes, read_more, prefetch_more, refresh_more);
if (total_fw_bytes >= in->max_bytes) {
// if we hit the limit just by prefetching, simply stop prefetching
if (!read_more) {
in->hyst_active = !!in->hyst_secs;
in->hyst_active = in->hyst_secs > 0 || in->hyst_bytes > 0;
return false;
}
if (!in->warned_queue_overflow) {
@@ -2313,7 +2321,7 @@ static bool read_packet(struct demux_internal *in)
}
if (!read_more && !prefetch_more && !refresh_more) {
in->hyst_active = !!in->hyst_secs;
in->hyst_active = in->hyst_secs > 0 || in->hyst_bytes > 0;
return false;
}
@@ -2533,6 +2541,7 @@ static void update_opts(struct demuxer *demuxer)
in->min_secs = opts->min_secs;
in->hyst_secs = opts->hyst_secs;
in->hyst_bytes = opts->hyst_bytes;
in->max_bytes = opts->max_bytes;
in->max_bytes_bw = opts->max_bytes_bw;
+1
View File
@@ -71,6 +71,7 @@ struct demux_opts {
bool donate_fw;
double min_secs;
double hyst_secs;
int64_t hyst_bytes;
bool force_seekable;
double min_secs_cache;
bool access_references;