From 051da40dc33ee1364a0e40ef540273dca3f596d3 Mon Sep 17 00:00:00 2001 From: olly Date: Sat, 5 May 2018 14:36:09 -0700 Subject: [PATCH] Misc cleanup ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=195552434 --- .../offline/DownloaderConstructorHelper.java | 17 ++-- .../offline/FilterableManifest.java | 13 +-- .../exoplayer2/offline/SegmentDownloader.java | 17 ++-- .../android/exoplayer2/offline/TrackKey.java | 5 +- .../source/dash/manifest/DashManifest.java | 12 +-- .../dash/offline/DashDownloadAction.java | 2 +- .../source/dash/offline/DashDownloader.java | 17 ++-- .../dash/offline/DashDownloaderTest.java | 2 +- .../source/hls/offline/HlsDownloadAction.java | 2 +- .../source/hls/offline/HlsDownloadHelper.java | 2 +- .../source/hls/offline/HlsDownloader.java | 95 ++++++++++++------- .../hls/playlist/HlsMasterPlaylist.java | 10 +- .../source/hls/playlist/HlsMediaPlaylist.java | 2 +- .../source/hls/playlist/HlsPlaylist.java | 3 +- .../source/hls/offline/HlsDownloaderTest.java | 2 +- .../smoothstreaming/manifest/SsManifest.java | 11 +-- .../offline/SsDownloadAction.java | 4 +- .../smoothstreaming/offline/SsDownloader.java | 15 ++- .../playbacktests/gts/DashDownloadTest.java | 2 +- 19 files changed, 127 insertions(+), 106 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java index 9ef9366397..18387b9d92 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java @@ -49,14 +49,17 @@ public final class DownloaderConstructorHelper { /** * @param cache Cache instance to be used to store downloaded data. * @param upstreamDataSourceFactory A {@link Factory} for downloading data. - * @param cacheReadDataSourceFactory A {@link Factory} for reading data from the cache. - * If null, null is passed to {@link Downloader} constructor. + * @param cacheReadDataSourceFactory A {@link Factory} for reading data from the cache. If null + * then standard {@link FileDataSource} instances will be used. * @param cacheWriteDataSinkFactory A {@link DataSink.Factory} for writing data to the cache. If - * null, null is passed to {@link Downloader} constructor. - * @param priorityTaskManager If one is given then the download priority is set lower than - * loading. If null, null is passed to {@link Downloader} constructor. + * null then standard {@link CacheDataSink} instances will be used. + * @param priorityTaskManager A {@link PriorityTaskManager} to use when downloading. If non-null, + * downloaders will register as tasks with priority {@link C#PRIORITY_DOWNLOAD} whilst + * downloading. */ - public DownloaderConstructorHelper(Cache cache, Factory upstreamDataSourceFactory, + public DownloaderConstructorHelper( + Cache cache, + Factory upstreamDataSourceFactory, @Nullable Factory cacheReadDataSourceFactory, @Nullable DataSink.Factory cacheWriteDataSinkFactory, @Nullable PriorityTaskManager priorityTaskManager) { @@ -73,7 +76,7 @@ public final class DownloaderConstructorHelper { return cache; } - /** Returns a {@link PriorityTaskManager} instance.*/ + /** Returns a {@link PriorityTaskManager} instance. */ public PriorityTaskManager getPriorityTaskManager() { // Return a dummy PriorityTaskManager if none is provided. Create a new PriorityTaskManager // each time so clients don't affect each other over the dummy PriorityTaskManager instance. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/FilterableManifest.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/FilterableManifest.java index 909bc81a45..35d05fd43b 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/FilterableManifest.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/FilterableManifest.java @@ -18,19 +18,20 @@ package com.google.android.exoplayer2.offline; import java.util.List; /** - * A manifest that can generate copies of itself including only the tracks specified by the given - * track keys. + * A manifest that can generate copies of itself including only the streams specified by the given + * keys. * * @param The manifest type. - * @param The track key type. + * @param The stream key type. */ public interface FilterableManifest { /** - * Returns a copy of the manifest including only the tracks specified by the given track keys. + * Returns a copy of the manifest including only the streams specified by the given keys. If the + * manifest is unchanged then the instance may return itself. * - * @param trackKeys A non-empty list of track keys. + * @param streamKeys A non-empty list of stream keys. * @return The filtered manifest. */ - T copy(List trackKeys); + T copy(List streamKeys); } 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 6790c086f8..6ce2121acd 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 @@ -35,7 +35,7 @@ import java.util.concurrent.atomic.AtomicBoolean; * Base class for multi segment stream downloaders. * * @param The type of the manifest object. - * @param The type of the track key object. + * @param The type of the streams key object. */ public abstract class SegmentDownloader, K> implements Downloader { @@ -68,7 +68,7 @@ public abstract class SegmentDownloader, K> private final Cache cache; private final CacheDataSource dataSource; private final CacheDataSource offlineDataSource; - private final ArrayList keys; + private final ArrayList streamKeys; private final AtomicBoolean isCanceled; private volatile int totalSegments; @@ -77,23 +77,24 @@ public abstract class SegmentDownloader, K> /** * @param manifestUri The {@link Uri} of the manifest to be downloaded. + * @param streamKeys Keys defining which streams in the manifest should be selected for download. + * If empty, all streams are downloaded. * @param constructorHelper A {@link DownloaderConstructorHelper} instance. - * @param trackKeys Track keys to select when downloading. If empty, all tracks are downloaded. */ public SegmentDownloader( - Uri manifestUri, DownloaderConstructorHelper constructorHelper, List trackKeys) { + Uri manifestUri, List streamKeys, DownloaderConstructorHelper constructorHelper) { this.manifestUri = manifestUri; + this.streamKeys = new ArrayList<>(streamKeys); this.cache = constructorHelper.getCache(); this.dataSource = constructorHelper.buildCacheDataSource(false); this.offlineDataSource = constructorHelper.buildCacheDataSource(true); this.priorityTaskManager = constructorHelper.getPriorityTaskManager(); - keys = new ArrayList<>(trackKeys); totalSegments = C.LENGTH_UNSET; isCanceled = new AtomicBoolean(); } /** - * Downloads the selected tracks in the media. If multiple tracks are selected, they are + * Downloads the selected streams in the media. If multiple streams are selected, they are * downloaded in sync with one another. * * @throws IOException Thrown when there is an error downloading. @@ -202,8 +203,8 @@ public abstract class SegmentDownloader, K> /** Initializes the download, returning a list of {@link Segment}s that need to be downloaded. */ private List initDownload() throws IOException, InterruptedException { M manifest = getManifest(dataSource, manifestUri); - if (!keys.isEmpty()) { - manifest = manifest.copy(keys); + if (!streamKeys.isEmpty()) { + manifest = manifest.copy(streamKeys); } List segments = getSegments(dataSource, manifest, /* allowIncompleteList= */ false); CachingCounters cachingCounters = new CachingCounters(); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/offline/TrackKey.java b/library/core/src/main/java/com/google/android/exoplayer2/offline/TrackKey.java index 7c65b3f9b2..f6a411c3a1 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/offline/TrackKey.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/offline/TrackKey.java @@ -19,10 +19,13 @@ package com.google.android.exoplayer2.offline; * Identifies a given track by the index of the containing period, the index of the containing group * within the period, and the index of the track within the group. */ -public class TrackKey { +public final class TrackKey { + /** The period index. */ public final int periodIndex; + /** The group index. */ public final int groupIndex; + /** The track index. */ public final int trackIndex; /** diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifest.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifest.java index 47e2650bec..639ad32d78 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifest.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/manifest/DashManifest.java @@ -122,17 +122,9 @@ public class DashManifest implements FilterableManifest representationKeys) { - LinkedList keys = new LinkedList<>(representationKeys); + public final DashManifest copy(List streamKeys) { + LinkedList keys = new LinkedList<>(streamKeys); Collections.sort(keys); keys.add(new RepresentationKey(-1, -1, -1)); // Add a stopper key to the end diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloadAction.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloadAction.java index b431c38130..c2facd9626 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloadAction.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloadAction.java @@ -61,7 +61,7 @@ public final class DashDownloadAction extends SegmentDownloadAction { - /** @see SegmentDownloader#SegmentDownloader(Uri, DownloaderConstructorHelper, List) */ + /** + * @param manifestUri The {@link Uri} of the manifest to be downloaded. + * @param representationKeys Keys defining which representations in the manifest should be + * selected for download. If empty, all representations are downloaded. + * @param constructorHelper A {@link DownloaderConstructorHelper} instance. + */ public DashDownloader( Uri manifestUri, - DownloaderConstructorHelper constructorHelper, - List trackKeys) { - super(manifestUri, constructorHelper, trackKeys); + List representationKeys, + DownloaderConstructorHelper constructorHelper) { + super(manifestUri, representationKeys, constructorHelper); } @Override diff --git a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DashDownloaderTest.java b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DashDownloaderTest.java index a096a4d4c2..4c96357528 100644 --- a/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DashDownloaderTest.java +++ b/library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DashDownloaderTest.java @@ -305,7 +305,7 @@ public class DashDownloaderTest { private DashDownloader getDashDownloader(Factory factory, RepresentationKey... keys) { return new DashDownloader( - TEST_MPD_URI, new DownloaderConstructorHelper(cache, factory), keysList(keys)); + TEST_MPD_URI, keysList(keys), new DownloaderConstructorHelper(cache, factory)); } private static ArrayList keysList(RepresentationKey... keys) { diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadAction.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadAction.java index ddf1e384a5..e56bf66efd 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadAction.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadAction.java @@ -63,7 +63,7 @@ public final class HlsDownloadAction extends SegmentDownloadAction @Override protected HlsDownloader createDownloader(DownloaderConstructorHelper constructorHelper) { - return new HlsDownloader(uri, constructorHelper, keys); + return new HlsDownloader(uri, keys, constructorHelper); } @Override diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadHelper.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadHelper.java index 0df1264f90..773aec49ee 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadHelper.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloadHelper.java @@ -43,7 +43,7 @@ public final class HlsDownloadHelper extends DownloadHelper { private final Uri uri; private final DataSource.Factory manifestDataSourceFactory; - private @MonotonicNonNull HlsPlaylist playlist; + private @MonotonicNonNull HlsPlaylist playlist; private int[] renditionTypes; public HlsDownloadHelper(Uri uri, DataSource.Factory manifestDataSourceFactory) { 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 9b06d81ff4..bd59eed447 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 @@ -34,54 +34,76 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; -/** A downloader for HLS streams. */ -public final class HlsDownloader extends SegmentDownloader { +/** + * A downloader for HLS streams. + * + *

Example usage: + * + *

{@code
+ * SimpleCache cache = new SimpleCache(downloadFolder, new NoOpCacheEvictor());
+ * DefaultHttpDataSourceFactory factory = new DefaultHttpDataSourceFactory("ExoPlayer", null);
+ * DownloaderConstructorHelper constructorHelper =
+ *     new DownloaderConstructorHelper(cache, factory);
+ * // Create a downloader for the first variant in a master playlist.
+ * HlsDownloader hlsDownloader =
+ *     new HlsDownloader(
+ *         playlistUri,
+ *         Collections.singletonList(new RenditionKey(RenditionKey.TYPE_VARIANT, 0)),
+ *         constructorHelper);
+ * // Perform the download.
+ * hlsDownloader.download();
+ * // Access downloaded data using CacheDataSource
+ * CacheDataSource cacheDataSource =
+ *     new CacheDataSource(cache, factory.createDataSource(), CacheDataSource.FLAG_BLOCK_ON_CACHE);
+ * }
+ */ +public final class HlsDownloader extends SegmentDownloader { - /** @see SegmentDownloader#SegmentDownloader(Uri, DownloaderConstructorHelper, List) */ + /** + * @param playlistUri The {@link Uri} of the playlist to be downloaded. + * @param renditionKeys Keys defining which renditions in the playlist should be selected for + * download. If empty, all renditions are downloaded. + * @param constructorHelper A {@link DownloaderConstructorHelper} instance. + */ public HlsDownloader( - Uri manifestUri, - DownloaderConstructorHelper constructorHelper, - List trackKeys) { - super(manifestUri, constructorHelper, trackKeys); + Uri playlistUri, + List renditionKeys, + DownloaderConstructorHelper constructorHelper) { + super(playlistUri, renditionKeys, constructorHelper); } @Override - protected HlsMasterPlaylist getManifest(DataSource dataSource, Uri uri) throws IOException { - HlsPlaylist hlsPlaylist = loadManifest(dataSource, uri); - if (hlsPlaylist instanceof HlsMasterPlaylist) { - return (HlsMasterPlaylist) hlsPlaylist; - } else { - return HlsMasterPlaylist.createSingleVariantMasterPlaylist(hlsPlaylist.baseUri); - } + protected HlsPlaylist getManifest(DataSource dataSource, Uri uri) throws IOException { + return loadManifest(dataSource, uri); } @Override protected List getSegments( - DataSource dataSource, HlsMasterPlaylist manifest, boolean allowIncompleteList) - throws IOException { - HashSet encryptionKeyUris = new HashSet<>(); - ArrayList renditionUrls = new ArrayList<>(); - renditionUrls.addAll(manifest.variants); - renditionUrls.addAll(manifest.audios); - renditionUrls.addAll(manifest.subtitles); + DataSource dataSource, HlsPlaylist playlist, boolean allowIncompleteList) throws IOException { + ArrayList mediaPlaylistUris = new ArrayList<>(); + if (playlist instanceof HlsMasterPlaylist) { + HlsMasterPlaylist masterPlaylist = (HlsMasterPlaylist) playlist; + addResolvedUris(masterPlaylist.baseUri, masterPlaylist.variants, mediaPlaylistUris); + addResolvedUris(masterPlaylist.baseUri, masterPlaylist.audios, mediaPlaylistUris); + addResolvedUris(masterPlaylist.baseUri, masterPlaylist.subtitles, mediaPlaylistUris); + } else { + mediaPlaylistUris.add(Uri.parse(playlist.baseUri)); + } ArrayList segments = new ArrayList<>(); - for (HlsUrl renditionUrl : renditionUrls) { - HlsMediaPlaylist mediaPlaylist = null; - Uri uri = UriUtil.resolveToUri(manifest.baseUri, renditionUrl.url); + HashSet seenEncryptionKeyUris = new HashSet<>(); + for (Uri mediaPlaylistUri : mediaPlaylistUris) { + HlsMediaPlaylist mediaPlaylist; try { - mediaPlaylist = (HlsMediaPlaylist) loadManifest(dataSource, uri); + mediaPlaylist = (HlsMediaPlaylist) loadManifest(dataSource, mediaPlaylistUri); + segments.add(new Segment(mediaPlaylist.startTimeUs, new DataSpec(mediaPlaylistUri))); } catch (IOException e) { if (!allowIncompleteList) { throw e; } - } - segments.add(new Segment(mediaPlaylist != null ? mediaPlaylist.startTimeUs : Long.MIN_VALUE, - new DataSpec(uri))); - if (mediaPlaylist == null) { + segments.add(new Segment(0, new DataSpec(mediaPlaylistUri))); continue; } - HlsMediaPlaylist.Segment lastInitSegment = null; List hlsSegments = mediaPlaylist.segments; for (int i = 0; i < hlsSegments.size(); i++) { @@ -89,9 +111,9 @@ public final class HlsDownloader extends SegmentDownloader segments, HlsMediaPlaylist mediaPlaylist, HlsMediaPlaylist.Segment hlsSegment, - HashSet encryptionKeyUris) { + HashSet seenEncryptionKeyUris) { long startTimeUs = mediaPlaylist.startTimeUs + hlsSegment.relativeStartTimeUs; if (hlsSegment.fullSegmentEncryptionKeyUri != null) { Uri keyUri = UriUtil.resolveToUri(mediaPlaylist.baseUri, hlsSegment.fullSegmentEncryptionKeyUri); - if (encryptionKeyUris.add(keyUri)) { + if (seenEncryptionKeyUris.add(keyUri)) { segments.add(new Segment(startTimeUs, new DataSpec(keyUri))); } } @@ -122,4 +144,9 @@ public final class HlsDownloader extends SegmentDownloader urls, List out) { + for (int i = 0; i < urls.size(); i++) { + out.add(UriUtil.resolveToUri(baseUri, urls.get(i).url)); + } + } } diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMasterPlaylist.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMasterPlaylist.java index ae55c539c9..5c29dca38e 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMasterPlaylist.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMasterPlaylist.java @@ -22,7 +22,7 @@ import java.util.Collections; import java.util.List; /** Represents an HLS master playlist. */ -public final class HlsMasterPlaylist extends HlsPlaylist { +public final class HlsMasterPlaylist extends HlsPlaylist { /** * Represents a url in an HLS master playlist. @@ -107,14 +107,6 @@ public final class HlsMasterPlaylist extends HlsPlaylist { ? Collections.unmodifiableList(muxedCaptionFormats) : null; } - /** - * Returns a copy of this playlist which includes only the renditions identified by the given - * keys. - * - * @param renditionKeys List of rendition keys. - * @return A copy of this playlist which includes only the renditions identified by the given - * urls. - */ @Override public HlsMasterPlaylist copy(List renditionKeys) { return new HlsMasterPlaylist( diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMediaPlaylist.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMediaPlaylist.java index 64c6c3749e..f905def54b 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMediaPlaylist.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsMediaPlaylist.java @@ -26,7 +26,7 @@ import java.util.Collections; import java.util.List; /** Represents an HLS media playlist. */ -public final class HlsMediaPlaylist extends HlsPlaylist { +public final class HlsMediaPlaylist extends HlsPlaylist { /** Media segment reference. */ @SuppressWarnings("ComparableType") diff --git a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylist.java b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylist.java index 98e8ffb3b6..34ecde229d 100644 --- a/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylist.java +++ b/library/hls/src/main/java/com/google/android/exoplayer2/source/hls/playlist/HlsPlaylist.java @@ -20,8 +20,7 @@ import java.util.Collections; import java.util.List; /** Represents an HLS playlist. */ -public abstract class HlsPlaylist> - implements FilterableManifest { +public abstract class HlsPlaylist implements FilterableManifest { /** * The base uri. Used to resolve relative paths. diff --git a/library/hls/src/test/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloaderTest.java b/library/hls/src/test/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloaderTest.java index 54a82a7e7d..6e816dd8a7 100644 --- a/library/hls/src/test/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloaderTest.java +++ b/library/hls/src/test/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloaderTest.java @@ -184,7 +184,7 @@ public class HlsDownloaderTest { private HlsDownloader getHlsDownloader(String mediaPlaylistUri, List keys) { Factory factory = new Factory(null).setFakeDataSet(fakeDataSet); return new HlsDownloader( - Uri.parse(mediaPlaylistUri), new DownloaderConstructorHelper(cache, factory), keys); + Uri.parse(mediaPlaylistUri), keys, new DownloaderConstructorHelper(cache, factory)); } private static ArrayList getKeys(int... variantIndices) { diff --git a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/manifest/SsManifest.java b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/manifest/SsManifest.java index 5ce7b18d61..396d29fb75 100644 --- a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/manifest/SsManifest.java +++ b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/manifest/SsManifest.java @@ -120,16 +120,9 @@ public class SsManifest implements FilterableManifest { this.streamElements = streamElements; } - /** - * Creates a copy of this manifest which includes only the tracks identified by the given keys. - * - * @param trackKeys List of keys for the tracks to be included in the copy. - * @return A copy of this manifest with the selected tracks. - * @throws IndexOutOfBoundsException If a key has an invalid index. - */ @Override - public final SsManifest copy(List trackKeys) { - ArrayList sortedKeys = new ArrayList<>(trackKeys); + public final SsManifest copy(List streamKeys) { + ArrayList sortedKeys = new ArrayList<>(streamKeys); Collections.sort(sortedKeys); StreamElement currentStreamElement = null; diff --git a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloadAction.java b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloadAction.java index 7fa89afef0..d4b3ef6622 100644 --- a/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloadAction.java +++ b/library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloadAction.java @@ -51,7 +51,7 @@ public final class SsDownloadAction extends SegmentDownloadAction { * @param uri The SmoothStreaming manifest URI. * @param isRemoveAction Whether the data will be removed. If {@code false} it will be downloaded. * @param data Optional custom data for this action. - * @param keys Keys of tracks to be downloaded. If empty, all tracks are downloaded. If {@code + * @param keys Keys of streams to be downloaded. If empty, all streams are downloaded. If {@code * removeAction} is true, {@code keys} must be empty. */ public SsDownloadAction( @@ -61,7 +61,7 @@ public final class SsDownloadAction extends SegmentDownloadAction { @Override protected SsDownloader createDownloader(DownloaderConstructorHelper constructorHelper) { - return new SsDownloader(uri, constructorHelper, keys); + return new SsDownloader(uri, keys, constructorHelper); } @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 cdb971426c..4fef3eb469 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 @@ -45,8 +45,8 @@ import java.util.List; * SsDownloader ssDownloader = * new SsDownloader( * manifestUrl, - * constructorHelper, - * Collections.singletonList(new StreamKey(0, 0))); + * Collections.singletonList(new StreamKey(0, 0)), + * constructorHelper); * // Perform the download. * ssDownloader.download(); * // Access downloaded data using CacheDataSource @@ -56,10 +56,15 @@ import java.util.List; */ public final class SsDownloader extends SegmentDownloader { - /** @see SegmentDownloader#SegmentDownloader(Uri, DownloaderConstructorHelper, List) */ + /** + * @param manifestUri The {@link Uri} of the manifest to be downloaded. + * @param streamKeys Keys defining which streams in the manifest should be selected for download. + * If empty, all streams are downloaded. + * @param constructorHelper A {@link DownloaderConstructorHelper} instance. + */ public SsDownloader( - Uri manifestUri, DownloaderConstructorHelper constructorHelper, List trackKeys) { - super(SsUtil.fixManifestUri(manifestUri), constructorHelper, trackKeys); + Uri manifestUri, List streamKeys, DownloaderConstructorHelper constructorHelper) { + super(SsUtil.fixManifestUri(manifestUri), streamKeys, constructorHelper); } @Override diff --git a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java index c5ac2131f3..5267d54bef 100644 --- a/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java +++ b/playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java @@ -123,7 +123,7 @@ public final class DashDownloadTest extends ActivityInstrumentationTestCase2