Skip to content

Commit

Permalink
fix: handle when target duration of one ad is higher than the content (
Browse files Browse the repository at this point in the history
  • Loading branch information
birme authored Jun 22, 2021
1 parent ed68709 commit 8fb589b
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 1 deletion.
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ class HLSSpliceVod {
this.bumperDuration += (bumperPlaylist.items.PlaylistItem[j].get('duration') * 1000);
}
this.playlists[bw].items.PlaylistItem[bumperLength].set('discontinuity', true);
this.playlists[bw].set('targetDuration', this.targetDuration);
}
resolve();
}).catch(reject);
Expand Down
46 changes: 46 additions & 0 deletions spec/hls_splice_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ describe("HLSSpliceVod", () => {
}
return fs.createReadStream(`testvectors/hls1/index_${bwmap[bw]}_av.m3u8`);
};
mockMasterManifest1b = () => {
return fs.createReadStream('testvectors/hls1b/master.m3u8')
};
mockMediaManifest1b = (bw) => {
const bwmap = {
4497000: "0",
2497000: "1"
}
return fs.createReadStream(`testvectors/hls1b/index_${bwmap[bw]}_av.m3u8`);
};
mockAdMasterManifest = () => {
return fs.createReadStream('testvectors/ad1/master.m3u8')
};
Expand Down Expand Up @@ -50,6 +60,16 @@ describe("HLSSpliceVod", () => {
}
return fs.createReadStream(`testvectors/ad3/index_${bwmap[bw]}_av.m3u8`);
};
mockAdMasterManifest4 = () => {
return fs.createReadStream('testvectors/ad4/master.m3u8')
};
mockAdMediaManifest4 = (bw) => {
const bwmap = {
4397000: "0",
2597000: "1"
}
return fs.createReadStream(`testvectors/ad4/index_${bwmap[bw]}_av.m3u8`);
};
mockBumperMasterManifest = () => {
return fs.createReadStream('testvectors/ad1/master.m3u8')
};
Expand Down Expand Up @@ -307,6 +327,32 @@ describe("HLSSpliceVod", () => {
});
});

it("handles target duration for video bumper and two ads in a row merged into one break", done => {
const mockVod = new HLSSpliceVod('http://mock.com/mock.m3u8', { merge: true });
mockVod.load(mockMasterManifest1b, mockMediaManifest1b)
.then(() => {
return mockVod.insertAdAt(0, 'http://mock.com/ad/mockad.m3u8', mockAdMasterManifest, mockAdMediaManifest);
})
.then(() => {
return mockVod.insertAdAt(0, 'http://mock.com/ad/mockad.m3u8', mockAdMasterManifest3, mockAdMediaManifest3);
})
.then(() => {
// This one will go first
return mockVod.insertAdAt(0, 'http://mock.com/ad/mockad.m3u8', mockAdMasterManifest4, mockAdMediaManifest4);
})
.then(() => {
return mockVod.insertBumper('http://mock.com/ad/mockbumper.m3u8', mockBumperMasterManifest, mockBumperMediaManifest);
})
.then(() => {
const m3u8 = mockVod.getMediaManifest(4497000);
const lines = m3u8.split('\n');
expect(lines[1]).toEqual("#EXT-X-TARGETDURATION:5");
expect(lines[10+8]).toEqual("#EXT-X-CUE-OUT:DURATION=23");
expect(lines[lines.length - 2]).toEqual("#EXT-X-ENDLIST");
done();
});
});

it("ensures that video bumper is always first", done => {
const mockVod = new HLSSpliceVod('http://mock.com/mock.m3u8');
mockVod.load(mockMasterManifest, mockMediaManifest)
Expand Down
9 changes: 9 additions & 0 deletions testvectors/ad4/index_0_av.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#EXTM3U
#EXT-X-TARGETDURATION:5
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:5.000,
ad1_0_av.ts
#EXT-X-ENDLIST
9 changes: 9 additions & 0 deletions testvectors/ad4/index_1_av.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#EXTM3U
#EXT-X-TARGETDURATION:5
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:3
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:5.000,
ad1_1_av.ts
#EXT-X-ENDLIST
5 changes: 5 additions & 0 deletions testvectors/ad4/master.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=4397000,RESOLUTION=1280x720,CODECS="avc1.77.30, mp4a.40.2",CLOSED-CAPTIONS=NONE
index_0_av.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2597000,RESOLUTION=1024x576,CODECS="avc1.77.30, mp4a.40.2",CLOSED-CAPTIONS=NONE
index_1_av.m3u8
28 changes: 28 additions & 0 deletions testvectors/hls1b/index_0_av.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#EXTM3U
#EXT-X-TARGETDURATION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:3
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-MEDIA-SEQUENCE:1
#EXTINF:3.000,
segment1_0_av.ts
#EXTINF:3.000,
segment2_0_av.ts
#EXTINF:3.000,
segment3_0_av.ts
#EXTINF:3.000,
segment4_0_av.ts
#EXTINF:3.000,
segment5_0_av.ts
#EXTINF:3.000,
segment6_0_av.ts
#EXTINF:3.000,
segment7_0_av.ts
#EXTINF:3.000,
segment8_0_av.ts
#EXTINF:3.000,
segment9_0_av.ts
#EXTINF:2.266,
segment10_0_av.ts
#EXT-X-ENDLIST
28 changes: 28 additions & 0 deletions testvectors/hls1b/index_1_av.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#EXTM3U
#EXT-X-TARGETDURATION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-VERSION:3
#EXT-X-INDEPENDENT-SEGMENTS
##EXT-X-MEDIA-SEQUENCE:1
#EXTINF:3.000,
segment1_1_av.ts
#EXTINF:3.000,
segment2_1_av.ts
#EXTINF:3.000,
segment3_1_av.ts
#EXTINF:3.000,
segment4_1_av.ts
#EXTINF:3.000,
segment5_1_av.ts
#EXTINF:3.000,
segment6_1_av.ts
#EXTINF:3.000,
segment7_1_av.ts
#EXTINF:3.000,
segment8_1_av.ts
#EXTINF:3.000,
segment9_1_av.ts
#EXTINF:2.266,
segment10_1_av.ts
#EXT-X-ENDLIST
5 changes: 5 additions & 0 deletions testvectors/hls1b/master.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=4497000,RESOLUTION=1280x720,CODECS="avc1.77.30, mp4a.40.2",CLOSED-CAPTIONS=NONE
index_0_av.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=2497000,RESOLUTION=1024x576,CODECS="avc1.77.30, mp4a.40.2",CLOSED-CAPTIONS=NONE
index_1_av.m3u8

0 comments on commit 8fb589b

Please sign in to comment.