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
b65baf7d
authored
Jan 30, 2023
by
lemondoglol
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
make merged segment size configurable
parent
e2ece2f5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
151 additions
and
14 deletions
libraries/exoplayer/src/main/java/androidx/media3/exoplayer/offline/SegmentDownloader.java
libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/offline/DashDownloader.java
libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/offline/HlsDownloader.java
libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/offline/SsDownloader.java
libraries/exoplayer/src/main/java/androidx/media3/exoplayer/offline/SegmentDownloader.java
View file @
b65baf7d
...
@@ -76,7 +76,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -76,7 +76,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
}
}
private
static
final
int
BUFFER_SIZE_BYTES
=
128
*
1024
;
private
static
final
int
BUFFER_SIZE_BYTES
=
128
*
1024
;
p
rivate
static
final
long
MAX_MERGED_SEGMENT_START_TIME_DIFF_US
=
20
*
C
.
MICROS_PER_SECOND
;
p
ublic
static
final
long
DEFAULT_
MAX_MERGED_SEGMENT_START_TIME_DIFF_US
=
20
*
C
.
MICROS_PER_SECOND
;
private
final
DataSpec
manifestDataSpec
;
private
final
DataSpec
manifestDataSpec
;
private
final
Parser
<
M
>
manifestParser
;
private
final
Parser
<
M
>
manifestParser
;
...
@@ -86,6 +86,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -86,6 +86,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
private
final
CacheKeyFactory
cacheKeyFactory
;
private
final
CacheKeyFactory
cacheKeyFactory
;
@Nullable
private
final
PriorityTaskManager
priorityTaskManager
;
@Nullable
private
final
PriorityTaskManager
priorityTaskManager
;
private
final
Executor
executor
;
private
final
Executor
executor
;
private
final
long
maxMergedSegmentStartTimeDiffUs
;
/**
/**
* The currently active runnables.
* The currently active runnables.
...
@@ -100,6 +101,30 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -100,6 +101,30 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
private
volatile
boolean
isCanceled
;
private
volatile
boolean
isCanceled
;
/**
/**
* @deprecated Use {@link SegmentDownloader#SegmentDownloader(MediaItem, Parser,
* CacheDataSource.Factory, Executor, long)} instead.
*/
@Deprecated
public
SegmentDownloader
(
MediaItem
mediaItem
,
Parser
<
M
>
manifestParser
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
checkNotNull
(
mediaItem
.
localConfiguration
);
this
.
manifestDataSpec
=
getCompressibleDataSpec
(
mediaItem
.
localConfiguration
.
uri
);
this
.
manifestParser
=
manifestParser
;
this
.
streamKeys
=
new
ArrayList
<>(
mediaItem
.
localConfiguration
.
streamKeys
);
this
.
cacheDataSourceFactory
=
cacheDataSourceFactory
;
this
.
executor
=
executor
;
cache
=
Assertions
.
checkNotNull
(
cacheDataSourceFactory
.
getCache
());
cacheKeyFactory
=
cacheDataSourceFactory
.
getCacheKeyFactory
();
priorityTaskManager
=
cacheDataSourceFactory
.
getUpstreamPriorityTaskManager
();
activeRunnables
=
new
ArrayList
<>();
maxMergedSegmentStartTimeDiffUs
=
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
;
}
/**
* @param mediaItem The {@link MediaItem} to be downloaded.
* @param mediaItem The {@link MediaItem} to be downloaded.
* @param manifestParser A parser for manifests belonging to the media to be downloaded.
* @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
* @param cacheDataSourceFactory A {@link CacheDataSource.Factory} for the cache into which the
...
@@ -107,12 +132,17 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -107,12 +132,17 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
* @param executor An {@link Executor} used to make requests for the media being downloaded.
* @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
* Providing an {@link Executor} that uses multiple threads will speed up the download by
* allowing parts of it to be executed in parallel.
* allowing parts of it to be executed in parallel.
* @param maxMergedSegmentStartTimeDiffMs The maximum difference of the start time of two segments,
* up to which the segments (of the same URI) should be merged into a single download segment,
* in milliseconds.
*/
*/
public
SegmentDownloader
(
public
SegmentDownloader
(
MediaItem
mediaItem
,
MediaItem
mediaItem
,
Parser
<
M
>
manifestParser
,
Parser
<
M
>
manifestParser
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
Executor
executor
,
long
maxMergedSegmentStartTimeDiffMs
)
{
checkNotNull
(
mediaItem
.
localConfiguration
);
checkNotNull
(
mediaItem
.
localConfiguration
);
this
.
manifestDataSpec
=
getCompressibleDataSpec
(
mediaItem
.
localConfiguration
.
uri
);
this
.
manifestDataSpec
=
getCompressibleDataSpec
(
mediaItem
.
localConfiguration
.
uri
);
this
.
manifestParser
=
manifestParser
;
this
.
manifestParser
=
manifestParser
;
...
@@ -123,6 +153,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -123,6 +153,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
cacheKeyFactory
=
cacheDataSourceFactory
.
getCacheKeyFactory
();
cacheKeyFactory
=
cacheDataSourceFactory
.
getCacheKeyFactory
();
priorityTaskManager
=
cacheDataSourceFactory
.
getUpstreamPriorityTaskManager
();
priorityTaskManager
=
cacheDataSourceFactory
.
getUpstreamPriorityTaskManager
();
activeRunnables
=
new
ArrayList
<>();
activeRunnables
=
new
ArrayList
<>();
maxMergedSegmentStartTimeDiffUs
=
Util
.
msToUs
(
maxMergedSegmentStartTimeDiffMs
);
}
}
@Override
@Override
...
@@ -145,7 +176,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -145,7 +176,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
// Sort the segments so that we download media in the right order from the start of the
// Sort the segments so that we download media in the right order from the start of the
// content, and merge segments where possible to minimize the number of server round trips.
// content, and merge segments where possible to minimize the number of server round trips.
Collections
.
sort
(
segments
);
Collections
.
sort
(
segments
);
mergeSegments
(
segments
,
cacheKeyFactory
);
mergeSegments
(
segments
,
cacheKeyFactory
,
maxMergedSegmentStartTimeDiffUs
);
// Scan the segments, removing any that are fully downloaded.
// Scan the segments, removing any that are fully downloaded.
int
totalSegments
=
segments
.
size
();
int
totalSegments
=
segments
.
size
();
...
@@ -416,7 +447,11 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -416,7 +447,11 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
}
}
}
}
private
static
void
mergeSegments
(
List
<
Segment
>
segments
,
CacheKeyFactory
keyFactory
)
{
private
static
void
mergeSegments
(
List
<
Segment
>
segments
,
CacheKeyFactory
keyFactory
,
long
maxMergedSegmentStartTimeDiffUs
)
{
HashMap
<
String
,
Integer
>
lastIndexByCacheKey
=
new
HashMap
<>();
HashMap
<
String
,
Integer
>
lastIndexByCacheKey
=
new
HashMap
<>();
int
nextOutIndex
=
0
;
int
nextOutIndex
=
0
;
for
(
int
i
=
0
;
i
<
segments
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
segments
.
size
();
i
++)
{
...
@@ -425,7 +460,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -425,7 +460,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
@Nullable
Integer
lastIndex
=
lastIndexByCacheKey
.
get
(
cacheKey
);
@Nullable
Integer
lastIndex
=
lastIndexByCacheKey
.
get
(
cacheKey
);
@Nullable
Segment
lastSegment
=
lastIndex
==
null
?
null
:
segments
.
get
(
lastIndex
);
@Nullable
Segment
lastSegment
=
lastIndex
==
null
?
null
:
segments
.
get
(
lastIndex
);
if
(
lastSegment
==
null
if
(
lastSegment
==
null
||
segment
.
startTimeUs
>
lastSegment
.
startTimeUs
+
MAX_MERGED_SEGMENT_START_TIME_DIFF_US
||
segment
.
startTimeUs
>
lastSegment
.
startTimeUs
+
maxMergedSegmentStartTimeDiffUs
||
!
canMergeSegments
(
lastSegment
.
dataSpec
,
segment
.
dataSpec
))
{
||
!
canMergeSegments
(
lastSegment
.
dataSpec
,
segment
.
dataSpec
))
{
lastIndexByCacheKey
.
put
(
cacheKey
,
nextOutIndex
);
lastIndexByCacheKey
.
put
(
cacheKey
,
nextOutIndex
);
segments
.
set
(
nextOutIndex
,
segment
);
segments
.
set
(
nextOutIndex
,
segment
);
...
...
libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/offline/DashDownloader.java
View file @
b65baf7d
...
@@ -100,7 +100,28 @@ public final class DashDownloader extends SegmentDownloader<DashManifest> {
...
@@ -100,7 +100,28 @@ public final class DashDownloader extends SegmentDownloader<DashManifest> {
*/
*/
public
DashDownloader
(
public
DashDownloader
(
MediaItem
mediaItem
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
MediaItem
mediaItem
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
this
(
mediaItem
,
new
DashManifestParser
(),
cacheDataSourceFactory
,
executor
);
this
(
mediaItem
,
new
DashManifestParser
(),
cacheDataSourceFactory
,
executor
,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
}
/**
* @deprecated Use {@link DashDownloader#DashDownloader(MediaItem, Parser,
* CacheDataSource.Factory, Executor, long)} instead.
*/
@Deprecated
public
DashDownloader
(
MediaItem
mediaItem
,
Parser
<
DashManifest
>
manifestParser
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
super
(
mediaItem
,
manifestParser
,
cacheDataSourceFactory
,
executor
,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
baseUrlExclusionList
=
new
BaseUrlExclusionList
();
}
}
/**
/**
...
@@ -113,13 +134,24 @@ public final class DashDownloader extends SegmentDownloader<DashManifest> {
...
@@ -113,13 +134,24 @@ public final class DashDownloader extends SegmentDownloader<DashManifest> {
* @param executor An {@link Executor} used to make requests for the media being downloaded.
* @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
* Providing an {@link Executor} that uses multiple threads will speed up the download by
* allowing parts of it to be executed in parallel.
* allowing parts of it to be executed in parallel.
* @param maxMergedSegmentStartTimeDiffMs The maximum difference of the start time of two segments,
* up to which the segments (of the same URI) should be merged into a single download segment,
* in milliseconds.
*/
*/
public
DashDownloader
(
public
DashDownloader
(
MediaItem
mediaItem
,
MediaItem
mediaItem
,
Parser
<
DashManifest
>
manifestParser
,
Parser
<
DashManifest
>
manifestParser
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
Executor
executor
,
super
(
mediaItem
,
manifestParser
,
cacheDataSourceFactory
,
executor
);
long
maxMergedSegmentStartTimeDiffMs
)
{
super
(
mediaItem
,
manifestParser
,
cacheDataSourceFactory
,
executor
,
maxMergedSegmentStartTimeDiffMs
);
baseUrlExclusionList
=
new
BaseUrlExclusionList
();
baseUrlExclusionList
=
new
BaseUrlExclusionList
();
}
}
...
...
libraries/exoplayer_hls/src/main/java/androidx/media3/exoplayer/hls/offline/HlsDownloader.java
View file @
b65baf7d
...
@@ -89,7 +89,33 @@ public final class HlsDownloader extends SegmentDownloader<HlsPlaylist> {
...
@@ -89,7 +89,33 @@ public final class HlsDownloader extends SegmentDownloader<HlsPlaylist> {
*/
*/
public
HlsDownloader
(
public
HlsDownloader
(
MediaItem
mediaItem
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
MediaItem
mediaItem
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
this
(
mediaItem
,
new
HlsPlaylistParser
(),
cacheDataSourceFactory
,
executor
);
this
(
mediaItem
,
new
HlsPlaylistParser
(),
cacheDataSourceFactory
,
executor
,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
}
/**
* @deprecated Use {@link HlsDownloader#HlsDownloader(MediaItem, Parser,
* CacheDataSource.Factory, Executor, long)} instead.
*/
@Deprecated
public
HlsDownloader
(
MediaItem
mediaItem
,
Parser
<
HlsPlaylist
>
manifestParser
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
super
(
mediaItem
,
manifestParser
,
cacheDataSourceFactory
,
executor
,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
}
}
/**
/**
...
@@ -102,13 +128,24 @@ public final class HlsDownloader extends SegmentDownloader<HlsPlaylist> {
...
@@ -102,13 +128,24 @@ public final class HlsDownloader extends SegmentDownloader<HlsPlaylist> {
* @param executor An {@link Executor} used to make requests for the media being downloaded.
* @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
* Providing an {@link Executor} that uses multiple threads will speed up the download by
* allowing parts of it to be executed in parallel.
* allowing parts of it to be executed in parallel.
* @param maxMergedSegmentStartTimeDiffMs The maximum difference of the start time of two segments,
* up to which the segments (of the same URI) should be merged into a single download segment,
* in milliseconds.
*/
*/
public
HlsDownloader
(
public
HlsDownloader
(
MediaItem
mediaItem
,
MediaItem
mediaItem
,
Parser
<
HlsPlaylist
>
manifestParser
,
Parser
<
HlsPlaylist
>
manifestParser
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
Executor
executor
,
super
(
mediaItem
,
manifestParser
,
cacheDataSourceFactory
,
executor
);
long
maxMergedSegmentStartTimeDiffMs
)
{
super
(
mediaItem
,
manifestParser
,
cacheDataSourceFactory
,
executor
,
maxMergedSegmentStartTimeDiffMs
);
}
}
@Override
@Override
...
...
libraries/exoplayer_smoothstreaming/src/main/java/androidx/media3/exoplayer/smoothstreaming/offline/SsDownloader.java
View file @
b65baf7d
...
@@ -93,7 +93,29 @@ public final class SsDownloader extends SegmentDownloader<SsManifest> {
...
@@ -93,7 +93,29 @@ public final class SsDownloader extends SegmentDownloader<SsManifest> {
.
build
(),
.
build
(),
new
SsManifestParser
(),
new
SsManifestParser
(),
cacheDataSourceFactory
,
cacheDataSourceFactory
,
executor
);
executor
,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
}
/**
* @deprecated Use {@link SsDownloader#SsDownloader(MediaItem, Parser,
* CacheDataSource.Factory, Executor, long)} instead.
*/
@Deprecated
public
SsDownloader
(
MediaItem
mediaItem
,
Parser
<
SsManifest
>
manifestParser
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
super
(
mediaItem
,
manifestParser
,
cacheDataSourceFactory
,
executor
,
DEFAULT_MAX_MERGED_SEGMENT_START_TIME_DIFF_US
);
}
}
/**
/**
...
@@ -106,13 +128,24 @@ public final class SsDownloader extends SegmentDownloader<SsManifest> {
...
@@ -106,13 +128,24 @@ public final class SsDownloader extends SegmentDownloader<SsManifest> {
* @param executor An {@link Executor} used to make requests for the media being downloaded.
* @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
* Providing an {@link Executor} that uses multiple threads will speed up the download by
* allowing parts of it to be executed in parallel.
* allowing parts of it to be executed in parallel.
* @param maxMergedSegmentStartTimeDiffMs The maximum difference of the start time of two segments,
* up to which the segments (of the same URI) should be merged into a single download segment,
* in milliseconds.
*/
*/
public
SsDownloader
(
public
SsDownloader
(
MediaItem
mediaItem
,
MediaItem
mediaItem
,
Parser
<
SsManifest
>
manifestParser
,
Parser
<
SsManifest
>
manifestParser
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
CacheDataSource
.
Factory
cacheDataSourceFactory
,
Executor
executor
)
{
Executor
executor
,
super
(
mediaItem
,
manifestParser
,
cacheDataSourceFactory
,
executor
);
long
maxMergedSegmentStartTimeDiffMs
)
{
super
(
mediaItem
,
manifestParser
,
cacheDataSourceFactory
,
executor
,
maxMergedSegmentStartTimeDiffMs
);
}
}
@Override
@Override
...
...
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