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
28e32072
authored
Jul 21, 2022
by
Jorge Antonio Diaz-Benito Soriano
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Cap concurrent removal DownloadManager.Tasks
parent
9271572e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
65 additions
and
2 deletions
libraries/exoplayer/src/main/java/androidx/media3/exoplayer/offline/DownloadManager.java
libraries/exoplayer/src/test/java/androidx/media3/exoplayer/offline/DownloadManagerTest.java
libraries/exoplayer/src/main/java/androidx/media3/exoplayer/offline/DownloadManager.java
View file @
28e32072
...
@@ -174,6 +174,7 @@ public final class DownloadManager {
...
@@ -174,6 +174,7 @@ public final class DownloadManager {
private
static
final
int
MSG_RELEASE
=
12
;
private
static
final
int
MSG_RELEASE
=
12
;
private
static
final
String
TAG
=
"DownloadManager"
;
private
static
final
String
TAG
=
"DownloadManager"
;
private
static
final
int
MAX_REMOVE_TASK_COUNT
=
1
;
private
final
Context
context
;
private
final
Context
context
;
private
final
WritableDownloadIndex
downloadIndex
;
private
final
WritableDownloadIndex
downloadIndex
;
...
@@ -709,6 +710,7 @@ public final class DownloadManager {
...
@@ -709,6 +710,7 @@ public final class DownloadManager {
private
int
maxParallelDownloads
;
private
int
maxParallelDownloads
;
private
int
minRetryCount
;
private
int
minRetryCount
;
private
int
activeDownloadTaskCount
;
private
int
activeDownloadTaskCount
;
private
int
activeRemoveTaskCount
;
public
InternalHandler
(
public
InternalHandler
(
HandlerThread
thread
,
HandlerThread
thread
,
...
@@ -1060,6 +1062,10 @@ public final class DownloadManager {
...
@@ -1060,6 +1062,10 @@ public final class DownloadManager {
return
;
return
;
}
}
if
(
activeRemoveTaskCount
>=
MAX_REMOVE_TASK_COUNT
)
{
return
;
}
// We can start a remove task.
// We can start a remove task.
Downloader
downloader
=
downloaderFactory
.
createDownloader
(
download
.
request
);
Downloader
downloader
=
downloaderFactory
.
createDownloader
(
download
.
request
);
activeTask
=
activeTask
=
...
@@ -1071,6 +1077,7 @@ public final class DownloadManager {
...
@@ -1071,6 +1077,7 @@ public final class DownloadManager {
minRetryCount
,
minRetryCount
,
/* internalHandler= */
this
);
/* internalHandler= */
this
);
activeTasks
.
put
(
download
.
request
.
id
,
activeTask
);
activeTasks
.
put
(
download
.
request
.
id
,
activeTask
);
activeRemoveTaskCount
++;
activeTask
.
start
();
activeTask
.
start
();
}
}
...
@@ -1100,7 +1107,9 @@ public final class DownloadManager {
...
@@ -1100,7 +1107,9 @@ public final class DownloadManager {
activeTasks
.
remove
(
downloadId
);
activeTasks
.
remove
(
downloadId
);
boolean
isRemove
=
task
.
isRemove
;
boolean
isRemove
=
task
.
isRemove
;
if
(!
isRemove
&&
--
activeDownloadTaskCount
==
0
)
{
if
(
isRemove
)
{
activeRemoveTaskCount
--;
}
else
if
(--
activeDownloadTaskCount
==
0
)
{
removeMessages
(
MSG_UPDATE_PROGRESS
);
removeMessages
(
MSG_UPDATE_PROGRESS
);
}
}
...
...
libraries/exoplayer/src/test/java/androidx/media3/exoplayer/offline/DownloadManagerTest.java
View file @
28e32072
...
@@ -713,7 +713,61 @@ public class DownloadManagerTest {
...
@@ -713,7 +713,61 @@ public class DownloadManagerTest {
assertEqualIgnoringUpdateTime
(
mergedDownload
,
expectedDownload
);
assertEqualIgnoringUpdateTime
(
mergedDownload
,
expectedDownload
);
}
}
@Test
public
void
remove_tasks_run_sequentially
()
throws
Throwable
{
DefaultDownloadIndex
defaultDownloadIndex
=
new
DefaultDownloadIndex
(
TestUtil
.
getInMemoryDatabaseProvider
());
defaultDownloadIndex
.
putDownload
(
new
Download
(
new
DownloadRequest
.
Builder
(
ID1
,
Uri
.
EMPTY
).
build
(),
Download
.
STATE_REMOVING
,
0
,
1
,
2
,
Download
.
STOP_REASON_NONE
,
Download
.
FAILURE_REASON_NONE
)
);
defaultDownloadIndex
.
putDownload
(
new
Download
(
new
DownloadRequest
.
Builder
(
ID2
,
Uri
.
EMPTY
).
build
(),
Download
.
STATE_RESTARTING
,
0
,
1
,
2
,
Download
.
STOP_REASON_NONE
,
Download
.
FAILURE_REASON_NONE
)
);
setupDownloadManager
(
100
,
defaultDownloadIndex
);
// The second removal should wait and the first one should be able to complete.
FakeDownloader
downloader0
=
getDownloaderAt
(
0
);
assertNoDownloaderAt
(
1
);
downloader0
.
assertId
(
ID1
);
downloader0
.
assertRemoveStarted
();
downloader0
.
finish
();
assertRemoved
(
ID1
);
// The second removal can start once the first one has completed, and removes a download with
// state STATE_RESTARTING, so it should result in a new download being queued.
FakeDownloader
downloader1
=
getDownloaderAt
(
1
);
downloader1
.
assertId
(
ID2
);
downloader1
.
assertRemoveStarted
();
downloader1
.
finish
();
assertQueued
(
ID2
);
}
private
void
setupDownloadManager
(
int
maxParallelDownloads
)
throws
Exception
{
private
void
setupDownloadManager
(
int
maxParallelDownloads
)
throws
Exception
{
setupDownloadManager
(
maxParallelDownloads
,
new
DefaultDownloadIndex
(
TestUtil
.
getInMemoryDatabaseProvider
())
);
}
private
void
setupDownloadManager
(
int
maxParallelDownloads
,
WritableDownloadIndex
writableDownloadIndex
)
throws
Exception
{
if
(
downloadManager
!=
null
)
{
if
(
downloadManager
!=
null
)
{
releaseDownloadManager
();
releaseDownloadManager
();
}
}
...
@@ -723,7 +777,7 @@ public class DownloadManagerTest {
...
@@ -723,7 +777,7 @@ public class DownloadManagerTest {
downloadManager
=
downloadManager
=
new
DownloadManager
(
new
DownloadManager
(
ApplicationProvider
.
getApplicationContext
(),
ApplicationProvider
.
getApplicationContext
(),
new
DefaultDownloadIndex
(
TestUtil
.
getInMemoryDatabaseProvider
())
,
writableDownloadIndex
,
new
FakeDownloaderFactory
());
new
FakeDownloaderFactory
());
downloadManager
.
setMaxParallelDownloads
(
maxParallelDownloads
);
downloadManager
.
setMaxParallelDownloads
(
maxParallelDownloads
);
downloadManager
.
setMinRetryCount
(
MIN_RETRY_COUNT
);
downloadManager
.
setMinRetryCount
(
MIN_RETRY_COUNT
);
...
...
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