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
9b064fb9
authored
Apr 02, 2019
by
eguven
Committed by
Oliver Woodman
Apr 05, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Use CachingCounters in SegmentDownloader
PiperOrigin-RevId: 241543543
parent
d5b19694
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
20 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java
library/core/src/main/java/com/google/android/exoplayer2/offline/SegmentDownloader.java
View file @
9b064fb9
...
...
@@ -70,11 +70,10 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
private
final
PriorityTaskManager
priorityTaskManager
;
private
final
ArrayList
<
StreamKey
>
streamKeys
;
private
final
AtomicBoolean
isCanceled
;
private
final
CacheUtil
.
CachingCounters
counters
;
private
volatile
int
totalSegments
;
private
volatile
int
downloadedSegments
;
private
volatile
long
downloadedBytes
;
private
volatile
long
totalBytes
;
/**
* @param manifestUri The {@link Uri} of the manifest to be downloaded.
...
...
@@ -92,8 +91,8 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
this
.
cacheKeyFactory
=
constructorHelper
.
getCacheKeyFactory
();
this
.
priorityTaskManager
=
constructorHelper
.
getPriorityTaskManager
();
totalSegments
=
C
.
LENGTH_UNSET
;
totalBytes
=
C
.
LENGTH_UNSET
;
isCanceled
=
new
AtomicBoolean
();
counters
=
new
CachingCounters
();
}
/**
...
...
@@ -130,7 +129,8 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
true
);
downloadedSegments
++;
}
finally
{
downloadedBytes
+=
cachingCounters
.
newlyCachedBytes
;
counters
.
newlyCachedBytes
+=
cachingCounters
.
newlyCachedBytes
;
updatePercentage
();
}
}
}
finally
{
...
...
@@ -145,27 +145,17 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
@Override
public
final
long
getDownloadedBytes
()
{
return
downloadedBytes
;
return
counters
.
totalCachedBytes
()
;
}
@Override
public
long
getTotalBytes
()
{
return
totalBytes
;
return
counters
.
contentLength
;
}
@Override
public
final
float
getDownloadPercentage
()
{
// Take local snapshot of the volatile fields
long
totalBytes
=
this
.
totalBytes
;
if
(
totalBytes
!=
C
.
LENGTH_UNSET
)
{
return
totalBytes
==
0
?
100
f
:
(
downloadedBytes
*
100
f
)
/
totalBytes
;
}
int
totalSegments
=
this
.
totalSegments
;
int
downloadedSegments
=
this
.
downloadedSegments
;
if
(
totalSegments
==
C
.
LENGTH_UNSET
||
downloadedSegments
==
C
.
LENGTH_UNSET
)
{
return
C
.
PERCENTAGE_UNSET
;
}
return
totalSegments
==
0
?
100
f
:
(
downloadedSegments
*
100
f
)
/
totalSegments
;
return
counters
.
percentage
;
}
@Override
...
...
@@ -225,12 +215,13 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
CachingCounters
cachingCounters
=
new
CachingCounters
();
totalSegments
=
segments
.
size
();
downloadedSegments
=
0
;
downloadedBytes
=
0
;
counters
.
alreadyCachedBytes
=
0
;
counters
.
newlyCachedBytes
=
0
;
long
totalBytes
=
0
;
for
(
int
i
=
segments
.
size
()
-
1
;
i
>=
0
;
i
--)
{
Segment
segment
=
segments
.
get
(
i
);
CacheUtil
.
getCached
(
segment
.
dataSpec
,
cache
,
cacheKeyFactory
,
cachingCounters
);
download
edBytes
+=
cachingCounters
.
alreadyCachedBytes
;
counters
.
alreadyCach
edBytes
+=
cachingCounters
.
alreadyCachedBytes
;
if
(
cachingCounters
.
contentLength
!=
C
.
LENGTH_UNSET
)
{
if
(
cachingCounters
.
alreadyCachedBytes
==
cachingCounters
.
contentLength
)
{
// The segment is fully downloaded.
...
...
@@ -244,10 +235,23 @@ public abstract class SegmentDownloader<M extends FilterableManifest<M>> impleme
totalBytes
=
C
.
LENGTH_UNSET
;
}
}
this
.
totalBytes
=
totalBytes
;
counters
.
contentLength
=
totalBytes
;
updatePercentage
();
return
segments
;
}
private
void
updatePercentage
()
{
counters
.
updatePercentage
();
if
(
counters
.
percentage
==
C
.
PERCENTAGE_UNSET
)
{
int
totalSegments
=
this
.
totalSegments
;
int
downloadedSegments
=
this
.
downloadedSegments
;
if
(
totalSegments
!=
C
.
LENGTH_UNSET
&&
downloadedSegments
!=
C
.
LENGTH_UNSET
)
{
counters
.
percentage
=
totalSegments
==
0
?
100
f
:
(
downloadedSegments
*
100
f
)
/
totalSegments
;
}
}
}
private
void
removeDataSpec
(
DataSpec
dataSpec
)
{
CacheUtil
.
remove
(
dataSpec
,
cache
,
cacheKeyFactory
);
}
...
...
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