From 0f5a8d32cdb1b96a587189015a4a3ab5ae1a7f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=CC=81lvaro=20Velad=20Galva=CC=81n?= Date: Wed, 18 Sep 2024 11:17:58 +0200 Subject: [PATCH] fix(offline): Text segments are downloaded before audio&video --- externs/shaka/player.js | 3 ++- lib/offline/storage.js | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/externs/shaka/player.js b/externs/shaka/player.js index 9601e523ad..e6d91fb083 100644 --- a/externs/shaka/player.js +++ b/externs/shaka/player.js @@ -2242,7 +2242,8 @@ shaka.extern.LcevcConfiguration; *
* Defaults to true. * @property {number} numberOfParallelDownloads - * Number of parallel downloads. + * Number of parallel downloads. If the value is 0, downloads will be + * sequential for each stream. * Note: normally browsers limit to 5 request in parallel, so putting a * number higher than this will not help it download faster. *
diff --git a/lib/offline/storage.js b/lib/offline/storage.js index fec5e5b6fd..563635b579 100644 --- a/lib/offline/storage.js +++ b/lib/offline/storage.js @@ -1613,7 +1613,7 @@ shaka.offline.Storage = class { manifest.presentationTimeline.getSegmentAvailabilityStart(); const numberOfParallelDownloads = config.offline.numberOfParallelDownloads; - let groupId = 0; + let groupId = numberOfParallelDownloads === 0 ? stream.id : 0; shaka.offline.Storage.forEachSegment_(stream, startTime, (segment) => { const pendingSegmentRefId = @@ -1666,7 +1666,9 @@ shaka.offline.Storage = class { thumbnailSprite: segment.thumbnailSprite, }; streamDb.segments.push(segmentDB); - groupId = (groupId + 1) % numberOfParallelDownloads; + if (numberOfParallelDownloads !== 0) { + groupId = (groupId + 1) % numberOfParallelDownloads; + } }); return streamDb; @@ -1861,14 +1863,6 @@ shaka.offline.Storage = class { /** @type {!Set.} */ const set = new Set(); - for (const text of manifest.textStreams) { - set.add(text); - } - - for (const image of manifest.imageStreams) { - set.add(image); - } - for (const variant of manifest.variants) { if (variant.audio) { set.add(variant.audio); @@ -1878,6 +1872,14 @@ shaka.offline.Storage = class { } } + for (const text of manifest.textStreams) { + set.add(text); + } + + for (const image of manifest.imageStreams) { + set.add(image); + } + return set; }