SubtitleExtractor: mark the limit of the input buffer

Before this change, the SubtitleExtractor did not mark the limit
of the input buffer, thus the SubtitleDecoder attempted to decode
more bytes. If the subtitle file had a new line at the end, this
bug would make the SubtitleDecoder append an line break after the
last subtitle.

PiperOrigin-RevId: 402523039
This commit is contained in:
christosts 2021-10-12 12:00:13 +01:00 committed by Oliver Woodman
parent 8a9dcadef3
commit a56af3d0e0
2 changed files with 2 additions and 1 deletions

View File

@ -212,6 +212,7 @@ public class SubtitleExtractor implements Extractor {
}
inputBuffer.ensureSpaceForWrite(bytesRead);
inputBuffer.data.put(subtitleData.getData(), /* offset= */ 0, bytesRead);
inputBuffer.data.limit(bytesRead);
subtitleDecoder.queueInputBuffer(inputBuffer);
@Nullable SubtitleOutputBuffer outputBuffer = subtitleDecoder.dequeueOutputBuffer();
while (outputBuffer == null) {

View File

@ -44,7 +44,7 @@ public class SubtitleExtractorTest {
+ "This is the second subtitle.\n"
+ "\n"
+ "00:02.600 --> 00:04.567\n"
+ "This is the third subtitle.";
+ "This is the third subtitle.\n";
@Test
public void extractor_outputsCues() throws Exception {