From 9c7f83bafcc9c12842a40f118035f36862c4b840 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 4 Feb 2016 22:47:47 +0100 Subject: ass: handle movement==0 in ass_step_sub() Finds the start of the subtitle at "now". --- libass/ass.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'libass') diff --git a/libass/ass.c b/libass/ass.c index 14264dc..dda61c5 100644 --- a/libass/ass.c +++ b/libass/ass.c @@ -1288,14 +1288,12 @@ long long ass_step_sub(ASS_Track *track, long long now, int movement) int i; ASS_Event *best = NULL; long long target = now; - int direction = movement > 0 ? 1 : -1; + int direction = (movement > 0 ? 1 : -1) * !!movement; - if (movement == 0) - return 0; if (track->n_events == 0) return 0; - while (movement) { + do { ASS_Event *closest = NULL; long long closest_time = now; for (i = 0; i < track->n_events; i++) { @@ -1308,7 +1306,7 @@ long long ass_step_sub(ASS_Track *track, long long now, int movement) closest_time = end; } } - } else { + } else if (direction > 0) { long long start = track->events[i].Start; if (start > target) { if (!closest || start < closest_time) { @@ -1316,13 +1314,21 @@ long long ass_step_sub(ASS_Track *track, long long now, int movement) closest_time = start; } } + } else { + long long start = track->events[i].Start; + if (start < target) { + if (!closest || start >= closest_time) { + closest = &track->events[i]; + closest_time = start; + } + } } } target = closest_time + direction; movement -= direction; if (closest) best = closest; - } + } while (movement); return best ? best->Start - now : 0; } -- cgit v1.2.3