Commit 13178515 by ibaker Committed by Oliver Woodman

Remove HLS WebVttExtractor from null-checking blacklist

The null-checker wasn't clever enough to understand the while-loop was safe
so I switched it to a for.

PiperOrigin-RevId: 275440464
parent 3150591b
...@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.extractor.PositionHolder; ...@@ -27,6 +27,7 @@ import com.google.android.exoplayer2.extractor.PositionHolder;
import com.google.android.exoplayer2.extractor.SeekMap; import com.google.android.exoplayer2.extractor.SeekMap;
import com.google.android.exoplayer2.extractor.TrackOutput; import com.google.android.exoplayer2.extractor.TrackOutput;
import com.google.android.exoplayer2.text.webvtt.WebvttParserUtil; import com.google.android.exoplayer2.text.webvtt.WebvttParserUtil;
import com.google.android.exoplayer2.util.Assertions;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.ParsableByteArray; import com.google.android.exoplayer2.util.ParsableByteArray;
import com.google.android.exoplayer2.util.TimestampAdjuster; import com.google.android.exoplayer2.util.TimestampAdjuster;
...@@ -34,6 +35,8 @@ import java.io.IOException; ...@@ -34,6 +35,8 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.RequiresNonNull;
/** /**
* A special purpose extractor for WebVTT content in HLS. * A special purpose extractor for WebVTT content in HLS.
...@@ -54,7 +57,7 @@ public final class WebvttExtractor implements Extractor { ...@@ -54,7 +57,7 @@ public final class WebvttExtractor implements Extractor {
private final TimestampAdjuster timestampAdjuster; private final TimestampAdjuster timestampAdjuster;
private final ParsableByteArray sampleDataWrapper; private final ParsableByteArray sampleDataWrapper;
private ExtractorOutput output; private @MonotonicNonNull ExtractorOutput output;
private byte[] sampleData; private byte[] sampleData;
private int sampleSize; private int sampleSize;
...@@ -107,6 +110,8 @@ public final class WebvttExtractor implements Extractor { ...@@ -107,6 +110,8 @@ public final class WebvttExtractor implements Extractor {
@Override @Override
public int read(ExtractorInput input, PositionHolder seekPosition) public int read(ExtractorInput input, PositionHolder seekPosition)
throws IOException, InterruptedException { throws IOException, InterruptedException {
// output == null suggests init() hasn't been called
Assertions.checkNotNull(output);
int currentFileSize = (int) input.getLength(); int currentFileSize = (int) input.getLength();
// Increase the size of sampleData if necessary. // Increase the size of sampleData if necessary.
...@@ -129,6 +134,7 @@ public final class WebvttExtractor implements Extractor { ...@@ -129,6 +134,7 @@ public final class WebvttExtractor implements Extractor {
return Extractor.RESULT_END_OF_INPUT; return Extractor.RESULT_END_OF_INPUT;
} }
@RequiresNonNull("output")
private void processSample() throws ParserException { private void processSample() throws ParserException {
ParsableByteArray webvttData = new ParsableByteArray(sampleData); ParsableByteArray webvttData = new ParsableByteArray(sampleData);
...@@ -140,8 +146,9 @@ public final class WebvttExtractor implements Extractor { ...@@ -140,8 +146,9 @@ public final class WebvttExtractor implements Extractor {
long tsTimestampUs = 0; long tsTimestampUs = 0;
// Parse the remainder of the header looking for X-TIMESTAMP-MAP. // Parse the remainder of the header looking for X-TIMESTAMP-MAP.
String line; for (String line = webvttData.readLine();
while (!TextUtils.isEmpty(line = webvttData.readLine())) { !TextUtils.isEmpty(line);
line = webvttData.readLine()) {
if (line.startsWith("X-TIMESTAMP-MAP")) { if (line.startsWith("X-TIMESTAMP-MAP")) {
Matcher localTimestampMatcher = LOCAL_TIMESTAMP.matcher(line); Matcher localTimestampMatcher = LOCAL_TIMESTAMP.matcher(line);
if (!localTimestampMatcher.find()) { if (!localTimestampMatcher.find()) {
...@@ -176,6 +183,7 @@ public final class WebvttExtractor implements Extractor { ...@@ -176,6 +183,7 @@ public final class WebvttExtractor implements Extractor {
trackOutput.sampleMetadata(sampleTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null); trackOutput.sampleMetadata(sampleTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
} }
@RequiresNonNull("output")
private TrackOutput buildTrackOutput(long subsampleOffsetUs) { private TrackOutput buildTrackOutput(long subsampleOffsetUs) {
TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT); TrackOutput trackOutput = output.track(0, C.TRACK_TYPE_TEXT);
trackOutput.format(Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null, trackOutput.format(Format.createTextSampleFormat(null, MimeTypes.TEXT_VTT, null,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment