Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

attach attributes property to playlist objects in cases the m3u8-pars… #1214

Merged
merged 5 commits into from
Aug 2, 2017

Conversation

mjneil
Copy link
Contributor

@mjneil mjneil commented Jul 28, 2017

…er does not

Description

The m3u8-parser does not attach attributes property to the playlist object when it is parsing a media playlist or a master manifest that has an EXT-X-STREAM-INF tag without an attribute list. This has caused some undefined reference errors as attributes is not always checked first.

Specific Changes proposed

This change attaches attributes property to any playlist object returned from the parser that does not have it.

addresses #1205

@@ -510,6 +508,12 @@ const PlaylistLoader = function(srcUrl, hls, withCredentials) {
playlist = loader.master.playlists[i];
loader.master.playlists[playlist.uri] = playlist;
playlist.resolvedUri = resolveUrl(loader.master.uri, playlist.uri);
// Although the spec states an #EXT-X-STREAM-INF tag MUST have a
// BANDWIDTH attribute, we can play the stream without it. This means a poorly
// formated master playlist may not have an attribute list. An attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

formatted

// formated master playlist may not have an attribute list. An attributes
// property is added here to prevent undefined references when we encounter
// this scenario.
playlist.attributes = playlist.attributes || {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to at least have a warning log here.

Copy link
Contributor

@gesinger gesinger left a comment

Choose a reason for hiding this comment

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

Would also be good to have a test for the warning log

// this scenario.
playlist.attributes = {};

log.warn('Invalid playlist STREAM-INF detected. Missing attribute list.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Since BANDWIDTH is the only required attribute, maybe it makes sense to just write something like "Invalid playlist STREAM-INF detected. Missing BANDWIDTH attribute."

let attributes = playlist.attributes;
// some playlist attributes are optional
if (playlist.attributes.RESOLUTION) {
let resolution = playlist.attributes.RESOLUTION;
Copy link
Contributor

Choose a reason for hiding this comment

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

Kind of a nitpick, by why let and not const? If statement is the scope and the value doesn't seem to change.

'video2/media.m3u8\n');

assert.ok(loader.master, 'infers a master playlist');
assert.ok(loader.master.playlists[0], 'parsed invalid stream');
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically, I think the second one is the one that is invalid, but it may be worth checking both.

assert.ok(loader.master, 'infers a master playlist');
assert.ok(loader.master.playlists[0], 'parsed invalid stream');
assert.ok(loader.master.playlists[0].attributes, 'attached attributes property');
assert.equal(this.env.log.warn.calls, 1, 'logged a warning');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can also check the warning text.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants