From 7f82f53d49ffff6468b0aacdc6e96b8e7a1e8332 Mon Sep 17 00:00:00 2001 From: Brandon Casey <2381475+brandonocasey@users.noreply.github.com> Date: Wed, 20 Jan 2021 10:31:06 -0500 Subject: [PATCH] feat: add support for #EXT-X-SERVER-CONTROL (#121) https://developer.apple.com/documentation/http_live_streaming/enabling_low-latency_hls#3281374 https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-08#section-4.4.3.8 --- src/parse-stream.js | 22 ++++++++++++++++++++++ src/parser.js | 3 +++ test/fixtures/m3u8/llhls.json | 7 +++++++ test/fixtures/m3u8/llhlsDelta.json | 7 +++++++ 4 files changed, 39 insertions(+) diff --git a/src/parse-stream.js b/src/parse-stream.js index 6633d12..47c7dc7 100644 --- a/src/parse-stream.js +++ b/src/parse-stream.js @@ -498,6 +498,28 @@ export default class ParseStream extends Stream { this.trigger('data', event); return; } + match = (/^#EXT-X-SERVER-CONTROL:(.*)$/).exec(newLine); + if (match && match[1]) { + event = { + type: 'tag', + tagType: 'server-control' + }; + event.attributes = parseAttributes(match[1]); + ['CAN-SKIP-UNTIL', 'PART-HOLD-BACK', 'HOLD-BACK'].forEach(function(key) { + if (event.attributes.hasOwnProperty(key)) { + event.attributes[key] = parseFloat(event.attributes[key]); + } + }); + + ['CAN-SKIP-DATERANGES', 'CAN-BLOCK-RELOAD'].forEach(function(key) { + if (event.attributes.hasOwnProperty(key)) { + event.attributes[key] = (/YES/).test(event.attributes[key]); + } + }); + + this.trigger('data', event); + return; + } match = (/^#EXT-X-PRELOAD-HINT:(.*)$/).exec(newLine); if (match && match[1]) { diff --git a/src/parser.js b/src/parser.js index f0c542f..bdf3538 100644 --- a/src/parser.js +++ b/src/parser.js @@ -391,6 +391,9 @@ export default class Parser extends Stream { this.manifest.parts = this.manifest.parts || []; this.manifest.parts.push(entry.attributes); }, + 'server-control'() { + this.manifest.serverControl = entry.attributes; + }, 'preload-hint'() { this.manifest.preloadHints = this.manifest.preloadHints || []; this.manifest.preloadHints.push(entry.attributes); diff --git a/test/fixtures/m3u8/llhls.json b/test/fixtures/m3u8/llhls.json index a034553..378ba6c 100644 --- a/test/fixtures/m3u8/llhls.json +++ b/test/fixtures/m3u8/llhls.json @@ -187,5 +187,12 @@ "uri": "fileSequence272.mp4" } ], + "serverControl": { + "CAN-SKIP-DATERANGES": true, + "CAN-BLOCK-RELOAD": true, + "CAN-SKIP-UNTIL": 12, + "PART-HOLD-BACK": 1, + "HOLD-BACK": 2 + }, "targetDuration": 4 } diff --git a/test/fixtures/m3u8/llhlsDelta.json b/test/fixtures/m3u8/llhlsDelta.json index 9272e3c..0caee88 100644 --- a/test/fixtures/m3u8/llhlsDelta.json +++ b/test/fixtures/m3u8/llhlsDelta.json @@ -160,5 +160,12 @@ "bar" ] }, + "serverControl": { + "CAN-SKIP-DATERANGES": true, + "CAN-BLOCK-RELOAD": true, + "CAN-SKIP-UNTIL": 12, + "PART-HOLD-BACK": 1, + "HOLD-BACK": 2 + }, "targetDuration": 4 }