From b0c75a1ff99dfbc8ab0e7a932e143da6a2cfc952 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 19 Nov 2013 22:18:56 +0100 Subject: player: select fallback stream in timeline code for better EDL handling The intention of the existing code was trying to match demuxer-reported stream IDs, instead of using possibly arbitrary ordering of the frontend track list. But EDL files can consist of quite different files, for which trying to match the stream IDs doesn't always make sense. --- mpvcore/player/loadfile.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'mpvcore') diff --git a/mpvcore/player/loadfile.c b/mpvcore/player/loadfile.c index f787b5e495..5dd94106dd 100644 --- a/mpvcore/player/loadfile.c +++ b/mpvcore/player/loadfile.c @@ -355,6 +355,23 @@ static void preselect_demux_streams(struct MPContext *mpctx) } } +static struct sh_stream *select_fallback_stream(struct demuxer *d, + enum stream_type type, + int index) +{ + struct sh_stream *best_stream = NULL; + for (int n = 0; n < d->num_streams; n++) { + struct sh_stream *s = d->streams[n]; + if (s->type == type) { + best_stream = s; + if (index == 0) + break; + index -= 1; + } + } + return best_stream; +} + bool timeline_set_part(struct MPContext *mpctx, int i, bool force) { struct timeline_part *p = mpctx->timeline + mpctx->timeline_part; @@ -381,6 +398,12 @@ bool timeline_set_part(struct MPContext *mpctx, int i, bool force) track->stream = demuxer_stream_by_demuxer_id(track->demuxer, track->type, track->demuxer_id); + // EDL can have mismatched files in the same timeline + if (!track->stream) { + track->stream = select_fallback_stream(track->demuxer, + track->type, + track->user_tid - 1); + } } } preselect_demux_streams(mpctx); -- cgit v1.2.3