Support passing custom manifest parsers to Downloaders

Issue: #5978
PiperOrigin-RevId: 315941765
This commit is contained in:
olly 2020-06-11 19:31:29 +01:00 committed by Oliver Woodman
parent 73283d495a
commit 5324dc37e3
4 changed files with 64 additions and 4 deletions

View File

@ -82,7 +82,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> 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.

View File

@ -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<DashManifest> {
*/
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<DashManifest> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor) {
super(mediaItem, manifestParser, cacheDataSourceFactory, executor);
}
@Override

View File

@ -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<HlsPlaylist> {
*/
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<HlsPlaylist> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor) {
super(mediaItem, manifestParser, cacheDataSourceFactory, executor);
}
@Override

View File

@ -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<SsManifest> {
*/
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<SsManifest> {
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<SsManifest> manifestParser,
CacheDataSource.Factory cacheDataSourceFactory,
Executor executor) {
super(mediaItem, manifestParser, cacheDataSourceFactory, executor);
}
@Override
protected List<Segment> getSegments(
DataSource dataSource, SsManifest manifest, boolean allowIncompleteList) {