diff options
-rw-r--r-- | DOCS/man/options.rst | 8 | ||||
-rw-r--r-- | demux/demux.c | 11 | ||||
-rw-r--r-- | demux/demux.h | 1 | ||||
-rw-r--r-- | options/options.c | 1 | ||||
-rw-r--r-- | options/options.h | 1 | ||||
-rw-r--r-- | player/loadfile.c | 13 |
6 files changed, 35 insertions, 0 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst index 526b2143fc..8da721c834 100644 --- a/DOCS/man/options.rst +++ b/DOCS/man/options.rst @@ -2995,6 +2995,14 @@ Demuxer requests), seeking will be disabled. This option can forcibly enable it. For seeks within the cache, there's a good chance of success. +``--demuxer-cache-wait=<yes|no>`` + Before starting playback, read data until either the end of the file was + reached, or the demuxer cache has reached maximum capacity. Only once this + is done, playback starts. This intentionally happens before the initial + seek triggered with ``--start``. This does not change any runtime behavior + after the initial caching. This option is useless if the file cannot be + cached completely. + Input ----- diff --git a/demux/demux.c b/demux/demux.c index be866b1642..36b6ec9231 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1100,6 +1100,17 @@ void demux_set_wakeup_cb(struct demuxer *demuxer, void (*cb)(void *ctx), void *c pthread_mutex_unlock(&in->lock); } +void demux_start_prefetch(struct demuxer *demuxer) +{ + struct demux_internal *in = demuxer->in; + assert(demuxer == in->d_user); + + pthread_mutex_lock(&in->lock); + in->reading = true; + pthread_cond_signal(&in->wakeup); + pthread_mutex_unlock(&in->lock); +} + const char *stream_type_name(enum stream_type type) { switch (type) { diff --git a/demux/demux.h b/demux/demux.h index 65566ea509..b7f75ce813 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -260,6 +260,7 @@ struct demuxer *demux_open_url(const char *url, void demux_start_thread(struct demuxer *demuxer); void demux_stop_thread(struct demuxer *demuxer); void demux_set_wakeup_cb(struct demuxer *demuxer, void (*cb)(void *ctx), void *ctx); +void demux_start_prefetch(struct demuxer *demuxer); bool demux_cancel_test(struct demuxer *demuxer); diff --git a/options/options.c b/options/options.c index 68d33fb000..2c2fcc941d 100644 --- a/options/options.c +++ b/options/options.c @@ -460,6 +460,7 @@ const m_option_t mp_opts[] = { OPT_STRING("sub-demuxer", sub_demuxer_name, 0), OPT_FLAG("demuxer-thread", demuxer_thread, 0), OPT_DOUBLE("demuxer-termination-timeout", demux_termination_timeout, 0), + OPT_FLAG("demuxer-cache-wait", demuxer_cache_wait, 0), OPT_FLAG("prefetch-playlist", prefetch_open, 0), OPT_FLAG("cache-pause", cache_pause, 0), OPT_FLAG("cache-pause-initial", cache_pause_initial, 0), diff --git a/options/options.h b/options/options.h index d9dc5b6a08..5f7c560e71 100644 --- a/options/options.h +++ b/options/options.h @@ -248,6 +248,7 @@ typedef struct MPOpts { char *demuxer_name; int demuxer_thread; double demux_termination_timeout; + int demuxer_cache_wait; int prefetch_open; char *audio_demuxer_name; char *sub_demuxer_name; diff --git a/player/loadfile.c b/player/loadfile.c index fc3bb97a96..48813c80a0 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1534,6 +1534,19 @@ static void play_current_file(struct MPContext *mpctx) goto terminate_playback; } + demux_start_prefetch(mpctx->demuxer); + + if (opts->demuxer_cache_wait) { + while (!mpctx->stop_play) { + struct demux_reader_state s; + demux_get_reader_state(mpctx->demuxer, &s); + if (s.idle) + break; + + mp_idle(mpctx); + } + } + double play_start_pts = get_play_start_pts(mpctx); if (play_start_pts != MP_NOPTS_VALUE) { /* |