mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Keep download in completed state if only metadata is updated
#minor-release Issue: #8116 PiperOrigin-RevId: 342269114
This commit is contained in:
parent
7fe68b52d5
commit
f6928c0ef9
2 changed files with 40 additions and 10 deletions
|
|
@ -666,21 +666,28 @@ public final class DownloadManager {
|
||||||
|
|
||||||
/* package */ static Download mergeRequest(
|
/* package */ static Download mergeRequest(
|
||||||
Download download, DownloadRequest request, int stopReason, long nowMs) {
|
Download download, DownloadRequest request, int stopReason, long nowMs) {
|
||||||
|
DownloadRequest mergedRequest = download.request.copyWithMergedRequest(request);
|
||||||
|
|
||||||
@Download.State int state = download.state;
|
@Download.State int state = download.state;
|
||||||
// Treat the merge as creating a new download if we're currently removing the existing one, or
|
// Treat the merge as creating a new download if we're currently removing the existing one, or
|
||||||
// if the existing download is in a terminal state. Else treat the merge as updating the
|
// if the existing download has failed. Else treat the merge as updating the existing download.
|
||||||
// existing download.
|
|
||||||
long startTimeMs =
|
long startTimeMs =
|
||||||
state == STATE_REMOVING || download.isTerminalState() ? nowMs : download.startTimeMs;
|
state == STATE_REMOVING || state == STATE_FAILED ? nowMs : download.startTimeMs;
|
||||||
if (state == STATE_REMOVING || state == STATE_RESTARTING) {
|
|
||||||
|
if (state == STATE_COMPLETED
|
||||||
|
&& mergedRequest.streamKeys.size() == download.request.streamKeys.size()) {
|
||||||
|
// A completed download is still completed if no new streams are added.
|
||||||
|
state = STATE_COMPLETED;
|
||||||
|
} else if (state == STATE_REMOVING || state == STATE_RESTARTING) {
|
||||||
state = STATE_RESTARTING;
|
state = STATE_RESTARTING;
|
||||||
} else if (stopReason != STOP_REASON_NONE) {
|
} else if (stopReason != STOP_REASON_NONE) {
|
||||||
state = STATE_STOPPED;
|
state = STATE_STOPPED;
|
||||||
} else {
|
} else {
|
||||||
state = STATE_QUEUED;
|
state = STATE_QUEUED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Download(
|
return new Download(
|
||||||
download.request.copyWithMergedRequest(request),
|
mergedRequest,
|
||||||
state,
|
state,
|
||||||
startTimeMs,
|
startTimeMs,
|
||||||
/* updateTimeMs= */ nowMs,
|
/* updateTimeMs= */ nowMs,
|
||||||
|
|
|
||||||
|
|
@ -635,22 +635,45 @@ public class DownloadManagerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void mergeRequest_completedWithStopReason_becomesStopped() {
|
public void mergeRequest_completedWithStopReason_mergesNewKeyAndBecomesStopped() {
|
||||||
DownloadRequest downloadRequest = createDownloadRequest(ID1);
|
StreamKey streamKey1 = new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0);
|
||||||
|
StreamKey streamKey2 = new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 1);
|
||||||
|
|
||||||
|
DownloadRequest downloadRequest1 = createDownloadRequest(ID1, streamKey1);
|
||||||
DownloadBuilder downloadBuilder =
|
DownloadBuilder downloadBuilder =
|
||||||
new DownloadBuilder(downloadRequest)
|
new DownloadBuilder(downloadRequest1)
|
||||||
.setState(Download.STATE_COMPLETED)
|
.setState(Download.STATE_COMPLETED)
|
||||||
.setStopReason(/* stopReason= */ 1);
|
.setStopReason(/* stopReason= */ 1);
|
||||||
Download download = downloadBuilder.build();
|
Download download = downloadBuilder.build();
|
||||||
|
|
||||||
|
DownloadRequest downloadRequest2 = createDownloadRequest(ID1, streamKey2);
|
||||||
Download mergedDownload =
|
Download mergedDownload =
|
||||||
DownloadManager.mergeRequest(download, downloadRequest, download.stopReason, NOW_MS);
|
DownloadManager.mergeRequest(download, downloadRequest2, download.stopReason, NOW_MS);
|
||||||
|
|
||||||
Download expectedDownload =
|
Download expectedDownload =
|
||||||
downloadBuilder.setStartTimeMs(NOW_MS).setState(Download.STATE_STOPPED).build();
|
downloadBuilder
|
||||||
|
.setStreamKeys(streamKey1, streamKey2)
|
||||||
|
.setState(Download.STATE_STOPPED)
|
||||||
|
.build();
|
||||||
assertEqualIgnoringUpdateTime(mergedDownload, expectedDownload);
|
assertEqualIgnoringUpdateTime(mergedDownload, expectedDownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void mergeRequest_completed_staysCompleted() {
|
||||||
|
StreamKey streamKey = new StreamKey(/* groupIndex= */ 0, /* trackIndex= */ 0);
|
||||||
|
|
||||||
|
DownloadRequest downloadRequest1 = createDownloadRequest(ID1, streamKey);
|
||||||
|
DownloadBuilder downloadBuilder =
|
||||||
|
new DownloadBuilder(downloadRequest1).setState(Download.STATE_COMPLETED);
|
||||||
|
Download download = downloadBuilder.build();
|
||||||
|
|
||||||
|
DownloadRequest downloadRequest2 = createDownloadRequest(ID1, streamKey);
|
||||||
|
Download mergedDownload =
|
||||||
|
DownloadManager.mergeRequest(download, downloadRequest2, /* stopReason= */ 0, NOW_MS);
|
||||||
|
|
||||||
|
assertEqualIgnoringUpdateTime(mergedDownload, download);
|
||||||
|
}
|
||||||
|
|
||||||
private void setupDownloadManager(int maxParallelDownloads) throws Exception {
|
private void setupDownloadManager(int maxParallelDownloads) throws Exception {
|
||||||
if (downloadManager != null) {
|
if (downloadManager != null) {
|
||||||
releaseDownloadManager();
|
releaseDownloadManager();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue