-
Notifications
You must be signed in to change notification settings - Fork 211
/
utils.clock.test.js
181 lines (169 loc) · 7.74 KB
/
utils.clock.test.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
'use strict';
var
QUnit = require('qunit'),
clock = require('../lib/utils/clock');
QUnit.module('Clock Utils');
QUnit.test('converts from seconds to video timestamps', function(assert) {
assert.equal(clock.secondsToVideoTs(0), 0, 'converts seconds to video timestamp');
assert.equal(clock.secondsToVideoTs(1), 90000, 'converts seconds to video timestamp');
assert.equal(clock.secondsToVideoTs(10), 900000, 'converts seconds to video timestamp');
assert.equal(clock.secondsToVideoTs(-1), -90000, 'converts seconds to video timestamp');
assert.equal(clock.secondsToVideoTs(3), 270000, 'converts seconds to video timestamp');
assert.equal(clock.secondsToVideoTs(0.1), 9000, 'converts seconds to video timestamp');
});
QUnit.test('converts from seconds to audio timestamps', function(assert) {
assert.equal(clock.secondsToAudioTs(0, 90000),
0,
'converts seconds to audio timestamp');
assert.equal(clock.secondsToAudioTs(1, 90000),
90000,
'converts seconds to audio timestamp');
assert.equal(clock.secondsToAudioTs(-1, 90000),
-90000,
'converts seconds to audio timestamp');
assert.equal(clock.secondsToAudioTs(3, 90000),
270000,
'converts seconds to audio timestamp');
assert.equal(clock.secondsToAudioTs(0, 44100),
0,
'converts seconds to audio timestamp');
assert.equal(clock.secondsToAudioTs(1, 44100),
44100,
'converts seconds to audio timestamp');
assert.equal(clock.secondsToAudioTs(3, 44100),
132300,
'converts seconds to audio timestamp');
assert.equal(clock.secondsToAudioTs(-1, 44100),
-44100,
'converts seconds to audio timestamp');
assert.equal(clock.secondsToAudioTs(0.1, 44100),
4410,
'converts seconds to audio timestamp');
});
QUnit.test('converts from video timestamp to seconds', function(assert) {
assert.equal(clock.videoTsToSeconds(0), 0, 'converts video timestamp to seconds');
assert.equal(clock.videoTsToSeconds(90000), 1, 'converts video timestamp to seconds');
assert.equal(clock.videoTsToSeconds(900000), 10, 'converts video timestamp to seconds');
assert.equal(clock.videoTsToSeconds(-90000), -1, 'converts video timestamp to seconds');
assert.equal(clock.videoTsToSeconds(270000), 3, 'converts video timestamp to seconds');
assert.equal(clock.videoTsToSeconds(9000), 0.1, 'converts video timestamp to seconds');
});
QUnit.test('converts from audio timestamp to seconds', function(assert) {
assert.equal(clock.audioTsToSeconds(0, 90000),
0,
'converts seconds to audio timestamp');
assert.equal(clock.audioTsToSeconds(90000, 90000),
1,
'converts seconds to audio timestamp');
assert.equal(clock.audioTsToSeconds(-90000, 90000),
-1,
'converts seconds to audio timestamp');
assert.equal(clock.audioTsToSeconds(270000, 90000),
3,
'converts seconds to audio timestamp');
assert.equal(clock.audioTsToSeconds(0, 44100),
0,
'converts seconds to audio timestamp');
assert.equal(clock.audioTsToSeconds(44100, 44100),
1,
'converts seconds to audio timestamp');
assert.equal(clock.audioTsToSeconds(132300, 44100),
3,
'converts seconds to audio timestamp');
assert.equal(clock.audioTsToSeconds(-44100, 44100),
-1,
'converts seconds to audio timestamp');
assert.equal(clock.audioTsToSeconds(4410, 44100),
0.1,
'converts seconds to audio timestamp');
});
QUnit.test('converts from audio timestamp to video timestamp', function(assert) {
assert.equal(clock.audioTsToVideoTs(0, 90000),
0,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(90000, 90000),
90000,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(900000, 90000),
900000,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(-90000, 90000),
-90000,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(270000, 90000),
270000,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(9000, 90000),
9000,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(0, 44100),
0,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(44100, 44100),
90000,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(441000, 44100),
900000,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(-44100, 44100),
-90000,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(132300, 44100),
270000,
'converts audio timestamp to video timestamp');
assert.equal(clock.audioTsToVideoTs(4410, 44100),
9000,
'converts audio timestamp to video timestamp');
});
QUnit.test('converts from video timestamp to audio timestamp', function(assert) {
assert.equal(clock.videoTsToAudioTs(0, 90000),
0,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(90000, 90000),
90000,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(900000, 90000),
900000,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(-90000, 90000),
-90000,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(270000, 90000),
270000,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(9000, 90000),
9000,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(0, 44100),
0,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(90000, 44100),
44100,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(900000, 44100),
441000,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(-90000, 44100),
-44100,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(270000, 44100),
132300,
'converts video timestamp to audio timestamp');
assert.equal(clock.videoTsToAudioTs(9000, 44100),
4410,
'converts video timestamp to audio timestamp');
});
QUnit.test('converts from metadata timestamp to seconds', function(assert) {
assert.equal(clock.metadataTsToSeconds(90000, 90000, false),
0,
'converts metadata timestamp to seconds and adjusts by timelineStartPts');
assert.equal(clock.metadataTsToSeconds(270000, 90000, false),
2,
'converts metadata timestamp to seconds and adjusts by timelineStartPts');
assert.equal(clock.metadataTsToSeconds(90000, 90000, true),
1,
'converts metadata timestamp to seconds while keeping original timestamps');
assert.equal(clock.metadataTsToSeconds(180000, 0, true),
2,
'converts metadata timestamp to seconds while keeping original timestamps');
});