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
cedada09
authored
Nov 17, 2019
by
Oliver Woodman
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Revert "Merge consecutive segments for downloading."
This reverts commit
c8e7ecd3
.
parent
79b7af65
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1 additions
and
45 deletions
RELEASENOTES.md
library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java
RELEASENOTES.md
View file @
cedada09
...
@@ -140,8 +140,6 @@
...
@@ -140,8 +140,6 @@
[
Cast demo app
](
https://github.com/google/ExoPlayer/tree/dev-v2/demos/cast
)
.
[
Cast demo app
](
https://github.com/google/ExoPlayer/tree/dev-v2/demos/cast
)
.
*
TestUtils: Publish the
`testutils`
module to simplify unit testing with
*
TestUtils: Publish the
`testutils`
module to simplify unit testing with
ExoPlayer (
[
#6267
](
https://github.com/google/ExoPlayer/issues/6267
)
).
ExoPlayer (
[
#6267
](
https://github.com/google/ExoPlayer/issues/6267
)
).
*
Downloads: Merge downloads in
`SegmentDownloader`
to improve overall download
speed (
[
#5978
](
https://github.com/google/ExoPlayer/issues/5978
)
).
### 2.10.7 (2019-11-12) ###
### 2.10.7 (2019-11-12) ###
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java
View file @
cedada09
...
@@ -25,13 +25,11 @@ import com.google.android.exoplayer2.upstream.cache.Cache;
...
@@ -25,13 +25,11 @@ import com.google.android.exoplayer2.upstream.cache.Cache;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSource
;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSource
;
import
com.google.android.exoplayer2.upstream.cache.CacheKeyFactory
;
import
com.google.android.exoplayer2.upstream.cache.CacheKeyFactory
;
import
com.google.android.exoplayer2.upstream.cache.CacheUtil
;
import
com.google.android.exoplayer2.upstream.cache.CacheUtil
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.PriorityTaskManager
;
import
com.google.android.exoplayer2.util.PriorityTaskManager
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
java.util.concurrent.atomic.AtomicBoolean
;
...
@@ -64,7 +62,6 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -64,7 +62,6 @@ 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
;
private
static
final
long
MAX_MERGED_SEGMENT_START_TIME_DIFF_US
=
20
*
C
.
MICROS_PER_SECOND
;
private
final
DataSpec
manifestDataSpec
;
private
final
DataSpec
manifestDataSpec
;
private
final
Cache
cache
;
private
final
Cache
cache
;
...
@@ -111,8 +108,6 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -111,8 +108,6 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
manifest
=
manifest
.
copy
(
streamKeys
);
manifest
=
manifest
.
copy
(
streamKeys
);
}
}
List
<
Segment
>
segments
=
getSegments
(
dataSource
,
manifest
,
/* allowIncompleteList= */
false
);
List
<
Segment
>
segments
=
getSegments
(
dataSource
,
manifest
,
/* allowIncompleteList= */
false
);
Collections
.
sort
(
segments
);
mergeSegments
(
segments
,
cacheKeyFactory
);
// 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
();
...
@@ -139,6 +134,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -139,6 +134,7 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
contentLength
=
C
.
LENGTH_UNSET
;
contentLength
=
C
.
LENGTH_UNSET
;
}
}
}
}
Collections
.
sort
(
segments
);
// Download the segments.
// Download the segments.
@Nullable
ProgressNotifier
progressNotifier
=
null
;
@Nullable
ProgressNotifier
progressNotifier
=
null
;
...
@@ -236,44 +232,6 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
...
@@ -236,44 +232,6 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
/* flags= */
DataSpec
.
FLAG_ALLOW_GZIP
);
/* flags= */
DataSpec
.
FLAG_ALLOW_GZIP
);
}
}
private
static
void
mergeSegments
(
List
<
Segment
>
segments
,
CacheKeyFactory
keyFactory
)
{
HashMap
<
String
,
Integer
>
lastIndexByCacheKey
=
new
HashMap
<>();
int
nextOutIndex
=
0
;
for
(
int
i
=
0
;
i
<
segments
.
size
();
i
++)
{
Segment
segment
=
segments
.
get
(
i
);
String
cacheKey
=
keyFactory
.
buildCacheKey
(
segment
.
dataSpec
);
@Nullable
Integer
lastIndex
=
lastIndexByCacheKey
.
get
(
cacheKey
);
@Nullable
Segment
lastSegment
=
lastIndex
==
null
?
null
:
segments
.
get
(
lastIndex
);
if
(
lastSegment
==
null
||
segment
.
startTimeUs
>
lastSegment
.
startTimeUs
+
MAX_MERGED_SEGMENT_START_TIME_DIFF_US
||
!
canMergeSegments
(
lastSegment
.
dataSpec
,
segment
.
dataSpec
))
{
lastIndexByCacheKey
.
put
(
cacheKey
,
nextOutIndex
);
segments
.
set
(
nextOutIndex
,
segment
);
nextOutIndex
++;
}
else
{
long
mergedLength
=
segment
.
dataSpec
.
length
==
C
.
LENGTH_UNSET
?
C
.
LENGTH_UNSET
:
lastSegment
.
dataSpec
.
length
+
segment
.
dataSpec
.
length
;
DataSpec
mergedDataSpec
=
lastSegment
.
dataSpec
.
subrange
(
/* offset= */
0
,
mergedLength
);
segments
.
set
(
Assertions
.
checkNotNull
(
lastIndex
),
new
Segment
(
lastSegment
.
startTimeUs
,
mergedDataSpec
));
}
}
Util
.
removeRange
(
segments
,
/* fromIndex= */
nextOutIndex
,
/* toIndex= */
segments
.
size
());
}
private
static
boolean
canMergeSegments
(
DataSpec
dataSpec1
,
DataSpec
dataSpec2
)
{
return
dataSpec1
.
uri
.
equals
(
dataSpec2
.
uri
)
&&
dataSpec1
.
length
!=
C
.
LENGTH_UNSET
&&
(
dataSpec1
.
absoluteStreamPosition
+
dataSpec1
.
length
==
dataSpec2
.
absoluteStreamPosition
)
&&
Util
.
areEqual
(
dataSpec1
.
key
,
dataSpec2
.
key
)
&&
dataSpec1
.
flags
==
dataSpec2
.
flags
&&
dataSpec1
.
httpMethod
==
dataSpec2
.
httpMethod
&&
dataSpec1
.
httpRequestHeaders
.
equals
(
dataSpec2
.
httpRequestHeaders
);
}
private
static
final
class
ProgressNotifier
implements
CacheUtil
.
ProgressListener
{
private
static
final
class
ProgressNotifier
implements
CacheUtil
.
ProgressListener
{
private
final
ProgressListener
progressListener
;
private
final
ProgressListener
progressListener
;
...
...
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