Skip to content

Commit

Permalink
Update SsaParser logic to show it never returns duration=UNSET
Browse files Browse the repository at this point in the history
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
  • Loading branch information
icbaker authored and oceanjules committed Aug 16, 2023
1 parent d3894e6 commit 9631923
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ public ImmutableList<CuesWithTiming> parse(byte[] data, int offset, int length)
// 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));
}
Expand Down

0 comments on commit 9631923

Please sign in to comment.