Skip to content

Commit

Permalink
Support for the special case when resolution is not set on video trac…
Browse files Browse the repository at this point in the history
…ks (#5)
  • Loading branch information
birme committed Apr 16, 2020
1 parent ca9e8ab commit 5cd6e66
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
25 changes: 18 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
22 changes: 21 additions & 1 deletion spec/hlsvod_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const Readable = require('stream').Readable;
describe("HLSVod standalone", () => {
let mockMasterManifest;
let mockMediaManifest;
let mockMasterManifest2;
let mockMediaManifest2;

beforeEach(() => {
mockMasterManifest = function() {
Expand All @@ -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 => {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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]);
}
Expand Down
20 changes: 20 additions & 0 deletions testvectors/hls15/index_1010931.m3u8
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions testvectors/hls15/master.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1010931
index_1010931.m3u8

0 comments on commit 5cd6e66

Please sign in to comment.