From 92d7dc9e88a1ec94f048f5d4c0edd077a7d9dd7a Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 25 Mar 2014 02:05:48 +0100 Subject: player: remove demuxer chapoter API wrappers Instead, always use the mpctx->chapters array. Before this commit, this array was used only for ordered chapters and such, but now it's always populated if there are chapters. --- player/loadfile.c | 19 +++++++++++++++++++ player/playloop.c | 36 ++++++------------------------------ player/timeline/tl_mpv_edl.c | 12 +++++++++--- 3 files changed, 34 insertions(+), 33 deletions(-) (limited to 'player') diff --git a/player/loadfile.c b/player/loadfile.c index bdea43b352..ea33e46aee 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1002,6 +1002,24 @@ static void print_timeline(struct MPContext *mpctx) } } +static void load_chapters(struct MPContext *mpctx) +{ + if (!mpctx->chapters && mpctx->master_demuxer && + mpctx->master_demuxer->num_chapters) + { + int count = mpctx->master_demuxer->num_chapters; + mpctx->chapters = talloc_array(NULL, struct chapter, count); + mpctx->num_chapters = count; + for (int n = 0; n < count; n++) { + struct demux_chapter *dchapter = &mpctx->master_demuxer->chapters[n]; + mpctx->chapters[n] = (struct chapter){ + .start = dchapter->start / 1e9, + .name = talloc_strdup(mpctx->chapters, dchapter->name), + }; + } + } +} + /* When demux performs a blocking operation (network connection or * cache filling) if the operation fails we use this function to check * if it was interrupted by the user. @@ -1189,6 +1207,7 @@ goto_reopen_demuxer: ; build_cue_timeline(mpctx); print_timeline(mpctx); + load_chapters(mpctx); if (mpctx->timeline) { // With Matroska, the "master" file usually dictates track layout etc. diff --git a/player/playloop.c b/player/playloop.c index 546d2e4cf8..790aeaa3ee 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -509,9 +509,6 @@ int get_current_chapter(struct MPContext *mpctx) break; return MPMAX(mpctx->last_chapter_seek, i - 1); } - if (mpctx->master_demuxer) - return MPMAX(mpctx->last_chapter_seek, - demuxer_get_current_chapter(mpctx->master_demuxer, current_pts)); return -2; } @@ -544,8 +541,6 @@ char *chapter_name(struct MPContext *mpctx, int chapter) return NULL; return talloc_strdup(NULL, mpctx->chapters[chapter].name); } - if (mpctx->master_demuxer) - return demuxer_chapter_name(mpctx->master_demuxer, chapter); return NULL; } @@ -554,20 +549,14 @@ double chapter_start_time(struct MPContext *mpctx, int chapter) { if (chapter == -1) return get_start_time(mpctx); - if (mpctx->chapters) + if (mpctx->chapters && chapter < mpctx->num_chapters) return mpctx->chapters[chapter].start; - if (mpctx->master_demuxer) - return demuxer_chapter_time(mpctx->master_demuxer, chapter); - return -1; + return -1.0; } int get_chapter_count(struct MPContext *mpctx) { - if (mpctx->chapters) - return mpctx->num_chapters; - if (mpctx->master_demuxer) - return demuxer_chapter_count(mpctx->master_demuxer); - return 0; + return mpctx->num_chapters; } // Seek to a given chapter. Queues the seek. @@ -581,23 +570,10 @@ bool mp_seek_chapter(struct MPContext *mpctx, int chapter) mpctx->last_chapter_seek = -2; - double pts; - if (chapter == -1) { - pts = get_start_time(mpctx); - goto do_seek; - } else if (mpctx->chapters) { - pts = mpctx->chapters[chapter].start; - goto do_seek; - } else if (mpctx->master_demuxer) { - int res = demuxer_seek_chapter(mpctx->master_demuxer, chapter, &pts); - if (res >= 0) { - chapter = res; - goto do_seek; - } - } - return false; + double pts = chapter_start_time(mpctx, chapter); + if (pts == -1.0) + return false; -do_seek: queue_seek(mpctx, MPSEEK_ABSOLUTE, pts, 0, true); mpctx->last_chapter_seek = chapter; mpctx->last_chapter_pts = pts; diff --git a/player/timeline/tl_mpv_edl.c b/player/timeline/tl_mpv_edl.c index 94d46e03a5..277db5b87f 100644 --- a/player/timeline/tl_mpv_edl.c +++ b/player/timeline/tl_mpv_edl.c @@ -157,19 +157,25 @@ static struct demuxer *open_source(struct MPContext *mpctx, char *filename) return d; } +static double demuxer_chapter_time(struct demuxer *demuxer, int n) +{ + if (n < 0 || n >= demuxer->num_chapters) + return -1; + return demuxer->chapters[n].start / 1e9; +} + // Append all chapters from src to the chapters array. // Ignore chapters outside of the given time range. static void copy_chapters(struct chapter **chapters, int *num_chapters, struct demuxer *src, double start, double len, double dest_offset) { - int count = demuxer_chapter_count(src); - for (int n = 0; n < count; n++) { + for (int n = 0; n < src->num_chapters; n++) { double time = demuxer_chapter_time(src, n); if (time >= start && time <= start + len) { struct chapter ch = { .start = dest_offset + time - start, - .name = talloc_steal(*chapters, demuxer_chapter_name(src, n)), + .name = talloc_strdup(*chapters, src->chapters[n].name), }; MP_TARRAY_APPEND(NULL, *chapters, *num_chapters, ch); } -- cgit v1.2.3