Simple ID3 parsing test
Create a test file for metadata streams and add a basic test for parsing an ID3 tag. The parser is not implemented yet so this test fails.
Showing
2 changed files
with
131 additions
and
0 deletions
test/metadata-stream_test.js
0 → 100644
1 | (function(window, videojs, undefined) { | ||
2 | 'use strict'; | ||
3 | /* | ||
4 | ======== A Handy Little QUnit Reference ======== | ||
5 | http://api.qunitjs.com/ | ||
6 | |||
7 | Test methods: | ||
8 | module(name, {[setup][ ,teardown]}) | ||
9 | test(name, callback) | ||
10 | expect(numberOfAssertions) | ||
11 | stop(increment) | ||
12 | start(decrement) | ||
13 | Test assertions: | ||
14 | ok(value, [message]) | ||
15 | equal(actual, expected, [message]) | ||
16 | notEqual(actual, expected, [message]) | ||
17 | deepEqual(actual, expected, [message]) | ||
18 | notDeepEqual(actual, expected, [message]) | ||
19 | strictEqual(actual, expected, [message]) | ||
20 | notStrictEqual(actual, expected, [message]) | ||
21 | throws(block, [expected], [message]) | ||
22 | */ | ||
23 | |||
24 | var metadataStream, stringToInts, stringToCString, id3Frame; | ||
25 | |||
26 | module('MetadataStream', { | ||
27 | setup: function() { | ||
28 | // metadataStream = new videojs.Hls.MetadataStream(); | ||
29 | } | ||
30 | }); | ||
31 | |||
32 | test('can construct a MetadataStream', function() { | ||
33 | ok(metadataStream, 'does not return null'); | ||
34 | }); | ||
35 | |||
36 | stringToInts = function(string) { | ||
37 | var result = [], i; | ||
38 | for (i = 0; i < string.length; i++) { | ||
39 | result[i] = string.charCodeAt(i); | ||
40 | } | ||
41 | return result; | ||
42 | }; | ||
43 | |||
44 | stringToCString = function(string) { | ||
45 | return stringToInts(string).concat([0x00]); | ||
46 | }; | ||
47 | |||
48 | id3Frame = function(type) { | ||
49 | var result = stringToInts(type).concat([ | ||
50 | 0x00, 0x00, 0x00, 0x00, // size | ||
51 | 0xe0, 0x00 // flags. tag/file alter preservation, read-only | ||
52 | ]), | ||
53 | size = result.length - 10; | ||
54 | |||
55 | // append the fields of the ID3 frame | ||
56 | result.concat(Array.prototype.slice.call(arguments, 1)); | ||
57 | |||
58 | // set the size | ||
59 | size = result.length - 10; | ||
60 | result[0] = (size >>> 24); | ||
61 | result[1] = (size >>> 16) & 0xff; | ||
62 | result[2] = (size >>> 8) & 0xff; | ||
63 | result[3] = (size) & 0xff; | ||
64 | |||
65 | return result; | ||
66 | }; | ||
67 | |||
68 | test('parses simple ID3 metadata out of PES packets', function() { | ||
69 | var events = [], id3Bytes, size; | ||
70 | // metadataStream.on('data', function(event) { | ||
71 | // events.push(event); | ||
72 | // }); | ||
73 | |||
74 | id3Bytes = new Uint8Array(stringToInts('ID3').concat([ | ||
75 | 0x03, 0x00, // version 3.0 of ID3v2 (aka ID3v.2.3.0) | ||
76 | 0x40, // flags. include an extended header | ||
77 | 0x00, 0x00, 0x00, 0x00, // size. set later | ||
78 | |||
79 | // extended header | ||
80 | 0x00, 0x00, 0x00, 0x01, // extended header size | ||
81 | 0x00, 0x00, // extended flags | ||
82 | 0x00, 0x00, 0x00, 0x02, // size of padding | ||
83 | 0xff // extended header payload | ||
84 | |||
85 | // frame 0 | ||
86 | // http://id3.org/id3v2.3.0#User_defined_text_information_frame | ||
87 | ], id3Frame('WXXX', | ||
88 | [0x00], // text encoding. ISO-8859-1 | ||
89 | stringToCString('ad tag URL'), // description | ||
90 | stringToInts('http://example.com/ad?v=1234&q=7')), // value | ||
91 | // frame 1 | ||
92 | // custom tag | ||
93 | id3Frame('XINF', | ||
94 | [ | ||
95 | 0x04, 0x03, 0x02, 0x01 // arbitrary data | ||
96 | ]), [ | ||
97 | 0x00, 0x00 // padding | ||
98 | ])); | ||
99 | |||
100 | // set header size field | ||
101 | size = id3Bytes.byteLength - 10; | ||
102 | id3Bytes[6] = (size >>> 21) & 0xef; | ||
103 | id3Bytes[7] = (size >>> 14) & 0xef; | ||
104 | id3Bytes[8] = (size >>> 7) & 0xef; | ||
105 | id3Bytes[9] = (size) & 0xef; | ||
106 | |||
107 | metadataStream.push({ | ||
108 | trackId: 7, | ||
109 | pts: 1000, | ||
110 | dts: 1000, | ||
111 | |||
112 | // header | ||
113 | data: id3Bytes | ||
114 | }); | ||
115 | |||
116 | equal(events.length, 1, 'parsed one tag'); | ||
117 | equal(events[0].frames.length, 2, 'parsed two frames'); | ||
118 | equal(events[0].frames[0].id, 'WXXX', 'parsed a WXXX frame'); | ||
119 | equal(events[0].frames[1].id, 'XINF', 'parsed a user-defined frame'); | ||
120 | }); | ||
121 | |||
122 | // missing cases: | ||
123 | // unsynchronization | ||
124 | // CRC | ||
125 | // no extended header | ||
126 | // compressed frames | ||
127 | // encrypted frames | ||
128 | // frame groups | ||
129 | |||
130 | })(window, videojs); |
... | @@ -55,6 +55,7 @@ | ... | @@ -55,6 +55,7 @@ |
55 | <script src="h264-stream_test.js"></script> | 55 | <script src="h264-stream_test.js"></script> |
56 | <script src="exp-golomb_test.js"></script> | 56 | <script src="exp-golomb_test.js"></script> |
57 | <script src="flv-tag_test.js"></script> | 57 | <script src="flv-tag_test.js"></script> |
58 | <script src="metadata-stream_test.js"></script> | ||
58 | <script src="m3u8_test.js"></script> | 59 | <script src="m3u8_test.js"></script> |
59 | <script src="playlist-loader_test.js"></script> | 60 | <script src="playlist-loader_test.js"></script> |
60 | <script src="decrypter_test.js"></script> | 61 | <script src="decrypter_test.js"></script> | ... | ... |
-
Please register or sign in to post a comment