From 47345219a342eeec822583110553ae41884b7f8f Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 8 Oct 2013 00:33:42 -0400 Subject: matroska: avoid requesting the same source multiple times --- mpvcore/timeline/tl_matroska.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mpvcore/timeline/tl_matroska.c b/mpvcore/timeline/tl_matroska.c index b4af848fa9..8ff5ae2074 100644 --- a/mpvcore/timeline/tl_matroska.c +++ b/mpvcore/timeline/tl_matroska.c @@ -148,6 +148,18 @@ static int enable_cache(struct MPContext *mpctx, struct stream **stream, return 1; } +static bool has_source_request(struct matroska_segment_uid *uids, + int num_sources, + struct matroska_segment_uid *new_uid) +{ + for (int i = 0; i < num_sources; ++i) { + if (demux_matroska_uid_cmp(uids + i, new_uid)) + return true; + } + + return false; +} + // segment = get Nth segment of a multi-segment file static bool check_file_seg(struct MPContext *mpctx, struct demuxer ***sources, int *num_sources, struct matroska_segment_uid **uids, @@ -192,6 +204,9 @@ static bool check_file_seg(struct MPContext *mpctx, struct demuxer ***sources, if (!c->has_segment_uid) continue; + if (has_source_request(*uids, *num_sources, &c->uid)) + continue; + /* Set the requested segment. */ MP_TARRAY_GROW(NULL, *uids, *num_sources); memcpy((*uids) + *num_sources, &c->uid, sizeof(c->uid)); @@ -446,6 +461,9 @@ void build_ordered_chapter_timeline(struct MPContext *mpctx) if (!c->has_segment_uid || demux_matroska_uid_cmp(&c->uid, &m->uid)) continue; + if (has_source_request(uids, num_sources, &c->uid)) + continue; + memcpy(uids + num_sources, &c->uid, sizeof(c->uid)); sources[num_sources] = NULL; num_sources++; -- cgit v1.2.3