From 6c2cd08afffa6d4fe5c16144b0c883f6997d0399 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 25 Mar 2014 02:27:22 +0100 Subject: [PATCH] player: handle chapter range like --start/--end Instead of comparing the current chapter every time, set the playback end timestamp to the chapter end. Likewise, don't execute an extra seek for the start chapter. Maybe we could also use the timeline facility to restrict playback to the given chapter range, but this would be strange when using --chapter=N to start playback at a given chapter. Then you couldn't seek back, which is possibly not what the user wants. --- player/loadfile.c | 10 +++++----- player/playloop.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/player/loadfile.c b/player/loadfile.c index ea33e46aee..948142fb45 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1335,17 +1335,17 @@ goto_reopen_demuxer: ; if (startpos == -1 && mpctx->resolve_result && mpctx->resolve_result->start_time > 0) startpos = mpctx->resolve_result->start_time; + if (startpos == -1 && opts->chapterrange[0] > 0) { + double start = chapter_start_time(mpctx, opts->chapterrange[0] - 1); + if (start != MP_NOPTS_VALUE) + startpos = start; + } if (startpos == -1 && mpctx->timeline) startpos = 0; if (startpos != -1) { queue_seek(mpctx, MPSEEK_ABSOLUTE, startpos, 0, true); execute_queued_seek(mpctx); } - if (opts->chapterrange[0] > 0) { - if (mp_seek_chapter(mpctx, opts->chapterrange[0] - 1)) - execute_queued_seek(mpctx); - } - get_relative_time(mpctx); // reset current delta if (mpctx->opts->pause) diff --git a/player/playloop.c b/player/playloop.c index 6121c7367c..bbcc9a3df7 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -947,9 +947,9 @@ void run_playloop(struct MPContext *mpctx) } if (opts->chapterrange[1] > 0) { - int cur_chapter = get_current_chapter(mpctx); - if (cur_chapter != -1 && cur_chapter + 1 > opts->chapterrange[1]) - mpctx->stop_play = PT_NEXT_ENTRY; + double end = chapter_start_time(mpctx, opts->chapterrange[1]); + if (end != MP_NOPTS_VALUE && (endpts == MP_NOPTS_VALUE || end < endpts)) + endpts = end; } if (mpctx->d_audio && !mpctx->restart_playback && !ao_untimed(mpctx->ao)) {