From 0da9ee79e768dfb12e2eeabf5115642f1fb9da32 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 28 Oct 2014 15:28:46 +0100 Subject: [PATCH] demux: seek to position 0 when loading, instead of restoring it This was originally done for DVD/BD/DVB, where the start position could be something different from 0, and seeking back to 0 would mess it up completely. Since we're not quite sure that these streams are unseekable, we can simplify this somewhat, and also make sure we also start at 0 for normal files. Helps a little bit with the following edition reloading commit. --- demux/demux.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/demux/demux.c b/demux/demux.c index a24082a7da..01c03026f7 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -844,13 +844,18 @@ static struct demuxer *open_given_type(struct mpv_global *global, in->d_user->metadata = talloc_zero(in->d_user, struct mp_tags); in->d_buffer->metadata = talloc_zero(in->d_buffer, struct mp_tags); - int64_t start_pos = stream_tell(stream); - mp_verbose(log, "Trying demuxer: %s (force-level: %s)\n", desc->name, d_level(check)); in->d_thread->params = params; // temporary during open() + if (stream->seekable) // not for DVD/BD/DVB in particular + stream_seek(stream, 0); + + // Peek this much data to avoid that stream_read() run by some demuxers + // or stream filters will flush previous peeked data. + stream_peek(stream, STREAM_BUFFER_SIZE); + int ret = demuxer->desc->open(in->d_thread, check); if (ret >= 0) { in->d_thread->params = NULL; @@ -873,7 +878,6 @@ static struct demuxer *open_given_type(struct mpv_global *global, } free_demuxer(demuxer); - stream_seek(stream, start_pos); return NULL; } @@ -909,10 +913,6 @@ struct demuxer *demux_open(struct stream *stream, char *force_format, } } - // Peek this much data to avoid that stream_read() run by some demuxers - // or stream filters will flush previous peeked data. - stream_peek(stream, STREAM_BUFFER_SIZE); - // Test demuxers from first to last, one pass for each check_levels[] entry for (int pass = 0; check_levels[pass] != -1; pass++) { enum demux_check level = check_levels[pass];