-
Notifications
You must be signed in to change notification settings - Fork 211
/
metadata-stream.test.js
732 lines (635 loc) · 24.3 KB
/
metadata-stream.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
'use strict';
/*
======== A Handy Little QUnit Reference ========
http://api.qunitjs.com/
Test methods:
module(name, {[setup][ ,teardown]})
test(name, callback)
expect(numberOfAssertions)
stop(increment)
start(decrement)
Test assertions:
ok(value, [message])
equal(actual, expected, [message])
notEqual(actual, expected, [message])
deepEqual(actual, expected, [message])
notDeepEqual(actual, expected, [message])
strictEqual(actual, expected, [message])
notStrictEqual(actual, expected, [message])
throws(block, [expected], [message])
*/
var metadataStream, stringToInts, stringToCString, id3Tag, id3Frame, id3Generator, mp2t, QUnit,
webworkify, MetadataStreamTestWorker;
mp2t = require('../lib/m2ts');
QUnit = require('qunit');
id3Generator = require('./utils/id3-generator');
MetadataStreamTestWorker = require('worker!./metadata-stream-test-worker.js');
stringToInts = id3Generator.stringToInts;
stringToCString = id3Generator.stringToCString;
id3Tag = id3Generator.id3Tag;
id3Frame = id3Generator.id3Frame;
QUnit.module('MetadataStream', {
beforeEach: function() {
metadataStream = new mp2t.MetadataStream();
}
});
QUnit.test('can construct a MetadataStream', function(assert) {
assert.ok(metadataStream, 'does not return null');
});
QUnit.test('triggers log for non-id3/invalid data', function(assert) {
var logs = [];
metadataStream.on('log', function(log) {
logs.push(log);
});
// id3 not long enough
metadataStream.push({type: 'timed-metadata', data: new Uint8Array()});
// invalid data
metadataStream.push({type: 'timed-metadata', data: new Uint8Array([
0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01
])});
const zeroFrames = new Uint8Array(stringToInts('ID3').concat([
0x03, 0x00, // version 3.0 of ID3v2 (aka ID3v.2.3.0)
0x40, // flags. include an extended header
0x00, 0x00, 0x00, 0x00, // size. set later
// extended header
0x00, 0x00, 0x00, 0x06, // extended header size. no CRC
0x00, 0x00, // extended flags
0x00, 0x00, 0x00, 0x02 // size of padding
]));
metadataStream.push({type: 'timed-metadata', data: zeroFrames});
assert.deepEqual(logs, [
{level: 'warn', message: 'Skipping unrecognized metadata packet'},
{level: 'warn', message: 'Skipping unrecognized metadata packet'},
{level: 'warn', message: 'Malformed ID3 frame encountered. Skipping remaining metadata parsing.'}
], 'logs as expected.');
});
QUnit.test('parses simple ID3 metadata out of PES packets', function(assert) {
var
events = [],
wxxxPayload = [
0x00 // text encoding. ISO-8859-1
].concat(stringToCString('ad tag URL'), // description
stringToInts('http://example.com/ad?v=1234&q=7')), // value
id3Bytes,
size;
metadataStream.on('data', function(event) {
events.push(event);
});
id3Bytes = new Uint8Array(stringToInts('ID3').concat([
0x03, 0x00, // version 3.0 of ID3v2 (aka ID3v.2.3.0)
0x40, // flags. include an extended header
0x00, 0x00, 0x00, 0x00, // size. set later
// extended header
0x00, 0x00, 0x00, 0x06, // extended header size. no CRC
0x00, 0x00, // extended flags
0x00, 0x00, 0x00, 0x02 // size of padding
// frame 0
// http://id3.org/id3v2.3.0#User_defined_text_information_frame
], id3Frame('WXXX',
wxxxPayload), // value
// frame 1
// custom tag
id3Frame('XINF',
[
0x04, 0x03, 0x02, 0x01 // arbitrary data
]), [
0x00, 0x00 // padding
]));
// set header size field
size = id3Bytes.byteLength - 10;
id3Bytes[6] = (size >>> 21) & 0x7f;
id3Bytes[7] = (size >>> 14) & 0x7f;
id3Bytes[8] = (size >>> 7) & 0x7f;
id3Bytes[9] = (size) & 0x7f;
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 1000,
// header
data: id3Bytes
});
assert.equal(events.length, 1, 'parsed one tag');
assert.equal(events[0].frames.length, 2, 'parsed two frames');
assert.equal(events[0].frames[0].key, 'WXXX', 'parsed a WXXX frame');
assert.deepEqual(new Uint8Array(events[0].frames[0].data),
new Uint8Array(wxxxPayload),
'attached the frame payload');
assert.equal(events[0].frames[1].key, 'XINF', 'parsed a user-defined frame');
assert.deepEqual(new Uint8Array(events[0].frames[1].data),
new Uint8Array([0x04, 0x03, 0x02, 0x01]),
'attached the frame payload');
assert.equal(events[0].pts, 1000, 'did not modify the PTS');
assert.equal(events[0].dts, 1000, 'did not modify the PTS');
});
QUnit.test('skips non-ID3 metadata events', function(assert) {
var events = [];
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 1000,
// header
data: new Uint8Array([0])
});
assert.equal(events.length, 0, 'did not emit an event');
});
// missing cases:
// unsynchronization
// CRC
// no extended header
// compressed frames
// encrypted frames
// frame groups
// too large/small tag size values
// too large/small frame size values
QUnit.test('parses TXXX frames without null terminators', function(assert) {
var events = [];
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
// header
data: new Uint8Array(id3Tag(id3Frame('TXXX',
0x03, // utf-8
stringToCString('get done'),
stringToInts('{ "key": "value" }')),
[0x00, 0x00]))
});
assert.equal(events.length, 1, 'parsed one tag');
assert.equal(events[0].frames.length, 1, 'parsed one frame');
assert.equal(events[0].frames[0].key, 'TXXX', 'parsed the frame key');
assert.equal(events[0].frames[0].description, 'get done', 'parsed the description');
assert.deepEqual(JSON.parse(events[0].frames[0].data), { key: 'value' }, 'parsed the data');
});
QUnit.test('parses TXXX frames with null terminators', function(assert) {
var events = [];
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
// header
data: new Uint8Array(id3Tag(id3Frame('TXXX',
0x03, // utf-8
stringToCString('get done'),
stringToCString('{ "key": "value" }')),
[0x00, 0x00]))
});
assert.equal(events.length, 1, 'parsed one tag');
assert.equal(events[0].frames.length, 1, 'parsed one frame');
assert.equal(events[0].frames[0].key, 'TXXX', 'parsed the frame key');
assert.equal(events[0].frames[0].description, 'get done', 'parsed the description');
assert.deepEqual(JSON.parse(events[0].frames[0].data), { key: 'value' }, 'parsed the data');
});
QUnit.test('parses WXXX frames', function(assert) {
var events = [], url = 'http://example.com/path/file?abc=7&d=4#ty';
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
// header
data: new Uint8Array(id3Tag(id3Frame('WXXX',
0x03, // utf-8
stringToCString(''),
stringToInts(url)),
[0x00, 0x00]))
});
assert.equal(events.length, 1, 'parsed one tag');
assert.equal(events[0].frames.length, 1, 'parsed one frame');
assert.equal(events[0].frames[0].key, 'WXXX', 'parsed the frame key');
assert.equal(events[0].frames[0].description, '', 'parsed the description');
assert.equal(events[0].frames[0].url, url, 'parsed the value');
});
QUnit.test('parses TXXX frames with characters that have a single-digit hexadecimal representation', function(assert) {
var events = [], value = String.fromCharCode(7);
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
// header
data: new Uint8Array(id3Tag(id3Frame('TXXX',
0x03, // utf-8
stringToCString(''),
stringToCString(value)),
[0x00, 0x00]))
});
assert.equal(events[0].frames[0].data,
value,
'parsed the single-digit character');
});
QUnit.test('parses PRIV frames', function(assert) {
var
events = [],
payload = stringToInts('arbitrary data may be included in the payload ' +
'of a PRIV frame');
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
// header
data: new Uint8Array(id3Tag(id3Frame('PRIV',
stringToCString('priv-owner@example.com'),
payload)))
});
assert.equal(events.length, 1, 'parsed a tag');
assert.equal(events[0].frames.length, 1, 'parsed a frame');
assert.equal(events[0].frames[0].key, 'PRIV', 'frame key is PRIV');
assert.equal(events[0].frames[0].owner, 'priv-owner@example.com', 'parsed the owner');
assert.deepEqual(new Uint8Array(events[0].frames[0].data),
new Uint8Array(payload),
'parsed the frame private data');
});
QUnit.test('parses tags split across pushes', function(assert) {
var
events = [],
owner = stringToCString('owner@example.com'),
payload = stringToInts('A TS packet is 188 bytes in length so that it can' +
' be easily transmitted over ATM networks, an ' +
'important medium at one time. We want to be sure' +
' that ID3 frames larger than a TS packet are ' +
'properly re-assembled.'),
tag = new Uint8Array(id3Tag(id3Frame('PRIV', owner, payload))),
front = tag.subarray(0, 100),
back = tag.subarray(100);
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
data: front,
dataAlignmentIndicator: true
});
assert.equal(events.length, 0, 'parsed zero tags');
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
data: back,
dataAlignmentIndicator: false
});
assert.equal(events.length, 1, 'parsed a tag');
assert.equal(events[0].frames.length, 1, 'parsed a frame');
assert.equal(events[0].frames[0].data.byteLength,
payload.length,
'collected data across pushes');
// parses subsequent fragmented tags
tag = new Uint8Array(id3Tag(id3Frame('PRIV',
owner, payload, payload)));
front = tag.subarray(0, 188);
back = tag.subarray(188);
events = [];
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 2000,
dts: 2000,
data: front,
dataAlignmentIndicator: true
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 2000,
dts: 2000,
data: back,
dataAlignmentIndicator: false
});
assert.equal(events.length, 1, 'parsed a tag');
assert.equal(events[0].frames.length, 1, 'parsed a frame');
assert.equal(events[0].frames[0].data.byteLength,
2 * payload.length,
'collected data across pushes');
});
QUnit.test('id3 frame is malformed first time but gets corrected in the next frame', function(assert) {
var
events = [],
owner = stringToCString('owner@example.com'),
payload = stringToInts('A TS packet is 188 bytes in length so that it can' +
' be easily transmitted over ATM networks, an ' +
'important medium at one time. We want to be sure' +
' that ID3 frames larger than a TS packet are ' +
'properly re-assembled.'),
tag = new Uint8Array(id3Tag(id3Frame('PRIV', owner, payload))),
front = tag.subarray(0, 100);
metadataStream.on('data', function(event) {
events.push(event);
});
// receives incomplete id3
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
data: front,
dataAlignmentIndicator: true
});
assert.equal(events.length, 0, 'parsed zero tags');
// receives complete id3
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
data: tag,
dataAlignmentIndicator: true
});
assert.equal(events.length, 1, 'parsed a tag');
assert.equal(events[0].frames.length, 1, 'parsed a frame');
assert.equal(events[0].frames[0].data.byteLength,
payload.length,
'collected data across pushes');
});
QUnit.test('id3 frame reports more data than its tagsize ', function(assert) {
var
events = [],
owner = stringToCString('owner@example.com'),
payload = stringToInts('A TS packet is 188 bytes in length so that it can' +
' be easily transmitted over ATM networks, an ' +
'important medium at one time. We want to be sure' +
' that ID3 frames larger than a TS packet are ' +
'properly re-assembled.'),
tag = new Uint8Array(id3Tag(id3Frame('PRIV', owner, payload))),
d = new Uint8Array([0x04, 0x05, 0x06]),
data = new Uint8Array(tag.byteLength + d.byteLength);
data.set(tag);
data.set(d, tag.length);
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
data: data,
dataAlignmentIndicator: true
});
assert.equal(events.length, 1, 'parsed a tag');
assert.equal(events[0].frames.length, 1, 'parsed a frame');
assert.equal(events[0].frames[0].data.byteLength,
payload.length,
'collected data across pushes');
});
QUnit.test('ignores tags when the header is fragmented', function(assert) {
var
events = [],
tag = new Uint8Array(id3Tag(id3Frame('PRIV',
stringToCString('owner@example.com'),
stringToInts('payload')))),
// split the 10-byte ID3 tag header in half
front = tag.subarray(0, 5),
back = tag.subarray(5);
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
data: front
});
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
data: back
});
assert.equal(events.length, 0, 'parsed zero tags');
metadataStream.push({
type: 'timed-metadata',
trackId: 7,
pts: 1500,
dts: 1500,
data: new Uint8Array(id3Tag(id3Frame('PRIV',
stringToCString('owner2'),
stringToInts('payload2'))))
});
assert.equal(events.length, 1, 'parsed one tag');
assert.equal(events[0].frames[0].owner, 'owner2', 'dropped the first tag');
});
// https://html.spec.whatwg.org/multipage/embedded-content.html#steps-to-expose-a-media-resource-specific-text-track
QUnit.test('constructs the dispatch type', function(assert) {
metadataStream = new mp2t.MetadataStream({
descriptor: new Uint8Array([0x03, 0x02, 0x01, 0x00])
});
assert.equal(metadataStream.dispatchType, '1503020100', 'built the dispatch type');
});
QUnit.test('should skip tag frame parsing on malformed frame, preserving previous frames', function(assert) {
var events = [],
validFrame = id3Frame('TIT2',
0x03, // utf-8
stringToCString('sample title')),
malformedFrame = id3Frame('WOAF'), // frame with size of 0B
tag = id3Tag(validFrame, malformedFrame);
metadataStream.on('data', function(event) {
events.push(event);
});
metadataStream.push({
type: 'timed-metadata',
data: new Uint8Array(tag)
})
assert.equal(events.length, 1, 'parsed 1 tag')
assert.equal(events[0].frames.length, 1, 'parsed 1 frame');
assert.equal(events[0].frames[0].key, 'TIT2');
});
QUnit.test('can parse APIC frame in web worker', function(assert) {
var worker = new MetadataStreamTestWorker(),
done = assert.async();
worker.addEventListener('message', function(e) {
assert.equal(e.data.frames[0].key, 'APIC', 'frame key is APIC');
assert.equal(e.data.frames[0].mimeType, 'image/jpeg', 'parsed MIME type is "image/jpeg"');
assert.equal(e.data.frames[0].pictureType, 0x03, 'parsed picture type is 0x03');
assert.equal(e.data.frames[0].description, 'sample description', 'parsed description');
assert.deepEqual(e.data.frames[0].pictureData, new Uint8Array(stringToInts("picture binary data")), 'parsed picture data');
assert.equal(e.data.frames[1].key, 'APIC', 'frame key is APIC');
assert.equal(e.data.frames[1].mimeType, '-->', 'parsed MIME type is "-->"');
assert.equal(e.data.frames[1].pictureType, 0x04, 'parsed picture type is 0x04');
assert.equal(e.data.frames[1].description, 'sample description 2', 'parsed description');
assert.equal(e.data.frames[1].url, 'http://example.org/cover-back.jpg', 'parsed picture data');
worker.terminate();
done();
});
worker.postMessage({
type: 'timed-metadata',
data: new Uint8Array(id3Tag(id3Frame('APIC',
0x03, // Text encoding: UTF-8
stringToCString('image/jpeg'), // MIME type + \0
0x03, // Picture type: Cover (front) [ID3v2.4.0 section 4.14]
stringToCString('sample description'), // Decription + \0
stringToInts('picture binary data')
),
id3Frame('APIC',
0x03, // Text encoding: UTF-8
stringToCString('-->'), // MIME type: link to the image [ID3v2.4.0 section 4.14] + \0
0x04, // Picture type: Cover (back) [ID3v2.4.0 section 4.14]
stringToCString('sample description 2'), // Decription + \0
stringToInts('http://example.org/cover-back.jpg')
)))
});
});
QUnit.test('can parse PRIV frames in web worker', function(assert) {
var payload = stringToInts('arbitrary'),
worker = new MetadataStreamTestWorker(),
done = assert.async();
worker.addEventListener('message', function(e) {
assert.equal(e.data.frames[0].key, 'PRIV', 'frame key is PRIV');
assert.deepEqual(new Uint8Array(e.data.frames[0].data), new Uint8Array(payload),
'parsed the frame private data');
worker.terminate();
done();
});
worker.postMessage({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
// header
data: new Uint8Array(id3Tag(id3Frame('PRIV',
stringToCString('priv-owner@example.com'),
payload)))
});
});
QUnit.test('can parse TXXX frames in web worker', function(assert) {
var worker = new MetadataStreamTestWorker(),
done = assert.async();
worker.addEventListener('message', function(e) {
assert.equal(e.data.frames[0].key, 'TXXX', 'frame key is TXXX');
assert.equal(e.data.frames[0].description, 'get done', 'parsed the description');
assert.deepEqual(JSON.parse(e.data.frames[0].data), { key: 'value' }, 'parsed the data');
worker.terminate();
done();
});
worker.postMessage({
type: 'timed-metadata',
trackId: 7,
pts: 1000,
dts: 900,
// header
data: new Uint8Array(id3Tag(id3Frame('TXXX',
0x03, // utf-8
stringToCString('get done'),
stringToCString('{ "key": "value" }')),
[0x00, 0x00]))
});
});
QUnit.test('should parse text frames in web worker', function(assert) {
var worker = new MetadataStreamTestWorker(),
done = assert.async();
worker.addEventListener('message', function(e) {
assert.equal(e.data.frames.length, 2, 'got 2 frames');
assert.equal(e.data.frames[0].key, 'TIT2', 'frame key is TIT2');
assert.equal(e.data.frames[0].value, 'sample song title', 'parsed value')
assert.equal(e.data.frames[0].values.length, 1, 'parsed value is an array of size 1')
assert.equal(e.data.frames[0].values[0], 'sample song title', 'parsed a non multiple strings value')
assert.equal(e.data.frames[1].key, 'TIT3', 'frame key is TIT3');
assert.equal(e.data.frames[1].value, 'sample title 1\0sample title 2', 'parsed value')
assert.equal(e.data.frames[1].values.length, 2, 'parsed value is an array of size 2')
assert.equal(e.data.frames[1].values[0], 'sample title 1', 'parsed 1st multiple strings value')
assert.equal(e.data.frames[1].values[1], 'sample title 2', 'parsed 2nd multiple strings value')
worker.terminate();
done();
});
worker.postMessage({
type: 'timed-metadata',
data: new Uint8Array(id3Tag(id3Frame('TIT2',
0x03, // utf-8
// frames that allow different types of encoding contain terminated text [ID3v2.4.0 section 4.]
stringToCString('sample song title')),
id3Frame('TIT3',
0x03, // utf-8
// frames that allow different types of encoding contain terminated text [ID3v2.4.0 section 4.]
// text information frames supports multiple strings, stored as a terminator separated list [ID3v2.4.0 section 4.2.]
stringToCString('sample title 1'), stringToCString('sample title 2'))))
});
});
QUnit.test('should parse URL link frames in web worker', function(assert) {
var worker = new MetadataStreamTestWorker(),
done = assert.async(),
payloadBytes;
// if the payload is followed by a string termination all the following information should be ignored [ID3v2.4.0 section 4.3]
payloadBytes = stringToInts('http://example.org\0 ignored \0 part')
worker.addEventListener('message', function(e) {
assert.equal(e.data.frames[0].key, 'WOAF', 'frame key is WOAF');
assert.equal(e.data.frames[0].url, 'http://example.org', 'parsed URL')
worker.terminate();
done();
});
worker.postMessage({
type: 'timed-metadata',
data: new Uint8Array(id3Tag(id3Frame('WOAF', payloadBytes)))
});
});
QUnit.test('triggers special event after parsing a timestamp ID3 tag', function(assert) {
var
array = new Uint8Array(73),
streamTimestamp = 'com.apple.streaming.transportStreamTimestamp',
priv = 'PRIV',
count = 0,
frame,
tag,
metadataStream,
chunk,
i;
metadataStream = new mp2t.MetadataStream();
metadataStream.on('timestamp', function(f) {
frame = f;
count += 1;
});
metadataStream.on('data', function(t) {
tag = t;
});
array[0] = 73;
array[1] = 68;
array[2] = 51;
array[3] = 4;
array[9] = 63;
array[17] = 53;
array[70] = 13;
array[71] = 187;
array[72] = 160;
for (i = 0; i < priv.length; i++) {
array[i + 10] = priv.charCodeAt(i);
}
for (i = 0; i < streamTimestamp.length; i++) {
array[i + 20] = streamTimestamp.charCodeAt(i);
}
chunk = {
type: 'timed-metadata',
data: array
};
metadataStream.push(chunk);
assert.equal(count, 1, 'timestamp event triggered once');
assert.equal(frame.timeStamp, 900000, 'Initial timestamp fired and calculated correctly');
assert.equal(tag.pts, 10 * 90e3, 'set tag PTS');
assert.equal(tag.dts, 10 * 90e3, 'set tag DTS');
});