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 authored Sep 18, 2024
1 parent 330e487 commit e28a07e
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 @@ -2250,7 +2250,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 @@ -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 =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1861,14 +1863,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 @@ -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;
}

Expand Down

0 comments on commit e28a07e

Please sign in to comment.