From 222af01e20c9cbbdf247ab02cf7ccf047afc8715 Mon Sep 17 00:00:00 2001 From: birme Date: Thu, 16 Apr 2020 14:11:34 +0200 Subject: [PATCH] Support for the special case when resolution is not set on video tracks --- index.js | 25 ++++++++++++++++++------- spec/hlsvod_spec.js | 22 +++++++++++++++++++++- testvectors/hls15/index_1010931.m3u8 | 20 ++++++++++++++++++++ testvectors/hls15/master.m3u8 | 3 +++ 4 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 testvectors/hls15/index_1010931.m3u8 create mode 100644 testvectors/hls15/master.m3u8 diff --git a/index.js b/index.js index 91d0c04..36dc605 100644 --- a/index.js +++ b/index.js @@ -66,13 +66,24 @@ class HLSVod { const streamItem = m3u.items.StreamItem[i]; let mediaManifestUrl = url.resolve(baseUrl, streamItem.properties.uri); - if (streamItem.attributes.attributes['resolution']) { - this.usageProfile.push({ - bw: streamItem.attributes.attributes['bandwidth'], - codecs: streamItem.attributes.attributes['codecs'], - resolution: streamItem.attributes.attributes['resolution'][0] + 'x' + streamItem.attributes.attributes['resolution'][1] - }); - mediaManifestPromises.push(this._loadMediaManifest(mediaManifestUrl, streamItem.attributes.attributes['bandwidth'], _injectMediaManifest)); + if (streamItem.get("bandwidth")) { + let usageProfile = { + bw: streamItem.get("bandwidth") + }; + if (streamItem.get("resolution")) { + usageProfile.resolution = streamItem.get("resolution")[0] + "x" + streamItem.get("resolution")[1]; + } + if (streamItem.get("codecs")) { + usageProfile.codecs = streamItem.get("codecs"); + } + this.usageProfile.push(usageProfile); + + // Do not add if it is a variant included in an audio group as it will be loaded and parsed seperate + if (!m3u.items.MediaItem.find(mediaItem => mediaItem.get("type") === "AUDIO" && mediaItem.get("uri") == streamItem.get("uri"))) { + if (streamItem.get("codecs") !== "mp4a.40.2") { + mediaManifestPromises.push(this._loadMediaManifest(mediaManifestUrl, streamItem.get("bandwidth"), _injectMediaManifest)); + } + } } if (streamItem.attributes.attributes['audio']) { let audioGroupId = streamItem.attributes.attributes['audio']; diff --git a/spec/hlsvod_spec.js b/spec/hlsvod_spec.js index ad4c53a..ea31936 100644 --- a/spec/hlsvod_spec.js +++ b/spec/hlsvod_spec.js @@ -6,6 +6,8 @@ const Readable = require('stream').Readable; describe("HLSVod standalone", () => { let mockMasterManifest; let mockMediaManifest; + let mockMasterManifest2; + let mockMediaManifest2; beforeEach(() => { mockMasterManifest = function() { @@ -15,6 +17,14 @@ describe("HLSVod standalone", () => { mockMediaManifest = function(bandwidth) { return fs.createReadStream('testvectors/hls1/' + bandwidth + '.m3u8'); }; + + mockMasterManifest2 = function() { + return fs.createReadStream('testvectors/hls15/master.m3u8'); + }; + + mockMediaManifest2 = function(bandwidth) { + return fs.createReadStream('testvectors/hls15/index_' + bandwidth + '.m3u8'); + }; }); it("return the correct vod URI", done => { @@ -45,6 +55,16 @@ describe("HLSVod standalone", () => { }); }); + it("can handle VOD without resolution specified in master manifest", done => { + mockVod = new HLSVod('http://mock.com/mock.m3u8'); + mockVod.load(mockMasterManifest2, mockMediaManifest2) + .then(() => { + expect(mockVod.getBandwidths().length).toBe(1); + expect(mockVod.getBandwidths()).toEqual(['1010931']); + done(); + }); + }); + it("has the first segments in the first media sequence and that they are ABR aligned", done => { mockVod = new HLSVod('http://mock.com/mock.m3u8'); mockVod.load(mockMasterManifest, mockMediaManifest) @@ -694,7 +714,7 @@ describe("HLSVod with separate audio variants", () => { }; mockAudioManifest = function(groupId) { const fname = { - 'audio-aacl-96': 'audio-96000.m3u8' + "audio-aacl-96": 'audio-96000.m3u8' }; return fs.createReadStream('testvectors/hls4/' + fname[groupId]); } diff --git a/testvectors/hls15/index_1010931.m3u8 b/testvectors/hls15/index_1010931.m3u8 new file mode 100644 index 0000000..e51a45a --- /dev/null +++ b/testvectors/hls15/index_1010931.m3u8 @@ -0,0 +1,20 @@ +#EXTM3U +#EXT-X-TARGETDURATION:4 +#EXT-X-ALLOW-CACHE:YES +#EXT-X-PLAYLIST-TYPE:VOD +#EXT-X-VERSION:3 +#EXT-X-MEDIA-SEQUENCE:1 +#EXTINF:2.000, +./1010931/seg-1-v1-a1.ts +#EXTINF:2.000, +./1010931/seg-2-v1-a1.ts +#EXTINF:2.000, +./1010931/seg-3-v1-a1.ts +#EXTINF:3.500, +./1010931/seg-4-v1-a1.ts +#EXTINF:2.000, +./1010931/seg-5-v1-a1.ts +#EXTINF:2.000, +./1010931/seg-6-v1-a1.ts +#EXTINF:2.000, +./1010931/seg-9-v1-a1.ts \ No newline at end of file diff --git a/testvectors/hls15/master.m3u8 b/testvectors/hls15/master.m3u8 new file mode 100644 index 0000000..fc4a471 --- /dev/null +++ b/testvectors/hls15/master.m3u8 @@ -0,0 +1,3 @@ +#EXTM3U +#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1010931 +index_1010931.m3u8