Skip to content

Commit

Permalink
chore: unit test for hls cmaf manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
birme committed Apr 22, 2024
1 parent 5206b32 commit e10a98d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/manifests/handlers/hls/media.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {});
});
});
6 changes: 6 additions & 0 deletions src/testvectors/hls/hls1_cmaf/manifest.m3u8
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions src/testvectors/hls/hls1_cmaf/manifest_1.m3u8
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e10a98d

Please sign in to comment.