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
e7d717b9
authored
Apr 08, 2019
by
olly
Committed by
Oliver Woodman
Apr 13, 2019
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Sanitize naming of keys variable.
PiperOrigin-RevId: 242460786
parent
a0c21461
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
36 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadAction.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadState.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadHelperTest.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadIndexUtilTest.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadStateBuilder.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DefaultDownloaderFactory.java
View file @
e7d717b9
...
@@ -99,7 +99,7 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
...
@@ -99,7 +99,7 @@ public class DefaultDownloaderFactory implements DownloaderFactory {
}
}
try
{
try
{
// TODO: Support customCacheKey in DASH/HLS/SS, for completeness.
// TODO: Support customCacheKey in DASH/HLS/SS, for completeness.
return
constructor
.
newInstance
(
action
.
uri
,
action
.
getKeys
()
,
downloaderConstructorHelper
);
return
constructor
.
newInstance
(
action
.
uri
,
action
.
streamKeys
,
downloaderConstructorHelper
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
"Failed to instantiate downloader for: "
+
action
.
type
,
e
);
throw
new
RuntimeException
(
"Failed to instantiate downloader for: "
+
action
.
type
,
e
);
}
}
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadAction.java
View file @
e7d717b9
...
@@ -48,7 +48,7 @@ public final class DownloadAction {
...
@@ -48,7 +48,7 @@ public final class DownloadAction {
private
static
final
int
VERSION
=
3
;
private
static
final
int
VERSION
=
3
;
/**
/**
* Deserializes a
n
action from the {@code data}.
* Deserializes a
download
action from the {@code data}.
*
*
* @param data The action data to deserialize.
* @param data The action data to deserialize.
* @return The deserialized action.
* @return The deserialized action.
...
@@ -62,10 +62,7 @@ public final class DownloadAction {
...
@@ -62,10 +62,7 @@ public final class DownloadAction {
}
}
/**
/**
* Deserializes one action that was serialized with {@link #serializeToStream(OutputStream)} from
* Deserializes a single download action from {@code input}.
* the {@code input}.
*
* <p>The caller is responsible for closing the given {@link InputStream}.
*
*
* @param input The stream from which to read.
* @param input The stream from which to read.
* @return The deserialized action.
* @return The deserialized action.
...
@@ -104,35 +101,35 @@ public final class DownloadAction {
...
@@ -104,35 +101,35 @@ public final class DownloadAction {
public
final
String
type
;
public
final
String
type
;
/** The uri being downloaded. */
/** The uri being downloaded. */
public
final
Uri
uri
;
public
final
Uri
uri
;
/**
Keys of stream
s to be downloaded. If empty, all streams will be downloaded. */
/**
Stream key
s to be downloaded. If empty, all streams will be downloaded. */
public
final
List
<
StreamKey
>
k
eys
;
public
final
List
<
StreamKey
>
streamK
eys
;
/**
A c
ustom key for cache indexing, or null. */
/**
C
ustom key for cache indexing, or null. */
@Nullable
public
final
String
customCacheKey
;
@Nullable
public
final
String
customCacheKey
;
/**
Custom data for this action
. May be empty. */
/**
Application defined data associated with the download
. May be empty. */
public
final
byte
[]
data
;
public
final
byte
[]
data
;
/**
/**
* @param id
The content id
.
* @param id
See {@link #id}
.
* @param type
The type of the action
.
* @param type
See {@link #type}
.
* @param uri
The uri being downloaded
.
* @param uri
See {@link #uri}
.
* @param
keys Keys of streams to be downloaded. If empty, all streams will be downloaded
.
* @param
streamKeys See {@link #streamKeys}
.
* @param customCacheKey
A custom key for cache indexing, or null
.
* @param customCacheKey
See {@link #customCacheKey}
.
* @param data
Custom data for this action
.
* @param data
See {@link #data}
.
*/
*/
private
DownloadAction
(
private
DownloadAction
(
String
id
,
String
id
,
String
type
,
String
type
,
Uri
uri
,
Uri
uri
,
List
<
StreamKey
>
k
eys
,
List
<
StreamKey
>
streamK
eys
,
@Nullable
String
customCacheKey
,
@Nullable
String
customCacheKey
,
@Nullable
byte
[]
data
)
{
@Nullable
byte
[]
data
)
{
this
.
id
=
id
;
this
.
id
=
id
;
this
.
type
=
type
;
this
.
type
=
type
;
this
.
uri
=
uri
;
this
.
uri
=
uri
;
this
.
customCacheKey
=
customCacheKey
;
this
.
customCacheKey
=
customCacheKey
;
ArrayList
<
StreamKey
>
mutableKeys
=
new
ArrayList
<>(
k
eys
);
ArrayList
<
StreamKey
>
mutableKeys
=
new
ArrayList
<>(
streamK
eys
);
Collections
.
sort
(
mutableKeys
);
Collections
.
sort
(
mutableKeys
);
this
.
k
eys
=
Collections
.
unmodifiableList
(
mutableKeys
);
this
.
streamK
eys
=
Collections
.
unmodifiableList
(
mutableKeys
);
this
.
data
=
data
!=
null
?
Arrays
.
copyOf
(
data
,
data
.
length
)
:
Util
.
EMPTY_BYTE_ARRAY
;
this
.
data
=
data
!=
null
?
Arrays
.
copyOf
(
data
,
data
.
length
)
:
Util
.
EMPTY_BYTE_ARRAY
;
}
}
...
@@ -148,11 +145,6 @@ public final class DownloadAction {
...
@@ -148,11 +145,6 @@ public final class DownloadAction {
return
output
.
toByteArray
();
return
output
.
toByteArray
();
}
}
/** Returns keys of streams to be downloaded. */
public
List
<
StreamKey
>
getKeys
()
{
return
keys
;
}
@Override
@Override
public
boolean
equals
(
@Nullable
Object
o
)
{
public
boolean
equals
(
@Nullable
Object
o
)
{
if
(!(
o
instanceof
DownloadAction
))
{
if
(!(
o
instanceof
DownloadAction
))
{
...
@@ -162,7 +154,7 @@ public final class DownloadAction {
...
@@ -162,7 +154,7 @@ public final class DownloadAction {
return
id
.
equals
(
that
.
id
)
return
id
.
equals
(
that
.
id
)
&&
type
.
equals
(
that
.
type
)
&&
type
.
equals
(
that
.
type
)
&&
uri
.
equals
(
that
.
uri
)
&&
uri
.
equals
(
that
.
uri
)
&&
keys
.
equals
(
that
.
k
eys
)
&&
streamKeys
.
equals
(
that
.
streamK
eys
)
&&
Util
.
areEqual
(
customCacheKey
,
that
.
customCacheKey
)
&&
Util
.
areEqual
(
customCacheKey
,
that
.
customCacheKey
)
&&
Arrays
.
equals
(
data
,
that
.
data
);
&&
Arrays
.
equals
(
data
,
that
.
data
);
}
}
...
@@ -172,7 +164,7 @@ public final class DownloadAction {
...
@@ -172,7 +164,7 @@ public final class DownloadAction {
int
result
=
type
.
hashCode
();
int
result
=
type
.
hashCode
();
result
=
31
*
result
+
id
.
hashCode
();
result
=
31
*
result
+
id
.
hashCode
();
result
=
31
*
result
+
uri
.
hashCode
();
result
=
31
*
result
+
uri
.
hashCode
();
result
=
31
*
result
+
k
eys
.
hashCode
();
result
=
31
*
result
+
streamK
eys
.
hashCode
();
result
=
31
*
result
+
(
customCacheKey
!=
null
?
customCacheKey
.
hashCode
()
:
0
);
result
=
31
*
result
+
(
customCacheKey
!=
null
?
customCacheKey
.
hashCode
()
:
0
);
result
=
31
*
result
+
Arrays
.
hashCode
(
data
);
result
=
31
*
result
+
Arrays
.
hashCode
(
data
);
return
result
;
return
result
;
...
@@ -194,9 +186,9 @@ public final class DownloadAction {
...
@@ -194,9 +186,9 @@ public final class DownloadAction {
dataOutputStream
.
writeBoolean
(
false
);
dataOutputStream
.
writeBoolean
(
false
);
dataOutputStream
.
writeInt
(
data
.
length
);
dataOutputStream
.
writeInt
(
data
.
length
);
dataOutputStream
.
write
(
data
);
dataOutputStream
.
write
(
data
);
dataOutputStream
.
writeInt
(
k
eys
.
size
());
dataOutputStream
.
writeInt
(
streamK
eys
.
size
());
for
(
int
i
=
0
;
i
<
k
eys
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
streamK
eys
.
size
();
i
++)
{
StreamKey
key
=
k
eys
.
get
(
i
);
StreamKey
key
=
streamK
eys
.
get
(
i
);
dataOutputStream
.
writeInt
(
key
.
periodIndex
);
dataOutputStream
.
writeInt
(
key
.
periodIndex
);
dataOutputStream
.
writeInt
(
key
.
groupIndex
);
dataOutputStream
.
writeInt
(
key
.
groupIndex
);
dataOutputStream
.
writeInt
(
key
.
trackIndex
);
dataOutputStream
.
writeInt
(
key
.
trackIndex
);
...
...
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloadState.java
View file @
e7d717b9
...
@@ -165,7 +165,7 @@ public final class DownloadState {
...
@@ -165,7 +165,7 @@ public final class DownloadState {
/* manualStopReason= */
0
,
/* manualStopReason= */
0
,
/* startTimeMs= */
currentTimeMs
,
/* startTimeMs= */
currentTimeMs
,
/* updateTimeMs= */
currentTimeMs
,
/* updateTimeMs= */
currentTimeMs
,
action
.
k
eys
.
toArray
(
new
StreamKey
[
0
]),
action
.
streamK
eys
.
toArray
(
new
StreamKey
[
0
]),
action
.
data
,
action
.
data
,
new
CachingCounters
());
new
CachingCounters
());
}
}
...
@@ -289,10 +289,10 @@ public final class DownloadState {
...
@@ -289,10 +289,10 @@ public final class DownloadState {
private
static
StreamKey
[]
mergeStreamKeys
(
DownloadState
downloadState
,
DownloadAction
action
)
{
private
static
StreamKey
[]
mergeStreamKeys
(
DownloadState
downloadState
,
DownloadAction
action
)
{
StreamKey
[]
streamKeys
=
downloadState
.
streamKeys
;
StreamKey
[]
streamKeys
=
downloadState
.
streamKeys
;
if
(
streamKeys
.
length
>
0
)
{
if
(
streamKeys
.
length
>
0
)
{
if
(
action
.
k
eys
.
isEmpty
())
{
if
(
action
.
streamK
eys
.
isEmpty
())
{
streamKeys
=
new
StreamKey
[
0
];
streamKeys
=
new
StreamKey
[
0
];
}
else
{
}
else
{
HashSet
<
StreamKey
>
keys
=
new
HashSet
<>(
action
.
k
eys
);
HashSet
<
StreamKey
>
keys
=
new
HashSet
<>(
action
.
streamK
eys
);
Collections
.
addAll
(
keys
,
downloadState
.
streamKeys
);
Collections
.
addAll
(
keys
,
downloadState
.
streamKeys
);
streamKeys
=
keys
.
toArray
(
new
StreamKey
[
0
]);
streamKeys
=
keys
.
toArray
(
new
StreamKey
[
0
]);
}
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadHelperTest.java
View file @
e7d717b9
...
@@ -398,7 +398,7 @@ public class DownloadHelperTest {
...
@@ -398,7 +398,7 @@ public class DownloadHelperTest {
assertThat
(
downloadAction
.
uri
).
isEqualTo
(
testUri
);
assertThat
(
downloadAction
.
uri
).
isEqualTo
(
testUri
);
assertThat
(
downloadAction
.
customCacheKey
).
isEqualTo
(
TEST_CACHE_KEY
);
assertThat
(
downloadAction
.
customCacheKey
).
isEqualTo
(
TEST_CACHE_KEY
);
assertThat
(
downloadAction
.
data
).
isEqualTo
(
data
);
assertThat
(
downloadAction
.
data
).
isEqualTo
(
data
);
assertThat
(
downloadAction
.
k
eys
)
assertThat
(
downloadAction
.
streamK
eys
)
.
containsExactly
(
.
containsExactly
(
new
StreamKey
(
/* periodIndex= */
0
,
/* groupIndex= */
0
,
/* trackIndex= */
0
),
new
StreamKey
(
/* periodIndex= */
0
,
/* groupIndex= */
0
,
/* trackIndex= */
0
),
new
StreamKey
(
/* periodIndex= */
0
,
/* groupIndex= */
0
,
/* trackIndex= */
1
),
new
StreamKey
(
/* periodIndex= */
0
,
/* groupIndex= */
0
,
/* trackIndex= */
1
),
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadIndexUtilTest.java
View file @
e7d717b9
...
@@ -147,7 +147,8 @@ public class DownloadIndexUtilTest {
...
@@ -147,7 +147,8 @@ public class DownloadIndexUtilTest {
assertThat
(
downloadState
.
cacheKey
).
isEqualTo
(
action
.
customCacheKey
);
assertThat
(
downloadState
.
cacheKey
).
isEqualTo
(
action
.
customCacheKey
);
assertThat
(
downloadState
.
customMetadata
).
isEqualTo
(
action
.
data
);
assertThat
(
downloadState
.
customMetadata
).
isEqualTo
(
action
.
data
);
assertThat
(
downloadState
.
uri
).
isEqualTo
(
action
.
uri
);
assertThat
(
downloadState
.
uri
).
isEqualTo
(
action
.
uri
);
assertThat
(
Arrays
.
asList
(
downloadState
.
streamKeys
)).
containsExactlyElementsIn
(
action
.
keys
);
assertThat
(
Arrays
.
asList
(
downloadState
.
streamKeys
))
.
containsExactlyElementsIn
(
action
.
streamKeys
);
assertThat
(
downloadState
.
state
).
isEqualTo
(
state
);
assertThat
(
downloadState
.
state
).
isEqualTo
(
state
);
}
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadManagerTest.java
View file @
e7d717b9
...
@@ -249,7 +249,7 @@ public class DownloadManagerTest {
...
@@ -249,7 +249,7 @@ public class DownloadManagerTest {
FakeDownloader
downloader2
=
runner
.
getDownloader
(
1
);
FakeDownloader
downloader2
=
runner
.
getDownloader
(
1
);
downloader2
.
assertStarted
();
downloader2
.
assertStarted
();
assertThat
(
downloader2
.
action
.
k
eys
).
containsExactly
(
streamKey1
,
streamKey2
);
assertThat
(
downloader2
.
action
.
streamK
eys
).
containsExactly
(
streamKey1
,
streamKey2
);
downloader2
.
unblock
();
downloader2
.
unblock
();
runner
.
getTask
().
assertCompleted
();
runner
.
getTask
().
assertCompleted
();
...
...
library/core/src/test/java/com/google/android/exoplayer2/offline/DownloadStateBuilder.java
View file @
e7d717b9
...
@@ -52,7 +52,7 @@ class DownloadStateBuilder {
...
@@ -52,7 +52,7 @@ class DownloadStateBuilder {
action
.
uri
,
action
.
uri
,
action
.
customCacheKey
,
action
.
customCacheKey
,
action
.
data
,
action
.
data
,
action
.
k
eys
.
toArray
(
new
StreamKey
[
0
]));
action
.
streamK
eys
.
toArray
(
new
StreamKey
[
0
]));
}
}
DownloadStateBuilder
(
DownloadStateBuilder
(
...
...
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