-
Notifications
You must be signed in to change notification settings - Fork 211
/
ts-inspector.test.js
205 lines (189 loc) · 5.29 KB
/
ts-inspector.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
'use strict';
var segments = require('data-files!segments');
var
QUnit = require('qunit'),
tsInspector = require('../lib/tools/ts-inspector.js'),
StreamTypes = require('../lib/m2ts/stream-types.js'),
tsSegment = segments['test-segment.ts'](),
tsNoAudioSegment = segments['test-no-audio-segment.ts'](),
aacSegment = segments['test-aac-segment.aac'](),
utils = require('./utils'),
inspect = tsInspector.inspect,
parseAudioPes_ = tsInspector.parseAudioPes_,
packetize = utils.packetize,
audioPes = utils.audioPes,
PES_TIMESCALE = 90000;
QUnit.module('TS Inspector');
QUnit.test('returns null for empty segment input', function(assert) {
assert.equal(inspect(new Uint8Array([])), null, 'returned null');
});
QUnit.test('can parse a ts segment', function(assert) {
var expected = {
video: [
{
type: 'video',
pts: 126000,
dts: 126000,
ptsTime: 126000 / PES_TIMESCALE,
dtsTime: 126000 / PES_TIMESCALE
},
{
type: 'video',
pts: 924000,
dts: 924000,
ptsTime: 924000 / PES_TIMESCALE,
dtsTime: 924000 / PES_TIMESCALE
}
],
firstKeyFrame: {
type: 'video',
pts: 126000,
dts: 126000,
ptsTime: 126000 / PES_TIMESCALE,
dtsTime: 126000 / PES_TIMESCALE
},
audio: [
{
type: 'audio',
pts: 126000,
dts: 126000,
ptsTime: 126000 / PES_TIMESCALE,
dtsTime: 126000 / PES_TIMESCALE
},
{
type: 'audio',
pts: 859518,
dts: 859518,
ptsTime: 859518 / PES_TIMESCALE,
dtsTime: 859518 / PES_TIMESCALE
}
]
};
assert.deepEqual(inspect(tsSegment), expected, 'parses ts segment timing data');
});
QUnit.test('adjusts timestamp values based on provided reference', function(assert) {
var rollover = Math.pow(2, 33);
var expected = {
video: [
{
type: 'video',
pts: (126000 + rollover),
dts: (126000 + rollover),
ptsTime: (126000 + rollover) / PES_TIMESCALE,
dtsTime: (126000 + rollover) / PES_TIMESCALE
},
{
type: 'video',
pts: (924000 + rollover),
dts: (924000 + rollover),
ptsTime: (924000 + rollover) / PES_TIMESCALE,
dtsTime: (924000 + rollover) / PES_TIMESCALE
}
],
firstKeyFrame: {
type: 'video',
pts: (126000 + rollover),
dts: (126000 + rollover),
ptsTime: (126000 + rollover) / PES_TIMESCALE,
dtsTime: (126000 + rollover) / PES_TIMESCALE
},
audio: [
{
type: 'audio',
pts: (126000 + rollover),
dts: (126000 + rollover),
ptsTime: (126000 + rollover) / PES_TIMESCALE,
dtsTime: (126000 + rollover) / PES_TIMESCALE
},
{
type: 'audio',
pts: (859518 + rollover),
dts: (859518 + rollover),
ptsTime: (859518 + rollover) / PES_TIMESCALE,
dtsTime: (859518 + rollover) / PES_TIMESCALE
}
]
};
assert.deepEqual(inspect(tsSegment, rollover - 1), expected,
'adjusts inspected time data to account for pts rollover');
});
QUnit.test('can parse an aac segment', function(assert) {
var expected = {
audio: [
{
type: 'audio',
pts: 895690,
dts: 895690,
ptsTime: 895690 / PES_TIMESCALE,
dtsTime: 895690 / PES_TIMESCALE
},
{
type: 'audio',
pts: (895690 + (430 * 1024 * PES_TIMESCALE / 44100)),
dts: (895690 + (430 * 1024 * PES_TIMESCALE / 44100)),
ptsTime: (895690 + (430 * 1024 * PES_TIMESCALE / 44100)) / PES_TIMESCALE,
dtsTime: (895690 + (430 * 1024 * PES_TIMESCALE / 44100)) / PES_TIMESCALE
}
]
};
assert.deepEqual(inspect(aacSegment), expected, 'parses aac segment timing data');
});
QUnit.test('can parse ts segment with no audio muxed in', function(assert) {
var expected = {
video: [
{
type: 'video',
pts: 126000,
dts: 126000,
ptsTime: 126000 / PES_TIMESCALE,
dtsTime: 126000 / PES_TIMESCALE
},
{
type: 'video',
pts: 924000,
dts: 924000,
ptsTime: 924000 / PES_TIMESCALE,
dtsTime: 924000 / PES_TIMESCALE
}
],
firstKeyFrame: {
type: 'video',
pts: 126000,
dts: 126000,
ptsTime: 126000 / PES_TIMESCALE,
dtsTime: 126000 / PES_TIMESCALE
}
};
var actual = inspect(tsNoAudioSegment);
assert.equal(typeof actual.audio, 'undefined', 'results do not contain audio info');
assert.deepEqual(actual, expected,
'parses ts segment without audio timing data');
});
QUnit.test('can parse audio PES when it\'s the only packet in a stream', function(assert) {
var
pts = 90000,
pmt = {
// fake pmt pid that doesn't clash with the audio pid
pid: 0x10,
table: {
// pid copied over from default of audioPes function
0x12: StreamTypes.ADTS_STREAM_TYPE
}
},
result = { audio: [] };
parseAudioPes_(packetize(audioPes([0x00], true, pts)), pmt, result);
// note that both the first and last packet timings are the same, as there's only one
// packet to parse
assert.deepEqual(
result.audio,
[{
dts: pts,
pts: pts,
type: 'audio'
}, {
dts: pts,
pts: pts,
type: 'audio'
}],
'parses audio pes for timing info');
});