From e10a98dec0cd61d8220b2a67913ec3da1f082b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Birm=C3=A9?= Date: Mon, 22 Apr 2024 15:35:41 +0200 Subject: [PATCH] chore: unit test for hls cmaf manifests --- src/manifests/handlers/hls/media.test.ts | 80 +++++++++++++++++++ src/testvectors/hls/hls1_cmaf/manifest.m3u8 | 6 ++ src/testvectors/hls/hls1_cmaf/manifest_1.m3u8 | 16 ++++ 3 files changed, 102 insertions(+) create mode 100644 src/testvectors/hls/hls1_cmaf/manifest.m3u8 create mode 100644 src/testvectors/hls/hls1_cmaf/manifest_1.m3u8 diff --git a/src/manifests/handlers/hls/media.test.ts b/src/manifests/handlers/hls/media.test.ts index e78a4af..d6b7b3a 100644 --- a/src/manifests/handlers/hls/media.test.ts +++ b/src/manifests/handlers/hls/media.test.ts @@ -375,6 +375,86 @@ https://mock.mock.com/stream/hls/manifest_1_00001.ts expect(response.body).toEqual(expected.body); }); + fit('should handle init segments for HLS cmaf media', async () => { + // Arrange + const getMedia = () => { + return new Promise((resolve) => { + const readStream: ReadStream = createReadStream( + path.join( + __dirname, + `../../../testvectors/hls/hls1_cmaf/manifest_1.m3u8` + ) + ); + resolve(readStream); + }); + }; + nock(mockBaseURL).persist().get('/manifest_1.m3u8').reply(200, getMedia, { + 'Content-Type': 'application/vnd.apple.mpegurl;charset=UTF-8', + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': 'Content-Type, Origin' + }); + + const queryParams = { + url: mockMediaURL, + statusCode: '[{i:2,ms:3000}]' + }; + const event: ALBEvent = { + requestContext: { + elb: { + targetGroupArn: '' + } + }, + path: '/stream/hls/manifest.m3u8', + httpMethod: 'GET', + headers: { + accept: 'application/vnd.apple.mpegurl;charset=UTF-8', + 'accept-language': 'en-US,en;q=0.8', + 'content-type': 'text/plain', + host: 'lambda-846800462-us-east-2.elb.amazonaws.com', + 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6)', + 'x-amzn-trace-id': 'Root=1-5bdb40ca-556d8b0c50dc66f0511bf520', + 'x-forwarded-for': '72.21.198.xx', + 'x-forwarded-port': '443', + 'x-forwarded-proto': 'https' + }, + isBase64Encoded: false, + queryStringParameters: queryParams, + body: '' + }; + + // Act + const response = await hlsMediaHandler(event); + + // Assert + const expected: ALBResult = { + statusCode: 200, + headers: { + 'Access-Control-Allow-Headers': 'Content-Type, Origin', + 'Access-Control-Allow-Origin': '*', + 'Content-Type': 'application/vnd.apple.mpegurl' + }, + body: `#EXTM3U +#EXT-X-VERSION:6 +#EXT-X-PLAYLIST-TYPE:VOD +#EXT-X-MEDIA-SEQUENCE:1 +#EXT-X-INDEPENDENT-SEGMENTS +#EXT-X-TARGETDURATION:4 +#USP-X-TIMESTAMP-MAP:MPEGTS=900000,LOCAL=1970-01-01T00:00:00Z +#EXT-X-MAP:URI="https://mock.mock.com/stream/hls/subdir/142d4370-56c9-11ee-a816-2da19aea6ed1_20571919-video=6500000.m4s" +#EXT-X-PROGRAM-DATE-TIME:1970-01-01T00:00:00Z +#EXTINF:3.8400, no desc +https://mock.mock.com/stream/hls/subdir/142d4370-56c9-11ee-a816-2da19aea6ed1_20571919-video=6500000-1.m4s +#EXTINF:3.8400, no desc +https://mock.mock.com/stream/hls/subdir/142d4370-56c9-11ee-a816-2da19aea6ed1_20571919-video=6500000-2.m4s +#EXTINF:3.8400, no desc +https://mock.mock.com/stream/hls/subdir/142d4370-56c9-11ee-a816-2da19aea6ed1_20571919-video=6500000-3.m4s +#EXT-X-ENDLIST` + }; + expect(response.statusCode).toEqual(expected.statusCode); + expect(response.headers).toEqual(expected.headers); + expect(response.body).toEqual(expected.body); + }); + //it('should return code 500 on Other Errors, eg M3U8 parser error', async () => {}); }); }); diff --git a/src/testvectors/hls/hls1_cmaf/manifest.m3u8 b/src/testvectors/hls/hls1_cmaf/manifest.m3u8 new file mode 100644 index 0000000..9de047f --- /dev/null +++ b/src/testvectors/hls/hls1_cmaf/manifest.m3u8 @@ -0,0 +1,6 @@ +#EXTM3U +#EXT-X-VERSION:3 +#EXT-X-INDEPENDENT-SEGMENTS +#EXT-X-STREAM-INF:BANDWIDTH=4255267,AVERAGE-BANDWIDTH=4255267,CODECS="avc1.4d4032,mp4a.40.2",RESOLUTION=2560x1440,FRAME-RATE=25.000,AUDIO="audio",SUBTITLES="subs" +manifest_1.m3u8 + diff --git a/src/testvectors/hls/hls1_cmaf/manifest_1.m3u8 b/src/testvectors/hls/hls1_cmaf/manifest_1.m3u8 new file mode 100644 index 0000000..a7d6751 --- /dev/null +++ b/src/testvectors/hls/hls1_cmaf/manifest_1.m3u8 @@ -0,0 +1,16 @@ +#EXTM3U +#EXT-X-VERSION:6 +#EXT-X-PLAYLIST-TYPE:VOD +#EXT-X-MEDIA-SEQUENCE:1 +#EXT-X-INDEPENDENT-SEGMENTS +#EXT-X-TARGETDURATION:4 +#USP-X-TIMESTAMP-MAP:MPEGTS=900000,LOCAL=1970-01-01T00:00:00Z +#EXT-X-MAP:URI="subdir/142d4370-56c9-11ee-a816-2da19aea6ed1_20571919-video=6500000.m4s" +#EXT-X-PROGRAM-DATE-TIME:1970-01-01T00:00:00Z +#EXTINF:3.84, no desc +subdir/142d4370-56c9-11ee-a816-2da19aea6ed1_20571919-video=6500000-1.m4s +#EXTINF:3.84, no desc +subdir/142d4370-56c9-11ee-a816-2da19aea6ed1_20571919-video=6500000-2.m4s +#EXTINF:3.84, no desc +subdir/142d4370-56c9-11ee-a816-2da19aea6ed1_20571919-video=6500000-3.m4s +#EXT-X-ENDLIST