From a0a089f6a48c2775478b544185a0ddeabf43cce8 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 17 Feb 2015 23:46:12 +0100 Subject: player: use a separate context for timeline loader stuff Instead of accessing MPContext in player/timeline/*, create a separate context struct, which the timeline loaders fill out. It turns out that there's not much in the way too big MPContext that these need to access. One major PITA is managing (and closing) the set of open demuxers. The problem is that we need a list of all demuxers to make sure no unneeded streams are enabled. This adds a callback to the demuxer_desc struct, with the intention of leaving to to the demuxer to call the right loader, instead of explicitly checking the demuxer type and dispatching manually in common code. I also considered making the timeline part of the demuxer state, but decided against: it's too much of a mess wrt. memory management and threading, and also doesn't make it clear who owns the child demuxers. With the struct timeline decoupled from the demuxer state, it's at least somewhat clear that the child demuxers are independent from the "main" demuxer. The actual changes to player/timeline/* are separated in the following commits, because they're quite verbose. Some artifacts will be removed later as soon as there's only 1 timeline loading mechanism. --- demux/demux.h | 3 +++ demux/timeline.c | 42 ++++++++++++++++++++++++++++++++++++++++++ demux/timeline.h | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 demux/timeline.c create mode 100644 demux/timeline.h (limited to 'demux') diff --git a/demux/demux.h b/demux/demux.h index acab2db2ba..8098c16e29 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -104,6 +104,7 @@ enum demux_event { #define MAX_SH_STREAMS 256 struct demuxer; +struct timeline; /** * Demuxer description structure @@ -121,6 +122,8 @@ typedef struct demuxer_desc { void (*close)(struct demuxer *demuxer); void (*seek)(struct demuxer *demuxer, double rel_seek_secs, int flags); int (*control)(struct demuxer *demuxer, int cmd, void *arg); + // See timeline.c + void (*load_timeline)(struct timeline *tl); } demuxer_desc_t; typedef struct demux_chapter diff --git a/demux/timeline.c b/demux/timeline.c new file mode 100644 index 0000000000..6274c25fa3 --- /dev/null +++ b/demux/timeline.c @@ -0,0 +1,42 @@ +#include "common/common.h" +#include "stream/stream.h" +#include "demux.h" + +#include "timeline.h" + +struct timeline *timeline_load(struct mpv_global *global, struct mp_log *log, + struct demuxer *demuxer) +{ + if (!demuxer->desc->load_timeline) + return NULL; + + struct timeline *tl = talloc_ptrtype(NULL, tl); + *tl = (struct timeline){ + .global = global, + .log = log, + .demuxer = demuxer, + .track_layout = demuxer, + }; + + demuxer->desc->load_timeline(tl); + + if (tl->num_parts) + return tl; + timeline_destroy(tl); + return NULL; +} + +void timeline_destroy(struct timeline *tl) +{ + if (!tl) + return; + for (int n = 0; n < tl->num_sources; n++) { + struct demuxer *d = tl->sources[n]; + if (d != tl->demuxer) { + struct stream *s = d->stream; + free_demuxer(d); + free_stream(s); + } + } + talloc_free(tl); +} diff --git a/demux/timeline.h b/demux/timeline.h new file mode 100644 index 0000000000..e4d6f67953 --- /dev/null +++ b/demux/timeline.h @@ -0,0 +1,37 @@ +#ifndef MP_TIMELINE_H_ +#define MP_TIMELINE_H_ + +struct timeline_part { + double start; + double source_start; + struct demuxer *source; +}; + +struct timeline { + struct mpv_global *global; + struct mp_log *log; + + // main source + struct demuxer *demuxer; + + // All referenced files. The source file must be at sources[0]. + struct demuxer **sources; + int num_sources; + + // Segments to play, ordered by time. parts[num_parts] must be valid; its + // start field sets the duration, and source must be NULL. + struct timeline_part *parts; + int num_parts; + + struct demux_chapter *chapters; + int num_chapters; + + // Which source defines the overall track list (over the full timeline). + struct demuxer *track_layout; +}; + +struct timeline *timeline_load(struct mpv_global *global, struct mp_log *log, + struct demuxer *demuxer); +void timeline_destroy(struct timeline *tl); + +#endif -- cgit v1.2.3