In continueBuffering, return whether a particular track has samples.

Issue: #595
This commit is contained in:
Oliver Woodman 2015-07-16 19:30:14 +01:00
parent 17c1b630b8
commit ebe9ae6b13
11 changed files with 44 additions and 46 deletions

View file

@ -153,7 +153,7 @@ public class LibopusAudioTrackRenderer extends TrackRenderer implements MediaClo
return;
}
try {
sourceIsReady = source.continueBuffering(positionUs);
sourceIsReady = source.continueBuffering(trackIndex, positionUs);
checkForDiscontinuity();
if (format == null) {
readFormat();

View file

@ -179,7 +179,7 @@ public class LibvpxVideoTrackRenderer extends TrackRenderer {
return;
}
try {
sourceIsReady = source.continueBuffering(positionUs);
sourceIsReady = source.continueBuffering(trackIndex, positionUs);
checkForDiscontinuity(positionUs);
if (format == null) {
readFormat(positionUs);

View file

@ -174,7 +174,7 @@ public final class FrameworkSampleSource implements SampleSource, SampleSourceRe
}
@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
// 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

View file

@ -490,7 +490,7 @@ public abstract class MediaCodecTrackRenderer extends TrackRenderer {
@Override
protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
try {
sourceState = source.continueBuffering(positionUs)
sourceState = source.continueBuffering(trackIndex, positionUs)
? (sourceState == SOURCE_STATE_NOT_READY ? SOURCE_STATE_READY : sourceState)
: SOURCE_STATE_NOT_READY;
checkForDiscontinuity(positionUs);

View file

@ -117,14 +117,15 @@ public interface SampleSource {
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.
* @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.
* @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.

View file

@ -188,8 +188,9 @@ public class ChunkSampleSource implements SampleSource, SampleSourceReader, Load
}
@Override
public boolean continueBuffering(long positionUs) throws IOException {
public boolean continueBuffering(int track, long positionUs) throws IOException {
Assertions.checkState(state == STATE_ENABLED);
Assertions.checkState(track == 0);
downstreamPositionUs = positionUs;
chunkSource.continueBuffering(positionUs);
updateLoadControl();

View file

@ -180,7 +180,7 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
loader = new Loader("Loader:ExtractorSampleSource");
}
continueBufferingInternal();
maybeStartLoading();
if (seekMap != null && tracksBuilt && haveFormatsForAllTracks()) {
int trackCount = sampleQueues.size();
@ -246,12 +246,23 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
}
@Override
public boolean continueBuffering(long playbackPositionUs) throws IOException {
public boolean continueBuffering(int track, long playbackPositionUs) throws IOException {
Assertions.checkState(prepared);
Assertions.checkState(enabledTrackCount > 0);
Assertions.checkState(trackEnabledStates[track]);
downstreamPositionUs = playbackPositionUs;
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
@ -411,18 +422,6 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
// 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) {
pendingResetPositionUs = positionUs;
loadingFinished = false;
@ -532,15 +531,6 @@ public class ExtractorSampleSource implements SampleSource, SampleSourceReader,
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) {
for (int i = 0; i < trackEnabledStates.length; i++) {
if (!trackEnabledStates[i]) {

View file

@ -218,26 +218,32 @@ public class HlsSampleSource implements SampleSource, SampleSourceReader, Loader
}
@Override
public boolean continueBuffering(long playbackPositionUs) throws IOException {
public boolean continueBuffering(int track, long playbackPositionUs) throws IOException {
Assertions.checkState(prepared);
Assertions.checkState(enabledTrackCount > 0);
Assertions.checkState(trackEnabledStates[track]);
downstreamPositionUs = playbackPositionUs;
if (!extractors.isEmpty()) {
discardSamplesForDisabledTracks(getCurrentExtractor(), downstreamPositionUs);
}
return loadingFinished || continueBufferingInternal();
}
private boolean continueBufferingInternal() throws IOException {
if (loadingFinished) {
return true;
}
maybeStartLoading();
if (isPendingReset() || extractors.isEmpty()) {
return false;
}
boolean haveSamples = prepared && haveSamplesForEnabledTracks(getCurrentExtractor());
if (!haveSamples) {
maybeThrowLoadableException();
for (int extractorIndex = 0; extractorIndex < extractors.size(); extractorIndex++) {
HlsExtractorWrapper extractor = extractors.get(extractorIndex);
if (!extractor.isPrepared()) {
break;
}
if (extractor.hasSamples(track)) {
return true;
}
}
return haveSamples;
maybeThrowLoadableException();
return false;
}
@Override

View file

@ -129,7 +129,7 @@ public class MetadataTrackRenderer<T> extends TrackRenderer implements Callback
protected void doSomeWork(long positionUs, long elapsedRealtimeUs)
throws ExoPlaybackException {
try {
source.continueBuffering(positionUs);
source.continueBuffering(trackIndex, positionUs);
} catch (IOException e) {
throw new ExoPlaybackException(e);
}

View file

@ -129,7 +129,7 @@ public class TextTrackRenderer extends TrackRenderer implements Callback {
@Override
protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
try {
source.continueBuffering(positionUs);
source.continueBuffering(trackIndex, positionUs);
} catch (IOException e) {
throw new ExoPlaybackException(e);
}

View file

@ -134,7 +134,7 @@ public class Eia608TrackRenderer extends TrackRenderer implements Callback {
@Override
protected void doSomeWork(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
try {
source.continueBuffering(positionUs);
source.continueBuffering(trackIndex, positionUs);
} catch (IOException e) {
throw new ExoPlaybackException(e);
}