summaryrefslogtreecommitdiffstats
path: root/demux/demux_mkv_timeline.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-01-11 13:52:29 +0100
committerwm4 <wm4@nowhere>2019-09-19 20:37:04 +0200
commita09396ee609af71f49f70521320e87989577b577 (patch)
treef6daf16eb6eefb20e68b4e1458136a38fc9a6c13 /demux/demux_mkv_timeline.c
parent6efcde06e31be4db0b2d9e3958bafffcdaa0a42e (diff)
downloadmpv-a09396ee609af71f49f70521320e87989577b577.tar.bz2
mpv-a09396ee609af71f49f70521320e87989577b577.tar.xz
demux_edl, cue, mkv: clean up timeline stuff slightly
Remove the singly linked list hack, replace it with a slightly more proper data structure. This probably gets rid of a few minor bugs along the way, caused by the awkward nonsensical sharing/duplication of some fields. Another change (because I'm touching everything related to timeline anyway) is that I'm removing the special semantics for parts[num_parts]. This is now strictly out of bounds, and instead of using the start time of the next/beyond-last part, there is an end time field now. Unfortunately, this also requires touching the code for cue and mkv ordered chapters. From some superficial testing, they still seem to mostly work. One observable change is that the "no_chapters" header is per-stream now, which is arguably more correct, and getting the old behavior would require adding code to handle it as special-case, so just adjust ytdl_hook.lua to the new behavior.
Diffstat (limited to 'demux/demux_mkv_timeline.c')
-rw-r--r--demux/demux_mkv_timeline.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/demux/demux_mkv_timeline.c b/demux/demux_mkv_timeline.c
index 1408ddf8f5..6d52995e26 100644
--- a/demux/demux_mkv_timeline.c
+++ b/demux/demux_mkv_timeline.c
@@ -455,12 +455,10 @@ static void build_timeline_loop(struct tl_ctx *ctx,
ctx->missing_time += info->limit - local_starttime;
}
-static void check_track_compatibility(struct timeline *tl)
+static void check_track_compatibility(struct tl_ctx *tl, struct demuxer *mainsrc)
{
- struct demuxer *mainsrc = tl->track_layout;
-
for (int n = 0; n < tl->num_parts; n++) {
- struct timeline_part *p = &tl->parts[n];
+ struct timeline_part *p = &tl->timeline[n];
if (p->source == mainsrc)
continue;
@@ -593,10 +591,11 @@ void build_ordered_chapter_timeline(struct timeline *tl)
MP_TARRAY_APPEND(NULL, ctx->timeline, ctx->num_parts, new);
}
- struct timeline_part new = {
- .start = ctx->start_time / 1e9,
+ for (int n = 0; n < ctx->num_parts; n++) {
+ ctx->timeline[n].end = n == ctx->num_parts - 1
+ ? ctx->start_time / 1e9
+ : ctx->timeline[n + 1].start;
};
- MP_TARRAY_APPEND(NULL, ctx->timeline, ctx->num_parts, new);
/* Ignore anything less than a millisecond when reporting missing time. If
* users really notice less than a millisecond missing, maybe this can be
@@ -606,22 +605,29 @@ void build_ordered_chapter_timeline(struct timeline *tl)
ctx->missing_time / 1e9);
}
- tl->sources = ctx->sources;
- tl->num_sources = ctx->num_sources;
- tl->parts = ctx->timeline;
- tl->num_parts = ctx->num_parts - 1; // minus termination
- tl->chapters = chapters;
- tl->num_chapters = m->num_ordered_chapters;
-
// With Matroska, the "master" file usually dictates track layout etc.,
// except maybe with playlist-like files.
- tl->track_layout = tl->parts[0].source;
- for (int n = 0; n < tl->num_parts; n++) {
- if (tl->parts[n].source == ctx->demuxer) {
- tl->track_layout = ctx->demuxer;
+ struct demuxer *track_layout = ctx->timeline[0].source;
+ for (int n = 0; n < ctx->num_parts; n++) {
+ if (ctx->timeline[n].source == ctx->demuxer) {
+ track_layout = ctx->demuxer;
break;
}
}
- check_track_compatibility(tl);
+ check_track_compatibility(ctx, track_layout);
+
+ tl->sources = ctx->sources;
+ tl->num_sources = ctx->num_sources;
+
+ struct timeline_par *par = talloc_ptrtype(tl, par);
+ *par = (struct timeline_par){
+ .parts = ctx->timeline,
+ .num_parts = ctx->num_parts,
+ .track_layout = track_layout,
+ };
+ MP_TARRAY_APPEND(tl, tl->pars, tl->num_pars, par);
+ tl->chapters = chapters;
+ tl->num_chapters = m->num_ordered_chapters;
+ tl->meta = track_layout;
}