summaryrefslogtreecommitdiffstats
path: root/libass
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-02-04 22:47:47 +0100
committerwm4 <wm4@nowhere>2016-02-04 22:47:47 +0100
commit9c7f83bafcc9c12842a40f118035f36862c4b840 (patch)
tree719007d732e3a577cdc46101c9f3366db0c2c3d2 /libass
parent99fcf36fda3eeb846861fdf9c8619b224f737311 (diff)
downloadlibass-9c7f83bafcc9c12842a40f118035f36862c4b840.tar.bz2
libass-9c7f83bafcc9c12842a40f118035f36862c4b840.tar.xz
ass: handle movement==0 in ass_step_sub()
Finds the start of the subtitle at "now".
Diffstat (limited to 'libass')
-rw-r--r--libass/ass.c18
1 files changed, 12 insertions, 6 deletions
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;
}