Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Option for Always Mapping Vod Bitrates By Nearest Value #113

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class HLSVod {
if (opts && opts.expectedSubtitleTracks) {
this.expectedSubtitleTracks = opts.expectedSubtitleTracks;
}
if (opts && opts.alwaysMapBandwidthByNearest) {
this.alwaysMapBandwidthByNearest = opts.alwaysMapBandwidthByNearest;
}
this.videoSequencesCount = 0;
this.audioSequencesCount = 0;
this.defaultAudioGroupAndLang = null;
Expand Down Expand Up @@ -116,6 +119,7 @@ class HLSVod {
subtitleSequencesCount: this.subtitleSequencesCount,
mediaStartExcessTime: this.mediaStartExcessTime,
audioCodecsMap: this.audioCodecsMap,
alwaysMapBandwidthByNearest: this.alwaysMapBandwidthByNearest
};
return JSON.stringify(serialized);
}
Expand Down Expand Up @@ -167,6 +171,7 @@ class HLSVod {
this.subtitleSequencesCount = de.subtitleSequencesCount
this.mediaStartExcessTime = de.mediaStartExcessTime;
this.audioCodecsMap = de.audioCodecsMap;
this.alwaysMapBandwidthByNearest = de.alwaysMapBandwidthByNearest;
}

/**
Expand All @@ -186,7 +191,7 @@ class HLSVod {
baseUrl = m[1] + "/";
}
const HAS_AUDIO_DEFAULTS = this.defaultAudioGroupAndLang === null ? false : true;
if (this.previousVod && this.previousVod.getBandwidths().length === m3u.items.StreamItem.length) {
if (!this.alwaysMapBandwidthByNearest && this.previousVod && this.previousVod.getBandwidths().length === m3u.items.StreamItem.length) {
debug(`Previous VOD bandwidths matches amount of current. A mapping is possible`);
const previousBandwidths = this.previousVod.getBandwidths().sort((a, b) => a - b);
this.usageProfileMapping = {};
Expand Down
26 changes: 26 additions & 0 deletions spec/hlsvod_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,9 @@ describe("HLSVod with not equal usage profiles", () => {
mockMasterManifest.push(function () {
return fs.createReadStream("testvectors/hls_abr4/master.m3u8");
});
mockMasterManifest.push(function () {
return fs.createReadStream("testvectors/hls_abr6/master.m3u8");
})
mockMediaManifest.push(function (bandwidth) {
return fs.createReadStream("testvectors/hls1/" + bandwidth + ".m3u8");
});
Expand All @@ -910,6 +913,9 @@ describe("HLSVod with not equal usage profiles", () => {
mockMediaManifest.push(function (bandwidth) {
return fs.createReadStream("testvectors/hls_abr4/" + bandwidth + ".m3u8");
});
mockMediaManifest.push(function (bandwidth) {
return fs.createReadStream("testvectors/hls_abr6/" + bandwidth + ".m3u8");
});
});

it("can find a correct match", (done) => {
Expand Down Expand Up @@ -1200,6 +1206,26 @@ describe("HLSVod with not equal usage profiles", () => {
done();
});
});

it("can match by true nearest when options-> alwaysMapBandwidthByNearest is true", (done) => {
mockVod = new HLSVod("http://mock.com/mock.m3u8", null, 0,0, null, { alwaysMapBandwidthByNearest: 1 });
mockVod2 = new HLSVod("http://mock.com/mock2.m3u8", null, 0,0, null, { alwaysMapBandwidthByNearest: 1 });
mockVod
.load(mockMasterManifest[0], mockMediaManifest[0])
.then(() => {
return mockVod2.loadAfter(mockVod, mockMasterManifest[7], mockMediaManifest[7]);
})
.then(() => {
const seqSegments = mockVod2.getLiveMediaSequenceSegments(0);
const lastIdx = seqSegments["1497000"].length - 1;
expect(seqSegments["1497000"][lastIdx].uri).toEqual("https://mock.vod.media/segment1_0_av.ts");
expect(seqSegments["3496000"][lastIdx].uri).toEqual("https://mock.vod.media/segment1_1_av.ts");
expect(seqSegments["4497000"][lastIdx].uri).toEqual("https://mock.vod.media/segment1_2_av.ts");
expect(seqSegments["5544000"][lastIdx].uri).toEqual("https://mock.vod.media/segment1_3_av.ts");
expect(seqSegments["6655000"][lastIdx].uri).toEqual("https://mock.vod.media/segment1_4_av.ts");
done();
});
});
});
/**
* Changes:
Expand Down
Loading
Loading