Commit 292b2402 by olly Committed by Oliver Woodman

More SampleSource simplification.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=118775144
parent a4d17282
...@@ -67,6 +67,7 @@ public class DashSourceBuilder implements SourceBuilder { ...@@ -67,6 +67,7 @@ public class DashSourceBuilder implements SourceBuilder {
public SampleSource buildRenderers(DemoPlayer player) { public SampleSource buildRenderers(DemoPlayer player) {
MediaPresentationDescriptionParser parser = new MediaPresentationDescriptionParser(); MediaPresentationDescriptionParser parser = new MediaPresentationDescriptionParser();
DataSource manifestDataSource = dataSourceFactory.createDataSource(); DataSource manifestDataSource = dataSourceFactory.createDataSource();
// TODO[REFACTOR]: This needs releasing.
ManifestFetcher<MediaPresentationDescription> manifestFetcher = new ManifestFetcher<>( ManifestFetcher<MediaPresentationDescription> manifestFetcher = new ManifestFetcher<>(
Uri.parse(url), manifestDataSource, parser); Uri.parse(url), manifestDataSource, parser);
......
...@@ -58,6 +58,7 @@ public class HlsSourceBuilder implements SourceBuilder { ...@@ -58,6 +58,7 @@ public class HlsSourceBuilder implements SourceBuilder {
public SampleSource buildRenderers(DemoPlayer player) { public SampleSource buildRenderers(DemoPlayer player) {
HlsPlaylistParser parser = new HlsPlaylistParser(); HlsPlaylistParser parser = new HlsPlaylistParser();
DataSource manifestDataSource = dataSourceFactory.createDataSource(); DataSource manifestDataSource = dataSourceFactory.createDataSource();
// TODO[REFACTOR]: This needs releasing.
ManifestFetcher<HlsPlaylist> manifestFetcher = new ManifestFetcher<>(Uri.parse(url), ManifestFetcher<HlsPlaylist> manifestFetcher = new ManifestFetcher<>(Uri.parse(url),
manifestDataSource, parser); manifestDataSource, parser);
......
...@@ -62,6 +62,7 @@ public class SmoothStreamingSourceBuilder implements SourceBuilder { ...@@ -62,6 +62,7 @@ public class SmoothStreamingSourceBuilder implements SourceBuilder {
@Override @Override
public SampleSource buildRenderers(DemoPlayer player) { public SampleSource buildRenderers(DemoPlayer player) {
SmoothStreamingManifestParser parser = new SmoothStreamingManifestParser(); SmoothStreamingManifestParser parser = new SmoothStreamingManifestParser();
// TODO[REFACTOR]: This needs releasing.
DataSource manifestDataSource = dataSourceFactory.createDataSource(); DataSource manifestDataSource = dataSourceFactory.createDataSource();
ManifestFetcher<SmoothStreamingManifest> manifestFetcher = new ManifestFetcher<>(Uri.parse(url), ManifestFetcher<SmoothStreamingManifest> manifestFetcher = new ManifestFetcher<>(Uri.parse(url),
manifestDataSource, parser); manifestDataSource, parser);
......
...@@ -65,18 +65,16 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load ...@@ -65,18 +65,16 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
private final Uri uri; private final Uri uri;
private final DataSource dataSource; private final DataSource dataSource;
private final Loader loader;
private final Format format; private final Format format;
private final long durationUs; private final long durationUs;
private final int minLoadableRetryCount;
private final TrackGroupArray tracks; private final TrackGroupArray tracks;
private final Handler eventHandler; private final Handler eventHandler;
private final EventListener eventListener; private final EventListener eventListener;
private final int eventSourceId; private final int eventSourceId;
private boolean prepared;
private long pendingResetPositionUs; private long pendingResetPositionUs;
private boolean loadingFinished; private boolean loadingFinished;
private Loader loader;
private int streamState; private int streamState;
private byte[] sampleData; private byte[] sampleData;
...@@ -98,10 +96,10 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load ...@@ -98,10 +96,10 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
this.dataSource = dataSource; this.dataSource = dataSource;
this.format = format; this.format = format;
this.durationUs = durationUs; this.durationUs = durationUs;
this.minLoadableRetryCount = minLoadableRetryCount;
this.eventHandler = eventHandler; this.eventHandler = eventHandler;
this.eventListener = eventListener; this.eventListener = eventListener;
this.eventSourceId = eventSourceId; this.eventSourceId = eventSourceId;
loader = new Loader("Loader:SingleSampleSource", minLoadableRetryCount);
tracks = new TrackGroupArray(new TrackGroup(format)); tracks = new TrackGroupArray(new TrackGroup(format));
sampleData = new byte[INITIAL_SAMPLE_SIZE]; sampleData = new byte[INITIAL_SAMPLE_SIZE];
} }
...@@ -113,11 +111,6 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load ...@@ -113,11 +111,6 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
@Override @Override
public boolean prepare(long positionUs) { public boolean prepare(long positionUs) {
if (prepared) {
return true;
}
loader = new Loader("Loader:" + format.sampleMimeType, minLoadableRetryCount);
prepared = true;
return true; return true;
} }
...@@ -134,7 +127,6 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load ...@@ -134,7 +127,6 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
@Override @Override
public TrackStream[] selectTracks(List<TrackStream> oldStreams, public TrackStream[] selectTracks(List<TrackStream> oldStreams,
List<TrackSelection> newSelections, long positionUs) { List<TrackSelection> newSelections, long positionUs) {
Assertions.checkState(prepared);
Assertions.checkState(oldStreams.size() <= 1); Assertions.checkState(oldStreams.size() <= 1);
Assertions.checkState(newSelections.size() <= 1); Assertions.checkState(newSelections.size() <= 1);
// Unselect old tracks. // Unselect old tracks.
...@@ -213,10 +205,7 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load ...@@ -213,10 +205,7 @@ public final class SingleSampleSource implements SampleSource, TrackStream, Load
@Override @Override
public void release() { public void release() {
streamState = STREAM_STATE_END_OF_STREAM; streamState = STREAM_STATE_END_OF_STREAM;
if (loader != null) {
loader.release(); loader.release();
loader = null;
}
} }
// Loader.Callback implementation. // Loader.Callback implementation.
......
...@@ -56,6 +56,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call ...@@ -56,6 +56,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
private static final long NO_RESET_PENDING = Long.MIN_VALUE; private static final long NO_RESET_PENDING = Long.MIN_VALUE;
private final Loader loader;
private final int eventSourceId; private final int eventSourceId;
private final LoadControl loadControl; private final LoadControl loadControl;
private final ChunkSource chunkSource; private final ChunkSource chunkSource;
...@@ -66,7 +67,6 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call ...@@ -66,7 +67,6 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
private final int bufferSizeContribution; private final int bufferSizeContribution;
private final Handler eventHandler; private final Handler eventHandler;
private final EventListener eventListener; private final EventListener eventListener;
private final int minLoadableRetryCount;
private boolean prepared; private boolean prepared;
private long downstreamPositionUs; private long downstreamPositionUs;
...@@ -78,7 +78,6 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call ...@@ -78,7 +78,6 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
private TrackGroupArray trackGroups; private TrackGroupArray trackGroups;
private long durationUs; private long durationUs;
private Loader loader;
private boolean loadingFinished; private boolean loadingFinished;
private boolean trackEnabled; private boolean trackEnabled;
private long currentLoadStartTimeMs; private long currentLoadStartTimeMs;
...@@ -132,7 +131,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call ...@@ -132,7 +131,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
this.eventHandler = eventHandler; this.eventHandler = eventHandler;
this.eventListener = eventListener; this.eventListener = eventListener;
this.eventSourceId = eventSourceId; this.eventSourceId = eventSourceId;
this.minLoadableRetryCount = minLoadableRetryCount; loader = new Loader("Loader:ChunkSampleSource", minLoadableRetryCount);
currentLoadableHolder = new ChunkOperationHolder(); currentLoadableHolder = new ChunkOperationHolder();
mediaChunks = new LinkedList<>(); mediaChunks = new LinkedList<>();
readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks); readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks);
...@@ -151,7 +150,6 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call ...@@ -151,7 +150,6 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
durationUs = chunkSource.getDurationUs(); durationUs = chunkSource.getDurationUs();
TrackGroup tracks = chunkSource.getTracks(); TrackGroup tracks = chunkSource.getTracks();
if (tracks != null) { if (tracks != null) {
loader = new Loader("Loader:" + tracks.getFormat(0).containerMimeType, minLoadableRetryCount);
trackGroups = new TrackGroupArray(tracks); trackGroups = new TrackGroupArray(tracks);
} else { } else {
trackGroups = new TrackGroupArray(); trackGroups = new TrackGroupArray();
...@@ -191,7 +189,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call ...@@ -191,7 +189,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
newStreams[0] = this; newStreams[0] = this;
} }
// Cancel or start requests as necessary. // Cancel or start requests as necessary.
if (!trackEnabled && loader != null) { if (!trackEnabled) {
if (loadControlRegistered) { if (loadControlRegistered) {
loadControl.unregister(this); loadControl.unregister(this);
loadControlRegistered = false; loadControlRegistered = false;
...@@ -335,10 +333,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call ...@@ -335,10 +333,7 @@ public class ChunkSampleSource implements SampleSource, TrackStream, Loader.Call
public void release() { public void release() {
prepared = false; prepared = false;
trackEnabled = false; trackEnabled = false;
if (loader != null) {
loader.release(); loader.release();
loader = null;
}
} }
// Loadable.Callback implementation. // Loadable.Callback implementation.
......
...@@ -114,7 +114,6 @@ public class DashChunkSource implements ChunkSource { ...@@ -114,7 +114,6 @@ public class DashChunkSource implements ChunkSource {
private final long[] availableRangeValues; private final long[] availableRangeValues;
private final int eventSourceId; private final int eventSourceId;
private boolean manifestFetcherEnabled;
private boolean live; private boolean live;
private long durationUs; private long durationUs;
private MediaPresentationDescription currentManifest; private MediaPresentationDescription currentManifest;
...@@ -229,11 +228,6 @@ public class DashChunkSource implements ChunkSource { ...@@ -229,11 +228,6 @@ public class DashChunkSource implements ChunkSource {
@Override @Override
public boolean prepare() throws IOException { public boolean prepare() throws IOException {
if (!manifestFetcherEnabled) {
// TODO[REFACTOR]: We need to disable this at some point.
manifestFetcher.enable();
manifestFetcherEnabled = true;
}
if (currentManifest == null) { if (currentManifest == null) {
currentManifest = manifestFetcher.getManifest(); currentManifest = manifestFetcher.getManifest();
if (currentManifest == null) { if (currentManifest == null) {
......
...@@ -192,6 +192,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu ...@@ -192,6 +192,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
} }
} }
private final Loader loader;
private final ExtractorHolder extractorHolder; private final ExtractorHolder extractorHolder;
private final Allocator allocator; private final Allocator allocator;
private final int requestedBufferSize; private final int requestedBufferSize;
...@@ -224,7 +225,6 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu ...@@ -224,7 +225,6 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
private long pendingNextSampleUs; private long pendingNextSampleUs;
private long sampleTimeOffsetUs; private long sampleTimeOffsetUs;
private Loader loader;
private ExtractingLoadable loadable; private ExtractingLoadable loadable;
private IOException fatalException; private IOException fatalException;
private boolean currentLoadExtractedSamples; private boolean currentLoadExtractedSamples;
...@@ -308,6 +308,10 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu ...@@ -308,6 +308,10 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
this.allocator = allocator; this.allocator = allocator;
this.requestedBufferSize = requestedBufferSize; this.requestedBufferSize = requestedBufferSize;
this.minLoadableRetryCount = minLoadableRetryCount; this.minLoadableRetryCount = minLoadableRetryCount;
// Assume on-demand until we know otherwise.
int initialMinRetryCount = minLoadableRetryCount == MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA
? DEFAULT_MIN_LOADABLE_RETRY_COUNT_ON_DEMAND : minLoadableRetryCount;
loader = new Loader("Loader:ExtractorSampleSource", initialMinRetryCount);
if (extractors == null || extractors.length == 0) { if (extractors == null || extractors.length == 0) {
extractors = new Extractor[DEFAULT_EXTRACTOR_CLASSES.size()]; extractors = new Extractor[DEFAULT_EXTRACTOR_CLASSES.size()];
for (int i = 0; i < extractors.length; i++) { for (int i = 0; i < extractors.length; i++) {
...@@ -330,12 +334,6 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu ...@@ -330,12 +334,6 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
if (prepared) { if (prepared) {
return true; return true;
} }
if (loader == null) {
// Assume on-demand until we know otherwise.
int initialMinLoadableRetryCount = minLoadableRetryCount == MIN_RETRY_COUNT_DEFAULT_FOR_MEDIA
? DEFAULT_MIN_LOADABLE_RETRY_COUNT_ON_DEMAND : minLoadableRetryCount;
loader = new Loader("Loader:ExtractorSampleSource", initialMinLoadableRetryCount);
}
maybeStartLoading(); maybeStartLoading();
if (seekMap == null || !tracksBuilt || !haveFormatsForAllTracks()) { if (seekMap == null || !tracksBuilt || !haveFormatsForAllTracks()) {
maybeThrowError(); maybeThrowError();
...@@ -517,10 +515,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu ...@@ -517,10 +515,7 @@ public final class ExtractorSampleSource implements SampleSource, ExtractorOutpu
@Override @Override
public void release() { public void release() {
enabledTrackCount = 0; enabledTrackCount = 0;
if (loader != null) {
loader.release(); loader.release();
loader = null;
}
} }
// Loader.Callback implementation. // Loader.Callback implementation.
......
...@@ -85,7 +85,6 @@ public class HlsChunkSource { ...@@ -85,7 +85,6 @@ public class HlsChunkSource {
private final HlsPlaylistParser playlistParser; private final HlsPlaylistParser playlistParser;
private final PtsTimestampAdjusterProvider timestampAdjusterProvider; private final PtsTimestampAdjusterProvider timestampAdjusterProvider;
private boolean manifestFetcherEnabled;
private byte[] scratchSpace; private byte[] scratchSpace;
private boolean live; private boolean live;
private long durationUs; private long durationUs;
...@@ -157,11 +156,6 @@ public class HlsChunkSource { ...@@ -157,11 +156,6 @@ public class HlsChunkSource {
* @return True if the source was prepared, false otherwise. * @return True if the source was prepared, false otherwise.
*/ */
public boolean prepare() throws IOException { public boolean prepare() throws IOException {
if (!manifestFetcherEnabled) {
// TODO[REFACTOR]: We need to disable this at some point.
manifestFetcher.enable();
manifestFetcherEnabled = true;
}
if (masterPlaylist == null) { if (masterPlaylist == null) {
HlsPlaylist playlist = manifestFetcher.getManifest(); HlsPlaylist playlist = manifestFetcher.getManifest();
if (playlist == null) { if (playlist == null) {
......
...@@ -63,9 +63,9 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback { ...@@ -63,9 +63,9 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
private static final int PRIMARY_TYPE_AUDIO = 2; private static final int PRIMARY_TYPE_AUDIO = 2;
private static final int PRIMARY_TYPE_VIDEO = 3; private static final int PRIMARY_TYPE_VIDEO = 3;
private final Loader loader;
private final HlsChunkSource chunkSource; private final HlsChunkSource chunkSource;
private final LinkedList<HlsExtractorWrapper> extractors; private final LinkedList<HlsExtractorWrapper> extractors;
private final int minLoadableRetryCount;
private final int bufferSizeContribution; private final int bufferSizeContribution;
private final ChunkOperationHolder chunkOperationHolder; private final ChunkOperationHolder chunkOperationHolder;
...@@ -99,7 +99,6 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback { ...@@ -99,7 +99,6 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
private TsChunk currentTsLoadable; private TsChunk currentTsLoadable;
private TsChunk previousTsLoadable; private TsChunk previousTsLoadable;
private Loader loader;
private long currentLoadStartTimeMs; private long currentLoadStartTimeMs;
public HlsSampleSource(HlsChunkSource chunkSource, LoadControl loadControl, public HlsSampleSource(HlsChunkSource chunkSource, LoadControl loadControl,
...@@ -120,11 +119,11 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback { ...@@ -120,11 +119,11 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
this.chunkSource = chunkSource; this.chunkSource = chunkSource;
this.loadControl = loadControl; this.loadControl = loadControl;
this.bufferSizeContribution = bufferSizeContribution; this.bufferSizeContribution = bufferSizeContribution;
this.minLoadableRetryCount = minLoadableRetryCount;
this.eventHandler = eventHandler; this.eventHandler = eventHandler;
this.eventListener = eventListener; this.eventListener = eventListener;
this.eventSourceId = eventSourceId; this.eventSourceId = eventSourceId;
this.pendingResetPositionUs = NO_RESET_PENDING; this.pendingResetPositionUs = NO_RESET_PENDING;
loader = new Loader("Loader:HLS", minLoadableRetryCount);
extractors = new LinkedList<>(); extractors = new LinkedList<>();
chunkOperationHolder = new ChunkOperationHolder(); chunkOperationHolder = new ChunkOperationHolder();
} }
...@@ -159,8 +158,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback { ...@@ -159,8 +158,7 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
} }
} }
// We're not prepared and we haven't loaded what we need. // We're not prepared and we haven't loaded what we need.
if (loader == null) { if (!loadControlRegistered) {
loader = new Loader("Loader:HLS", minLoadableRetryCount);
loadControl.register(this, bufferSizeContribution); loadControl.register(this, bufferSizeContribution);
loadControlRegistered = true; loadControlRegistered = true;
} }
...@@ -368,14 +366,11 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback { ...@@ -368,14 +366,11 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback {
@Override @Override
public void release() { public void release() {
enabledTrackCount = 0; enabledTrackCount = 0;
if (loader != null) {
if (loadControlRegistered) { if (loadControlRegistered) {
loadControl.unregister(this); loadControl.unregister(this);
loadControlRegistered = false; loadControlRegistered = false;
} }
loader.release(); loader.release();
loader = null;
}
} }
// Loader.Callback implementation. // Loader.Callback implementation.
......
...@@ -65,7 +65,6 @@ public class SmoothStreamingChunkSource implements ChunkSource { ...@@ -65,7 +65,6 @@ public class SmoothStreamingChunkSource implements ChunkSource {
private final ManifestFetcher<SmoothStreamingManifest> manifestFetcher; private final ManifestFetcher<SmoothStreamingManifest> manifestFetcher;
private final FormatEvaluator adaptiveFormatEvaluator; private final FormatEvaluator adaptiveFormatEvaluator;
private boolean manifestFetcherEnabled;
private boolean live; private boolean live;
private long durationUs; private long durationUs;
private TrackEncryptionBox[] trackEncryptionBoxes; private TrackEncryptionBox[] trackEncryptionBoxes;
...@@ -122,11 +121,6 @@ public class SmoothStreamingChunkSource implements ChunkSource { ...@@ -122,11 +121,6 @@ public class SmoothStreamingChunkSource implements ChunkSource {
@Override @Override
public boolean prepare() throws IOException { public boolean prepare() throws IOException {
if (!manifestFetcherEnabled) {
// TODO[REFACTOR]: We need to disable this at some point.
manifestFetcher.enable();
manifestFetcherEnabled = true;
}
if (currentManifest == null) { if (currentManifest == null) {
currentManifest = manifestFetcher.getManifest(); currentManifest = manifestFetcher.getManifest();
if (currentManifest == null) { if (currentManifest == null) {
......
...@@ -69,6 +69,7 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -69,6 +69,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
} }
private final Loader loader;
private final UriLoadable.Parser<T> parser; private final UriLoadable.Parser<T> parser;
private final DataSource dataSource; private final DataSource dataSource;
private final Handler eventHandler; private final Handler eventHandler;
...@@ -76,8 +77,6 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -76,8 +77,6 @@ public class ManifestFetcher<T> implements Loader.Callback {
private volatile Uri manifestUri; private volatile Uri manifestUri;
private int enabledCount;
private Loader loader;
private UriLoadable<T> currentLoadable; private UriLoadable<T> currentLoadable;
private long currentLoadStartTimestamp; private long currentLoadStartTimestamp;
...@@ -109,6 +108,7 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -109,6 +108,7 @@ public class ManifestFetcher<T> implements Loader.Callback {
this.dataSource = dataSource; this.dataSource = dataSource;
this.eventHandler = eventHandler; this.eventHandler = eventHandler;
this.eventListener = eventListener; this.eventListener = eventListener;
loader = new Loader("Loader:ManifestFetcher", 1);
} }
/** /**
...@@ -168,31 +168,9 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -168,31 +168,9 @@ public class ManifestFetcher<T> implements Loader.Callback {
} }
/** /**
* Enables refresh functionality.
*/
public void enable() {
enabledCount++;
}
/**
* Disables refresh functionality.
*/
public void disable() {
if (--enabledCount == 0) {
if (loader != null) {
loader.release();
loader = null;
}
}
}
/**
* Should be invoked repeatedly by callers who require an updated manifest. * Should be invoked repeatedly by callers who require an updated manifest.
*/ */
public void requestRefresh() { public void requestRefresh() {
if (loader == null) {
loader = new Loader("manifestLoader", 1);
}
if (loader.isLoading()) { if (loader.isLoading()) {
return; return;
} }
...@@ -202,17 +180,22 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -202,17 +180,22 @@ public class ManifestFetcher<T> implements Loader.Callback {
notifyManifestRefreshStarted(); notifyManifestRefreshStarted();
} }
@Override /**
public void onLoadCompleted(Loadable loadable) { * Releases the fetcher.
if (currentLoadable != loadable) { * <p>
// Stale event. * This method should be called when the fetcher is no longer required.
return; */
public void release() {
loader.release();
} }
// Loadable.Callback implementation.
@Override
public void onLoadCompleted(Loadable loadable) {
manifest = currentLoadable.getResult(); manifest = currentLoadable.getResult();
manifestLoadStartTimestamp = currentLoadStartTimestamp; manifestLoadStartTimestamp = currentLoadStartTimestamp;
manifestLoadCompleteTimestamp = SystemClock.elapsedRealtime(); manifestLoadCompleteTimestamp = SystemClock.elapsedRealtime();
if (manifest instanceof RedirectingManifest) { if (manifest instanceof RedirectingManifest) {
RedirectingManifest redirectingManifest = (RedirectingManifest) manifest; RedirectingManifest redirectingManifest = (RedirectingManifest) manifest;
Uri nextUri = redirectingManifest.getNextManifestUri(); Uri nextUri = redirectingManifest.getNextManifestUri();
...@@ -220,7 +203,6 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -220,7 +203,6 @@ public class ManifestFetcher<T> implements Loader.Callback {
manifestUri = nextUri; manifestUri = nextUri;
} }
} }
notifyManifestRefreshed(); notifyManifestRefreshed();
} }
...@@ -231,15 +213,12 @@ public class ManifestFetcher<T> implements Loader.Callback { ...@@ -231,15 +213,12 @@ public class ManifestFetcher<T> implements Loader.Callback {
@Override @Override
public int onLoadError(Loadable loadable, IOException exception) { public int onLoadError(Loadable loadable, IOException exception) {
if (currentLoadable != loadable) {
// Stale event.
return Loader.DONT_RETRY;
}
notifyManifestError(new ManifestIOException(exception)); notifyManifestError(new ManifestIOException(exception));
return Loader.RETRY; return Loader.RETRY;
} }
// Private methods.
private void notifyManifestRefreshStarted() { private void notifyManifestRefreshStarted() {
if (eventHandler != null && eventListener != null) { if (eventHandler != null && eventListener != null) {
eventHandler.post(new Runnable() { eventHandler.post(new Runnable() {
......
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