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
05d5096b
authored
Mar 19, 2018
by
Jianyong Xiao
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Provide an option to skip file descriptor sync in CacheDataSink
parent
18b1ec7a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
17 deletions
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSinkFactory.java
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSource.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest.java
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest2.java
library/core/src/main/java/com/google/android/exoplayer2/offline/DownloaderConstructorHelper.java
View file @
05d5096b
...
...
@@ -93,7 +93,7 @@ public final class DownloaderConstructorHelper {
}
else
{
DataSink
cacheWriteDataSink
=
cacheWriteDataSinkFactory
!=
null
?
cacheWriteDataSinkFactory
.
createDataSink
()
:
new
CacheDataSink
(
cache
,
CacheDataSource
.
DEFAULT_MAX_CACHE_FILE_SIZE
);
:
new
CacheDataSink
(
cache
,
CacheDataSource
.
DEFAULT_MAX_CACHE_FILE_SIZE
,
false
);
DataSource
upstream
=
upstreamDataSourceFactory
.
createDataSource
();
upstream
=
priorityTaskManager
==
null
?
upstream
:
new
PriorityDataSource
(
upstream
,
priorityTaskManager
,
C
.
PRIORITY_DOWNLOAD
);
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSink.java
View file @
05d5096b
...
...
@@ -43,6 +43,7 @@ public final class CacheDataSink implements DataSink {
private
final
Cache
cache
;
private
final
long
maxCacheFileSize
;
private
final
int
bufferSize
;
private
final
boolean
skipFDSync
;
private
DataSpec
dataSpec
;
private
File
file
;
...
...
@@ -70,9 +71,10 @@ public final class CacheDataSink implements DataSink {
* @param maxCacheFileSize The maximum size of a cache file, in bytes. If the sink is opened for
* a {@link DataSpec} whose size exceeds this value, then the data will be fragmented into
* multiple cache files.
* @param skipFDSync Skip file descriptor sync when closing current output stream.
*/
public
CacheDataSink
(
Cache
cache
,
long
maxCacheFileSize
)
{
this
(
cache
,
maxCacheFileSize
,
DEFAULT_BUFFER_SIZE
);
public
CacheDataSink
(
Cache
cache
,
long
maxCacheFileSize
,
boolean
skipFDSync
)
{
this
(
cache
,
maxCacheFileSize
,
DEFAULT_BUFFER_SIZE
,
skipFDSync
);
}
/**
...
...
@@ -82,11 +84,13 @@ public final class CacheDataSink implements DataSink {
* multiple cache files.
* @param bufferSize The buffer size in bytes for writing to a cache file. A zero or negative
* value disables buffering.
* @param skipFDSync Skip file descriptor sync when closing current output stream.
*/
public
CacheDataSink
(
Cache
cache
,
long
maxCacheFileSize
,
int
bufferSize
)
{
public
CacheDataSink
(
Cache
cache
,
long
maxCacheFileSize
,
int
bufferSize
,
boolean
skipFDSync
)
{
this
.
cache
=
Assertions
.
checkNotNull
(
cache
);
this
.
maxCacheFileSize
=
maxCacheFileSize
;
this
.
bufferSize
=
bufferSize
;
this
.
skipFDSync
=
skipFDSync
;
}
@Override
...
...
@@ -170,7 +174,9 @@ public final class CacheDataSink implements DataSink {
boolean
success
=
false
;
try
{
outputStream
.
flush
();
if
(!
skipFDSync
)
{
underlyingFileOutputStream
.
getFD
().
sync
();
}
success
=
true
;
}
finally
{
Util
.
closeQuietly
(
outputStream
);
...
...
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSinkFactory.java
View file @
05d5096b
...
...
@@ -44,7 +44,7 @@ public final class CacheDataSinkFactory implements DataSink.Factory {
@Override
public
DataSink
createDataSink
()
{
return
new
CacheDataSink
(
cache
,
maxCacheFileSize
,
bufferSize
);
return
new
CacheDataSink
(
cache
,
maxCacheFileSize
,
bufferSize
,
false
);
}
}
library/core/src/main/java/com/google/android/exoplayer2/upstream/cache/CacheDataSource.java
View file @
05d5096b
...
...
@@ -157,7 +157,7 @@ public final class CacheDataSource implements DataSource {
*/
public
CacheDataSource
(
Cache
cache
,
DataSource
upstream
,
@Flags
int
flags
,
long
maxCacheFileSize
)
{
this
(
cache
,
upstream
,
new
FileDataSource
(),
new
CacheDataSink
(
cache
,
maxCacheFileSize
),
this
(
cache
,
upstream
,
new
FileDataSource
(),
new
CacheDataSink
(
cache
,
maxCacheFileSize
,
false
),
flags
,
null
);
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest.java
View file @
05d5096b
...
...
@@ -79,29 +79,49 @@ public final class CacheDataSourceTest {
@Test
public
void
testCacheAndRead
()
throws
Exception
{
assertCacheAndRead
(
false
,
false
);
assertCacheAndRead
(
false
,
false
,
false
);
}
@Test
public
void
testCacheAndReadUnboundedRequest
()
throws
Exception
{
assertCacheAndRead
(
true
,
false
);
assertCacheAndRead
(
true
,
false
,
false
);
}
@Test
public
void
testCacheAndReadUnknownLength
()
throws
Exception
{
assertCacheAndRead
(
false
,
true
);
assertCacheAndRead
(
false
,
true
,
false
);
}
@Test
public
void
testCacheAndReadUnboundedRequestUnknownLength
()
throws
Exception
{
assertCacheAndRead
(
true
,
true
);
assertCacheAndRead
(
true
,
true
,
false
);
}
@Test
public
void
testCacheAndReadSkipFDSync
()
throws
Exception
{
assertCacheAndRead
(
false
,
false
,
false
);
}
@Test
public
void
testCacheAndReadUnboundedRequestSkipFDSync
()
throws
Exception
{
assertCacheAndRead
(
true
,
false
,
false
);
}
@Test
public
void
testCacheAndReadUnknownLengthSkipFDSync
()
throws
Exception
{
assertCacheAndRead
(
false
,
true
,
false
);
}
@Test
public
void
testCacheAndReadUnboundedRequestUnknownLengthSkipFDSync
()
throws
Exception
{
assertCacheAndRead
(
true
,
true
,
false
);
}
@Test
public
void
testUnsatisfiableRange
()
throws
Exception
{
// Bounded request but the content length is unknown. This forces all data to be cached but not
// the length
assertCacheAndRead
(
false
,
true
);
assertCacheAndRead
(
false
,
true
,
false
);
// Now do an unbounded request. This will read all of the data from cache and then try to read
// more from upstream which will cause to a 416 so CDS will store the length.
...
...
@@ -347,10 +367,11 @@ public final class CacheDataSourceTest {
cacheDataSource
.
close
();
}
private
void
assertCacheAndRead
(
boolean
unboundedRequest
,
boolean
simulateUnknownLength
)
private
void
assertCacheAndRead
(
boolean
unboundedRequest
,
boolean
simulateUnknownLength
,
boolean
skipFDSync
)
throws
IOException
{
// Read all data from upstream and write to cache
CacheDataSource
cacheDataSource
=
createCacheDataSource
(
false
,
simulateUnknownLength
);
CacheDataSource
cacheDataSource
=
createCacheDataSource
(
false
,
simulateUnknownLength
,
skipFDSync
);
assertReadDataContentLength
(
cacheDataSource
,
unboundedRequest
,
simulateUnknownLength
);
// Just read from cache
...
...
@@ -391,14 +412,19 @@ public final class CacheDataSourceTest {
private
CacheDataSource
createCacheDataSource
(
boolean
setReadException
,
boolean
simulateUnknownLength
)
{
return
createCacheDataSource
(
setReadException
,
simulateUnknownLength
,
false
);
}
private
CacheDataSource
createCacheDataSource
(
boolean
setReadException
,
boolean
simulateUnknownLength
,
boolean
skipFDSync
)
{
return
createCacheDataSource
(
setReadException
,
simulateUnknownLength
,
CacheDataSource
.
FLAG_BLOCK_ON_CACHE
);
CacheDataSource
.
FLAG_BLOCK_ON_CACHE
,
skipFDSync
);
}
private
CacheDataSource
createCacheDataSource
(
boolean
setReadException
,
boolean
simulateUnknownLength
,
@CacheDataSource
.
Flags
int
flags
)
{
boolean
simulateUnknownLength
,
@CacheDataSource
.
Flags
int
flags
,
boolean
skipFDSync
)
{
return
createCacheDataSource
(
setReadException
,
simulateUnknownLength
,
flags
,
new
CacheDataSink
(
cache
,
MAX_CACHE_FILE_SIZE
));
new
CacheDataSink
(
cache
,
MAX_CACHE_FILE_SIZE
,
skipFDSync
));
}
private
CacheDataSource
createCacheDataSource
(
boolean
setReadException
,
...
...
library/core/src/test/java/com/google/android/exoplayer2/upstream/cache/CacheDataSourceTest2.java
View file @
05d5096b
...
...
@@ -166,7 +166,7 @@ public final class CacheDataSourceTest2 {
?
new
AesCipherDataSource
(
Util
.
getUtf8Bytes
(
secretKey
),
file
)
:
file
;
// Sink and cipher
CacheDataSink
cacheSink
=
new
CacheDataSink
(
cache
,
EXO_CACHE_MAX_FILESIZE
);
CacheDataSink
cacheSink
=
new
CacheDataSink
(
cache
,
EXO_CACHE_MAX_FILESIZE
,
false
);
byte
[]
scratch
=
new
byte
[
3897
];
DataSink
cacheWriteDataSink
=
useAesEncryption
?
new
AesCipherDataSink
(
Util
.
getUtf8Bytes
(
secretKey
),
cacheSink
,
scratch
)
:
cacheSink
;
...
...
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