Skip to content

Commit

Permalink
fix: Fix download of some HLS assets (#3934)
Browse files Browse the repository at this point in the history
Fix download of https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_ts/master.m3u8

The filterManifestByMediaCapabilities method is async, but the code doesn't wait for it to finish before continuing the download process. This PR fix it.

This also fixes a hidden compiler issue caused by the use of an alias for StreamUtils.
  • Loading branch information
Álvaro Velad Galván authored and joeyparrish committed Feb 16, 2022
1 parent 02030bf commit b20dadb
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions lib/offline/storage.js
Expand Up @@ -477,47 +477,46 @@ shaka.offline.Storage = class {
* @private
*/
async filterManifest_(manifest, drmEngine, config) {
const StreamUtils = shaka.util.StreamUtils;

// Filter the manifest based on the restrictions given in the player
// configuration.
const maxHwRes = {width: Infinity, height: Infinity};
StreamUtils.filterByRestrictions(manifest, config.restrictions, maxHwRes);
shaka.util.StreamUtils.filterByRestrictions(
manifest, config.restrictions, maxHwRes);

// Filter the manifest based on what we know media source will be able to
// play later (no point storing something we can't play).
if (config.useMediaCapabilities) {
StreamUtils.filterManifestByMediaCapabilities(
await shaka.util.StreamUtils.filterManifestByMediaCapabilities(
manifest, config.offline.usePersistentLicense);
} else {
StreamUtils.filterManifestByMediaSource(manifest);
shaka.util.StreamUtils.filterManifestByMediaSource(manifest);
// Filter the manifest based on what we know our drm system will support
// playing later.
StreamUtils.filterManifestByDrm(manifest, drmEngine);
shaka.util.StreamUtils.filterManifestByDrm(manifest, drmEngine);
}

// Gather all tracks.
const allTracks = [];

// Choose the codec that has the lowest average bandwidth.
const preferredAudioChannelCount = config.preferredAudioChannelCount;
StreamUtils.chooseCodecsAndFilterManifest(
shaka.util.StreamUtils.chooseCodecsAndFilterManifest(
manifest, preferredAudioChannelCount);

for (const variant of manifest.variants) {
goog.asserts.assert(
StreamUtils.isPlayable(variant),
shaka.util.StreamUtils.isPlayable(variant),
'We should have already filtered by "is playable"');

allTracks.push(StreamUtils.variantToTrack(variant));
allTracks.push(shaka.util.StreamUtils.variantToTrack(variant));
}

for (const text of manifest.textStreams) {
allTracks.push(StreamUtils.textStreamToTrack(text));
allTracks.push(shaka.util.StreamUtils.textStreamToTrack(text));
}

for (const image of manifest.imageStreams) {
allTracks.push(StreamUtils.imageStreamToTrack(image));
allTracks.push(shaka.util.StreamUtils.imageStreamToTrack(image));
}

// Let the application choose which tracks to store.
Expand Down

0 comments on commit b20dadb

Please sign in to comment.