mirror of
https://github.com/androidx/media.git
synced 2025-05-07 15:40:37 +08:00
Enable nullness checks for the text package
PiperOrigin-RevId: 322539147
This commit is contained in:
parent
1c6aaac958
commit
0efec5f6c1
@ -159,7 +159,7 @@ public final class TextRenderer extends BaseRenderer implements Callback {
|
|||||||
replaceDecoder();
|
replaceDecoder();
|
||||||
} else {
|
} else {
|
||||||
releaseBuffers();
|
releaseBuffers();
|
||||||
decoder.flush();
|
Assertions.checkNotNull(decoder).flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,9 +170,9 @@ public final class TextRenderer extends BaseRenderer implements Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (nextSubtitle == null) {
|
if (nextSubtitle == null) {
|
||||||
decoder.setPositionUs(positionUs);
|
Assertions.checkNotNull(decoder).setPositionUs(positionUs);
|
||||||
try {
|
try {
|
||||||
nextSubtitle = decoder.dequeueOutputBuffer();
|
nextSubtitle = Assertions.checkNotNull(decoder).dequeueOutputBuffer();
|
||||||
} catch (SubtitleDecoderException e) {
|
} catch (SubtitleDecoderException e) {
|
||||||
handleDecoderError(e);
|
handleDecoderError(e);
|
||||||
return;
|
return;
|
||||||
@ -194,8 +194,8 @@ public final class TextRenderer extends BaseRenderer implements Callback {
|
|||||||
textRendererNeedsUpdate = true;
|
textRendererNeedsUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextSubtitle != null) {
|
if (nextSubtitle != null) {
|
||||||
|
SubtitleOutputBuffer nextSubtitle = this.nextSubtitle;
|
||||||
if (nextSubtitle.isEndOfStream()) {
|
if (nextSubtitle.isEndOfStream()) {
|
||||||
if (!textRendererNeedsUpdate && getNextEventTime() == Long.MAX_VALUE) {
|
if (!textRendererNeedsUpdate && getNextEventTime() == Long.MAX_VALUE) {
|
||||||
if (decoderReplacementState == REPLACEMENT_STATE_WAIT_END_OF_STREAM) {
|
if (decoderReplacementState == REPLACEMENT_STATE_WAIT_END_OF_STREAM) {
|
||||||
@ -210,14 +210,16 @@ public final class TextRenderer extends BaseRenderer implements Callback {
|
|||||||
if (subtitle != null) {
|
if (subtitle != null) {
|
||||||
subtitle.release();
|
subtitle.release();
|
||||||
}
|
}
|
||||||
|
nextSubtitleEventIndex = nextSubtitle.getNextEventTimeIndex(positionUs);
|
||||||
subtitle = nextSubtitle;
|
subtitle = nextSubtitle;
|
||||||
nextSubtitle = null;
|
this.nextSubtitle = null;
|
||||||
nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs);
|
|
||||||
textRendererNeedsUpdate = true;
|
textRendererNeedsUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textRendererNeedsUpdate) {
|
if (textRendererNeedsUpdate) {
|
||||||
|
// If textRendererNeedsUpdate then subtitle must be non-null.
|
||||||
|
Assertions.checkNotNull(subtitle);
|
||||||
// textRendererNeedsUpdate is set and we're playing. Update the renderer.
|
// textRendererNeedsUpdate is set and we're playing. Update the renderer.
|
||||||
updateOutput(subtitle.getCues(positionUs));
|
updateOutput(subtitle.getCues(positionUs));
|
||||||
}
|
}
|
||||||
@ -227,17 +229,18 @@ public final class TextRenderer extends BaseRenderer implements Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@Nullable SubtitleInputBuffer nextInputBuffer = this.nextInputBuffer;
|
||||||
while (!inputStreamEnded) {
|
while (!inputStreamEnded) {
|
||||||
if (nextInputBuffer == null) {
|
if (nextInputBuffer == null) {
|
||||||
nextInputBuffer = decoder.dequeueInputBuffer();
|
nextInputBuffer = Assertions.checkNotNull(decoder).dequeueInputBuffer();
|
||||||
if (nextInputBuffer == null) {
|
if (nextInputBuffer == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (decoderReplacementState == REPLACEMENT_STATE_SIGNAL_END_OF_STREAM) {
|
if (decoderReplacementState == REPLACEMENT_STATE_SIGNAL_END_OF_STREAM) {
|
||||||
nextInputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
|
nextInputBuffer.setFlags(C.BUFFER_FLAG_END_OF_STREAM);
|
||||||
decoder.queueInputBuffer(nextInputBuffer);
|
Assertions.checkNotNull(decoder).queueInputBuffer(nextInputBuffer);
|
||||||
nextInputBuffer = null;
|
this.nextInputBuffer = null;
|
||||||
decoderReplacementState = REPLACEMENT_STATE_WAIT_END_OF_STREAM;
|
decoderReplacementState = REPLACEMENT_STATE_WAIT_END_OF_STREAM;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -248,13 +251,18 @@ public final class TextRenderer extends BaseRenderer implements Callback {
|
|||||||
inputStreamEnded = true;
|
inputStreamEnded = true;
|
||||||
waitingForKeyFrame = false;
|
waitingForKeyFrame = false;
|
||||||
} else {
|
} 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();
|
nextInputBuffer.flip();
|
||||||
waitingForKeyFrame &= !nextInputBuffer.isKeyFrame();
|
waitingForKeyFrame &= !nextInputBuffer.isKeyFrame();
|
||||||
}
|
}
|
||||||
if (!waitingForKeyFrame) {
|
if (!waitingForKeyFrame) {
|
||||||
decoder.queueInputBuffer(nextInputBuffer);
|
Assertions.checkNotNull(decoder).queueInputBuffer(nextInputBuffer);
|
||||||
nextInputBuffer = null;
|
this.nextInputBuffer = null;
|
||||||
}
|
}
|
||||||
} else if (result == C.RESULT_NOTHING_READ) {
|
} else if (result == C.RESULT_NOTHING_READ) {
|
||||||
return;
|
return;
|
||||||
@ -300,14 +308,14 @@ public final class TextRenderer extends BaseRenderer implements Callback {
|
|||||||
|
|
||||||
private void releaseDecoder() {
|
private void releaseDecoder() {
|
||||||
releaseBuffers();
|
releaseBuffers();
|
||||||
decoder.release();
|
Assertions.checkNotNull(decoder).release();
|
||||||
decoder = null;
|
decoder = null;
|
||||||
decoderReplacementState = REPLACEMENT_STATE_NONE;
|
decoderReplacementState = REPLACEMENT_STATE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDecoder() {
|
private void initDecoder() {
|
||||||
waitingForKeyFrame = true;
|
waitingForKeyFrame = true;
|
||||||
decoder = decoderFactory.createDecoder(streamFormat);
|
decoder = decoderFactory.createDecoder(Assertions.checkNotNull(streamFormat));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void replaceDecoder() {
|
private void replaceDecoder() {
|
||||||
@ -316,6 +324,7 @@ public final class TextRenderer extends BaseRenderer implements Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private long getNextEventTime() {
|
private long getNextEventTime() {
|
||||||
|
Assertions.checkNotNull(subtitle);
|
||||||
return nextSubtitleEventIndex == C.INDEX_UNSET
|
return nextSubtitleEventIndex == C.INDEX_UNSET
|
||||||
|| nextSubtitleEventIndex >= subtitle.getEventTimeCount()
|
|| nextSubtitleEventIndex >= subtitle.getEventTimeCount()
|
||||||
? Long.MAX_VALUE : subtitle.getEventTime(nextSubtitleEventIndex);
|
? Long.MAX_VALUE : subtitle.getEventTime(nextSubtitleEventIndex);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user