From cf1cbf49c693a80f6924dcc58f1fd7e37925c4dd Mon Sep 17 00:00:00 2001 From: brandonocasey Date: Tue, 19 Jan 2021 14:07:16 -0500 Subject: [PATCH] feat: add support for #EXT-X-RENDITION-REPORT https://developer.apple.com/documentation/http_live_streaming/enabling_low-latency_hls#3282435 https://tools.ietf.org/html/draft-pantos-hls-rfc8216bis-08#section-4.4.5.4 --- src/parse-stream.js | 17 +++++++++++++++++ src/parser.js | 4 ++++ test/fixtures/m3u8/llhls.json | 4 ++++ test/fixtures/m3u8/llhlsDelta.json | 4 ++++ 4 files changed, 29 insertions(+) diff --git a/src/parse-stream.js b/src/parse-stream.js index 8890680..b74b2f8 100644 --- a/src/parse-stream.js +++ b/src/parse-stream.js @@ -443,6 +443,23 @@ export default class ParseStream extends Stream { return; } + match = (/^#EXT-X-RENDITION-REPORT:(.*)$/).exec(newLine); + if (match && match[1]) { + event = { + type: 'tag', + tagType: 'rendition-report' + }; + event.attributes = parseAttributes(match[1]); + ['LAST-MSN', 'LAST-PART'].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', diff --git a/src/parser.js b/src/parser.js index de67f5f..c1675bf 100644 --- a/src/parser.js +++ b/src/parser.js @@ -383,6 +383,10 @@ export default class Parser extends Stream { }, 'cue-in'() { currentUri.cueIn = entry.data; + }, + 'rendition-report'() { + this.manifest.renditionReports = this.manifest.renditionReports || []; + this.manifest.renditionReports.push(entry.attributes); } })[entry.tagType] || noop).call(self); }, diff --git a/test/fixtures/m3u8/llhls.json b/test/fixtures/m3u8/llhls.json index 3d82211..99aaa01 100644 --- a/test/fixtures/m3u8/llhls.json +++ b/test/fixtures/m3u8/llhls.json @@ -5,6 +5,10 @@ "discontinuitySequence": 0, "discontinuityStarts": [], "mediaSequence": 266, + "renditionReports": [ + {"LAST-MSN": 273, "LAST-PART": 2, "URI": "../1M/waitForMSN.php"}, + {"LAST-MSN": 273, "LAST-PART": 1, "URI": "../4M/waitForMSN.php"} + ], "segments": [ { "dateTimeObject": new Date("2019-02-14T02:13:36.106Z"), diff --git a/test/fixtures/m3u8/llhlsDelta.json b/test/fixtures/m3u8/llhlsDelta.json index 0528896..e3c3b48 100644 --- a/test/fixtures/m3u8/llhlsDelta.json +++ b/test/fixtures/m3u8/llhlsDelta.json @@ -5,6 +5,10 @@ "discontinuitySequence": 0, "discontinuityStarts": [], "mediaSequence": 266, + "renditionReports": [ + {"LAST-MSN": 273, "LAST-PART": 3, "URI": "../1M/waitForMSN.php"}, + {"LAST-MSN": 273, "LAST-PART": 3, "URI": "../4M/waitForMSN.php"} + ], "segments": [ { "duration": 4.00008,