Commit e10a78e6 by olly Committed by Oliver Woodman

Add NonNull annotations to text packages

PiperOrigin-RevId: 283951181
parent cab05cb7
...@@ -333,7 +333,7 @@ public class Cue { ...@@ -333,7 +333,7 @@ public class Cue {
*/ */
public Cue( public Cue(
CharSequence text, CharSequence text,
Alignment textAlignment, @Nullable Alignment textAlignment,
float line, float line,
@LineType int lineType, @LineType int lineType,
@AnchorType int lineAnchor, @AnchorType int lineAnchor,
......
...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.text; ...@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.text;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.decoder.SimpleDecoder; import com.google.android.exoplayer2.decoder.SimpleDecoder;
import com.google.android.exoplayer2.util.Assertions;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
/** /**
...@@ -29,9 +30,8 @@ public abstract class SimpleSubtitleDecoder extends ...@@ -29,9 +30,8 @@ public abstract class SimpleSubtitleDecoder extends
private final String name; private final String name;
/** /** @param name The name of the decoder. */
* @param name The name of the decoder. @SuppressWarnings("initialization:method.invocation.invalid")
*/
protected SimpleSubtitleDecoder(String name) { protected SimpleSubtitleDecoder(String name) {
super(new SubtitleInputBuffer[2], new SubtitleOutputBuffer[2]); super(new SubtitleInputBuffer[2], new SubtitleOutputBuffer[2]);
this.name = name; this.name = name;
...@@ -74,7 +74,7 @@ public abstract class SimpleSubtitleDecoder extends ...@@ -74,7 +74,7 @@ public abstract class SimpleSubtitleDecoder extends
protected final SubtitleDecoderException decode( protected final SubtitleDecoderException decode(
SubtitleInputBuffer inputBuffer, SubtitleOutputBuffer outputBuffer, boolean reset) { SubtitleInputBuffer inputBuffer, SubtitleOutputBuffer outputBuffer, boolean reset) {
try { try {
ByteBuffer inputData = inputBuffer.data; ByteBuffer inputData = Assertions.checkNotNull(inputBuffer.data);
Subtitle subtitle = decode(inputData.array(), inputData.limit(), reset); Subtitle subtitle = decode(inputData.array(), inputData.limit(), reset);
outputBuffer.setContent(inputBuffer.timeUs, subtitle, inputBuffer.subsampleOffsetUs); outputBuffer.setContent(inputBuffer.timeUs, subtitle, inputBuffer.subsampleOffsetUs);
// Clear BUFFER_FLAG_DECODE_ONLY (see [Internal: b/27893809]). // Clear BUFFER_FLAG_DECODE_ONLY (see [Internal: b/27893809]).
......
...@@ -80,11 +80,11 @@ public final class TextRenderer extends BaseRenderer implements Callback { ...@@ -80,11 +80,11 @@ public final class TextRenderer extends BaseRenderer implements Callback {
private boolean inputStreamEnded; private boolean inputStreamEnded;
private boolean outputStreamEnded; private boolean outputStreamEnded;
@ReplacementState private int decoderReplacementState; @ReplacementState private int decoderReplacementState;
private Format streamFormat; @Nullable private Format streamFormat;
private SubtitleDecoder decoder; @Nullable private SubtitleDecoder decoder;
private SubtitleInputBuffer nextInputBuffer; @Nullable private SubtitleInputBuffer nextInputBuffer;
private SubtitleOutputBuffer subtitle; @Nullable private SubtitleOutputBuffer subtitle;
private SubtitleOutputBuffer nextSubtitle; @Nullable private SubtitleOutputBuffer nextSubtitle;
private int nextSubtitleEventIndex; private int nextSubtitleEventIndex;
/** /**
...@@ -132,7 +132,7 @@ public final class TextRenderer extends BaseRenderer implements Callback { ...@@ -132,7 +132,7 @@ public final class TextRenderer extends BaseRenderer implements Callback {
} }
@Override @Override
protected void onStreamChanged(Format[] formats, long offsetUs) throws ExoPlaybackException { protected void onStreamChanged(Format[] formats, long offsetUs) {
streamFormat = formats[0]; streamFormat = formats[0];
if (decoder != null) { if (decoder != null) {
decoderReplacementState = REPLACEMENT_STATE_SIGNAL_END_OF_STREAM; decoderReplacementState = REPLACEMENT_STATE_SIGNAL_END_OF_STREAM;
......
...@@ -25,11 +25,6 @@ import com.google.android.exoplayer2.text.Cue; ...@@ -25,11 +25,6 @@ import com.google.android.exoplayer2.text.Cue;
/* package */ final class Cea708Cue extends Cue implements Comparable<Cea708Cue> { /* package */ final class Cea708Cue extends Cue implements Comparable<Cea708Cue> {
/** /**
* An unset priority.
*/
public static final int PRIORITY_UNSET = -1;
/**
* The priority of the cue box. * The priority of the cue box.
*/ */
public final int priority; public final int priority;
...@@ -64,5 +59,4 @@ import com.google.android.exoplayer2.text.Cue; ...@@ -64,5 +59,4 @@ import com.google.android.exoplayer2.text.Cue;
} }
return 0; return 0;
} }
} }
...@@ -25,6 +25,7 @@ import android.text.style.BackgroundColorSpan; ...@@ -25,6 +25,7 @@ import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan; import android.text.style.StyleSpan;
import android.text.style.UnderlineSpan; import android.text.style.UnderlineSpan;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.text.Cue; import com.google.android.exoplayer2.text.Cue;
...@@ -152,7 +153,8 @@ public final class Cea708Decoder extends CeaDecoder { ...@@ -152,7 +153,8 @@ public final class Cea708Decoder extends CeaDecoder {
private DtvCcPacket currentDtvCcPacket; private DtvCcPacket currentDtvCcPacket;
private int currentWindow; private int currentWindow;
public Cea708Decoder(int accessibilityChannel, List<byte[]> initializationData) { // TODO: Retrieve isWideAspectRatio from initializationData and use it.
public Cea708Decoder(int accessibilityChannel, @Nullable List<byte[]> initializationData) {
ccData = new ParsableByteArray(); ccData = new ParsableByteArray();
serviceBlockPacket = new ParsableBitArray(); serviceBlockPacket = new ParsableBitArray();
selectedServiceNumber = accessibilityChannel == Format.NO_VALUE ? 1 : accessibilityChannel; selectedServiceNumber = accessibilityChannel == Format.NO_VALUE ? 1 : accessibilityChannel;
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.text.cea;
import com.google.android.exoplayer2.util.NonNullApi;
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.text.dvb;
import com.google.android.exoplayer2.util.NonNullApi;
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.text;
import com.google.android.exoplayer2.util.NonNullApi;
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
*/ */
package com.google.android.exoplayer2.text.ssa; package com.google.android.exoplayer2.text.ssa;
import static com.google.android.exoplayer2.util.Util.castNonNull;
import android.text.Layout; import android.text.Layout;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
...@@ -115,7 +117,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -115,7 +117,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
* @param data A {@link ParsableByteArray} from which the header should be read. * @param data A {@link ParsableByteArray} from which the header should be read.
*/ */
private void parseHeader(ParsableByteArray data) { private void parseHeader(ParsableByteArray data) {
String currentLine; @Nullable String currentLine;
while ((currentLine = data.readLine()) != null) { while ((currentLine = data.readLine()) != null) {
if ("[Script Info]".equalsIgnoreCase(currentLine)) { if ("[Script Info]".equalsIgnoreCase(currentLine)) {
parseScriptInfo(data); parseScriptInfo(data);
...@@ -140,7 +142,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -140,7 +142,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
* set to the beginning of of the first line after {@code [Script Info]}. * set to the beginning of of the first line after {@code [Script Info]}.
*/ */
private void parseScriptInfo(ParsableByteArray data) { private void parseScriptInfo(ParsableByteArray data) {
String currentLine; @Nullable String currentLine;
while ((currentLine = data.readLine()) != null while ((currentLine = data.readLine()) != null
&& (data.bytesLeft() == 0 || data.peekUnsignedByte() != '[')) { && (data.bytesLeft() == 0 || data.peekUnsignedByte() != '[')) {
String[] infoNameAndValue = currentLine.split(":"); String[] infoNameAndValue = currentLine.split(":");
...@@ -176,9 +178,9 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -176,9 +178,9 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
* at the beginning of of the first line after {@code [V4+ Styles]}. * at the beginning of of the first line after {@code [V4+ Styles]}.
*/ */
private static Map<String, SsaStyle> parseStyles(ParsableByteArray data) { private static Map<String, SsaStyle> parseStyles(ParsableByteArray data) {
SsaStyle.Format formatInfo = null;
Map<String, SsaStyle> styles = new LinkedHashMap<>(); Map<String, SsaStyle> styles = new LinkedHashMap<>();
String currentLine; @Nullable SsaStyle.Format formatInfo = null;
@Nullable String currentLine;
while ((currentLine = data.readLine()) != null while ((currentLine = data.readLine()) != null
&& (data.bytesLeft() == 0 || data.peekUnsignedByte() != '[')) { && (data.bytesLeft() == 0 || data.peekUnsignedByte() != '[')) {
if (currentLine.startsWith(FORMAT_LINE_PREFIX)) { if (currentLine.startsWith(FORMAT_LINE_PREFIX)) {
...@@ -188,7 +190,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -188,7 +190,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
Log.w(TAG, "Skipping 'Style:' line before 'Format:' line: " + currentLine); Log.w(TAG, "Skipping 'Style:' line before 'Format:' line: " + currentLine);
continue; continue;
} }
SsaStyle style = SsaStyle.fromStyleLine(currentLine, formatInfo); @Nullable SsaStyle style = SsaStyle.fromStyleLine(currentLine, formatInfo);
if (style != null) { if (style != null) {
styles.put(style.name, style); styles.put(style.name, style);
} }
...@@ -205,8 +207,9 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -205,8 +207,9 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
* @param cueTimesUs A sorted list to which parsed cue timestamps will be added. * @param cueTimesUs A sorted list to which parsed cue timestamps will be added.
*/ */
private void parseEventBody(ParsableByteArray data, List<List<Cue>> cues, List<Long> cueTimesUs) { private void parseEventBody(ParsableByteArray data, List<List<Cue>> cues, List<Long> cueTimesUs) {
@Nullable
SsaDialogueFormat format = haveInitializationData ? dialogueFormatFromInitializationData : null; SsaDialogueFormat format = haveInitializationData ? dialogueFormatFromInitializationData : null;
String currentLine; @Nullable String currentLine;
while ((currentLine = data.readLine()) != null) { while ((currentLine = data.readLine()) != null) {
if (currentLine.startsWith(FORMAT_LINE_PREFIX)) { if (currentLine.startsWith(FORMAT_LINE_PREFIX)) {
format = SsaDialogueFormat.fromFormatLine(currentLine); format = SsaDialogueFormat.fromFormatLine(currentLine);
...@@ -250,6 +253,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -250,6 +253,7 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
return; return;
} }
@Nullable
SsaStyle style = SsaStyle style =
styles != null && format.styleIndex != C.INDEX_UNSET styles != null && format.styleIndex != C.INDEX_UNSET
? styles.get(lineValues[format.styleIndex].trim()) ? styles.get(lineValues[format.styleIndex].trim())
...@@ -281,10 +285,11 @@ public final class SsaDecoder extends SimpleSubtitleDecoder { ...@@ -281,10 +285,11 @@ public final class SsaDecoder extends SimpleSubtitleDecoder {
if (!matcher.matches()) { if (!matcher.matches()) {
return C.TIME_UNSET; return C.TIME_UNSET;
} }
long timestampUs = Long.parseLong(matcher.group(1)) * 60 * 60 * C.MICROS_PER_SECOND; long timestampUs =
timestampUs += Long.parseLong(matcher.group(2)) * 60 * C.MICROS_PER_SECOND; Long.parseLong(castNonNull(matcher.group(1))) * 60 * 60 * C.MICROS_PER_SECOND;
timestampUs += Long.parseLong(matcher.group(3)) * C.MICROS_PER_SECOND; timestampUs += Long.parseLong(castNonNull(matcher.group(2))) * 60 * C.MICROS_PER_SECOND;
timestampUs += Long.parseLong(matcher.group(4)) * 10000; // 100ths of a second. timestampUs += Long.parseLong(castNonNull(matcher.group(3))) * C.MICROS_PER_SECOND;
timestampUs += Long.parseLong(castNonNull(matcher.group(4))) * 10000; // 100ths of a second.
return timestampUs; return timestampUs;
} }
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.text.ssa;
import com.google.android.exoplayer2.util.NonNullApi;
...@@ -73,8 +73,8 @@ public final class SubripDecoder extends SimpleSubtitleDecoder { ...@@ -73,8 +73,8 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
ArrayList<Cue> cues = new ArrayList<>(); ArrayList<Cue> cues = new ArrayList<>();
LongArray cueTimesUs = new LongArray(); LongArray cueTimesUs = new LongArray();
ParsableByteArray subripData = new ParsableByteArray(bytes, length); ParsableByteArray subripData = new ParsableByteArray(bytes, length);
String currentLine;
@Nullable String currentLine;
while ((currentLine = subripData.readLine()) != null) { while ((currentLine = subripData.readLine()) != null) {
if (currentLine.length() == 0) { if (currentLine.length() == 0) {
// Skip blank lines. // Skip blank lines.
...@@ -119,7 +119,7 @@ public final class SubripDecoder extends SimpleSubtitleDecoder { ...@@ -119,7 +119,7 @@ public final class SubripDecoder extends SimpleSubtitleDecoder {
Spanned text = Html.fromHtml(textBuilder.toString()); Spanned text = Html.fromHtml(textBuilder.toString());
String alignmentTag = null; @Nullable String alignmentTag = null;
for (int i = 0; i < tags.size(); i++) { for (int i = 0; i < tags.size(); i++) {
String tag = tags.get(i); String tag = tags.get(i);
if (tag.matches(SUBRIP_ALIGNMENT_TAG)) { if (tag.matches(SUBRIP_ALIGNMENT_TAG)) {
......
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package com.google.android.exoplayer2.text.ttml;
import com.google.android.exoplayer2.util.NonNullApi;
...@@ -220,7 +220,7 @@ public final class WebvttCssStyle { ...@@ -220,7 +220,7 @@ public final class WebvttCssStyle {
return fontFamily; return fontFamily;
} }
public WebvttCssStyle setFontFamily(String fontFamily) { public WebvttCssStyle setFontFamily(@Nullable String fontFamily) {
this.fontFamily = Util.toLowerInvariant(fontFamily); this.fontFamily = Util.toLowerInvariant(fontFamily);
return this; return this;
} }
...@@ -264,7 +264,7 @@ public final class WebvttCssStyle { ...@@ -264,7 +264,7 @@ public final class WebvttCssStyle {
return textAlign; return textAlign;
} }
public WebvttCssStyle setTextAlign(Layout.Alignment textAlign) { public WebvttCssStyle setTextAlign(@Nullable Layout.Alignment textAlign) {
this.textAlign = textAlign; this.textAlign = textAlign;
return this; return this;
} }
......
...@@ -26,9 +26,7 @@ import com.google.android.exoplayer2.util.Log; ...@@ -26,9 +26,7 @@ import com.google.android.exoplayer2.util.Log;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
/** /** A representation of a WebVTT cue. */
* A representation of a WebVTT cue.
*/
public final class WebvttCue extends Cue { public final class WebvttCue extends Cue {
private static final float DEFAULT_POSITION = 0.5f; private static final float DEFAULT_POSITION = 0.5f;
......
...@@ -44,9 +44,7 @@ import java.util.List; ...@@ -44,9 +44,7 @@ import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /** Parser for WebVTT cues. (https://w3c.github.io/webvtt/#cues) */
* Parser for WebVTT cues. (https://w3c.github.io/webvtt/#cues)
*/
public final class WebvttCueParser { public final class WebvttCueParser {
public static final Pattern CUE_HEADER_PATTERN = Pattern public static final Pattern CUE_HEADER_PATTERN = Pattern
...@@ -94,7 +92,7 @@ public final class WebvttCueParser { ...@@ -94,7 +92,7 @@ public final class WebvttCueParser {
*/ */
public boolean parseCue( public boolean parseCue(
ParsableByteArray webvttData, WebvttCue.Builder builder, List<WebvttCssStyle> styles) { ParsableByteArray webvttData, WebvttCue.Builder builder, List<WebvttCssStyle> styles) {
String firstLine = webvttData.readLine(); @Nullable String firstLine = webvttData.readLine();
if (firstLine == null) { if (firstLine == null) {
return false; return false;
} }
...@@ -104,7 +102,7 @@ public final class WebvttCueParser { ...@@ -104,7 +102,7 @@ public final class WebvttCueParser {
return parseCue(null, cueHeaderMatcher, webvttData, builder, textBuilder, styles); return parseCue(null, cueHeaderMatcher, webvttData, builder, textBuilder, styles);
} }
// The first line is not the timestamps, but could be the cue id. // The first line is not the timestamps, but could be the cue id.
String secondLine = webvttData.readLine(); @Nullable String secondLine = webvttData.readLine();
if (secondLine == null) { if (secondLine == null) {
return false; return false;
} }
......
...@@ -52,7 +52,7 @@ public final class WebvttParserUtil { ...@@ -52,7 +52,7 @@ public final class WebvttParserUtil {
* @param input The input from which the line should be read. * @param input The input from which the line should be read.
*/ */
public static boolean isWebvttHeaderLine(ParsableByteArray input) { public static boolean isWebvttHeaderLine(ParsableByteArray input) {
String line = input.readLine(); @Nullable String line = input.readLine();
return line != null && line.startsWith(WEBVTT_HEADER); return line != null && line.startsWith(WEBVTT_HEADER);
} }
...@@ -101,7 +101,7 @@ public final class WebvttParserUtil { ...@@ -101,7 +101,7 @@ public final class WebvttParserUtil {
*/ */
@Nullable @Nullable
public static Matcher findNextCueHeader(ParsableByteArray input) { public static Matcher findNextCueHeader(ParsableByteArray input) {
String line; @Nullable String line;
while ((line = input.readLine()) != null) { while ((line = input.readLine()) != null) {
if (COMMENT.matcher(line).matches()) { if (COMMENT.matcher(line).matches()) {
// Skip until the end of the comment block. // Skip until the end of the comment block.
......
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