Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9e35c6c2
authored
May 14, 2020
by
bachinger
Committed by
Oliver Woodman
May 14, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Make all segment downloader use the media item
PiperOrigin-RevId: 311527440
parent
c1aa9b91
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
141 additions
and
54 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java
library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloader.java
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DashDownloaderTest.java
library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java
library/hls/src/test/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloaderTest.java
library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java
playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java
library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java
View file @
9e35c6c2
...
...
@@ -15,10 +15,13 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
offline
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
android.net.Uri
;
import
android.util.Pair
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.ParsingLoadable
;
...
...
@@ -79,10 +82,8 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
@Nullable
private
volatile
Thread
downloadThread
;
/**
* @param m
anifestUri The {@link Uri} of the manifest
to be downloaded.
* @param m
ediaItem The {@link MediaItem}
to be downloaded.
* @param manifestParser A parser for the manifest.
* @param streamKeys Keys defining which streams in the manifest should be selected for download.
* If empty, all streams are 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.
...
...
@@ -90,14 +91,14 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
* allowing parts of it to be executed in parallel.
*/
public
SegmentDownloader
(
Uri
manifestUri
,
MediaItem
mediaItem
,
Parser
<
M
>
manifestParser
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
this
.
manifestDataSpec
=
getCompressibleDataSpec
(
manifestUri
);
checkNotNull
(
mediaItem
.
playbackProperties
);
this
.
manifestDataSpec
=
getCompressibleDataSpec
(
mediaItem
.
playbackProperties
.
uri
);
this
.
manifestParser
=
manifestParser
;
this
.
streamKeys
=
new
ArrayList
<>(
streamKeys
);
this
.
streamKeys
=
new
ArrayList
<>(
mediaItem
.
playbackProperties
.
streamKeys
);
this
.
cacheDataSourceFactory
=
cacheDataSourceFactory
;
this
.
executor
=
executor
;
isCanceled
=
new
AtomicBoolean
();
...
...
library/dash/src/main/java/com/google/android/exoplayer2/source/dash/offline/DashDownloader.java
View file @
9e35c6c2
...
...
@@ -18,6 +18,7 @@ package com.google.android.exoplayer2.source.dash.offline;
import
android.net.Uri
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.extractor.ChunkIndex
;
import
com.google.android.exoplayer2.offline.DownloadException
;
import
com.google.android.exoplayer2.offline.SegmentDownloader
;
...
...
@@ -54,7 +55,11 @@ import java.util.concurrent.Executor;
* // period.
* DashDownloader dashDownloader =
* new DashDownloader(
* manifestUrl, Collections.singletonList(new StreamKey(0, 0, 0)), cacheDataSourceFactory);
* new MediaItem.Builder()
* .setUri(manifestUrl)
* .setStreamKeys(Collections.singletonList(new StreamKey(0, 0, 0)))
* .build(),
* cacheDataSourceFactory);
* // Perform the download.
* dashDownloader.download(progressListener);
* // Use the downloaded data for playback.
...
...
@@ -64,22 +69,44 @@ import java.util.concurrent.Executor;
*/
public
final
class
DashDownloader
extends
SegmentDownloader
<
DashManifest
>
{
/** @deprecated Use {@link #DashDownloader(MediaItem, CacheDataSource.Factory)} instead. */
@SuppressWarnings
(
"deprecation"
)
@Deprecated
public
DashDownloader
(
Uri
manifestUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
)
{
this
(
manifestUri
,
streamKeys
,
cacheDataSourceFactory
,
Runnable:
:
run
);
}
/**
*
@param manifestUri The {@link Uri} of the manifest to be downloaded
.
*
@param streamKeys Keys defining which representations in the manifest should be selected for
*
download. If empty, all representations ar
e downloaded.
*
Creates a new instance
.
*
*
@param mediaItem The {@link MediaItem} to b
e downloaded.
* @param cacheDataSourceFactory A {@link CacheDataSource.Factory} for the cache into which the
* download will be written.
*/
public
DashDownloader
(
MediaItem
mediaItem
,
CacheDataSource
.
Factory
cacheDataSourceFactory
)
{
this
(
mediaItem
,
cacheDataSourceFactory
,
Runnable:
:
run
);
}
/**
* @deprecated Use {@link #DashDownloader(MediaItem, CacheDataSource.Factory, Executor)} instead.
*/
@Deprecated
public
DashDownloader
(
Uri
manifestUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
)
{
this
(
manifestUri
,
streamKeys
,
cacheDataSourceFactory
,
Runnable:
:
run
);
Uri
manifestUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
this
(
new
MediaItem
.
Builder
().
setUri
(
manifestUri
).
setStreamKeys
(
streamKeys
).
build
(),
cacheDataSourceFactory
,
executor
);
}
/**
*
@param manifestUri The {@link Uri} of the manifest to be downloaded
.
*
@param streamKeys Keys defining which representations in the manifest should be selected for
*
download. If empty, all representations ar
e downloaded.
*
Creates a new instance
.
*
*
@param mediaItem The {@link MediaItem} to b
e 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.
...
...
@@ -87,11 +114,8 @@ public final class DashDownloader extends SegmentDownloader<DashManifest> {
* allowing parts of it to be executed in parallel.
*/
public
DashDownloader
(
Uri
manifestUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
super
(
manifestUri
,
new
DashManifestParser
(),
streamKeys
,
cacheDataSourceFactory
,
executor
);
MediaItem
mediaItem
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
super
(
mediaItem
,
new
DashManifestParser
(),
cacheDataSourceFactory
,
executor
);
}
@Override
...
...
library/dash/src/test/java/com/google/android/exoplayer2/source/dash/offline/DashDownloaderTest.java
View file @
9e35c6c2
...
...
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
import
android.net.Uri
;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.offline.DefaultDownloaderFactory
;
import
com.google.android.exoplayer2.offline.DownloadException
;
import
com.google.android.exoplayer2.offline.DownloadRequest
;
...
...
@@ -337,7 +338,9 @@ public class DashDownloaderTest {
new
CacheDataSource
.
Factory
()
.
setCache
(
cache
)
.
setUpstreamDataSourceFactory
(
upstreamDataSourceFactory
);
return
new
DashDownloader
(
TEST_MPD_URI
,
keysList
(
keys
),
cacheDataSourceFactory
);
return
new
DashDownloader
(
new
MediaItem
.
Builder
().
setUri
(
TEST_MPD_URI
).
setStreamKeys
(
keysList
(
keys
)).
build
(),
cacheDataSourceFactory
);
}
private
static
ArrayList
<
StreamKey
>
keysList
(
StreamKey
...
keys
)
{
...
...
library/hls/src/main/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloader.java
View file @
9e35c6c2
...
...
@@ -17,6 +17,7 @@ package com.google.android.exoplayer2.source.hls.offline;
import
android.net.Uri
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.offline.SegmentDownloader
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.source.hls.playlist.HlsMasterPlaylist
;
...
...
@@ -47,8 +48,13 @@ import java.util.concurrent.Executor;
* // Create a downloader for the first variant in a master playlist.
* HlsDownloader hlsDownloader =
* new HlsDownloader(
* playlistUri,
* Collections.singletonList(new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, 0));
* new MediaItem.Builder()
* .setUri(playlistUri)
* .setStreamKeys(
* Collections.singletonList(
* new StreamKey(HlsMasterPlaylist.GROUP_INDEX_VARIANT, 0)))
* .build(),
* Collections.singletonList();
* // Perform the download.
* hlsDownloader.download(progressListener);
* // Use the downloaded data for playback.
...
...
@@ -58,22 +64,44 @@ import java.util.concurrent.Executor;
*/
public
final
class
HlsDownloader
extends
SegmentDownloader
<
HlsPlaylist
>
{
/** @deprecated Use {@link #HlsDownloader(MediaItem, CacheDataSource.Factory)} instead. */
@SuppressWarnings
(
"deprecation"
)
@Deprecated
public
HlsDownloader
(
Uri
playlistUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
)
{
this
(
playlistUri
,
streamKeys
,
cacheDataSourceFactory
,
Runnable:
:
run
);
}
/**
*
@param playlistUri The {@link Uri} of the playlist to be downloaded
.
*
@param streamKeys Keys defining which renditions in the playlist should be selected for
*
download. If empty, all renditions ar
e downloaded.
*
Creates a new instance
.
*
*
@param mediaItem The {@link MediaItem} to b
e downloaded.
* @param cacheDataSourceFactory A {@link CacheDataSource.Factory} for the cache into which the
* download will be written.
*/
public
HlsDownloader
(
MediaItem
mediaItem
,
CacheDataSource
.
Factory
cacheDataSourceFactory
)
{
this
(
mediaItem
,
cacheDataSourceFactory
,
Runnable:
:
run
);
}
/**
* @deprecated Use {@link #HlsDownloader(MediaItem, CacheDataSource.Factory, Executor)} instead.
*/
@Deprecated
public
HlsDownloader
(
Uri
playlistUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
)
{
this
(
playlistUri
,
streamKeys
,
cacheDataSourceFactory
,
Runnable:
:
run
);
Uri
playlistUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
this
(
new
MediaItem
.
Builder
().
setUri
(
playlistUri
).
setStreamKeys
(
streamKeys
).
build
(),
cacheDataSourceFactory
,
executor
);
}
/**
*
@param playlistUri The {@link Uri} of the playlist to be downloaded
.
*
@param streamKeys Keys defining which renditions in the playlist should be selected for
*
download. If empty, all renditions ar
e downloaded.
*
Creates a new instance
.
*
*
@param mediaItem The {@link MediaItem} to b
e 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.
...
...
@@ -81,11 +109,8 @@ public final class HlsDownloader extends SegmentDownloader<HlsPlaylist> {
* allowing parts of it to be executed in parallel.
*/
public
HlsDownloader
(
Uri
playlistUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
super
(
playlistUri
,
new
HlsPlaylistParser
(),
streamKeys
,
cacheDataSourceFactory
,
executor
);
MediaItem
mediaItem
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
super
(
mediaItem
,
new
HlsPlaylistParser
(),
cacheDataSourceFactory
,
executor
);
}
@Override
...
...
library/hls/src/test/java/com/google/android/exoplayer2/source/hls/offline/HlsDownloaderTest.java
View file @
9e35c6c2
...
...
@@ -37,6 +37,7 @@ import static com.google.common.truth.Truth.assertThat;
import
android.net.Uri
;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.offline.DefaultDownloaderFactory
;
import
com.google.android.exoplayer2.offline.DownloadRequest
;
import
com.google.android.exoplayer2.offline.Downloader
;
...
...
@@ -219,7 +220,9 @@ public class HlsDownloaderTest {
new
CacheDataSource
.
Factory
()
.
setCache
(
cache
)
.
setUpstreamDataSourceFactory
(
new
FakeDataSource
.
Factory
().
setFakeDataSet
(
fakeDataSet
));
return
new
HlsDownloader
(
Uri
.
parse
(
mediaPlaylistUri
),
keys
,
cacheDataSourceFactory
);
return
new
HlsDownloader
(
new
MediaItem
.
Builder
().
setUri
(
mediaPlaylistUri
).
setStreamKeys
(
keys
).
build
(),
cacheDataSourceFactory
);
}
private
static
ArrayList
<
StreamKey
>
getKeys
(
int
...
variantIndices
)
{
...
...
library/smoothstreaming/src/main/java/com/google/android/exoplayer2/source/smoothstreaming/offline/SsDownloader.java
View file @
9e35c6c2
...
...
@@ -15,7 +15,10 @@
*/
package
com
.
google
.
android
.
exoplayer2
.
source
.
smoothstreaming
.
offline
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
android.net.Uri
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.offline.SegmentDownloader
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest
;
...
...
@@ -43,8 +46,10 @@ import java.util.concurrent.Executor;
* // Create a downloader for the first track of the first stream element.
* SsDownloader ssDownloader =
* new SsDownloader(
* manifestUrl,
* Collections.singletonList(new StreamKey(0, 0)),
* new MediaItem.Builder()
* .setUri(manifestUri)
* .setStreamKeys(Collections.singletonList(new StreamKey(0, 0)))
* .build(),
* cacheDataSourceFactory);
* // Perform the download.
* ssDownloader.download(progressListener);
...
...
@@ -56,36 +61,59 @@ import java.util.concurrent.Executor;
public
final
class
SsDownloader
extends
SegmentDownloader
<
SsManifest
>
{
/**
* @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 cacheDataSourceFactory A {@link CacheDataSource.Factory} for the cache into which the
* download will be written.
* @deprecated Use {@link #SsDownloader(MediaItem, CacheDataSource.Factory, Executor)} instead.
*/
@SuppressWarnings
(
"deprecation"
)
@Deprecated
public
SsDownloader
(
Uri
manifestUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
)
{
this
(
manifestUri
,
streamKeys
,
cacheDataSourceFactory
,
Runnable:
:
run
);
}
/**
*
@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 ar
e downloaded.
*
Creates an instance
.
*
*
@param mediaItem The {@link MediaItem} to b
e 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.
* 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
,
CacheDataSource
.
Factory
cacheDataSourceFactory
)
{
this
(
mediaItem
,
cacheDataSourceFactory
,
Runnable:
:
run
);
}
/**
* @deprecated Use {@link #SsDownloader(MediaItem, CacheDataSource.Factory, Executor)} instead.
*/
@Deprecated
public
SsDownloader
(
Uri
manifestUri
,
List
<
StreamKey
>
streamKeys
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
this
(
new
MediaItem
.
Builder
().
setUri
(
manifestUri
).
setStreamKeys
(
streamKeys
).
build
(),
cacheDataSourceFactory
,
executor
);
}
/**
* Creates an instance.
*
* @param mediaItem The {@link MediaItem} 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.
* 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
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
super
(
SsUtil
.
fixManifestUri
(
manifestUri
),
mediaItem
.
buildUpon
()
.
setUri
(
SsUtil
.
fixManifestUri
(
checkNotNull
(
mediaItem
.
playbackProperties
).
uri
))
.
build
(),
new
SsManifestParser
(),
streamKeys
,
cacheDataSourceFactory
,
executor
);
}
...
...
playbacktests/src/androidTest/java/com/google/android/exoplayer2/playbacktests/gts/DashDownloadTest.java
View file @
9e35c6c2
...
...
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertWithMessage;
import
android.net.Uri
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.rule.ActivityTestRule
;
import
com.google.android.exoplayer2.MediaItem
;
import
com.google.android.exoplayer2.offline.StreamKey
;
import
com.google.android.exoplayer2.source.dash.DashUtil
;
import
com.google.android.exoplayer2.source.dash.manifest.AdaptationSet
;
...
...
@@ -120,7 +121,9 @@ public final class DashDownloadTest {
new
CacheDataSource
.
Factory
()
.
setCache
(
cache
)
.
setUpstreamDataSourceFactory
(
httpDataSourceFactory
);
return
new
DashDownloader
(
MANIFEST_URI
,
keys
,
cacheDataSourceFactory
);
return
new
DashDownloader
(
new
MediaItem
.
Builder
().
setUri
(
MANIFEST_URI
).
setStreamKeys
(
keys
).
build
(),
cacheDataSourceFactory
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment