Skip to content

Commit

Permalink
Enable nullness checks for the text package
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 322539147
  • Loading branch information
icbaker authored and ojw28 committed Jul 24, 2020
1 parent 1c6aaac commit 0efec5f
Showing 1 changed file with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ protected void onPositionReset(long positionUs, boolean joining) {
replaceDecoder();
} else {
releaseBuffers();
decoder.flush();
Assertions.checkNotNull(decoder).flush();
}
}

Expand All @@ -170,9 +170,9 @@ public void render(long positionUs, long elapsedRealtimeUs) {
}

if (nextSubtitle == null) {
decoder.setPositionUs(positionUs);
Assertions.checkNotNull(decoder).setPositionUs(positionUs);
try {
nextSubtitle = decoder.dequeueOutputBuffer();
nextSubtitle = Assertions.checkNotNull(decoder).dequeueOutputBuffer();
} catch (SubtitleDecoderException e) {
handleDecoderError(e);
return;
Expand All @@ -194,8 +194,8 @@ public void render(long positionUs, long elapsedRealtimeUs) {
textRendererNeedsUpdate = true;
}
}

if (nextSubtitle != null) {
SubtitleOutputBuffer nextSubtitle = this.nextSubtitle;
if (nextSubtitle.isEndOfStream()) {
if (!textRendererNeedsUpdate && getNextEventTime() == Long.MAX_VALUE) {
if (decoderReplacementState == REPLACEMENT_STATE_WAIT_END_OF_STREAM) {
Expand All @@ -210,14 +210,16 @@ public void render(long positionUs, long elapsedRealtimeUs) {
if (subtitle != null) {
subtitle.release();
}
nextSubtitleEventIndex = nextSubtitle.getNextEventTimeIndex(positionUs);
subtitle = nextSubtitle;
nextSubtitle = null;
nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs);
this.nextSubtitle = null;
textRendererNeedsUpdate = true;
}
}

if (textRendererNeedsUpdate) {
// If textRendererNeedsUpdate then subtitle must be non-null.
Assertions.checkNotNull(subtitle);
// textRendererNeedsUpdate is set and we're playing. Update the renderer.
updateOutput(subtitle.getCues(positionUs));
}
Expand All @@ -227,17 +229,18 @@ public void render(long positionUs, long elapsedRealtimeUs) {
}

try {
@Nullable SubtitleInputBuffer nextInputBuffer = this.nextInputBuffer;
while (!inputStreamEnded) {
if (nextInputBuffer == null) {
nextInputBuffer = decoder.dequeueInputBuffer();
nextInputBuffer = Assertions.checkNotNull(decoder).dequeueInputBuffer();
if (nextInputBuffer == null) {
return;
}
}
if (decoderReplacementState == REPLACEMENT_STATE_SIGNAL_END_OF_STREAM) {
nextInputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
decoder.queueInputBuffer(nextInputBuffer);
nextInputBuffer = null;
Assertions.checkNotNull(decoder).queueInputBuffer(nextInputBuffer);
this.nextInputBuffer = null;
decoderReplacementState = REPLACEMENT_STATE_WAIT_END_OF_STREAM;
return;
}
Expand All @@ -248,13 +251,18 @@ public void render(long positionUs, long elapsedRealtimeUs) {
inputStreamEnded = true;
waitingForKeyFrame = false;
} else {
nextInputBuffer.subsampleOffsetUs = formatHolder.format.subsampleOffsetUs;
@Nullable Format format = formatHolder.format;
if (format == null) {
// We haven't received a format yet.
return;
}
nextInputBuffer.subsampleOffsetUs = format.subsampleOffsetUs;
nextInputBuffer.flip();
waitingForKeyFrame &= !nextInputBuffer.isKeyFrame();
}
if (!waitingForKeyFrame) {
decoder.queueInputBuffer(nextInputBuffer);
nextInputBuffer = null;
Assertions.checkNotNull(decoder).queueInputBuffer(nextInputBuffer);
this.nextInputBuffer = null;
}
} else if (result == C.RESULT_NOTHING_READ) {
return;
Expand Down Expand Up @@ -300,14 +308,14 @@ private void releaseBuffers() {

private void releaseDecoder() {
releaseBuffers();
decoder.release();
Assertions.checkNotNull(decoder).release();
decoder = null;
decoderReplacementState = REPLACEMENT_STATE_NONE;
}

private void initDecoder() {
waitingForKeyFrame = true;
decoder = decoderFactory.createDecoder(streamFormat);
decoder = decoderFactory.createDecoder(Assertions.checkNotNull(streamFormat));
}

private void replaceDecoder() {
Expand All @@ -316,6 +324,7 @@ private void replaceDecoder() {
}

private long getNextEventTime() {
Assertions.checkNotNull(subtitle);
return nextSubtitleEventIndex == C.INDEX_UNSET
|| nextSubtitleEventIndex >= subtitle.getEventTimeCount()
? Long.MAX_VALUE : subtitle.getEventTime(nextSubtitleEventIndex);
Expand Down

0 comments on commit 0efec5f

Please sign in to comment.