summaryrefslogtreecommitdiffstats
path: root/player/misc.c
diff options
context:
space:
mode:
authorLeo Izen <leo.izen@gmail.com>2017-12-03 22:19:16 -0500
committerLeo Izen <leo.izen@gmail.com>2017-12-03 22:23:24 -0500
commitff7e2946103ce35da702e57e03012c29215017d2 (patch)
treecb13071a68dbd3609b44d205964a65e7e4386783 /player/misc.c
parenta6ca1677941b817cce401eb4d75f9c049b789b55 (diff)
downloadmpv-ff7e2946103ce35da702e57e03012c29215017d2.tar.bz2
mpv-ff7e2946103ce35da702e57e03012c29215017d2.tar.xz
player: use start timestamp for ab-looping if --ab-loop-a is absent
If --ab-loop-b is present, then ab-looping will be enabled and will attempt to seek to the beginning of the file. This patch changes it so it will instead seek to the start of playback, either via --start or some equivalent, rather than always to the beginning of the file.
Diffstat (limited to 'player/misc.c')
-rw-r--r--player/misc.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/player/misc.c b/player/misc.c
index 9ca1ea9750..d68ca22138 100644
--- a/player/misc.c
+++ b/player/misc.c
@@ -104,8 +104,11 @@ double get_play_end_pts(struct MPContext *mpctx)
if (cend != MP_NOPTS_VALUE && (end == MP_NOPTS_VALUE || cend < end))
end = cend;
}
+ // even though MP_NOPTS_VALUE is currently negative
+ // it doesn't necessarily have to remain that way
+ double ab_loop_start_time = get_ab_loop_start_time(mpctx);
if (mpctx->ab_loop_clip && opts->ab_loop[1] != MP_NOPTS_VALUE &&
- opts->ab_loop[1] > opts->ab_loop[0])
+ (ab_loop_start_time == MP_NOPTS_VALUE || opts->ab_loop[1] > ab_loop_start_time))
{
if (end == MP_NOPTS_VALUE || end > opts->ab_loop[1])
end = opts->ab_loop[1];
@@ -145,6 +148,32 @@ double get_play_start_pts(struct MPContext *mpctx)
return play_start_pts;
}
+/**
+ * Get the time that an ab-loop seek should seek to.
+ * The order of priority is as follows:
+ * 1. --ab-loop-a, if set.
+ * 2. The Playback Start PTS, if set.
+ * 3. MP_NOPTS_VALUE.
+ * If unspecified, return MP_NOPTS_VALUE.
+ * Does not return zero unless the start time is explicitly set to zero.
+ */
+double get_ab_loop_start_time(struct MPContext *mpctx)
+{
+ struct MPOpts *opts = mpctx->opts;
+ double ab_loop_start_time;
+ if (opts->ab_loop[0] != MP_NOPTS_VALUE) {
+ ab_loop_start_time = opts->ab_loop[0];
+ } else {
+ /*
+ * There is no check for MP_NOPTS_VALUE here
+ * because that's exactly what we want to return
+ * if get_play_start_pts comes up empty here.
+ */
+ ab_loop_start_time = get_play_start_pts(mpctx);
+ }
+ return ab_loop_start_time;
+}
+
double get_track_seek_offset(struct MPContext *mpctx, struct track *track)
{
struct MPOpts *opts = mpctx->opts;