Skip to content

Commit

Permalink
feat: add support for #EXT-X-PRELOAD-HINT (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey authored Jan 20, 2021
1 parent 9f5a224 commit 4fd693a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/parse-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,23 @@ export default class ParseStream extends Stream {
return;
}

match = (/^#EXT-X-PRELOAD-HINT:(.*)$/).exec(newLine);
if (match && match[1]) {
event = {
type: 'tag',
tagType: 'preload-hint'
};
event.attributes = parseAttributes(match[1]);
['BYTERANGE-START', 'BYTERANGE-LENGTH'].forEach(function(key) {
if (event.attributes.hasOwnProperty(key)) {
event.attributes[key] = parseInt(event.attributes[key], 10);
}
});

this.trigger('data', event);
return;
}

// unknown tag type
this.trigger('data', {
type: 'tag',
Expand Down
4 changes: 4 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ export default class Parser extends Stream {
'part'() {
this.manifest.parts = this.manifest.parts || [];
this.manifest.parts.push(entry.attributes);
},
'preload-hint'() {
this.manifest.preloadHints = this.manifest.preloadHints || [];
this.manifest.preloadHints.push(entry.attributes);
}
})[entry.tagType] || noop).call(self);
},
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/m3u8/llhls.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"discontinuitySequence": 0,
"discontinuityStarts": [],
"mediaSequence": 266,
"preloadHints": [
{"TYPE": "PART", "URI": "filePart273.3.mp4"},
{"TYPE": "PART", "URI": "filePart273.4.mp4"}
],
"parts": [
{
"DURATION": 0.33334,
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/m3u8/llhlsDelta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
"discontinuitySequence": 0,
"discontinuityStarts": [],
"mediaSequence": 266,
"preloadHints": [
{"TYPE": "PART", "URI": "filePart273.4.mp4"},
{"TYPE": "PART", "URI": "filePart273.5.mp4"}
],
"parts": [
{
"DURATION": 0.33334,
Expand Down

0 comments on commit 4fd693a

Please sign in to comment.