Commit 730e4ac9 by olly Committed by Oliver Woodman

Remove workaround for FrameworkSampleSource.

FrameworkSampleSource will still be useful for audio, where
sample interleaving isn't an issue. We could optionally add
a "don't wait for first frame" boolean to the video renderer
if we *really* need to keep some form of this workaround in
place, but I'd rather not do so for now.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=119733224
parent 35e0dd84
......@@ -90,7 +90,6 @@ public final class LibflacAudioTrackRenderer extends SampleSourceTrackRenderer
private boolean allowPositionDiscontinuity;
private boolean inputStreamEnded;
private boolean outputStreamEnded;
private boolean sourceIsReady;
private final AudioTrack audioTrack;
private int audioSessionId;
......@@ -131,12 +130,10 @@ public final class LibflacAudioTrackRenderer extends SampleSourceTrackRenderer
}
@Override
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
throws ExoPlaybackException {
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (outputStreamEnded) {
return;
}
this.sourceIsReady = sourceIsReady;
// Try and read a format if we don't have one already.
if (format == null && !readFormat()) {
......@@ -275,7 +272,7 @@ public final class LibflacAudioTrackRenderer extends SampleSourceTrackRenderer
@Override
protected boolean isReady() {
return audioTrack.hasPendingData()
|| (format != null && (sourceIsReady || outputBuffer != null));
|| (format != null && (isSourceReady() || outputBuffer != null));
}
@Override
......@@ -296,7 +293,6 @@ public final class LibflacAudioTrackRenderer extends SampleSourceTrackRenderer
allowPositionDiscontinuity = true;
inputStreamEnded = false;
outputStreamEnded = false;
sourceIsReady = false;
if (decoder != null) {
flushDecoder();
}
......
......@@ -92,7 +92,6 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
private boolean allowPositionDiscontinuity;
private boolean inputStreamEnded;
private boolean outputStreamEnded;
private boolean sourceIsReady;
private int audioSessionId;
......@@ -139,12 +138,10 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
}
@Override
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
throws ExoPlaybackException {
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (outputStreamEnded) {
return;
}
this.sourceIsReady = sourceIsReady;
// Try and read a format if we don't have one already.
if (format == null && !readFormat()) {
......@@ -287,7 +284,7 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
@Override
protected boolean isReady() {
return audioTrack.hasPendingData()
|| (format != null && (sourceIsReady || outputBuffer != null));
|| (format != null && (isSourceReady() || outputBuffer != null));
}
@Override
......@@ -308,7 +305,6 @@ public final class LibopusAudioTrackRenderer extends SampleSourceTrackRenderer
allowPositionDiscontinuity = true;
inputStreamEnded = false;
outputStreamEnded = false;
sourceIsReady = false;
if (decoder != null) {
flushDecoder();
}
......
......@@ -137,23 +137,6 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
}
/**
* Value returned by {@link #getSourceState()} when the source is not ready.
*/
protected static final int SOURCE_STATE_NOT_READY = 0;
/**
* Value returned by {@link #getSourceState()} when the source is ready and we're able to read
* from it.
*/
protected static final int SOURCE_STATE_READY = 1;
/**
* Value returned by {@link #getSourceState()} when the source is ready but we might not be able
* to read from it. We transition to this state when an attempt to read a sample fails despite the
* source reporting that samples are available. This can occur when the next sample to be provided
* by the source is for another renderer.
*/
protected static final int SOURCE_STATE_READY_READ_MAY_FAIL = 2;
/**
* If the {@link MediaCodec} is hotswapped (i.e. replaced during playback), this is the period of
* time during which {@link #isReady()} will report true regardless of whether the new codec has
* output frames that are ready to be rendered.
......@@ -227,7 +210,6 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
private boolean codecReceivedBuffers;
private boolean codecReceivedEos;
private int sourceState;
private boolean inputStreamEnded;
private boolean outputStreamEnded;
private boolean waitingForKeys;
......@@ -462,7 +444,6 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
@Override
protected void reset(long positionUs) throws ExoPlaybackException {
sourceState = SOURCE_STATE_NOT_READY;
inputStreamEnded = false;
outputStreamEnded = false;
if (codec != null) {
......@@ -481,11 +462,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
}
@Override
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
throws ExoPlaybackException {
sourceState = sourceIsReady
? (sourceState == SOURCE_STATE_NOT_READY ? SOURCE_STATE_READY : sourceState)
: SOURCE_STATE_NOT_READY;
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (format == null) {
readFormat();
}
......@@ -493,9 +470,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
if (codec != null) {
TraceUtil.beginSection("drainAndFeed");
while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
if (feedInputBuffer(true)) {
while (feedInputBuffer(false)) {}
}
while (feedInputBuffer()) {}
TraceUtil.endSection();
}
codecCounters.ensureUpdated();
......@@ -536,12 +511,10 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
}
/**
* @param firstFeed True if this is the first call to this method from the current invocation of
* {@link #render(long, long)}. False otherwise.
* @return True if it may be possible to feed more input data. False otherwise.
* @throws ExoPlaybackException If an error occurs feeding the input buffer.
*/
private boolean feedInputBuffer(boolean firstFeed) throws ExoPlaybackException {
private boolean feedInputBuffer() throws ExoPlaybackException {
if (inputStreamEnded
|| codecReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM) {
// The input stream has ended, or we need to re-initialize the codec but are still waiting
......@@ -587,9 +560,6 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
codecReconfigurationState = RECONFIGURATION_STATE_QUEUE_PENDING;
}
result = readSource(formatHolder, buffer);
if (firstFeed && sourceState == SOURCE_STATE_READY && result == TrackStream.NOTHING_READ) {
sourceState = SOURCE_STATE_READY_READ_MAY_FAIL;
}
}
if (result == TrackStream.NOTHING_READ) {
......@@ -807,17 +777,7 @@ public abstract class MediaCodecTrackRenderer extends SampleSourceTrackRenderer
@Override
protected boolean isReady() {
return format != null && !waitingForKeys
&& (sourceState != SOURCE_STATE_NOT_READY || outputIndex >= 0 || isWithinHotswapPeriod());
}
/**
* Gets the source state.
*
* @return One of {@link #SOURCE_STATE_NOT_READY}, {@link #SOURCE_STATE_READY} and
* {@link #SOURCE_STATE_READY_READ_MAY_FAIL}.
*/
protected final int getSourceState() {
return sourceState;
&& (isSourceReady() || outputIndex >= 0 || isWithinHotswapPeriod());
}
private boolean isWithinHotswapPeriod() {
......
......@@ -293,8 +293,7 @@ public class MediaCodecVideoTrackRenderer extends MediaCodecTrackRenderer {
@Override
protected boolean isReady() {
if (super.isReady()
&& (renderedFirstFrame || getSourceState() == SOURCE_STATE_READY_READ_MAY_FAIL)) {
if (renderedFirstFrame && super.isReady()) {
// Ready. If we were joining then we've now joined, so clear the joining deadline.
joiningDeadlineUs = -1;
return true;
......
......@@ -44,12 +44,6 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
}
@Override
protected final void render(long positionUs, long elapsedRealtimeUs)
throws ExoPlaybackException {
render(positionUs, elapsedRealtimeUs, trackStream.isReady());
}
@Override
protected final void maybeThrowError() throws IOException {
trackStream.maybeThrowError();
}
......@@ -70,6 +64,15 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
return trackStream.readData(formatHolder, buffer);
}
/**
* Returns whether the upstream source is ready.
*
* @return True if the source is ready. False otherwise.
*/
protected final boolean isSourceReady() {
return trackStream.isReady();
}
// Abstract methods.
/**
......@@ -80,17 +83,4 @@ public abstract class SampleSourceTrackRenderer extends TrackRenderer {
*/
protected abstract void reset(long positionUs) throws ExoPlaybackException;
/**
* Called by {@link #render(long, long)}.
*
* @param positionUs The current media time in microseconds, measured at the start of the
* current iteration of the rendering loop.
* @param elapsedRealtimeUs {@link android.os.SystemClock#elapsedRealtime()} in microseconds,
* measured at the start of the current iteration of the rendering loop.
* @param sourceIsReady The result of the most recent call to {@link TrackStream#isReady()}.
* @throws ExoPlaybackException If an error occurs.
*/
protected abstract void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
throws ExoPlaybackException;
}
......@@ -98,8 +98,7 @@ public final class MetadataTrackRenderer<T> extends SampleSourceTrackRenderer im
}
@Override
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
throws ExoPlaybackException {
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (!inputStreamEnded && pendingMetadata == null) {
buffer.clear();
int result = readSource(formatHolder, buffer);
......
......@@ -126,8 +126,7 @@ public final class TextTrackRenderer extends SampleSourceTrackRenderer implement
}
@Override
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
throws ExoPlaybackException {
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (outputStreamEnded) {
return;
}
......
......@@ -104,8 +104,7 @@ public final class Eia608TrackRenderer extends SampleSourceTrackRenderer impleme
}
@Override
protected void render(long positionUs, long elapsedRealtimeUs, boolean sourceIsReady)
throws ExoPlaybackException {
protected void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (isBufferPending()) {
maybeParsePendingBuffer(positionUs);
}
......
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