-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenericHeaders.spec.js
127 lines (116 loc) · 3.45 KB
/
genericHeaders.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const equal = require('assert').deepEqual
const { addOpenTag, addVersionTag, findTargetDuration, extractTimes, extractFrameTimeAsInt, getLargestDuration, greaterThan, extractDiffFromList, mediaSequence, closingTag } = require('./genericHeaders')
describe('genericHeaders.js', () => {
const iFrames = [
{
pkt_dts_time: '0.000000',
pkt_pts_time: '0.000000',
pkt_pos: '40223',
pkt_size: '1222',
pict_type: 'I'
},
{
pkt_dts_time: '2.000000',
pkt_pts_time: '2.000000',
pkt_pos: '159174',
pkt_size: '4576',
pict_type: 'I'
},
{
pkt_dts_time: '4.000000',
pkt_pts_time: '4.000000',
pkt_pos: '224053',
pkt_size: '5503',
pict_type: 'I'
}
]
describe('addOpenTag()', () => {
it('should return a string with m3u8 opening tag', () => {
const expectedResult = ['#EXTM3U']
const result = addOpenTag()
equal(result, expectedResult)
})
})
describe('addVersionTag()', () => {
it('should append the version tag', () => {
const version = 4
const expectedResult = [`#EXT-X-VERSION:${version}`]
const result = addVersionTag(version)([])
equal(result, expectedResult)
})
})
describe('findTargetDuration()', () => {
it('should return the target duration', () => {
const iFrames = [
{
pkt_dts_time: '0.000000',
pkt_pos: '40223',
pkt_size: '1222',
pict_type: 'I'
},
{ pkt_dts_time: '2.000000',
pkt_pos: '159174',
pkt_size: '4576',
pict_type: 'I'
},
{ pkt_dts_time: '4.000000',
pkt_pos: '224053',
pkt_size: '5503',
pict_type: 'I'
}
]
const largestDuration = 2
const expectedResult = [`#EXT-X-TARGETDURATION:${largestDuration}`]
const result = findTargetDuration(iFrames)([])
equal(result, expectedResult)
})
describe('extractDiffFromList()', () => {
it('should return the diff', () => {
const list = [[2,0],[2,1,5]]
const result = extractDiffFromList(list)
equal(result, 2)
})
})
describe('greaterThan()', () => {
it('should return the larger number', () => {
const result = greaterThan([0, 0], 4)
equal(result, [[4,4], 4])
})
it('should return the larger number again', () => {
const result = greaterThan([0, 2], 5)
equal(result, [[3, 5], 5])
})
describe('extractFrameTimeAsInt()', () => {
it('should return the keyframe decode time', () => {
const frame = {
pkt_dts_time: '4.000000',
pkt_pos: '224053',
pkt_size: '5503',
pict_type: 'I'
}
const result = extractFrameTimeAsInt(frame)
equal(result === parseInt(frame.pkt_dts_time), true)
})
})
describe('extractTimes()', () => {
it('should return list of time integers', () => {
const result = extractTimes(iFrames)
equal(result, [0, 2, 4])
})
})
})
})
describe('mediaSequence()', () => {
it('should include that line', () => {
const sequence = 0
const result = mediaSequence(sequence)([])
equal(result, [`#EXT-X-MEDIA-SEQUENCE:${sequence}`])
})
})
describe('closingTag()', () => {
it('should add closing tag', () => {
const result = closingTag([])
equal(result, ['#EXT-X-ENDLIST'])
})
})
})