BaseRenderer: Add getStartPositionUs

This is useful for subclasses to easily query the point up to which
they should only decode (but not render) content, rather than each
subclass having to have its own startPositionUs and update it in
onPositionReset.

PiperOrigin-RevId: 320163677
This commit is contained in:
olly 2020-07-08 12:30:48 +01:00 committed by kim-vde
parent 61acd434f6
commit 01249bf1cd

View File

@ -36,6 +36,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
private SampleStream stream;
private Format[] streamFormats;
private long streamOffsetUs;
private long startPositionUs;
private long readingPositionUs;
private boolean streamIsFinal;
private boolean throwRendererExceptionIsExecuting;
@ -89,6 +90,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
Assertions.checkState(state == STATE_DISABLED);
this.configuration = configuration;
state = STATE_ENABLED;
startPositionUs = positionUs;
onEnabled(joining, mayRenderStartOfStream);
replaceStream(formats, stream, offsetUs);
onPositionReset(positionUs, joining);
@ -146,6 +148,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
@Override
public final void resetPosition(long positionUs) throws ExoPlaybackException {
streamIsFinal = false;
startPositionUs = positionUs;
readingPositionUs = positionUs;
onPositionReset(positionUs, false);
}
@ -282,6 +285,14 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
// Methods to be called by subclasses.
/**
* Returns the position passed to the most recent call to {@link #enable} or {@link
* #resetPosition}.
*/
protected final long getStartPositionUs() {
return startPositionUs;
}
/** Returns a clear {@link FormatHolder}. */
protected final FormatHolder getFormatHolder() {
formatHolder.clear();