Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ module.exports = (config) => {
// eslint-disable-next-line @stylistic/max-len
{pattern: 'test/test/assets/hls-text-no-discontinuity/*', included: false},
{pattern: 'test/test/assets/hls-text-offset/*', included: false},
{pattern: 'test/test/assets/hls-track-filtering/*', included: false},
{pattern: 'test/test/assets/hls-ts-aac/*', included: false},
{pattern: 'test/test/assets/hls-ts-ac3/*', included: false},
{pattern: 'test/test/assets/hls-ts-b-frames/*', included: false},
Expand Down
30 changes: 29 additions & 1 deletion lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ shaka.hls.HlsParser = class {
*/
this.uriToStreamInfosMap_ = new Map();

/**
* A map from each stream to the variants it is a part of.
* This is used to reset variant decodingInfo when streams are updated.
* @private {!Map<!shaka.extern.Stream, !Set<!shaka.extern.Variant>>}
*/
this.streamToVariants_ = new Map();

/** @private {?shaka.media.PresentationTimeline} */
this.presentationTimeline_ = null;

Expand Down Expand Up @@ -2321,6 +2328,19 @@ shaka.hls.HlsParser = class {
decodingInfos: [],
};

if (audioStream) {
const mappedAudioVariantSet =
this.streamToVariants_.get(audioStream) || new Set();
mappedAudioVariantSet.add(audioStream);
this.streamToVariants_.set(audioStream, mappedAudioVariantSet);
}
if (videoStream) {
const mappedVideoVariantSet =
this.streamToVariants_.get(videoStream) || new Set();
mappedVideoVariantSet.add(videoStream);
this.streamToVariants_.set(videoStream, mappedVideoVariantSet);
}

variants.push(variant);
this.variantUriSet_.add(variantUriKey);
}
Expand Down Expand Up @@ -2821,8 +2841,16 @@ shaka.hls.HlsParser = class {
this.setFullTypeForStream_(stream);

// Since we lazy-loaded this content, the player may need to create new
// sessions for the DRM info in this stream.
// sessions for the DRM info in this stream, and recheck decodingInfo.
if (stream.drmInfos.length) {
const variants = this.streamToVariants_.get(stream) || new Set();
for (const variant of variants) {
variant.decodingInfos = [];
}

if (this.manifest_) {
this.playerInterface_.filter(this.manifest_);
}
Comment on lines +2846 to +2853
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code block is causing load hangs on android-based Cast devices, which can be repro'd by using a fresh top-of-tree build of v4.16.11, and patching this entire PR.

But the load hangs stop if I specifically comment out this block of code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it truly hangs, that means the Promise isn't resolved. I'll need to dig through the individual awaits within this call to find the one that's hanging.

this.playerInterface_.newDrmInfo(stream);
}

Expand Down
22 changes: 14 additions & 8 deletions lib/util/stream_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ shaka.util.StreamUtils = class {
}
return true;
});

