Skip to content

Commit

Permalink
fix(offline): Text segments are downloaded before audio&video (#7336)
Browse files Browse the repository at this point in the history
Support for using the old parallel download mechanism is also added.

Fixes: #4878
  • Loading branch information
avelad committed Sep 18, 2024
1 parent a9617b1 commit 2db857b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2235,7 +2235,8 @@ shaka.extern.LcevcConfiguration;
* <br>
* Defaults to <code>true</code>.
* @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.
* <br>
Expand Down
22 changes: 12 additions & 10 deletions lib/offline/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,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 =
Expand Down Expand Up @@ -1398,7 +1398,9 @@ shaka.offline.Storage = class {
codecs: segment.codecs,
};
streamDb.segments.push(segmentDB);
groupId = (groupId + 1) % numberOfParallelDownloads;
if (numberOfParallelDownloads !== 0) {
groupId = (groupId + 1) % numberOfParallelDownloads;
}
});

return streamDb;
Expand Down Expand Up @@ -1593,14 +1595,6 @@ shaka.offline.Storage = class {
/** @type {!Set.<shaka.extern.Stream>} */
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);
Expand All @@ -1610,6 +1604,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;
}

Expand Down

0 comments on commit 2db857b

Please sign in to comment.