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
d5b19694
authored
Apr 02, 2019
by
eguven
Committed by
Oliver Woodman
Apr 05, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add percentage field to CacheUtil.CachingCounters
PiperOrigin-RevId: 241524766
parent
9aacef47
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
4 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/ProgressiveDownloader.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheUtil.java
library/core/src/main/java/com/google/android/exoplayer2/offline/ProgressiveDownloader.java
View file @
d5b19694
...
...
@@ -103,10 +103,7 @@ public final class ProgressiveDownloader implements Downloader {
@Override
public
float
getDownloadPercentage
()
{
long
contentLength
=
cachingCounters
.
contentLength
;
return
contentLength
==
C
.
LENGTH_UNSET
?
C
.
PERCENTAGE_UNSET
:
((
cachingCounters
.
totalCachedBytes
()
*
100
f
)
/
contentLength
);
return
cachingCounters
.
percentage
;
}
@Override
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheUtil.java
View file @
d5b19694
...
...
@@ -42,6 +42,8 @@ public final class CacheUtil {
public
volatile
long
newlyCachedBytes
;
/** The length of the content being cached in bytes, or {@link C#LENGTH_UNSET} if unknown. */
public
volatile
long
contentLength
=
C
.
LENGTH_UNSET
;
/** The percentage of cached data, or {@link C#PERCENTAGE_UNSET} if unavailable. */
public
volatile
float
percentage
;
/**
* Returns the sum of {@link #alreadyCachedBytes} and {@link #newlyCachedBytes}.
...
...
@@ -49,6 +51,16 @@ public final class CacheUtil {
public
long
totalCachedBytes
()
{
return
alreadyCachedBytes
+
newlyCachedBytes
;
}
/** Updates {@link #percentage} value using other values. */
public
void
updatePercentage
()
{
// Take local snapshot of the volatile field
long
contentLength
=
this
.
contentLength
;
percentage
=
contentLength
==
C
.
LENGTH_UNSET
?
C
.
PERCENTAGE_UNSET
:
((
totalCachedBytes
()
*
100
f
)
/
contentLength
);
}
}
/** Default buffer size to be used while caching. */
...
...
@@ -105,6 +117,7 @@ public final class CacheUtil {
start
+=
blockLength
;
left
-=
left
==
C
.
LENGTH_UNSET
?
0
:
blockLength
;
}
counters
.
updatePercentage
();
}
/**
...
...
@@ -293,6 +306,7 @@ public final class CacheUtil {
}
totalRead
+=
read
;
counters
.
newlyCachedBytes
+=
read
;
counters
.
updatePercentage
();
}
return
totalRead
;
}
catch
(
PriorityTaskManager
.
PriorityTooLowException
exception
)
{
...
...
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