Skip to content

Commit

Permalink
feat: add support for #EXT-X-PRELOAD-HINT
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jan 15, 2021
1 parent 4ae3a3f commit e9d6471
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/parse-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,22 @@ export default class ParseStream extends Stream {
this.trigger('data', event);
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', {
Expand Down
4 changes: 4 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ export default class Parser extends Stream {
},
'skip'() {
this.manifest.skip = 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"}
],
"segments": [
{
"dateTimeObject": new Date("2019-02-14T02:13:36.106Z"),
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/m3u8/llhls.m3u8
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ fileSequence272.mp4
#EXT-X-PART:DURATION=0.33334,URI="filePart273.1.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart273.2.mp4"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart273.3.mp4"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart273.4.mp4"

#EXT-X-RENDITION-REPORT:URI="../1M/waitForMSN.php",LAST-MSN=273,LAST-PART=2
#EXT-X-RENDITION-REPORT:URI="../4M/waitForMSN.php",LAST-MSN=273,LAST-PART=1
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"}
],
"segments": [
{
"duration": 4.00008,
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/m3u8/llhlsDelta.m3u8
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fileSequence272.mp4
#EXT-X-PART:DURATION=0.33334,URI="filePart273.2.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart273.3.mp4"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart273.4.mp4"
#EXT-X-PRELOAD-HINT:TYPE=PART,URI="filePart273.5.mp4"

#EXT-X-RENDITION-REPORT:URI="../1M/waitForMSN.php",LAST-MSN=273,LAST-PART=3
#EXT-X-RENDITION-REPORT:URI="../4M/waitForMSN.php",LAST-MSN=273,LAST-PART=3

0 comments on commit e9d6471

Please sign in to comment.