From 985ab687187147e4b96f39248f47047679e6ab7a Mon Sep 17 00:00:00 2001 From: Brandon Casey <2381475+brandonocasey@users.noreply.github.com> Date: Wed, 20 Jan 2021 10:37:14 -0500 Subject: [PATCH] feat: add support for #EXT-X-PART-INF (#126) https://developer.apple.com/documentation/http_live_streaming/enabling_low-latency_hls#3282434 https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-08#section-4.4.3.7 --- src/parse-stream.js | 16 ++++++++++++++++ src/parser.js | 3 +++ test/fixtures/m3u8/llhls.json | 3 +++ test/fixtures/m3u8/llhlsDelta.json | 3 +++ 4 files changed, 25 insertions(+) diff --git a/src/parse-stream.js b/src/parse-stream.js index fb43c83..a82a137 100644 --- a/src/parse-stream.js +++ b/src/parse-stream.js @@ -520,6 +520,22 @@ export default class ParseStream extends Stream { this.trigger('data', event); return; } + match = (/^#EXT-X-PART-INF:(.*)$/).exec(newLine); + if (match && match[1]) { + event = { + type: 'tag', + tagType: 'part-inf' + }; + event.attributes = parseAttributes(match[1]); + ['PART-TARGET'].forEach(function(key) { + if (event.attributes.hasOwnProperty(key)) { + event.attributes[key] = parseFloat(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 2fd7c6d..e7dc109 100644 --- a/src/parser.js +++ b/src/parser.js @@ -401,6 +401,9 @@ export default class Parser extends Stream { 'rendition-report'() { this.manifest.renditionReports = this.manifest.renditionReports || []; this.manifest.renditionReports.push(entry.attributes); + }, + 'part-inf'() { + this.manifest.partInf = entry.attributes; } })[entry.tagType] || noop).call(self); }, diff --git a/test/fixtures/m3u8/llhls.json b/test/fixtures/m3u8/llhls.json index 1e8093d..7614219 100644 --- a/test/fixtures/m3u8/llhls.json +++ b/test/fixtures/m3u8/llhls.json @@ -13,6 +13,9 @@ {"LAST-MSN": 273, "LAST-PART": 2, "URI": "../1M/waitForMSN.php"}, {"LAST-MSN": 273, "LAST-PART": 1, "URI": "../4M/waitForMSN.php"} ], + "partInf": { + "PART-TARGET": 0.33334 + }, "parts": [ { "DURATION": 0.33334, diff --git a/test/fixtures/m3u8/llhlsDelta.json b/test/fixtures/m3u8/llhlsDelta.json index e5341a2..4905c84 100644 --- a/test/fixtures/m3u8/llhlsDelta.json +++ b/test/fixtures/m3u8/llhlsDelta.json @@ -13,6 +13,9 @@ {"LAST-MSN": 273, "LAST-PART": 3, "URI": "../1M/waitForMSN.php"}, {"LAST-MSN": 273, "LAST-PART": 3, "URI": "../4M/waitForMSN.php"} ], + "partInf": { + "PART-TARGET": 0.33334 + }, "parts": [ { "DURATION": 0.33334,