Commit ebe9ae6b by Oliver Woodman

In continueBuffering, return whether a particular track has samples.

Issue: #595
parent 17c1b630
...@@ -153,7 +153,7 @@ public class LibopusAudioTrackRenderer extends TrackRenderer implements MediaClo ...@@ -153,7 +153,7 @@ public class LibopusAudioTrackRenderer extends TrackRenderer implements MediaClo
return; return;
} }
try { try {
sourceIsReady = source.continueBuffering(positionUs); sourceIsReady = source.continueBuffering(trackIndex, positionUs);
checkForDiscontinuity(); checkForDiscontinuity();
if (format == null) { if (format == null) {
readFormat(); readFormat();
......
...@@ -179,7 +179,7 @@ public class LibvpxVideoTrackRenderer extends TrackRenderer { ...@@ -179,7 +179,7 @@ public class LibvpxVideoTrackRenderer extends TrackRenderer {
return; return;
} }
try { try {
sourceIsReady = source.continueBuffering(positionUs); sourceIsReady = source.continueBuffering(trackIndex, positionUs);
checkForDiscontinuity(positionUs); checkForDiscontinuity(positionUs);
if (format == null) { if (format == null) {
readFormat(positionUs); readFormat(positionUs);
......
...@@ -174,7 +174,7 @@ public final class FrameworkSampleSource implements SampleSource, SampleSourceRe ...@@ -174,7 +174,7 @@ public final class FrameworkSampleSource implements SampleSource, SampleSourceRe
} }
@Override @Override
public boolean continueBuffering(long positionUs) { public boolean continueBuffering(int track, long positionUs) {
// MediaExtractor takes care of buffering and blocks until it has samples, so we can always // MediaExtractor takes care of buffering and blocks until it has samples, so we can always
// return true here. Although note that the blocking behavior is itself as bug, as per the // return true here. Although note that the blocking behavior is itself as bug, as per the
// TODO further up this file. This method will need to return something else as part of fixing // TODO further up this file. This method will need to return something else as part of fixing
......
...@@ -490,7 +490,7 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer { ...@@ -490,7 +490,7 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
@Override @Override
protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException { protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
try { try {
sourceState = source.continueBuffering(positionUs) sourceState = source.continueBuffering(trackIndex, positionUs)
? (sourceState == SOURCE_STATE_NOT_READY ? SOURCE_STATE_READY : sourceState) ? (sourceState == SOURCE_STATE_NOT_READY ? SOURCE_STATE_READY : sourceState)
: SOURCE_STATE_NOT_READY; : SOURCE_STATE_NOT_READY;
checkForDiscontinuity(positionUs); checkForDiscontinuity(positionUs);
......
...@@ -117,14 +117,15 @@ public interface SampleSource { ...@@ -117,14 +117,15 @@ public interface SampleSource {
public void disable(int track); public void disable(int track);
/** /**
* Indicates to the source that it should still be buffering data. * Indicates to the source that it should still be buffering data for the specified track.
* *
* @param track The track to continue buffering.
* @param positionUs The current playback position. * @param positionUs The current playback position.
* @return True if the source has available samples, or if the end of the stream has been * @return True if the track has available samples, or if the end of the stream has been
* reached. False if more data needs to be buffered for samples to become available. * reached. False if more data needs to be buffered for samples to become available.
* @throws IOException If an error occurred reading from the source. * @throws IOException If an error occurred reading from the source.
*/ */
public boolean continueBuffering(long positionUs) throws IOException; public boolean continueBuffering(int track, long positionUs) throws IOException;
/** /**
* Attempts to read either a sample, a new format or or a discontinuity from the source. * Attempts to read either a sample, a new format or or a discontinuity from the source.
......
...@@ -188,8 +188,9 @@ public class ChunkSampleSource implements SampleSource, SampleSourceReader, Load ...@@ -188,8 +188,9 @@ public class ChunkSampleSource implements SampleSource, SampleSourceReader, Load
} }
@Override @Override
public boolean continueBuffering(long positionUs) throws IOException { public boolean continueBuffering(int track, long positionUs) throws IOException {
Assertions.checkState(state == STATE_ENABLED); Assertions.checkState(state == STATE_ENABLED);
Assertions.checkState(track == 0);
downstreamPositionUs = positionUs; downstreamPositionUs = positionUs;
chunkSource.continueBuffering(positionUs); chunkSource.continueBuffering(positionUs);
updateLoadControl(); updateLoadControl();
......
...@@ -180,7 +180,7 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader, ...@@ -180,7 +180,7 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
loader = new Loader("Loader:ExtractorSampleSource"); loader = new Loader("Loader:ExtractorSampleSource");
} }
continueBufferingInternal(); maybeStartLoading();
if (seekMap != null && tracksBuilt && haveFormatsForAllTracks()) { if (seekMap != null && tracksBuilt && haveFormatsForAllTracks()) {
int trackCount = sampleQueues.size(); int trackCount = sampleQueues.size();
...@@ -246,12 +246,23 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader, ...@@ -246,12 +246,23 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
} }
@Override @Override
public boolean continueBuffering(long playbackPositionUs) throws IOException { public boolean continueBuffering(int track, long playbackPositionUs) throws IOException {
Assertions.checkState(prepared); Assertions.checkState(prepared);
Assertions.checkState(enabledTrackCount > 0); Assertions.checkState(trackEnabledStates[track]);
downstreamPositionUs = playbackPositionUs; downstreamPositionUs = playbackPositionUs;
discardSamplesForDisabledTracks(downstreamPositionUs); discardSamplesForDisabledTracks(downstreamPositionUs);
return loadingFinished || continueBufferingInternal(); if (loadingFinished) {
return true;
}
maybeStartLoading();
if (isPendingReset()) {
return false;
}
if (sampleQueues.valueAt(track).isEmpty()) {
maybeThrowLoadableException();
return false;
}
return true;
} }
@Override @Override
...@@ -411,18 +422,6 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader, ...@@ -411,18 +422,6 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
// Internal stuff. // Internal stuff.
private boolean continueBufferingInternal() throws IOException {
maybeStartLoading();
if (isPendingReset()) {
return false;
}
boolean haveSamples = prepared && haveSampleForOneEnabledTrack();
if (!haveSamples) {
maybeThrowLoadableException();
}
return haveSamples;
}
private void restartFrom(long positionUs) { private void restartFrom(long positionUs) {
pendingResetPositionUs = positionUs; pendingResetPositionUs = positionUs;
loadingFinished = false; loadingFinished = false;
...@@ -532,15 +531,6 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader, ...@@ -532,15 +531,6 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
return true; return true;
} }
private boolean haveSampleForOneEnabledTrack() {
for (int i = 0; i < trackEnabledStates.length; i++) {
if (trackEnabledStates[i] && !sampleQueues.valueAt(i).isEmpty()) {
return true;
}
}
return false;
}
private void discardSamplesForDisabledTracks(long timeUs) { private void discardSamplesForDisabledTracks(long timeUs) {
for (int i = 0; i < trackEnabledStates.length; i++) { for (int i = 0; i < trackEnabledStates.length; i++) {
if (!trackEnabledStates[i]) { if (!trackEnabledStates[i]) {
......
...@@ -218,26 +218,32 @@ public class HlsSampleSource implements SampleSource, SampleSourceReader, Loader ...@@ -218,26 +218,32 @@ public class HlsSampleSource implements SampleSource, SampleSourceReader, Loader
} }
@Override @Override
public boolean continueBuffering(long playbackPositionUs) throws IOException { public boolean continueBuffering(int track, long playbackPositionUs) throws IOException {
Assertions.checkState(prepared); Assertions.checkState(prepared);
Assertions.checkState(enabledTrackCount > 0); Assertions.checkState(trackEnabledStates[track]);
downstreamPositionUs = playbackPositionUs; downstreamPositionUs = playbackPositionUs;
if (!extractors.isEmpty()) { if (!extractors.isEmpty()) {
discardSamplesForDisabledTracks(getCurrentExtractor(), downstreamPositionUs); discardSamplesForDisabledTracks(getCurrentExtractor(), downstreamPositionUs);
} }
return loadingFinished || continueBufferingInternal(); if (loadingFinished) {
} return true;
}
private boolean continueBufferingInternal() throws IOException {
maybeStartLoading(); maybeStartLoading();
if (isPendingReset() || extractors.isEmpty()) { if (isPendingReset() || extractors.isEmpty()) {
return false; return false;
} }
boolean haveSamples = prepared && haveSamplesForEnabledTracks(getCurrentExtractor());
if (!haveSamples) { for (int extractorIndex = 0; extractorIndex < extractors.size(); extractorIndex++) {
maybeThrowLoadableException(); HlsExtractorWrapper extractor = extractors.get(extractorIndex);
if (!extractor.isPrepared()) {
break;
}
if (extractor.hasSamples(track)) {
return true;
}
} }
return haveSamples; maybeThrowLoadableException();
return false;
} }
@Override @Override
......
...@@ -129,7 +129,7 @@ public class MetadataTrackRenderer<T> extends TrackRenderer implements Callback ...@@ -129,7 +129,7 @@ public class MetadataTrackRenderer<T> extends TrackRenderer implements Callback
protected void doSomeWork(long positionUs, long elapsedRealtimeUs) protected void doSomeWork(long positionUs, long elapsedRealtimeUs)
throws ExoPlaybackException { throws ExoPlaybackException {
try { try {
source.continueBuffering(positionUs); source.continueBuffering(trackIndex, positionUs);
} catch (IOException e) { } catch (IOException e) {
throw new ExoPlaybackException(e); throw new ExoPlaybackException(e);
} }
......
...@@ -129,7 +129,7 @@ public class TextTrackRenderer extends TrackRenderer implements Callback { ...@@ -129,7 +129,7 @@ public class TextTrackRenderer extends TrackRenderer implements Callback {
@Override @Override
protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException { protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
try { try {
source.continueBuffering(positionUs); source.continueBuffering(trackIndex, positionUs);
} catch (IOException e) { } catch (IOException e) {
throw new ExoPlaybackException(e); throw new ExoPlaybackException(e);
} }
......
...@@ -134,7 +134,7 @@ public class Eia608TrackRenderer extends TrackRenderer implements Callback { ...@@ -134,7 +134,7 @@ public class Eia608TrackRenderer extends TrackRenderer implements Callback {
@Override @Override
protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException { protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
try { try {
source.continueBuffering(positionUs); source.continueBuffering(trackIndex, positionUs);
} catch (IOException e) { } catch (IOException e) {
throw new ExoPlaybackException(e); throw new ExoPlaybackException(e);
} }
......
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