From 155f7fac9dd8d756656a05376da9495e1348daad Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 4 Feb 2016 22:44:18 +0100 Subject: sub: implement "sub-seek 0" For bitmap subs, implement it properly. For libass, you need newest git master. Fixes #2791. --- sub/sd_lavc.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'sub') diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 2da69e937e..4fbabaf864 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -398,15 +398,15 @@ static double step_sub(struct sd *sd, double now, int movement) struct sd_lavc_priv *priv = sd->priv; int best = -1; double target = now; - int direction = movement > 0 ? 1 : -1; + int direction = (movement > 0 ? 1 : -1) * !!movement; - if (movement == 0 || priv->num_seekpoints == 0) + if (priv->num_seekpoints == 0) return MP_NOPTS_VALUE; qsort(priv->seekpoints, priv->num_seekpoints, sizeof(priv->seekpoints[0]), compare_seekpoint); - while (movement) { + do { int closest = -1; double closest_time = 0; for (int i = 0; i < priv->num_seekpoints; i++) { @@ -420,13 +420,20 @@ static double step_sub(struct sd *sd, double now, int movement) closest_time = end; } } - } else { + } else if (direction > 0) { if (start > target) { if (closest < 0 || start < closest_time) { closest = i; closest_time = start; } } + } else { + if (start < target) { + if (closest < 0 || start >= closest_time) { + closest = i; + closest_time = start; + } + } } } if (closest < 0) @@ -434,7 +441,7 @@ static double step_sub(struct sd *sd, double now, int movement) target = closest_time + direction; best = closest; movement -= direction; - } + } while (movement); return best < 0 ? 0 : priv->seekpoints[best].pts - now; } -- cgit v1.2.3