From 5324dc37e3175cf6ed95d1a5793878f3c04ef5b9 Mon Sep 17 00:00:00 2001 From: olly Date: Thu, 11 Jun 2020 19:31:29 +0100 Subject: [PATCH] Support passing custom manifest parsers to Downloaders Issue: #5978 PiperOrigin-RevId: 315941765 --- .../exoplayer2/offline/SegmentDownloader.java | 2 +- .../source/dash/offline/DashDownloader.java | 22 ++++++++++++++++++- .../source/hls/offline/HlsDownloader.java | 22 ++++++++++++++++++- .../smoothstreaming/offline/SsDownloader.java | 22 ++++++++++++++++++- 4 files changed, 64 insertions(+), 4 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java index f5abd3228e..7360b65f70 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java @@ -82,7 +82,7 @@ public abstract class SegmentDownloader> impleme /** * @param mediaItem The {@link MediaItem} to be downloaded. - * @param manifestParser A parser for the manifest. + * @param manifestParser A parser for manifests belonging to the media to be downloaded. * @param cacheDataSourceFactory A {@link CacheDataSource.Factory} for the cache into which the * download will be written. * @param executor An {@link Executor} used to make requests for the media being downloaded. diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloader.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloader.java index a367c73747..31a1f84674 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloader.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloader.java @@ -34,6 +34,7 @@ import com.google.android.exoplayer2.source.dash.manifest.RangedUri; import com.google.android.exoplayer2.source.dash.manifest.Representation; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSpec; +import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser; import com.google.android.exoplayer2.upstream.cache.CacheDataSource; import java.io.IOException; import java.util.ArrayList; @@ -115,7 +116,26 @@ public final class DashDownloader extends SegmentDownloader { */ public DashDownloader( MediaItem mediaItem, CacheDataSource.Factory cacheDataSourceFactory, Executor executor) { - super(mediaItem, new DashManifestParser(), cacheDataSourceFactory, executor); + this(mediaItem, new DashManifestParser(), cacheDataSourceFactory, executor); + } + + /** + * Creates a new instance. + * + * @param mediaItem The {@link MediaItem} to be downloaded. + * @param manifestParser A parser for DASH manifests. + * @param cacheDataSourceFactory A {@link CacheDataSource.Factory} for the cache into which the + * download will be written. + * @param executor An {@link Executor} used to make requests for the media being downloaded. + * Providing an {@link Executor} that uses multiple threads will speed up the download by + * allowing parts of it to be executed in parallel. + */ + public DashDownloader( + MediaItem mediaItem, + Parser manifestParser, + CacheDataSource.Factory cacheDataSourceFactory, + Executor executor) { + super(mediaItem, manifestParser, cacheDataSourceFactory, executor); } @Override diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java index 2b604ee8be..858fe8f527 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java @@ -26,6 +26,7 @@ import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylist; import com.google.android.exoplayer2.source.hls.playlist.HlsPlaylistParser; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSpec; +import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser; import com.google.android.exoplayer2.upstream.cache.CacheDataSource; import com.google.android.exoplayer2.util.UriUtil; import java.io.IOException; @@ -110,7 +111,26 @@ public final class HlsDownloader extends SegmentDownloader { */ public HlsDownloader( MediaItem mediaItem, CacheDataSource.Factory cacheDataSourceFactory, Executor executor) { - super(mediaItem, new HlsPlaylistParser(), cacheDataSourceFactory, executor); + this(mediaItem, new HlsPlaylistParser(), cacheDataSourceFactory, executor); + } + + /** + * Creates a new instance. + * + * @param mediaItem The {@link MediaItem} to be downloaded. + * @param manifestParser A parser for HLS playlists. + * @param cacheDataSourceFactory A {@link CacheDataSource.Factory} for the cache into which the + * download will be written. + * @param executor An {@link Executor} used to make requests for the media being downloaded. + * Providing an {@link Executor} that uses multiple threads will speed up the download by + * allowing parts of it to be executed in parallel. + */ + public HlsDownloader( + MediaItem mediaItem, + Parser manifestParser, + CacheDataSource.Factory cacheDataSourceFactory, + Executor executor) { + super(mediaItem, manifestParser, cacheDataSourceFactory, executor); } @Override diff --git a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java index bb1bb06e6c..05828703f6 100644 --- a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java +++ b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java @@ -27,6 +27,7 @@ import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifestP import com.google.android.exoplayer2.source.smoothstreaming.manifest.SsUtil; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DataSpec; +import com.google.android.exoplayer2.upstream.ParsingLoadable.Parser; import com.google.android.exoplayer2.upstream.cache.CacheDataSource; import java.util.ArrayList; import java.util.List; @@ -108,7 +109,7 @@ public final class SsDownloader extends SegmentDownloader { */ public SsDownloader( MediaItem mediaItem, CacheDataSource.Factory cacheDataSourceFactory, Executor executor) { - super( + this( mediaItem .buildUpon() .setUri(SsUtil.fixManifestUri(checkNotNull(mediaItem.playbackProperties).uri)) @@ -118,6 +119,25 @@ public final class SsDownloader extends SegmentDownloader { executor); } + /** + * Creates a new instance. + * + * @param mediaItem The {@link MediaItem} to be downloaded. + * @param manifestParser A parser for SmoothStreaming manifests. + * @param cacheDataSourceFactory A {@link CacheDataSource.Factory} for the cache into which the + * download will be written. + * @param executor An {@link Executor} used to make requests for the media being downloaded. + * Providing an {@link Executor} that uses multiple threads will speed up the download by + * allowing parts of it to be executed in parallel. + */ + public SsDownloader( + MediaItem mediaItem, + Parser manifestParser, + CacheDataSource.Factory cacheDataSourceFactory, + Executor executor) { + super(mediaItem, manifestParser, cacheDataSourceFactory, executor); + } + @Override protected List getSegments( DataSource dataSource, SsManifest manifest, boolean allowIncompleteList) {