From 3b13a4799314fba316bcd4e7abce2685415c262b Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 29 Sep 2019 02:24:29 +0200 Subject: loadfile: don't always accidentally always prefetching demux_start_prefetch() was called unconditionally in two cases. This is completely wrong. I'm not sure what part of my brain died off that something this obviously wrong went in. The prefetch case is a bit more complicated. It's a different thread, so you can't access just access mpctx->opts there. So add an explicit field for this, which is the simplest way to get this done. (Even if it's bad factoring.) Fixes: c1f1a0845e03885eebe63 Fixes: 556e204a112ee286972e5 --- player/core.h | 1 + player/loadfile.c | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/player/core.h b/player/core.h index 893a4cf3e8..11e741bb78 100644 --- a/player/core.h +++ b/player/core.h @@ -457,6 +457,7 @@ typedef struct MPContext { char *open_url; char *open_format; int open_url_flags; + bool open_for_prefetch; // --- All fields below are owned by open_thread, unless open_done was set // to true. struct demuxer *open_res_demuxer; diff --git a/player/loadfile.c b/player/loadfile.c index 8f0d091b29..70fe0e42a7 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -983,13 +983,15 @@ static void *open_demux_thread(void *ctx) if (demux) { MP_VERBOSE(mpctx, "Opening done: %s\n", mpctx->open_url); - int num_streams = demux_get_num_stream(demux); - for (int n = 0; n < num_streams; n++) { - struct sh_stream *sh = demux_get_stream(demux, n); - demuxer_select_track(demux, sh, MP_NOPTS_VALUE, true); - } + if (mpctx->open_for_prefetch && !demux->fully_read) { + int num_streams = demux_get_num_stream(demux); + for (int n = 0; n < num_streams; n++) { + struct sh_stream *sh = demux_get_stream(demux, n); + demuxer_select_track(demux, sh, MP_NOPTS_VALUE, true); + } - demux_start_prefetch(demux); + demux_start_prefetch(demux); + } } else { MP_VERBOSE(mpctx, "Opening failed or was aborted: %s\n", mpctx->open_url); @@ -1026,7 +1028,8 @@ static void cancel_open(struct MPContext *mpctx) } // Setup all the field to open this url, and make sure a thread is running. -static void start_open(struct MPContext *mpctx, char *url, int url_flags) +static void start_open(struct MPContext *mpctx, char *url, int url_flags, + bool for_prefetch) { cancel_open(mpctx); @@ -1039,6 +1042,7 @@ static void start_open(struct MPContext *mpctx, char *url, int url_flags) mpctx->open_url = talloc_strdup(NULL, url); mpctx->open_format = talloc_strdup(NULL, mpctx->opts->demuxer_name); mpctx->open_url_flags = url_flags; + mpctx->open_for_prefetch = for_prefetch; if (mpctx->opts->load_unsafe_playlists) mpctx->open_url_flags = 0; @@ -1075,7 +1079,7 @@ static void open_demux_reentrant(struct MPContext *mpctx) } if (!mpctx->open_active) - start_open(mpctx, url, mpctx->playing->stream_flags); + start_open(mpctx, url, mpctx->playing->stream_flags, false); // User abort should cancel the opener now. mp_cancel_set_parent(mpctx->open_cancel, mpctx->playback_abort); @@ -1106,7 +1110,7 @@ void prefetch_next(struct MPContext *mpctx) struct playlist_entry *new_entry = mp_next_file(mpctx, +1, false, false); if (new_entry && !mpctx->open_active && new_entry->filename) { MP_VERBOSE(mpctx, "Prefetching: %s\n", new_entry->filename); - start_open(mpctx, new_entry->filename, new_entry->stream_flags); + start_open(mpctx, new_entry->filename, new_entry->stream_flags, true); } } @@ -1553,9 +1557,9 @@ static void play_current_file(struct MPContext *mpctx) goto terminate_playback; } - demux_start_prefetch(mpctx->demuxer); - if (opts->demuxer_cache_wait) { + demux_start_prefetch(mpctx->demuxer); + while (!mpctx->stop_play) { struct demux_reader_state s; demux_get_reader_state(mpctx->demuxer, &s); -- cgit v1.2.3