Update SsaParser logic to show it never returns duration=UNSET

In an upcoming change I'm going to mark SSA subtitles as 'merge
replacement behavior', which will mean that
`CuesWithTiming.durationUs=C.TIME_UNSET` will not be permitted. This CL
makes it clear that `SsaParser` obeys that invariant.

PiperOrigin-RevId: 557504633
This commit is contained in:
ibaker 2023-08-16 17:05:37 +01:00 committed by oceanjules
parent d3894e6691
commit 9631923440

View file

@ -139,11 +139,13 @@ public final class SsaParser implements SubtitleParser {
// An empty cue list has already been implicitly encoded in the duration of the previous
// sample (unless there was no previous sample).
continue;
} else if (i == cues.size() - 1) {
// The last cue list must be empty
throw new IllegalStateException();
}
long startTimeUs = startTimesUs.get(i);
// The duration of the last CuesWithTiming is C.TIME_UNSET by design
long durationUs =
i == cues.size() - 1 ? C.TIME_UNSET : startTimesUs.get(i + 1) - startTimesUs.get(i);
// It's safe to inspect element i+1, because we already exited the loop above if i=size()-1.
long durationUs = startTimesUs.get(i + 1) - startTimesUs.get(i);
cuesWithStartTimeAndDuration.add(
new CuesWithTiming(cuesForThisStartTime, startTimeUs, durationUs));
}