From 06fd826a5c16f3ee8de4ba51a9281d3fde6ba1b5 Mon Sep 17 00:00:00 2001 From: olly Date: Tue, 5 Jul 2016 11:53:27 -0700 Subject: [PATCH] Restore injection of non-default retry count. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=126646585 --- .../exoplayer/dash/DashSampleSource.java | 21 +++++++++++++------ .../exoplayer/hls/HlsSampleSource.java | 17 +++++++++++---- .../SmoothStreamingSampleSource.java | 17 +++++++++++---- .../exoplayer/playbacktests/gts/DashTest.java | 5 +++-- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/dash/DashSampleSource.java b/library/src/main/java/com/google/android/exoplayer/dash/DashSampleSource.java index 635860bc83..cf5cba5954 100644 --- a/library/src/main/java/com/google/android/exoplayer/dash/DashSampleSource.java +++ b/library/src/main/java/com/google/android/exoplayer/dash/DashSampleSource.java @@ -66,15 +66,16 @@ import java.util.TimeZone; public final class DashSampleSource implements SampleSource, SequenceableLoader.Callback> { - private static final String TAG = "DashSampleSource"; - /** - * The minimum number of times to retry loading data prior to failing. + * The default minimum number of times to retry loading data prior to failing. */ - private static final int MIN_LOADABLE_RETRY_COUNT = 3; + public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 3; + + private static final String TAG = "DashSampleSource"; private final DataSourceFactory dataSourceFactory; private final BandwidthMeter bandwidthMeter; + private final int minLoadableRetryCount; private final EventDispatcher eventDispatcher; private final Loader loader; private final DataSource dataSource; @@ -101,9 +102,17 @@ public final class DashSampleSource implements SampleSource, public DashSampleSource(Uri manifestUri, DataSourceFactory dataSourceFactory, BandwidthMeter bandwidthMeter, Handler eventHandler, AdaptiveSourceEventListener eventListener) { + this(manifestUri, dataSourceFactory, bandwidthMeter, DEFAULT_MIN_LOADABLE_RETRY_COUNT, + eventHandler, eventListener); + } + + public DashSampleSource(Uri manifestUri, DataSourceFactory dataSourceFactory, + BandwidthMeter bandwidthMeter, int minLoadableRetryCount, Handler eventHandler, + AdaptiveSourceEventListener eventListener) { this.manifestUri = manifestUri; this.dataSourceFactory = dataSourceFactory; this.bandwidthMeter = bandwidthMeter; + this.minLoadableRetryCount = minLoadableRetryCount; eventDispatcher = new EventDispatcher(eventHandler, eventListener); dataSource = dataSourceFactory.createDataSource(); loader = new Loader("Loader:DashSampleSource"); @@ -282,7 +291,7 @@ public final class DashSampleSource implements SampleSource, private void startLoadingManifest() { startLoading(new ParsingLoadable<>(dataSource, manifestUri, C.DATA_TYPE_MANIFEST, - manifestParser), manifestCallback, MIN_LOADABLE_RETRY_COUNT); + manifestParser), manifestCallback, minLoadableRetryCount); } private void resolveUtcTimingElement(UtcTimingElement timingElement) { @@ -402,7 +411,7 @@ public final class DashSampleSource implements SampleSource, trackGroups.get(selection.group), selectedTracks, dataSource, adaptiveEvaluator, elapsedRealtimeOffset); return new ChunkTrackStream<>(adaptationSetType, chunkSource, this, allocator, positionUs, - MIN_LOADABLE_RETRY_COUNT, eventDispatcher); + minLoadableRetryCount, eventDispatcher); } @SuppressWarnings("unchecked") diff --git a/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java b/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java index 1285d10965..1cacbd8601 100644 --- a/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java +++ b/library/src/main/java/com/google/android/exoplayer/hls/HlsSampleSource.java @@ -57,13 +57,14 @@ public final class HlsSampleSource implements SampleSource, Loader.Callback>, HlsTrackStreamWrapper.Callback { /** - * The minimum number of times to retry loading data prior to failing. + * The default minimum number of times to retry loading data prior to failing. */ - private static final int MIN_LOADABLE_RETRY_COUNT = 3; + public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 3; private final Uri manifestUri; private final DataSourceFactory dataSourceFactory; private final BandwidthMeter bandwidthMeter; + private final int minLoadableRetryCount; private final EventDispatcher eventDispatcher; private final IdentityHashMap trackStreamSources; private final PtsTimestampAdjusterProvider timestampAdjusterProvider; @@ -88,9 +89,17 @@ public final class HlsSampleSource implements SampleSource, public HlsSampleSource(Uri manifestUri, DataSourceFactory dataSourceFactory, BandwidthMeter bandwidthMeter, Handler eventHandler, AdaptiveSourceEventListener eventListener) { + this(manifestUri, dataSourceFactory, bandwidthMeter, DEFAULT_MIN_LOADABLE_RETRY_COUNT, + eventHandler, eventListener); + } + + public HlsSampleSource(Uri manifestUri, DataSourceFactory dataSourceFactory, + BandwidthMeter bandwidthMeter, int minLoadableRetryCount, Handler eventHandler, + AdaptiveSourceEventListener eventListener) { this.manifestUri = manifestUri; this.dataSourceFactory = dataSourceFactory; this.bandwidthMeter = bandwidthMeter; + this.minLoadableRetryCount = minLoadableRetryCount; eventDispatcher = new EventDispatcher(eventHandler, eventListener); timestampAdjusterProvider = new PtsTimestampAdjusterProvider(); @@ -109,7 +118,7 @@ public final class HlsSampleSource implements SampleSource, ParsingLoadable loadable = new ParsingLoadable<>(manifestDataSource, manifestUri, C.DATA_TYPE_MANIFEST, manifestParser); long elapsedRealtimeMs = manifestFetcher.startLoading(loadable, this, - MIN_LOADABLE_RETRY_COUNT); + minLoadableRetryCount); eventDispatcher.loadStarted(loadable.dataSpec, loadable.type, elapsedRealtimeMs); } @@ -355,7 +364,7 @@ public final class HlsSampleSource implements SampleSource, HlsChunkSource defaultChunkSource = new HlsChunkSource(baseUri, variants, dataSource, timestampAdjusterProvider, formatEvaluator); return new HlsTrackStreamWrapper(trackType, this, defaultChunkSource, allocator, - preparePositionUs, muxedAudioFormat, muxedCaptionFormat, MIN_LOADABLE_RETRY_COUNT, + preparePositionUs, muxedAudioFormat, muxedCaptionFormat, minLoadableRetryCount, eventDispatcher); } diff --git a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingSampleSource.java b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingSampleSource.java index 77c1c5fe50..e59b0bd3d1 100644 --- a/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingSampleSource.java +++ b/library/src/main/java/com/google/android/exoplayer/smoothstreaming/SmoothStreamingSampleSource.java @@ -58,9 +58,9 @@ public final class SmoothStreamingSampleSource implements SampleSource, Loader.Callback> { /** - * The minimum number of times to retry loading data prior to failing. + * The default minimum number of times to retry loading data prior to failing. */ - private static final int MIN_LOADABLE_RETRY_COUNT = 3; + public static final int DEFAULT_MIN_LOADABLE_RETRY_COUNT = 3; private static final int MINIMUM_MANIFEST_REFRESH_PERIOD_MS = 5000; private static final int INITIALIZATION_VECTOR_SIZE = 8; @@ -68,6 +68,7 @@ public final class SmoothStreamingSampleSource implements SampleSource, private final Uri manifestUri; private final DataSourceFactory dataSourceFactory; private final BandwidthMeter bandwidthMeter; + private final int minLoadableRetryCount; private final EventDispatcher eventDispatcher; private final Loader manifestLoader; private final DataSource manifestDataSource; @@ -91,10 +92,18 @@ public final class SmoothStreamingSampleSource implements SampleSource, public SmoothStreamingSampleSource(Uri manifestUri, DataSourceFactory dataSourceFactory, BandwidthMeter bandwidthMeter, Handler eventHandler, AdaptiveSourceEventListener eventListener) { + this(manifestUri, dataSourceFactory, bandwidthMeter, DEFAULT_MIN_LOADABLE_RETRY_COUNT, + eventHandler, eventListener); + } + + public SmoothStreamingSampleSource(Uri manifestUri, DataSourceFactory dataSourceFactory, + BandwidthMeter bandwidthMeter, int minLoadableRetryCount, Handler eventHandler, + AdaptiveSourceEventListener eventListener) { this.manifestUri = Util.toLowerInvariant(manifestUri.getLastPathSegment()).equals("manifest") ? manifestUri : Uri.withAppendedPath(manifestUri, "Manifest"); this.dataSourceFactory = dataSourceFactory; this.bandwidthMeter = bandwidthMeter; + this.minLoadableRetryCount = minLoadableRetryCount; this.eventDispatcher = new EventDispatcher(eventHandler, eventListener); trackStreams = newTrackStreamArray(0); sequenceableLoader = new CompositeSequenceableLoader(trackStreams); @@ -274,7 +283,7 @@ public final class SmoothStreamingSampleSource implements SampleSource, private void startLoadingManifest() { ParsingLoadable loadable = new ParsingLoadable<>(manifestDataSource, manifestUri, C.DATA_TYPE_MANIFEST, manifestParser); - long elapsedRealtimeMs = manifestLoader.startLoading(loadable, this, MIN_LOADABLE_RETRY_COUNT); + long elapsedRealtimeMs = manifestLoader.startLoading(loadable, this, minLoadableRetryCount); eventDispatcher.loadStarted(loadable.dataSpec, loadable.type, elapsedRealtimeMs); } @@ -313,7 +322,7 @@ public final class SmoothStreamingSampleSource implements SampleSource, manifest, streamElementIndex, trackGroups.get(selection.group), selectedTracks, dataSource, adaptiveEvaluator, trackEncryptionBoxes); return new ChunkTrackStream<>(streamElementType, chunkSource, this, allocator, positionUs, - MIN_LOADABLE_RETRY_COUNT, eventDispatcher); + minLoadableRetryCount, eventDispatcher); } @SuppressWarnings("unchecked") diff --git a/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/gts/DashTest.java b/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/gts/DashTest.java index 8fbf5bd75c..e9d677c8dc 100644 --- a/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/gts/DashTest.java +++ b/playbacktests/src/main/java/com/google/android/exoplayer/playbacktests/gts/DashTest.java @@ -63,7 +63,7 @@ public final class DashTest extends ActivityInstrumentationTestCase2