From 36ca820877965db8bcc8b9c4b2a428317301bb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 10 Feb 2022 17:36:50 +0100 Subject: [PATCH] fix: Fix download of some HLS assets (#3934) 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. --- lib/offline/storage.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/offline/storage.js b/lib/offline/storage.js index 6e37360ec7..23c6958e73 100644 --- a/lib/offline/storage.js +++ b/lib/offline/storage.js @@ -681,16 +681,15 @@ 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 MediaCapabilities will be able // to play later (no point storing something we can't play). - StreamUtils.filterManifestByMediaCapabilities( + await shaka.util.StreamUtils.filterManifestByMediaCapabilities( manifest, config.offline.usePersistentLicense); // Gather all tracks. @@ -702,24 +701,24 @@ shaka.offline.Storage = class { const preferredVideoCodecs = config.preferredVideoCodecs; const preferredAudioCodecs = config.preferredAudioCodecs; - StreamUtils.chooseCodecsAndFilterManifest( + shaka.util.StreamUtils.chooseCodecsAndFilterManifest( manifest, preferredVideoCodecs, preferredAudioCodecs, preferredAudioChannelCount, preferredDecodingAttributes); 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.