summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-05-16 16:29:45 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:04 +0200
commit556e204a112ee286972e50d636dec8b46ca125d7 (patch)
treefb388c85c5ea1de9283ee1957bdd9e154a1d9d66
parentd7c7f80cc1cf5b6a8207a3954ccdc984316c0602 (diff)
downloadmpv-556e204a112ee286972e50d636dec8b46ca125d7.tar.bz2
mpv-556e204a112ee286972e50d636dec8b46ca125d7.tar.xz
player: add --demuxer-cache-wait option
-rw-r--r--DOCS/man/options.rst8
-rw-r--r--demux/demux.c11
-rw-r--r--demux/demux.h1
-rw-r--r--options/options.c1
-rw-r--r--options/options.h1
-rw-r--r--player/loadfile.c13
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) {
/*