summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-02-17 23:46:12 +0100
committerwm4 <wm4@nowhere>2015-02-17 23:46:12 +0100
commita0a089f6a48c2775478b544185a0ddeabf43cce8 (patch)
treed690f3a578fd550b343969aa0e48e61d70dfda46 /player
parent3efeee446e50c0cd4674137a680e6d3660c74a22 (diff)
downloadmpv-a0a089f6a48c2775478b544185a0ddeabf43cce8.tar.bz2
mpv-a0a089f6a48c2775478b544185a0ddeabf43cce8.tar.xz
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.
Diffstat (limited to 'player')
-rw-r--r--player/core.h8
-rw-r--r--player/loadfile.c60
2 files changed, 46 insertions, 22 deletions
diff --git a/player/core.h b/player/core.h
index 5b69541d24..1ac5ac7817 100644
--- a/player/core.h
+++ b/player/core.h
@@ -26,6 +26,7 @@
#include "common/common.h"
#include "options/options.h"
#include "sub/osd.h"
+#include "demux/timeline.h"
// definitions used internally by the core player code
@@ -41,12 +42,6 @@ enum stop_play_reason {
PT_ERROR, // play next playlist entry (due to an error)
};
-struct timeline_part {
- double start;
- double source_start;
- struct demuxer *source;
-};
-
enum mp_osd_seek_info {
OSD_SEEK_INFO_BAR = 1,
OSD_SEEK_INFO_TEXT = 2,
@@ -188,6 +183,7 @@ typedef struct MPContext {
struct demuxer **sources;
int num_sources;
+ struct timeline *tl;
struct timeline_part *timeline;
int num_timeline_parts;
int timeline_part;
diff --git a/player/loadfile.c b/player/loadfile.c
index 72e0d14590..c6b2133e51 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -100,12 +100,19 @@ static void uninit_demuxer(struct MPContext *mpctx)
mpctx->track_layout = NULL;
mpctx->master_demuxer = NULL;
mpctx->demuxer = NULL;
- talloc_free(mpctx->timeline);
- mpctx->timeline = NULL;
- mpctx->num_timeline_parts = 0;
+ if (!mpctx->tl)
+ mpctx->num_timeline_parts = 0;
for (int i = 0; i < mpctx->num_sources; i++)
uninit_stream_sub_decoders(mpctx->sources[i]);
close_unused_demuxers(mpctx);
+ if (mpctx->tl) {
+ timeline_destroy(mpctx->tl);
+ } else {
+ talloc_free(mpctx->timeline);
+ }
+ mpctx->timeline = NULL;
+ mpctx->num_timeline_parts = 0;
+ mpctx->tl = NULL;
if (mpctx->num_sources > 0)
free_demuxer(mpctx->sources[0]);
talloc_free(mpctx->sources);
@@ -975,6 +982,39 @@ static struct demuxer *open_demux_async(struct MPContext *mpctx,
return args.demux;
}
+static void load_timeline(struct MPContext *mpctx)
+{
+ mpctx->track_layout = mpctx->demuxer;
+
+ MP_TARRAY_APPEND(NULL, mpctx->sources, mpctx->num_sources, mpctx->demuxer);
+
+ if (mpctx->demuxer->matroska_data.ordered_chapters)
+ build_ordered_chapter_timeline(mpctx);
+
+ if (mpctx->demuxer->type == DEMUXER_TYPE_EDL)
+ build_mpv_edl_timeline(mpctx);
+
+ if (mpctx->demuxer->type == DEMUXER_TYPE_CUE)
+ build_cue_timeline(mpctx);
+
+ mpctx->tl = timeline_load(mpctx->global, mpctx->log, mpctx->demuxer);
+ if (mpctx->tl) {
+ mpctx->timeline = mpctx->tl->parts;
+ mpctx->num_timeline_parts = mpctx->tl->num_parts;
+ mpctx->num_chapters = mpctx->tl->num_chapters;
+ mpctx->chapters = demux_copy_chapter_data(mpctx->tl->chapters,
+ mpctx->tl->num_chapters);
+ mpctx->track_layout = mpctx->tl->track_layout;
+ mpctx->num_sources = 0;
+ for (int n = 0; n < mpctx->tl->num_sources; n++) {
+ MP_TARRAY_APPEND(NULL, mpctx->sources, mpctx->num_sources,
+ mpctx->tl->sources[n]);
+ }
+ }
+
+ print_timeline(mpctx);
+}
+
// Start playing the current playlist entry.
// Handle initialization and deinitialization.
static void play_current_file(struct MPContext *mpctx)
@@ -1088,7 +1128,7 @@ goto_reopen_demuxer: ;
}
mpctx->master_demuxer = mpctx->demuxer;
- MP_TARRAY_APPEND(NULL, mpctx->sources, mpctx->num_sources, mpctx->demuxer);
+ load_timeline(mpctx);
if (mpctx->demuxer->playlist) {
int entry_stream_flags =
@@ -1103,18 +1143,6 @@ goto_reopen_demuxer: ;
goto terminate_playback;
}
- mpctx->track_layout = mpctx->demuxer;
-
- if (mpctx->demuxer->matroska_data.ordered_chapters)
- build_ordered_chapter_timeline(mpctx);
-
- if (mpctx->demuxer->type == DEMUXER_TYPE_EDL)
- build_mpv_edl_timeline(mpctx);
-
- if (mpctx->demuxer->type == DEMUXER_TYPE_CUE)
- build_cue_timeline(mpctx);
-
- print_timeline(mpctx);
load_chapters(mpctx);
add_demuxer_tracks(mpctx, mpctx->track_layout);