mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Enable nullness checking for BaseRenderer
#exofixit PiperOrigin-RevId: 322567104
This commit is contained in:
parent
6e751c35c7
commit
3ad1b95460
1 changed files with 29 additions and 11 deletions
|
|
@ -30,11 +30,11 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
||||||
private final int trackType;
|
private final int trackType;
|
||||||
private final FormatHolder formatHolder;
|
private final FormatHolder formatHolder;
|
||||||
|
|
||||||
private RendererConfiguration configuration;
|
@Nullable private RendererConfiguration configuration;
|
||||||
private int index;
|
private int index;
|
||||||
private int state;
|
private int state;
|
||||||
private SampleStream stream;
|
@Nullable private SampleStream stream;
|
||||||
private Format[] streamFormats;
|
@Nullable private Format[] streamFormats;
|
||||||
private long streamOffsetUs;
|
private long streamOffsetUs;
|
||||||
private long lastResetPositionUs;
|
private long lastResetPositionUs;
|
||||||
private long readingPositionUs;
|
private long readingPositionUs;
|
||||||
|
|
@ -144,7 +144,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void maybeThrowStreamError() throws IOException {
|
public final void maybeThrowStreamError() throws IOException {
|
||||||
stream.maybeThrowError();
|
Assertions.checkNotNull(stream).maybeThrowError();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -303,16 +303,24 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
||||||
return formatHolder;
|
return formatHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the formats of the currently enabled stream. */
|
/**
|
||||||
|
* Returns the formats of the currently enabled stream.
|
||||||
|
*
|
||||||
|
* <p>This method may be called when the renderer is in the following states: {@link
|
||||||
|
* #STATE_ENABLED}, {@link #STATE_STARTED}.
|
||||||
|
*/
|
||||||
protected final Format[] getStreamFormats() {
|
protected final Format[] getStreamFormats() {
|
||||||
return streamFormats;
|
return Assertions.checkNotNull(streamFormats);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the configuration set when the renderer was most recently enabled.
|
* Returns the configuration set when the renderer was most recently enabled.
|
||||||
|
*
|
||||||
|
* <p>This method may be called when the renderer is in the following states: {@link
|
||||||
|
* #STATE_ENABLED}, {@link #STATE_STARTED}.
|
||||||
*/
|
*/
|
||||||
protected final RendererConfiguration getConfiguration() {
|
protected final RendererConfiguration getConfiguration() {
|
||||||
return configuration;
|
return Assertions.checkNotNull(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -352,6 +360,9 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
||||||
* {@link C#RESULT_BUFFER_READ} is only returned if {@link #setCurrentStreamFinal()} has been
|
* {@link C#RESULT_BUFFER_READ} is only returned if {@link #setCurrentStreamFinal()} has been
|
||||||
* called. {@link C#RESULT_NOTHING_READ} is returned otherwise.
|
* called. {@link C#RESULT_NOTHING_READ} is returned otherwise.
|
||||||
*
|
*
|
||||||
|
* <p>This method may be called when the renderer is in the following states: {@link
|
||||||
|
* #STATE_ENABLED}, {@link #STATE_STARTED}.
|
||||||
|
*
|
||||||
* @param formatHolder A {@link FormatHolder} to populate in the case of reading a format.
|
* @param formatHolder A {@link FormatHolder} to populate in the case of reading a format.
|
||||||
* @param buffer A {@link DecoderInputBuffer} to populate in the case of reading a sample or the
|
* @param buffer A {@link DecoderInputBuffer} to populate in the case of reading a sample or the
|
||||||
* end of the stream. If the end of the stream has been reached, the {@link
|
* end of the stream. If the end of the stream has been reached, the {@link
|
||||||
|
|
@ -364,7 +375,8 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
||||||
@SampleStream.ReadDataResult
|
@SampleStream.ReadDataResult
|
||||||
protected final int readSource(
|
protected final int readSource(
|
||||||
FormatHolder formatHolder, DecoderInputBuffer buffer, boolean formatRequired) {
|
FormatHolder formatHolder, DecoderInputBuffer buffer, boolean formatRequired) {
|
||||||
@SampleStream.ReadDataResult int result = stream.readData(formatHolder, buffer, formatRequired);
|
@SampleStream.ReadDataResult
|
||||||
|
int result = Assertions.checkNotNull(stream).readData(formatHolder, buffer, formatRequired);
|
||||||
if (result == C.RESULT_BUFFER_READ) {
|
if (result == C.RESULT_BUFFER_READ) {
|
||||||
if (buffer.isEndOfStream()) {
|
if (buffer.isEndOfStream()) {
|
||||||
readingPositionUs = C.TIME_END_OF_SOURCE;
|
readingPositionUs = C.TIME_END_OF_SOURCE;
|
||||||
|
|
@ -373,7 +385,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
||||||
buffer.timeUs += streamOffsetUs;
|
buffer.timeUs += streamOffsetUs;
|
||||||
readingPositionUs = Math.max(readingPositionUs, buffer.timeUs);
|
readingPositionUs = Math.max(readingPositionUs, buffer.timeUs);
|
||||||
} else if (result == C.RESULT_FORMAT_READ) {
|
} else if (result == C.RESULT_FORMAT_READ) {
|
||||||
Format format = formatHolder.format;
|
Format format = Assertions.checkNotNull(formatHolder.format);
|
||||||
if (format.subsampleOffsetUs != Format.OFFSET_SAMPLE_RELATIVE) {
|
if (format.subsampleOffsetUs != Format.OFFSET_SAMPLE_RELATIVE) {
|
||||||
format =
|
format =
|
||||||
format
|
format
|
||||||
|
|
@ -390,17 +402,23 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
||||||
* Attempts to skip to the keyframe before the specified position, or to the end of the stream if
|
* Attempts to skip to the keyframe before the specified position, or to the end of the stream if
|
||||||
* {@code positionUs} is beyond it.
|
* {@code positionUs} is beyond it.
|
||||||
*
|
*
|
||||||
|
* <p>This method may be called when the renderer is in the following states: {@link
|
||||||
|
* #STATE_ENABLED}, {@link #STATE_STARTED}.
|
||||||
|
*
|
||||||
* @param positionUs The position in microseconds.
|
* @param positionUs The position in microseconds.
|
||||||
* @return The number of samples that were skipped.
|
* @return The number of samples that were skipped.
|
||||||
*/
|
*/
|
||||||
protected int skipSource(long positionUs) {
|
protected int skipSource(long positionUs) {
|
||||||
return stream.skipData(positionUs - streamOffsetUs);
|
return Assertions.checkNotNull(stream).skipData(positionUs - streamOffsetUs);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether the upstream source is ready.
|
* Returns whether the upstream source is ready.
|
||||||
|
*
|
||||||
|
* <p>This method may be called when the renderer is in the following states: {@link
|
||||||
|
* #STATE_ENABLED}, {@link #STATE_STARTED}.
|
||||||
*/
|
*/
|
||||||
protected final boolean isSourceReady() {
|
protected final boolean isSourceReady() {
|
||||||
return hasReadStreamToEnd() ? streamIsFinal : stream.isReady();
|
return hasReadStreamToEnd() ? streamIsFinal : Assertions.checkNotNull(stream).isReady();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue