From c7269e4e84f4d0a0709a560acbfe2fa3b02a5527 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 27 May 2019 01:46:34 +0200 Subject: player: fix --loop with backward playback Obviously should seek back to the end of the file when it loops. Also remove some minor code duplication around start times. This isn't the correct solution by the way. Rather than hoping we know a reasonable start/end time, this stuff should instruct the demuxer to seek to the exact location. It'll work with 99% of all normal files, but add an appropriate comment (that basically says the function is bullshit) to get_start_time() anyway. --- player/playloop.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'player/playloop.c') diff --git a/player/playloop.c b/player/playloop.c index 4067e13459..30c1bbb5d6 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -488,6 +488,20 @@ double get_time_length(struct MPContext *mpctx) return demuxer && demuxer->duration >= 0 ? demuxer->duration : MP_NOPTS_VALUE; } +// Return approximate PTS of first frame played. This can be completely wrong +// for a number of reasons in a number of situations. +double get_start_time(struct MPContext *mpctx, int dir) +{ + double res = 0; + if (mpctx->demuxer) { + if (!mpctx->opts->rebase_start_time) + res += mpctx->demuxer->start_time; + if (dir < 0) + res += MPMAX(mpctx->demuxer->duration, 0); + } + return res; +} + double get_current_time(struct MPContext *mpctx) { struct demuxer *demuxer = mpctx->demuxer; @@ -827,7 +841,7 @@ static void handle_loop_file(struct MPContext *mpctx) } else if (opts->loop_file) { if (opts->loop_file > 0) opts->loop_file--; - target = 0; + target = get_start_time(mpctx, mpctx->play_dir); } if (target != MP_NOPTS_VALUE) { -- cgit v1.2.3