if (!variantSupported) {
return false;
}
Expand Down Expand Up @@ -715,17 +716,18 @@ shaka.util.StreamUtils = class {
*/
static async getDecodingInfosForVariants(variants, usePersistentLicenses,
srcEquals, preferredKeySystems) {
const gotDecodingInfo = variants.some((variant) =>
variant.decodingInfos.length);
if (gotDecodingInfo) {
shaka.log.debug('Already got the variants\' decodingInfo.');
return;
}

// Try to get preferred key systems first to avoid unneeded calls to CDM.
for (const preferredKeySystem of preferredKeySystems) {
let keySystemSatisfied = false;
for (const variant of variants) {
if (variant.decodingInfos.length) {
// We already have decoding info for this variant. The decoding info
// will be wiped out for lazy-loaded, DRM-encrypted HLS streams when
// they are finally loaded, triggering a recheck. In all other
// cases, the decoding info won't change.
continue;
}

/** @type {!Array<!Array<!MediaDecodingConfiguration>>} */
const decodingConfigs = shaka.util.StreamUtils.getDecodingConfigs_(
variant, usePersistentLicenses, srcEquals)
Expand All @@ -734,7 +736,11 @@ shaka.util.StreamUtils = class {
const config = configs[0];
const keySystem = config.keySystemConfiguration &&
config.keySystemConfiguration.keySystem;
return keySystem === preferredKeySystem;
// Accept unencrypted content as well as the preferred key system.
// For lazy-loaded HLS playlists, playlists we haven't loaded yet
// look unencrypted until we load them, so it's also important
// not to filter these out for HLS.
return !keySystem || keySystem === preferredKeySystem;
});

// The reason we are performing this await in a loop rather than
Expand Down
38 changes: 25 additions & 13 deletions test/hls/hls_parser_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ describe('HlsParser', () => {
// longer than 30 seconds, fail the test.
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 8, 30);

await player.unload();

// The stream has 6 #EXT-X-KEY but only 5 different keys.
expect(keyRequests).toBe(5);
});
Expand All @@ -100,8 +98,6 @@ describe('HlsParser', () => {
// Play for 8 seconds, but stop early if the video ends. If it takes
// longer than 30 seconds, fail the test.
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 8, 30);

await player.unload();
});

it('supports text discontinuity', async () => {
Expand All @@ -121,8 +117,6 @@ describe('HlsParser', () => {
expect(cues[1].endTime).toBeCloseTo(4, 0);
expect(cues[2].startTime).toBeCloseTo(6, 0);
expect(cues[2].endTime).toBeCloseTo(8, 0);

await player.unload();
});

it('supports text without discontinuity', async () => {
Expand All @@ -144,8 +138,6 @@ describe('HlsParser', () => {
expect(cues[1].endTime).toBeCloseTo(4.96, 0);
expect(cues[2].startTime).toBeCloseTo(4.96, 0);
expect(cues[2].endTime).toBeCloseTo(9.28, 0);

await player.unload();
});

it('allow switch between mp4 muxed and ts muxed', async () => {
Expand Down Expand Up @@ -176,8 +168,6 @@ describe('HlsParser', () => {
player.selectVariantTrack(nonActiveVariant, /* clearBuffer= */ true);

await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 5, 30);

await player.unload();
});

it('supports com.apple.hls.chapters', async () => {
Expand All @@ -190,8 +180,6 @@ describe('HlsParser', () => {
const chapters = await player.getChaptersAsync('und');

expect(chapters.length).toBe(7);

await player.unload();
});

it('supports mp4 muxed with AAC and H.264', async () => {
Expand All @@ -206,7 +194,31 @@ describe('HlsParser', () => {
// Play for 8 seconds, but stop early if the video ends. If it takes
// longer than 30 seconds, fail the test.
await waiter.waitUntilPlayheadReachesOrFailOnTimeout(video, 8, 30);
});

// We used to have a bug in preferredKeySystems-specific filtering where
// variants went missing at the Shaka level and languages went missing at the
// CAF level.
drmIt('filters multilingual variants with preferredKeySystems', async () => {
if (!checkWidevineSupport()) {
pending('Widevine is not supported');
}
player.configure('drm.servers', {
'com.widevine.alpha': 'https://proxy.uat.widevine.com/proxy',
});
player.configure('drm.preferredKeySystems', [
'com.widevine.alpha',
]);

await player.load('/base/test/test/assets/hls-track-filtering/hls.m3u8');
await video.play();

// Wait for the video to start playback. If it takes longer than 10
// seconds, fail the test.
await waiter.waitForMovementOrFailOnTimeout(video, 10);

await player.unload();
// In the original issue, this would be 3 due to buggy filtering in a path
// specific to the preferredKeySystems config.
expect(player.getVariantTracks().length).toBe(4);
});
});
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions test/test/assets/hls-track-filtering/hls.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#EXTM3U
## Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release

#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-MEDIA:TYPE=AUDIO,URI="stream_1.m3u8",GROUP-ID="aac",LANGUAGE="en",NAME="English",DEFAULT=NO,AUTOSELECT=YES,CHANNELS="2"
#EXT-X-MEDIA:TYPE=AUDIO,URI="stream_4.m3u8",GROUP-ID="aac",LANGUAGE="es",NAME="Spanish",DEFAULT=NO,AUTOSELECT=YES,CHANNELS="2"
#EXT-X-MEDIA:TYPE=AUDIO,URI="stream_5.m3u8",GROUP-ID="opus",LANGUAGE="en",NAME="English",DEFAULT=NO,AUTOSELECT=YES,CHANNELS="2"
#EXT-X-MEDIA:TYPE=AUDIO,URI="stream_2.m3u8",GROUP-ID="opus",LANGUAGE="es",NAME="Spanish",DEFAULT=NO,AUTOSELECT=YES,CHANNELS="2"

#EXT-X-STREAM-INF:BANDWIDTH=4181915,AVERAGE-BANDWIDTH=2483917,CODECS="avc1.64001f,mp4a.40.2",RESOLUTION=1280x546,FRAME-RATE=24.000,AUDIO="aac",CLOSED-CAPTIONS=NONE
stream_3.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1895289,AVERAGE-BANDWIDTH=1245692,CODECS="avc1.4d401e,mp4a.40.2",RESOLUTION=854x364,FRAME-RATE=24.000,AUDIO="aac",CLOSED-CAPTIONS=NONE
stream_0.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=670544,AVERAGE-BANDWIDTH=652699,CODECS="av01.0.05M.08,mp4a.40.2",RESOLUTION=1280x546,FRAME-RATE=24.000,AUDIO="aac",CLOSED-CAPTIONS=NONE
stream_7.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=544379,AVERAGE-BANDWIDTH=528974,CODECS="av01.0.04M.08,mp4a.40.2",RESOLUTION=854x364,FRAME-RATE=24.000,AUDIO="aac",CLOSED-CAPTIONS=NONE
stream_6.m3u8

#EXT-X-STREAM-INF:BANDWIDTH=4135626,AVERAGE-BANDWIDTH=2427353,CODECS="avc1.64001f,opus",RESOLUTION=1280x546,FRAME-RATE=24.000,AUDIO="opus",CLOSED-CAPTIONS=NONE
stream_3.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=1849000,AVERAGE-BANDWIDTH=1189128,CODECS="avc1.4d401e,opus",RESOLUTION=854x364,FRAME-RATE=24.000,AUDIO="opus",CLOSED-CAPTIONS=NONE
stream_0.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=624255,AVERAGE-BANDWIDTH=596135,CODECS="av01.0.05M.08,opus",RESOLUTION=1280x546,FRAME-RATE=24.000,AUDIO="opus",CLOSED-CAPTIONS=NONE
stream_7.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=498090,AVERAGE-BANDWIDTH=472410,CODECS="av01.0.04M.08,opus",RESOLUTION=854x364,FRAME-RATE=24.000,AUDIO="opus",CLOSED-CAPTIONS=NONE
stream_6.m3u8
14 changes: 14 additions & 0 deletions test/test/assets/hls-track-filtering/stream_0.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#EXTM3U
#EXT-X-VERSION:6
## Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release
#EXT-X-TARGETDURATION:11
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="video_480p_1M_h264_init.mp4"
#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI="data:text/plain;base64,AAAAOHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABgiEIylSxG1rhIsgGndN+aTxWtI49yVmwY=",KEYID=0x7a4d63a12e395c989d3fe3278b099c4d,KEYFORMATVERSIONS="1",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
#EXTINF:10.000,
video_480p_1M_h264_1.mp4
#EXTINF:10.000,
video_480p_1M_h264_2.mp4
#EXTINF:5.000,
video_480p_1M_h264_3.mp4
#EXT-X-ENDLIST
14 changes: 14 additions & 0 deletions test/test/assets/hls-track-filtering/stream_1.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#EXTM3U
#EXT-X-VERSION:6
## Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release
#EXT-X-TARGETDURATION:11
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="audio_en_2c_128k_aac_init.mp4"
#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI="data:text/plain;base64,AAAAOHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABgiEIylSxG1rhIsgGndN+aTxWtI49yVmwY=",KEYID=0xce0786df75ef55e080043bc124d46f3d,KEYFORMATVERSIONS="1",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
#EXTINF:10.005,
audio_en_2c_128k_aac_1.mp4
#EXTINF:10.005,
audio_en_2c_128k_aac_2.mp4
#EXTINF:5.035,
audio_en_2c_128k_aac_3.mp4
#EXT-X-ENDLIST
14 changes: 14 additions & 0 deletions test/test/assets/hls-track-filtering/stream_2.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#EXTM3U
#EXT-X-VERSION:6
## Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release
#EXT-X-TARGETDURATION:11
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="audio_es_2c_64k_opus_init.mp4"
#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI="data:text/plain;base64,AAAAOHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABgiEIylSxG1rhIsgGndN+aTxWtI49yVmwY=",KEYID=0xce0786df75ef55e080043bc124d46f3d,KEYFORMATVERSIONS="1",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
#EXTINF:10.020,
audio_es_2c_64k_opus_1.mp4
#EXTINF:10.000,
audio_es_2c_64k_opus_2.mp4
#EXTINF:5.011,
audio_es_2c_64k_opus_3.mp4
#EXT-X-ENDLIST
14 changes: 14 additions & 0 deletions test/test/assets/hls-track-filtering/stream_3.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#EXTM3U
#EXT-X-VERSION:6
## Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release
#EXT-X-TARGETDURATION:11
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="video_720p_2M_h264_init.mp4"
#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI="data:text/plain;base64,AAAAOHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABgiEIylSxG1rhIsgGndN+aTxWtI49yVmwY=",KEYID=0x034f5e3097ca52c882cfceb248cf1686,KEYFORMATVERSIONS="1",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
#EXTINF:10.000,
video_720p_2M_h264_1.mp4
#EXTINF:10.000,
video_720p_2M_h264_2.mp4
#EXTINF:5.000,
video_720p_2M_h264_3.mp4
#EXT-X-ENDLIST
14 changes: 14 additions & 0 deletions test/test/assets/hls-track-filtering/stream_4.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#EXTM3U
#EXT-X-VERSION:6
## Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release
#EXT-X-TARGETDURATION:11
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="audio_es_2c_128k_aac_init.mp4"
#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI="data:text/plain;base64,AAAAOHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABgiEIylSxG1rhIsgGndN+aTxWtI49yVmwY=",KEYID=0xce0786df75ef55e080043bc124d46f3d,KEYFORMATVERSIONS="1",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
#EXTINF:10.005,
audio_es_2c_128k_aac_1.mp4
#EXTINF:10.005,
audio_es_2c_128k_aac_2.mp4
#EXTINF:5.035,
audio_es_2c_128k_aac_3.mp4
#EXT-X-ENDLIST
14 changes: 14 additions & 0 deletions test/test/assets/hls-track-filtering/stream_5.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#EXTM3U
#EXT-X-VERSION:6
## Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release
#EXT-X-TARGETDURATION:11
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="audio_en_2c_64k_opus_init.mp4"
#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI="data:text/plain;base64,AAAAOHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABgiEIylSxG1rhIsgGndN+aTxWtI49yVmwY=",KEYID=0xce0786df75ef55e080043bc124d46f3d,KEYFORMATVERSIONS="1",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
#EXTINF:10.020,
audio_en_2c_64k_opus_1.mp4
#EXTINF:10.000,
audio_en_2c_64k_opus_2.mp4
#EXTINF:5.011,
audio_en_2c_64k_opus_3.mp4
#EXT-X-ENDLIST
14 changes: 14 additions & 0 deletions test/test/assets/hls-track-filtering/stream_6.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#EXTM3U
#EXT-X-VERSION:6
## Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release
#EXT-X-TARGETDURATION:11
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="video_480p_389k_av1_init.mp4"
#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI="data:text/plain;base64,AAAAOHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABgiEIylSxG1rhIsgGndN+aTxWtI49yVmwY=",KEYID=0x7a4d63a12e395c989d3fe3278b099c4d,KEYFORMATVERSIONS="1",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
#EXTINF:10.000,
video_480p_389k_av1_1.mp4
#EXTINF:10.000,
video_480p_389k_av1_2.mp4
#EXTINF:5.000,
video_480p_389k_av1_3.mp4
#EXT-X-ENDLIST
14 changes: 14 additions & 0 deletions test/test/assets/hls-track-filtering/stream_7.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#EXTM3U
#EXT-X-VERSION:6
## Generated with https://github.com/shaka-project/shaka-packager version v3.4.0-1f0a4d1-release
#EXT-X-TARGETDURATION:11
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MAP:URI="video_720p_512k_av1_init.mp4"
#EXT-X-KEY:METHOD=SAMPLE-AES-CTR,URI="data:text/plain;base64,AAAAOHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABgiEIylSxG1rhIsgGndN+aTxWtI49yVmwY=",KEYID=0x034f5e3097ca52c882cfceb248cf1686,KEYFORMATVERSIONS="1",KEYFORMAT="urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
#EXTINF:10.000,
video_720p_512k_av1_1.mp4
#EXTINF:10.000,
video_720p_512k_av1_2.mp4
#EXTINF:5.000,
video_720p_512k_av1_3.mp4
#EXT-X-ENDLIST
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading