summaryrefslogtreecommitdiffstats
path: root/demux/demux_mkv_timeline.c
diff options
context:
space:
mode:
authorUoti Urpala <uau@glyph.nonexistent.invalid>2016-10-22 18:55:31 +0300
committerwm4 <wm4@nowhere>2016-10-22 18:45:06 +0200
commit18681a7dd26cacac9a9df9aac696d5c4f172b34d (patch)
tree60e584e11f56ca9a61e17188573b577370c43ce3 /demux/demux_mkv_timeline.c
parent3a78eefc88ecb354d1415f43bbf19d57caa31918 (diff)
downloadmpv-18681a7dd26cacac9a9df9aac696d5c4f172b34d.tar.bz2
mpv-18681a7dd26cacac9a9df9aac696d5c4f172b34d.tar.xz
demux_mkv: fix ordered chapter sources with ordered editions
Commit f72a900892 (and others) added support for ordered editions that recursively refer to other ordered editions. However, this recursion code incorrectly activated if the source files had ordered chapters even if the main file only wanted to use them as raw video, resulting in broken timeline info overall. Ordered chapters can specify a ChapterSegmentEditionUID value if they want to use a specific edition from a source file. Otherwise the source is supposed to be used as a raw video file. The code checked demuxer->matroska_data.num_ordered_chapters for an opened source file to see whether it was using a recursive ordered edition, but demux_mkv could enable a default ordered edition for the file using the normal playback rules even if the main file had not specified any ChapterSegmentEditionUID. Thus this incorrectly enabled recursion if a source file had a default edition using ordered chapters. Check demuxer->matroska_data.uid.edition instead, and ensure it's never set if a file is opened without ChapterSegmentEditionUID. Also fix what seems like a memory leak in demux_mkv.c. Signed-off-by: wm4 <wm4@nowhere>
Diffstat (limited to 'demux/demux_mkv_timeline.c')
-rw-r--r--demux/demux_mkv_timeline.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/demux/demux_mkv_timeline.c b/demux/demux_mkv_timeline.c
index 6e18fd2562..15f9a5d594 100644
--- a/demux/demux_mkv_timeline.c
+++ b/demux/demux_mkv_timeline.c
@@ -188,27 +188,31 @@ static bool check_file_seg(struct tl_ctx *ctx, char *filename, int segment)
if (ctx->sources[i])
continue;
/* Accept the source if the segment uid matches and the edition
- * either matches or isn't specified. */
+ * either matches or isn't specified. */
if (!memcmp(uid->segment, m->uid.segment, 16) &&
(!uid->edition || uid->edition == m->uid.edition))
{
MP_INFO(ctx, "Match for source %d: %s\n", i, d->filename);
- for (int j = 0; j < m->num_ordered_chapters; j++) {
- struct matroska_chapter *c = m->ordered_chapters + j;
+ if (!uid->edition) {
+ m->uid.edition = 0;
+ } else {
+ for (int j = 0; j < m->num_ordered_chapters; j++) {
+ struct matroska_chapter *c = m->ordered_chapters + j;
- if (!c->has_segment_uid)
- continue;
+ if (!c->has_segment_uid)
+ continue;
- if (has_source_request(ctx, &c->uid))
- continue;
+ if (has_source_request(ctx, &c->uid))
+ continue;
- /* Set the requested segment. */
- MP_TARRAY_GROW(NULL, ctx->uids, ctx->num_sources);
- ctx->uids[ctx->num_sources] = c->uid;
+ /* Set the requested segment. */
+ MP_TARRAY_GROW(NULL, ctx->uids, ctx->num_sources);
+ ctx->uids[ctx->num_sources] = c->uid;
- /* Add a new source slot. */
- MP_TARRAY_APPEND(NULL, ctx->sources, ctx->num_sources, NULL);
+ /* Add a new source slot. */
+ MP_TARRAY_APPEND(NULL, ctx->sources, ctx->num_sources, NULL);
+ }
}
if (stream_wants_cache(d->stream, ctx->opts->stream_cache)) {
@@ -379,7 +383,7 @@ static void build_timeline_loop(struct tl_ctx *ctx,
/* If we're the source or it's a non-ordered edition reference,
* just add a timeline part from the source. */
- if (current_source == j || !linked_m->num_ordered_chapters) {
+ if (current_source == j || !linked_m->uid.edition) {
uint64_t source_full_length =
demuxer_get_time_length(linked_source) * 1e9;
uint64_t source_length = source_full_length - c->start;