diff --git a/demux/cache.c b/demux/cache.c index 01d94323fc5a8..d89685d82b996 100644 --- a/demux/cache.c +++ b/demux/cache.c @@ -50,6 +50,7 @@ const struct m_sub_options demux_cache_conf = { .defaults = &(const struct demux_cache_opts){ .unlink_files = 2, }, + .change_flags = UPDATE_DEMUXER, }; struct demux_cache { diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 8bba964295ae1..5c01a82611e3d 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -128,6 +128,7 @@ const struct m_sub_options demux_lavf_conf = { .linearize_ts = -1, .propagate_opts = true, }, + .change_flags = UPDATE_DEMUXER, }; struct format_hack { diff --git a/demux/demux_libarchive.c b/demux/demux_libarchive.c index a85e40ff8921f..f08bfba0f4aa9 100644 --- a/demux/demux_libarchive.c +++ b/demux/demux_libarchive.c @@ -116,5 +116,6 @@ const struct demuxer_desc demuxer_desc_libarchive = { {0} }, .size = sizeof(OPT_BASE_STRUCT), + .change_flags = UPDATE_DEMUXER, }, }; diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 804f07a9ba440..7aed542a16f2d 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -257,6 +257,7 @@ const struct m_sub_options demux_mkv_conf = { .subtitle_preroll_secs_index = 10.0, .probe_start_time = true, }, + .change_flags = UPDATE_DEMUXER, }; #define REALHEADER_SIZE 16 diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c index 94c2ede5942ca..ea9c16412141a 100644 --- a/demux/demux_playlist.c +++ b/demux/demux_playlist.c @@ -75,6 +75,7 @@ struct m_sub_options demux_playlist_conf = { "video", "audio", "image", NULL }, }, + .change_flags = UPDATE_DEMUXER, }; static bool check_mimetype(struct stream *s, const char *const *list) diff --git a/demux/demux_raw.c b/demux/demux_raw.c index acb02518476e4..8a2786ca8e0ce 100644 --- a/demux/demux_raw.c +++ b/demux/demux_raw.c @@ -85,6 +85,7 @@ const struct m_sub_options demux_rawaudio_conf = { .samplerate = 44100, .aformat = PCM(1, 0, 16, 0), // s16le }, + .change_flags = UPDATE_DEMUXER, }; #undef PCM diff --git a/options/m_option.h b/options/m_option.h index c28b0309934bd..5bc4d3e4d7841 100644 --- a/options/m_option.h +++ b/options/m_option.h @@ -459,7 +459,8 @@ char *format_file_size(int64_t size); #define UPDATE_VIDEO (1 << 24) // force redraw if needed #define UPDATE_VO (1 << 25) // reinit the VO #define UPDATE_CLIPBOARD (1 << 26) // reinit the clipboard -#define UPDATE_OPT_LAST (1 << 26) +#define UPDATE_DEMUXER (1 << 27) // invalidate prefetched files +#define UPDATE_OPT_LAST (1 << 27) // All bits between _FIRST and _LAST (inclusive) #define UPDATE_OPTS_MASK \ diff --git a/options/options.c b/options/options.c index dab3716f63d6e..e7cd5318b6913 100644 --- a/options/options.c +++ b/options/options.c @@ -621,7 +621,7 @@ static const m_option_t mp_opts[] = { #endif // demuxer.c - select audio/sub file/demuxer - {"demuxer", OPT_STRING(demuxer_name), .help = demuxer_help}, + {"demuxer", OPT_STRING(demuxer_name), .help = demuxer_help, .flags = UPDATE_DEMUXER}, {"audio-demuxer", OPT_STRING(audio_demuxer_name), .help = demuxer_help}, {"sub-demuxer", OPT_STRING(sub_demuxer_name), .help = demuxer_help}, {"demuxer-thread", OPT_BOOL(demuxer_thread)}, diff --git a/player/command.c b/player/command.c index ddf4d992aea3f..8efe10a503750 100644 --- a/player/command.c +++ b/player/command.c @@ -7808,6 +7808,9 @@ void mp_option_change_callback(void *ctx, struct m_config_option *co, int flags, && mpctx->vo_chain->is_sparse && !mpctx->ao_chain && mpctx->video_status == STATUS_DRAINING) mpctx->time_frame = opts->image_display_duration; + + if (flags & UPDATE_DEMUXER) + mpctx->demuxer_changed = true; } void mp_notify_property(struct MPContext *mpctx, const char *property) diff --git a/player/core.h b/player/core.h index 23c167128de09..059a3a4c0f80f 100644 --- a/player/core.h +++ b/player/core.h @@ -463,6 +463,7 @@ typedef struct MPContext { char *open_format; int open_url_flags; bool open_for_prefetch; + bool demuxer_changed; // --- 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 4f204c20e75fa..c50b74092146d 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1178,6 +1178,7 @@ static void start_open(struct MPContext *mpctx, char *url, int url_flags, mpctx->open_format = talloc_strdup(NULL, mpctx->opts->demuxer_name); mpctx->open_url_flags = url_flags; mpctx->open_for_prefetch = for_prefetch && mpctx->opts->demuxer_thread; + mpctx->demuxer_changed = false; #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION // Don't allow to open local paths or stdin during fuzzing @@ -1208,13 +1209,16 @@ static void open_demux_reentrant(struct MPContext *mpctx) bool failed = done && !mpctx->open_res_demuxer; bool correct_url = strcmp(mpctx->open_url, url) == 0; - if (correct_url && !failed) { + if (correct_url && !mpctx->demuxer_changed && !failed) { MP_VERBOSE(mpctx, "Using prefetched/prefetching URL.\n"); - } else if (correct_url && failed) { - MP_VERBOSE(mpctx, "Prefetched URL failed, retrying.\n"); - cancel_open(mpctx); } else { - if (done) { + if (correct_url && !mpctx->demuxer_changed && failed) { + MP_VERBOSE(mpctx, "Prefetched URL failed, retrying.\n"); + } else if (mpctx->demuxer_changed && done) { + MP_VERBOSE(mpctx, "Dropping finished prefetch because demuxer options changed.\n"); + } else if (mpctx->demuxer_changed) { + MP_VERBOSE(mpctx, "Aborting ongoing prefetch because demuxer options changed.\n"); + } else if (done) { MP_VERBOSE(mpctx, "Dropping finished prefetch of wrong URL.\n"); } else { MP_VERBOSE(mpctx, "Aborting ongoing prefetch of wrong URL.\n");