1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-16 20:27:23 +00:00

matroska: avoid requesting the same source multiple times

This commit is contained in:
Ben Boeckel 2013-10-08 00:33:42 -04:00
parent f72a900892
commit 47345219a3

View File

@ -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++;