Commit 7f08ab72 by tonihei

Merge pull request #126 from stoyicker:cap_concurrent_remove_tasks

PiperOrigin-RevId: 463792127
parents 0f96d861 28e32072
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
* Use `SingleThreadExecutor` for releasing `AudioTrack` instances to avoid * Use `SingleThreadExecutor` for releasing `AudioTrack` instances to avoid
OutOfMemory errors when releasing multiple players at the same time OutOfMemory errors when releasing multiple players at the same time
([#10057](https://github.com/google/ExoPlayer/issues/10057)). ([#10057](https://github.com/google/ExoPlayer/issues/10057)).
* Limit parallel download removals to 1 to avoid excessive thread creation
([#10458](https://github.com/google/ExoPlayer/issues/10458)).
* Metadata:
* `MetadataRenderer` can now be configured to render metadata as soon as * `MetadataRenderer` can now be configured to render metadata as soon as
they are available. Create an instance with they are available. Create an instance with
`MetadataRenderer(MetadataOutput, Looper, MetadataDecoderFactory, `MetadataRenderer(MetadataOutput, Looper, MetadataDecoderFactory,
......
...@@ -709,6 +709,7 @@ public final class DownloadManager { ...@@ -709,6 +709,7 @@ public final class DownloadManager {
private int maxParallelDownloads; private int maxParallelDownloads;
private int minRetryCount; private int minRetryCount;
private int activeDownloadTaskCount; private int activeDownloadTaskCount;
private boolean hasActiveRemoveTask;
public InternalHandler( public InternalHandler(
HandlerThread thread, HandlerThread thread,
...@@ -1060,6 +1061,10 @@ public final class DownloadManager { ...@@ -1060,6 +1061,10 @@ public final class DownloadManager {
return; return;
} }
if (hasActiveRemoveTask) {
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 +1076,7 @@ public final class DownloadManager { ...@@ -1071,6 +1076,7 @@ public final class DownloadManager {
minRetryCount, minRetryCount,
/* internalHandler= */ this); /* internalHandler= */ this);
activeTasks.put(download.request.id, activeTask); activeTasks.put(download.request.id, activeTask);
hasActiveRemoveTask = true;
activeTask.start(); activeTask.start();
} }
...@@ -1100,7 +1106,9 @@ public final class DownloadManager { ...@@ -1100,7 +1106,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) {
hasActiveRemoveTask = false;
} else if (--activeDownloadTaskCount == 0) {
removeMessages(MSG_UPDATE_PROGRESS); removeMessages(MSG_UPDATE_PROGRESS);
} }
......
...@@ -284,14 +284,14 @@ public class DownloadManagerTest { ...@@ -284,14 +284,14 @@ public class DownloadManagerTest {
postRemoveAllRequest(); postRemoveAllRequest();
// Both downloads should be removed. // Both downloads should be removed.
FakeDownloader downloader2 = getDownloaderAt(2); FakeDownloader downloader2 = getDownloaderAt(2);
FakeDownloader downloader3 = getDownloaderAt(3);
downloader2.assertId(ID1); downloader2.assertId(ID1);
downloader3.assertId(ID2);
downloader2.assertRemoveStarted(); downloader2.assertRemoveStarted();
downloader3.assertRemoveStarted();
downloader2.finish(); downloader2.finish();
downloader3.finish();
assertRemoved(ID1); assertRemoved(ID1);
FakeDownloader downloader3 = getDownloaderAt(3);
downloader3.assertId(ID2);
downloader3.assertRemoveStarted();
downloader3.finish();
assertRemoved(ID2); assertRemoved(ID2);
downloadManagerListener.blockUntilIdleAndThrowAnyFailure(); downloadManagerListener.blockUntilIdleAndThrowAnyFailure();
...@@ -713,6 +713,36 @@ public class DownloadManagerTest { ...@@ -713,6 +713,36 @@ public class DownloadManagerTest {
assertEqualIgnoringUpdateTime(mergedDownload, expectedDownload); assertEqualIgnoringUpdateTime(mergedDownload, expectedDownload);
} }
@Test
public void removeRequests_runSequentially() throws Throwable {
// Trigger two remove requests.
postDownloadRequest(ID1);
getDownloaderAt(0).finish();
postDownloadRequest(ID2);
getDownloaderAt(1).finish();
postRemoveRequest(ID1);
postRemoveRequest(ID2);
// Assert first remove request is executing, second one is queued.
assertRemoving(ID1);
assertQueued(ID2);
FakeDownloader downloader2 = getDownloaderAt(2);
downloader2.assertId(ID1);
downloader2.assertRemoveStarted();
downloader2.finish();
assertRemoved(ID1);
// Assert second one is running after first one finished
assertRemoving(ID2);
FakeDownloader downloader3 = getDownloaderAt(3);
downloader3.assertId(ID2);
downloader3.assertRemoveStarted();
downloader3.finish();
assertRemoved(ID2);
downloadManagerListener.blockUntilIdleAndThrowAnyFailure();
}
private void setupDownloadManager(int maxParallelDownloads) throws Exception { private void setupDownloadManager(int maxParallelDownloads) throws Exception {
if (downloadManager != null) { if (downloadManager != null) {
releaseDownloadManager(); releaseDownloadManager();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment