Skip to content

Commit

Permalink
feat: Support #EXT-X-SKIP
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonocasey committed Jan 14, 2021
1 parent 68e7644 commit 4ae3a3f
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/parse-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
import Stream from '@videojs/vhs-utils/es/stream.js';

const TAB = String.fromCharCode(0x09);

/**
* "forgiving" attribute list psuedo-grammar:
* attributes -> keyvalue (',' keyvalue)*
Expand Down Expand Up @@ -463,6 +465,26 @@ export default class ParseStream extends Stream {
this.trigger('data', event);
return;
}
match = (/^#EXT-X-SKIP:(.*)$/).exec(newLine);
if (match && match[1]) {
event = {
type: 'tag',
tagType: 'skip'
};
event.attributes = parseAttributes(match[1]);

if (event.attributes.hasOwnProperty('SKIPPED-SEGMENTS')) {
event.attributes['SKIPPED-SEGMENTS'] = parseInt(event.attributes['SKIPPED-SEGMENTS'], 10);
}

if (event.attributes.hasOwnProperty('RECENTLY-REMOVED-DATERANGES')) {
event.attributes['RECENTLY-REMOVED-DATERANGES'] =
event.attributes['RECENTLY-REMOVED-DATERANGES'].split(TAB);
}

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

// unknown tag type
this.trigger('data', {
Expand Down
3 changes: 3 additions & 0 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ export default class Parser extends Stream {
},
'server-control'() {
this.manifest.serverControl = entry.attributes;
},
'skip'() {
this.manifest.skip = entry.attributes;
}
})[entry.tagType] || noop).call(self);
},
Expand Down
47 changes: 47 additions & 0 deletions test/fixtures/m3u8/llhlsDelta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"allowCache": true,
"dateTimeObject": new Date("2019-02-14T02:14:00.106Z"),
"dateTimeString": "2019-02-14T02:14:00.106Z",
"discontinuitySequence": 0,
"discontinuityStarts": [],
"mediaSequence": 266,
"segments": [
{
"duration": 4.00008,
"timeline": 0,
"uri": "fileSequence269.mp4"
},
{
"duration": 4.00008,
"timeline": 0,
"uri": "fileSequence270.mp4"
},
{
"duration": 4.00008,
"timeline": 0,
"uri": "fileSequence271.mp4"
},
{
"dateTimeObject": new Date("2019-02-14T02:14:00.106Z"),
"dateTimeString": "2019-02-14T02:14:00.106Z",
"duration": 4.00008,
"timeline": 0,
"uri": "fileSequence272.mp4"
}
],
"serverControl": {
"CAN-SKIP-DATERANGES": true,
"CAN-BLOCK-RELOAD": true,
"CAN-SKIP-UNTIL": 12,
"PART-HOLD-BACK": 1,
"HOLD-BACK": 2
},
"skip": {
"SKIPPED-SEGMENTS": 3,
"RECENTLY-REMOVED-DATERANGES": [
"foo",
"bar"
]
},
"targetDuration": 4
}
49 changes: 49 additions & 0 deletions test/fixtures/m3u8/llhlsDelta.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#EXTM3U
# Following the example above, this Playlist is a response to: GET https://example.com/2M/waitForMSN.php?_HLS_msn=273&_HLS_part=3 &_HLS_skip=YES
#EXT-X-TARGETDURATION:4
#EXT-X-VERSION:9
#EXT-X-SERVER-CONTROL:CAN-BLOCK-RELOAD=YES,CAN-SKIP-DATERANGES=YES,PART-HOLD-BACK=1.0,CAN-SKIP-UNTIL=12.0,HOLD-BACK=2.0
#EXT-X-PART-INF:PART-TARGET=0.33334
#EXT-X-MEDIA-SEQUENCE:266
#EXT-X-SKIP:SKIPPED-SEGMENTS=3,RECENTLY-REMOVED-DATERANGES=foo bar
#EXTINF:4.00008,
fileSequence269.mp4
#EXTINF:4.00008,
fileSequence270.mp4
#EXT-X-PART:DURATION=0.33334,URI="filePart271.0.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.1.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.2.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.3.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.4.mp4",INDEPENDENT=YES
#EXT-X-PART:DURATION=0.33334,URI="filePart271.5.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.6.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.7.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.8.mp4",INDEPENDENT=YES
#EXT-X-PART:DURATION=0.33334,URI="filePart271.9.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.10.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart271.11.mp4"
#EXTINF:4.00008,
fileSequence271.mp4
#EXT-X-PROGRAM-DATE-TIME:2019-02-14T02:14:00.106Z
#EXT-X-PART:DURATION=0.33334,URI="filePart272.a.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.b.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.c.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.d.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.e.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.f.mp4",INDEPENDENT=YES
#EXT-X-PART:DURATION=0.33334,URI="filePart272.g.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.h.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.i.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.j.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.k.mp4"
#EXT-X-PART:DURATION=0.33334,URI="filePart272.l.mp4"
#EXTINF:4.00008,
fileSequence272.mp4
#EXT-X-PART:DURATION=0.33334,URI="filePart273.0.mp4",INDEPENDENT=YES
#EXT-X-PART:DURATION=0.33334,URI="filePart273.1.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-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 4ae3a3f

Please sign in to comment.