Commit 3cb58626 by olly Committed by Oliver Woodman

Only pass "throwing" part of Loader to MediaSource children

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=128492613
parent 47346c39
......@@ -18,7 +18,7 @@ package com.google.android.exoplayer2.source.dash;
import com.google.android.exoplayer2.source.chunk.ChunkSource;
import com.google.android.exoplayer2.source.dash.manifest.DashManifest;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
/**
* An {@link ChunkSource} for DASH streams.
......@@ -27,9 +27,9 @@ public interface DashChunkSource extends ChunkSource {
interface Factory {
DashChunkSource createDashChunkSource(Loader manifestLoader, DashManifest manifest,
int periodIndex, int adaptationSetIndex, TrackSelection trackSelection,
long elapsedRealtimeOffsetMs);
DashChunkSource createDashChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
DashManifest manifest, int periodIndex, int adaptationSetIndex,
TrackSelection trackSelection, long elapsedRealtimeOffsetMs);
}
......
......@@ -31,7 +31,7 @@ import com.google.android.exoplayer2.source.dash.manifest.Period;
import com.google.android.exoplayer2.source.dash.manifest.Representation;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
import java.io.IOException;
import java.util.List;
......@@ -46,7 +46,7 @@ import java.util.List;
private final int minLoadableRetryCount;
private final EventDispatcher eventDispatcher;
private final long elapsedRealtimeOffset;
private final Loader loader;
private final LoaderErrorThrower manifestLoaderErrorThrower;
private final TrackGroupArray trackGroups;
private ChunkSampleStream<DashChunkSource>[] sampleStreams;
......@@ -60,14 +60,15 @@ import java.util.List;
public DashMediaPeriod(DashManifest manifest, int index,
DashChunkSource.Factory chunkSourceFactory, int minLoadableRetryCount,
EventDispatcher eventDispatcher, long elapsedRealtimeOffset, Loader loader) {
EventDispatcher eventDispatcher, long elapsedRealtimeOffset,
LoaderErrorThrower manifestLoaderErrorThrower) {
this.manifest = manifest;
this.index = index;
this.chunkSourceFactory = chunkSourceFactory;
this.minLoadableRetryCount = minLoadableRetryCount;
this.eventDispatcher = eventDispatcher;
this.elapsedRealtimeOffset = elapsedRealtimeOffset;
this.loader = loader;
this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
durationUs = manifest.dynamic ? C.UNSET_TIME_US : manifest.getPeriodDuration(index) * 1000;
period = manifest.getPeriod(index);
trackGroups = buildTrackGroups(period);
......@@ -99,7 +100,7 @@ import java.util.List;
@Override
public void maybeThrowPrepareError() throws IOException {
loader.maybeThrowError();
manifestLoaderErrorThrower.maybeThrowError();
}
@Override
......@@ -219,8 +220,9 @@ import java.util.List;
long positionUs) {
int adaptationSetIndex = trackGroups.indexOf(selection.group);
AdaptationSet adaptationSet = period.adaptationSets.get(adaptationSetIndex);
DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(loader, manifest, index,
adaptationSetIndex, selection, elapsedRealtimeOffset);
DashChunkSource chunkSource = chunkSourceFactory.createDashChunkSource(
manifestLoaderErrorThrower, manifest, index, adaptationSetIndex, selection,
elapsedRealtimeOffset);
return new ChunkSampleStream<>(adaptationSet.type, chunkSource, this, allocator, positionUs,
minLoadableRetryCount, eventDispatcher);
}
......
......@@ -15,7 +15,6 @@
*/
package com.google.android.exoplayer2.source.dash;
import android.os.SystemClock;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.extractor.ChunkIndex;
......@@ -41,9 +40,12 @@ import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.HttpDataSource.InvalidResponseCodeException;
import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import android.os.SystemClock;
import java.io.IOException;
import java.util.List;
......@@ -64,19 +66,20 @@ public class DefaultDashChunkSource implements DashChunkSource {
}
@Override
public DashChunkSource createDashChunkSource(Loader manifestLoader, DashManifest manifest,
int periodIndex, int adaptationSetIndex, TrackSelection trackSelection,
long elapsedRealtimeOffsetMs) {
public DashChunkSource createDashChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
DashManifest manifest, int periodIndex, int adaptationSetIndex,
TrackSelection trackSelection, long elapsedRealtimeOffsetMs) {
FormatEvaluator adaptiveEvaluator = trackSelection.length > 1
? formatEvaluatorFactory.createFormatEvaluator() : null;
DataSource dataSource = dataSourceFactory.createDataSource();
return new DefaultDashChunkSource(manifestLoader, manifest, periodIndex, adaptationSetIndex,
trackSelection, dataSource, adaptiveEvaluator, elapsedRealtimeOffsetMs);
return new DefaultDashChunkSource(manifestLoaderErrorThrower, manifest, periodIndex,
adaptationSetIndex, trackSelection, dataSource, adaptiveEvaluator,
elapsedRealtimeOffsetMs);
}
}
private final Loader manifestLoader;
private final LoaderErrorThrower manifestLoaderErrorThrower;
private final int adaptationSetIndex;
private final TrackSelection trackSelection;
private final RepresentationHolder[] representationHolders;
......@@ -93,7 +96,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
private boolean missingLastSegment;
/**
* @param manifestLoader The {@link Loader} being used to load manifests.
* @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
* @param manifest The initial manifest.
* @param periodIndex The index of the period in the manifest.
* @param adaptationSetIndex The index of the adaptation set in the period.
......@@ -104,10 +107,11 @@ public class DefaultDashChunkSource implements DashChunkSource {
* server-side unix time and {@link SystemClock#elapsedRealtime()} in milliseconds, specified
* as the server's unix time minus the local elapsed time. If unknown, set to 0.
*/
public DefaultDashChunkSource(Loader manifestLoader, DashManifest manifest, int periodIndex,
int adaptationSetIndex, TrackSelection trackSelection, DataSource dataSource,
FormatEvaluator adaptiveFormatEvaluator, long elapsedRealtimeOffsetMs) {
this.manifestLoader = manifestLoader;
public DefaultDashChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
DashManifest manifest, int periodIndex, int adaptationSetIndex, TrackSelection trackSelection,
DataSource dataSource, FormatEvaluator adaptiveFormatEvaluator,
long elapsedRealtimeOffsetMs) {
this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
this.manifest = manifest;
this.adaptationSetIndex = adaptationSetIndex;
this.trackSelection = trackSelection;
......@@ -151,7 +155,7 @@ public class DefaultDashChunkSource implements DashChunkSource {
if (fatalError != null) {
throw fatalError;
} else {
manifestLoader.maybeThrowError();
manifestLoaderErrorThrower.maybeThrowError();
}
}
......
......@@ -33,7 +33,7 @@ import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
import android.net.Uri;
......@@ -57,19 +57,19 @@ public class DefaultSsChunkSource implements SsChunkSource {
}
@Override
public SsChunkSource createChunkSource(Loader manifestLoader, SsManifest manifest,
int elementIndex, TrackSelection trackSelection,
public SsChunkSource createChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
SsManifest manifest, int elementIndex, TrackSelection trackSelection,
TrackEncryptionBox[] trackEncryptionBoxes) {
FormatEvaluator adaptiveEvaluator = trackSelection.length > 1
? formatEvaluatorFactory.createFormatEvaluator() : null;
DataSource dataSource = dataSourceFactory.createDataSource();
return new DefaultSsChunkSource(manifestLoader, manifest, elementIndex, trackSelection,
dataSource, adaptiveEvaluator, trackEncryptionBoxes);
return new DefaultSsChunkSource(manifestLoaderErrorThrower, manifest, elementIndex,
trackSelection, dataSource, adaptiveEvaluator, trackEncryptionBoxes);
}
}
private final Loader manifestLoader;
private final LoaderErrorThrower manifestLoaderErrorThrower;
private final int elementIndex;
private final TrackSelection trackSelection;
private final ChunkExtractorWrapper[] extractorWrappers;
......@@ -84,7 +84,7 @@ public class DefaultSsChunkSource implements SsChunkSource {
private IOException fatalError;
/**
* @param manifestLoader The {@link Loader} being used to load manifests.
* @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
* @param manifest The initial manifest.
* @param elementIndex The index of the stream element in the manifest.
* @param trackSelection The track selection.
......@@ -92,10 +92,10 @@ public class DefaultSsChunkSource implements SsChunkSource {
* @param adaptiveFormatEvaluator For adaptive tracks, selects from the available formats.
* @param trackEncryptionBoxes Track encryption boxes for the stream.
*/
public DefaultSsChunkSource(Loader manifestLoader, SsManifest manifest, int elementIndex,
TrackSelection trackSelection, DataSource dataSource, FormatEvaluator adaptiveFormatEvaluator,
TrackEncryptionBox[] trackEncryptionBoxes) {
this.manifestLoader = manifestLoader;
public DefaultSsChunkSource(LoaderErrorThrower manifestLoaderErrorThrower, SsManifest manifest,
int elementIndex, TrackSelection trackSelection, DataSource dataSource,
FormatEvaluator adaptiveFormatEvaluator, TrackEncryptionBox[] trackEncryptionBoxes) {
this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
this.manifest = manifest;
this.elementIndex = elementIndex;
this.trackSelection = trackSelection;
......@@ -156,7 +156,7 @@ public class DefaultSsChunkSource implements SsChunkSource {
if (fatalError != null) {
throw fatalError;
} else {
manifestLoader.maybeThrowError();
manifestLoaderErrorThrower.maybeThrowError();
}
}
......
......@@ -19,7 +19,7 @@ import com.google.android.exoplayer2.extractor.mp4.TrackEncryptionBox;
import com.google.android.exoplayer2.source.chunk.ChunkSource;
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
/**
* A {@link ChunkSource} for SmoothStreaming.
......@@ -28,8 +28,9 @@ public interface SsChunkSource extends ChunkSource {
interface Factory {
SsChunkSource createChunkSource(Loader manifestLoader, SsManifest manifest, int elementIndex,
TrackSelection trackSelection, TrackEncryptionBox[] trackEncryptionBoxes);
SsChunkSource createChunkSource(LoaderErrorThrower manifestLoaderErrorThrower,
SsManifest manifest, int elementIndex, TrackSelection trackSelection,
TrackEncryptionBox[] trackEncryptionBoxes);
}
......
......@@ -29,7 +29,7 @@ import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest;
import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.ProtectionElement;
import com.google.android.exoplayer2.trackselection.TrackSelection;
import com.google.android.exoplayer2.upstream.Allocator;
import com.google.android.exoplayer2.upstream.Loader;
import com.google.android.exoplayer2.upstream.LoaderErrorThrower;
import android.util.Base64;
......@@ -45,7 +45,7 @@ import java.util.List;
private static final int INITIALIZATION_VECTOR_SIZE = 8;
private final SsChunkSource.Factory chunkSourceFactory;
private final Loader manifestLoader;
private final LoaderErrorThrower manifestLoaderErrorThrower;
private final int minLoadableRetryCount;
private final EventDispatcher eventDispatcher;
private final TrackGroupArray trackGroups;
......@@ -58,10 +58,11 @@ import java.util.List;
private Allocator allocator;
public SsMediaPeriod(SsManifest manifest, SsChunkSource.Factory chunkSourceFactory,
int minLoadableRetryCount, EventDispatcher eventDispatcher, Loader manifestLoader) {
int minLoadableRetryCount, EventDispatcher eventDispatcher,
LoaderErrorThrower manifestLoaderErrorThrower) {
this.manifest = manifest;
this.chunkSourceFactory = chunkSourceFactory;
this.manifestLoader = manifestLoader;
this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
this.minLoadableRetryCount = minLoadableRetryCount;
this.eventDispatcher = eventDispatcher;
trackGroups = buildTrackGroups(manifest);
......@@ -96,7 +97,7 @@ import java.util.List;
@Override
public void maybeThrowPrepareError() throws IOException {
manifestLoader.maybeThrowError();
manifestLoaderErrorThrower.maybeThrowError();
}
@Override
......@@ -199,8 +200,8 @@ import java.util.List;
private ChunkSampleStream<SsChunkSource> buildSampleStream(TrackSelection selection,
long positionUs) {
int streamElementIndex = trackGroups.indexOf(selection.group);
SsChunkSource chunkSource = chunkSourceFactory.createChunkSource(manifestLoader, manifest,
streamElementIndex, selection, trackEncryptionBoxes);
SsChunkSource chunkSource = chunkSourceFactory.createChunkSource(manifestLoaderErrorThrower,
manifest, streamElementIndex, selection, trackEncryptionBoxes);
return new ChunkSampleStream<>(manifest.streamElements[streamElementIndex].type, chunkSource,
this, allocator, positionUs, minLoadableRetryCount, eventDispatcher);
}
......
......@@ -32,7 +32,7 @@ import java.util.concurrent.ExecutorService;
/**
* Manages the background loading of {@link Loadable}s.
*/
public final class Loader {
public final class Loader implements LoaderErrorThrower {
/**
* Thrown when an unexpected exception is encountered during loading.
......@@ -174,34 +174,6 @@ public final class Loader {
}
/**
* Throws an error if a fatal error has been encountered, or if the current {@link Loadable} has
* incurred a number of errors greater than its default minimum number of retries and if the load
* is currently backed off, then an error is thrown. Else does nothing.
*
* @throws IOException The error.
*/
public void maybeThrowError() throws IOException {
maybeThrowError(Integer.MIN_VALUE);
}
/**
* Throws an error if a fatal error has been encountered, or if the current {@link Loadable} has
* incurred a number of errors greater than the specified minimum number of retries and if the
* load is currently backed off, then an error is thrown.
*
* @param minRetryCount A minimum retry count that must be exceeded.
* @throws IOException The error.
*/
public void maybeThrowError(int minRetryCount) throws IOException {
if (fatalError != null) {
throw fatalError;
} else if (currentTask != null) {
currentTask.maybeThrowError(minRetryCount == Integer.MIN_VALUE
? currentTask.defaultMinRetryCount : minRetryCount);
}
}
/**
* Cancels the current load. This method should only be called when a load is in progress.
*/
public void cancelLoading() {
......@@ -233,6 +205,25 @@ public final class Loader {
downloadExecutorService.shutdown();
}
// LoaderErrorThrower implementation.
@Override
public void maybeThrowError() throws IOException {
maybeThrowError(Integer.MIN_VALUE);
}
@Override
public void maybeThrowError(int minRetryCount) throws IOException {
if (fatalError != null) {
throw fatalError;
} else if (currentTask != null) {
currentTask.maybeThrowError(minRetryCount == Integer.MIN_VALUE
? currentTask.defaultMinRetryCount : minRetryCount);
}
}
// Internal classes.
@SuppressLint("HandlerLeak")
private final class LoadTask<T extends Loadable> extends Handler implements Runnable {
......
/*
* Copyright (C) 2016 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.upstream;
import com.google.android.exoplayer2.upstream.Loader.Loadable;
import java.io.IOException;
/**
* Conditionally throws errors affecting a {@link Loader}.
*/
public interface LoaderErrorThrower {
/**
* Throws a fatal error, or a non-fatal error if loading is currently backed off and the current
* {@link Loadable} has incurred a number of errors greater than the {@link Loader}s default
* minimum number of retries. Else does nothing.
*
* @throws IOException The error.
*/
void maybeThrowError() throws IOException;
/**
* Throws a fatal error, or a non-fatal error if loading is currently backed off and the current
* {@link Loadable} has incurred a number of errors greater than the specified minimum number
* of retries. Else does nothing.
*
* @param minRetryCount A minimum retry count that must be exceeded for a non-fatal error to be
* thrown. Should be non-negative.
* @throws IOException The error.
*/
void maybeThrowError(int minRetryCount) throws IOException;
}
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