Skip to content

Commit

Permalink
feat: added 3rd mock hls for audio tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nfrederiksen committed May 26, 2021
1 parent 9925a70 commit 8fa0fde
Show file tree
Hide file tree
Showing 15 changed files with 845 additions and 30 deletions.
48 changes: 27 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class HLSVod {

// # Need to clean up langs loaded from prev. VOD that current VOD doesn't have.
// # Necessary, for the case when getLiveMediaSequenceAudioSegments() tries to
// # access an audioGroups' language that the current VOD never had.
// # access an audioGroups' language that the current VOD never had.
let allLangs = Object.keys(this.audioSegments[audioGroupId]);
let toRemove = [];
allLangs.map((lang) => {
Expand Down Expand Up @@ -251,7 +251,7 @@ class HLSVod {
// # Prevents 'loading' an audio track with same GID and LANG.
// # otherwise it just would've loaded OVER the latest occurens of the LANG in GID.
if (!audioGroups[audioGroupId][audioLang]) {
audioGroups[audioGroupId][audioLang] = true;
audioGroups[audioGroupId][audioLang] = true;
audioManifestPromises.push(
this._loadAudioManifest(
audioManifestUrl,
Expand Down Expand Up @@ -381,20 +381,9 @@ class HLSVod {
* @param {number} seqIdx - media sequence index (first is 0)
*/
getLiveMediaSequenceAudioSegments(audioGroupId, audioLanguage, seqIdx) {
// <-------------------------------------------------------------------------- I'VE BEEN HERE
// # No lang found?
// # Rather than returning 'undefined', just use the first one (usually the default)
if (!this.mediaSequences[seqIdx].audioSegments[audioGroupId][audioLanguage])
{
const AllLangsObj = this.mediaSequences[seqIdx].audioSegments[audioGroupId];
return this.mediaSequences[seqIdx].audioSegments[audioGroupId][
Object.keys(AllLangsObj)[0]
];
} else {
return this.mediaSequences[seqIdx].audioSegments[audioGroupId][
audioLanguage
];
}
// <------------------------------------------ I'VE BEEN HERE
// # How to handle when language not found? Right now it returns undefined.
return this.mediaSequences[seqIdx].audioSegments[audioGroupId][audioLanguage];
}

/**
Expand Down Expand Up @@ -561,7 +550,13 @@ class HLSVod {
* Gets a hls/makes m3u8-file with all of the correct audio segments
* belonging to a given groupID for a particular sequence.
*/
getLiveMediaAudioSequences(offset, audioGroupId, audioLanguage, seqIdx, discOffset) {
getLiveMediaAudioSequences(
offset,
audioGroupId,
audioLanguage,
seqIdx,
discOffset
) {
// <--------------------------------------------------------------------------------------- BEEN HERE
debug(
`Get live audio media sequence [${seqIdx}] for audioGroupId=${audioGroupId}`
Expand All @@ -572,6 +567,12 @@ class HLSVod {
seqIdx
);

// # If failed to find segments for given language,
// # return null rather than an error.
if (!mediaSeqAudioSegments){
return null;
}

const targetDuration = this._determineTargetDuration(mediaSeqAudioSegments);

let m3u8 = "#EXTM3U\n";
Expand Down Expand Up @@ -1256,10 +1257,15 @@ class HLSVod {
});
}

_loadAudioManifest(audioManifestUri, groupId, language, _injectAudioManifest) {
// <-------------------------------------------------------------------------- I'VE BEEN HERE
// # Updated so that segment objects are pushed to Language array instead.
// # Updated input args for _injectAudioManifest().
_loadAudioManifest(
audioManifestUri,
groupId,
language,
_injectAudioManifest
) {
// <-------------------------------------------------------------------------- I'VE BEEN HERE
// # Updated so that segment objects are pushed to Language array instead.
// # Updated input args for _injectAudioManifest().
return new Promise((resolve, reject) => {
const parser = m3u8.createStream();
debug(`Loading audio manifest for lang=${language} of group=${groupId}`);
Expand Down
65 changes: 56 additions & 9 deletions spec/hlsvod_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ describe("HLSVod with not equal usage profiles", () => {
});
});
/**
* Changes:
* Changes:
* - Read from new mock manifests and
* update input arguments for vod.getLiveMediaSequenceAudioSegments(id, *new*->lang, seqIdx)
* - Added 3 more unittests for different VOD after VOD cases.
Expand Down Expand Up @@ -1340,12 +1340,14 @@ describe("HLSVod with separate audio variants", () => {
`testvectors/hls_multiaudiotracks/${fname[groupId]}-${lang}.m3u8`
);
} else {
return fs.createReadStream(`testvectors/hls_multiaudiotracks/${fname[groupId]}.m3u8`);
return fs.createReadStream(
`testvectors/hls_multiaudiotracks/${fname[groupId]}.m3u8`
);
}
};
mockAudioManifest2 = function (groupId, lang) {
const fname = {
"aac": "audio",
aac: "audio",
"audio-aacl-96": "audio",
"audio-aacl-97": "audio",
};
Expand All @@ -1359,6 +1361,39 @@ describe("HLSVod with separate audio variants", () => {
);
}
};
mockMasterManifest3 = function () {
//return fs.createReadStream("testvectors/hls4/master.m3u8");
return fs.createReadStream(
"testvectors/hls_multiaudiotracks3/master.m3u8"
);
};
mockMediaManifest3 = function (bandwidth) {
const fname = {
354000: "video-241929.m3u8",
819000: "video-680761.m3u8",
1538000: "video-1358751.m3u8",
2485000: "video-2252188.m3u8",
3396000: "video-3112126.m3u8",
};
return fs.createReadStream(
"testvectors/hls_multiaudiotracks3/" + fname[bandwidth]
);
};
mockAudioManifest3 = function (groupId, lang) {
const fname = {
"audio-aacl-96": "audio-96000",
"audio-aacl-97": "audio-96000",
};
if (groupId && lang) {
return fs.createReadStream(
`testvectors/hls_multiaudiotracks3/${fname[groupId]}-${lang}.m3u8`
);
} else {
return fs.createReadStream(
`testvectors/hls_multiaudiotracks3/${fname[groupId]}.m3u8`
);
}
};
});

it("returns the correct number of bandwidths", (done) => {
Expand Down Expand Up @@ -1484,7 +1519,6 @@ describe("HLSVod with separate audio variants", () => {
});
});


it("can handle vod after another vod, loading same groupId but missing a language and gives default language instead", (done) => {
const now = Date.now();
// # Two demuxed vods with some different languages.
Expand Down Expand Up @@ -1515,19 +1549,27 @@ describe("HLSVod with separate audio variants", () => {
).toEqual(
"http://mock.com/1woxvooiidb(11186147_ISMUSP)-video=241929-1.ts"
);

const seqAudioSegments1 = mockVod.getLiveMediaSequenceAudioSegments(
"audio-aacl-96",
"pl",
"zxx",
0
);
const seqAudioSegments2 = mockVod2.getLiveMediaSequenceAudioSegments(
let seqAudioSegments2 = mockVod2.getLiveMediaSequenceAudioSegments(
// If group does not have that lang. then pick the top most lang. for that group.
"audio-aacl-96",
"zxx",
0
);
if (!seqAudioSegments2) {
seqAudioSegments2 = mockVod2.getLiveMediaSequenceAudioSegments(
"audio-aacl-96",
"de",
0
);
}
expect(seqAudioSegments1[0].uri).toEqual(
"http://mock.com/1woxvooiidb(11186147_ISMUSP)-audio=96000_pl-1.aac"
"http://mock.com/1woxvooiidb(11186147_ISMUSP)-audio=96000_zxx-1.aac"
);
expect(
seqAudioSegments2[seqAudioSegments2.length - 1 - 1].discontinuity
Expand All @@ -1539,6 +1581,11 @@ describe("HLSVod with separate audio variants", () => {
});
});

// TODO
it("can handle vod after another vod, going from missing track redirection to real track.", (done) => {
done();
});

it("can handle vod after another vod that has different Group ID", (done) => {
const now = Date.now();
// # Two demuxed vods with different languages.
Expand Down Expand Up @@ -1585,14 +1632,14 @@ describe("HLSVod with separate audio variants", () => {
"http://mock.com/1woxvooiidb(11186147_ISMUSP)-audio=96000_pl-1.aac"
);
//expect(seqAudioSegments2[seqAudioSegments2.length - 1 - 1].discontinuity).toBe(false);
// # This isn't the final expected behavior.
expect(seqAudioSegments2[0].uri).toEqual(
"http://mock.com/media_mock/audioplaylist/i-audio_sv-1.aac"
);
done();
});
});


it("can return an audio variant manifest", (done) => {
const now = Date.now();
mockVod = new HLSVod("http://mock.com/mock.m3u8", [], now);
Expand All @@ -1619,7 +1666,7 @@ describe("HLSVod with separate audio variants", () => {
done();
});
});
});
});

describe("HLSVod with discontinuites in the source", () => {
let mockMasterManifest;
Expand Down
61 changes: 61 additions & 0 deletions testvectors/hls_multiaudiotracks3/audio-96000-de.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#EXTM3U
#EXT-X-VERSION:4
## Created with Unified Streaming Platform(version=1.7.25)
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:3
#USP-X-TIMESTAMP-MAP:MPEGTS=900000,LOCAL=1970-01-01T00:00:00Z
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-1.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-2.aac
#EXTINF:2.9866, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-3.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-4.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-5.aac
#EXTINF:2.9867, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-6.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-7.aac
#EXTINF:2.9867, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-8.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-9.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-10.aac
#EXTINF:2.9866, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-11.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-12.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-13.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-14.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-15.aac
#EXTINF:2.9866, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-16.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-17.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-18.aac
#EXTINF:2.9867, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-19.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-20.aac
#EXTINF:2.9867, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-21.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-22.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-23.aac
#EXTINF:2.9866, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-24.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-25.aac
#EXTINF:2.0054, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_de-26.aac
#EXT-X-ENDLIST
61 changes: 61 additions & 0 deletions testvectors/hls_multiaudiotracks3/audio-96000-en.m3u8
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#EXTM3U
#EXT-X-VERSION:4
## Created with Unified Streaming Platform(version=1.7.25)
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MEDIA-SEQUENCE:1
#EXT-X-INDEPENDENT-SEGMENTS
#EXT-X-TARGETDURATION:3
#USP-X-TIMESTAMP-MAP:MPEGTS=900000,LOCAL=1970-01-01T00:00:00Z
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-1.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-2.aac
#EXTINF:2.9866, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-3.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-4.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-5.aac
#EXTINF:2.9867, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-6.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-7.aac
#EXTINF:2.9867, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-8.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-9.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-10.aac
#EXTINF:2.9866, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-11.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-12.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-13.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-14.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-15.aac
#EXTINF:2.9866, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-16.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-17.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-18.aac
#EXTINF:2.9867, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-19.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-20.aac
#EXTINF:2.9867, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-21.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-22.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-23.aac
#EXTINF:2.9866, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-24.aac
#EXTINF:3.008, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-25.aac
#EXTINF:2.0054, no desc
1woxvooiidb(11186147_ISMUSP)-audio=96000_en-26.aac
#EXT-X-ENDLIST
Loading

0 comments on commit 8fa0fde

Please sign in to comment.