Fix up karma configuration and tests
Move dependencies into the right order. Stub out some end-to-end transmuxer tests.
Showing
5 changed files
with
95 additions
and
19 deletions
... | @@ -259,6 +259,9 @@ ParseStream.STREAM_TYPES = { | ... | @@ -259,6 +259,9 @@ ParseStream.STREAM_TYPES = { |
259 | adts: 0x0f | 259 | adts: 0x0f |
260 | }; | 260 | }; |
261 | 261 | ||
262 | /** | ||
263 | * Reconsistutes program stream packets from multiple transport stream packets. | ||
264 | */ | ||
262 | ProgramStream = function() { | 265 | ProgramStream = function() { |
263 | var | 266 | var |
264 | // PES packet fragments | 267 | // PES packet fragments |
... | @@ -303,7 +306,8 @@ ProgramStream = function() { | ... | @@ -303,7 +306,8 @@ ProgramStream = function() { |
303 | this.push = function(data) { | 306 | this.push = function(data) { |
304 | ({ | 307 | ({ |
305 | pat: function() { | 308 | pat: function() { |
306 | self.trigger('data', data); | 309 | // we have to wait for the PMT to arrive as well before we |
310 | // have any meaningful metadata | ||
307 | }, | 311 | }, |
308 | pes: function() { | 312 | pes: function() { |
309 | var stream, streamType; | 313 | var stream, streamType; |
... | @@ -328,7 +332,29 @@ ProgramStream = function() { | ... | @@ -328,7 +332,29 @@ ProgramStream = function() { |
328 | stream.size += data.data.byteLength; | 332 | stream.size += data.data.byteLength; |
329 | }, | 333 | }, |
330 | pmt: function() { | 334 | pmt: function() { |
331 | self.trigger('data', data); | 335 | var |
336 | event = { | ||
337 | type: 'metadata', | ||
338 | tracks: [] | ||
339 | }, | ||
340 | programMapTable = data.programMapTable, | ||
341 | k, | ||
342 | track; | ||
343 | |||
344 | // translate streams to tracks | ||
345 | for (k in programMapTable) { | ||
346 | if (programMapTable.hasOwnProperty(k)) { | ||
347 | track = {}; | ||
348 | track.id = +k; | ||
349 | if (programMapTable[k] === H264_STREAM_TYPE) { | ||
350 | track.codec = 'avc'; | ||
351 | } else if (programMapTable[k] === ADTS_STREAM_TYPE) { | ||
352 | track.codec = 'adts'; | ||
353 | } | ||
354 | event.tracks.push(track); | ||
355 | } | ||
356 | } | ||
357 | self.trigger('data', event); | ||
332 | } | 358 | } |
333 | })[data.type](); | 359 | })[data.type](); |
334 | }; | 360 | }; |
... | @@ -361,6 +387,9 @@ Transmuxer = function() { | ... | @@ -361,6 +387,9 @@ Transmuxer = function() { |
361 | packetStream.pipe(parseStream); | 387 | packetStream.pipe(parseStream); |
362 | parseStream.pipe(programStream); | 388 | parseStream.pipe(programStream); |
363 | 389 | ||
390 | // generate an init segment | ||
391 | this.initSegment = mp4.initSegment(); | ||
392 | |||
364 | programStream.on('data', function(data) { | 393 | programStream.on('data', function(data) { |
365 | self.trigger('data', data); | 394 | self.trigger('data', data); |
366 | }); | 395 | }); | ... | ... |
... | @@ -56,6 +56,7 @@ module.exports = function(config) { | ... | @@ -56,6 +56,7 @@ module.exports = function(config) { |
56 | '../src/decrypter.js', | 56 | '../src/decrypter.js', |
57 | '../src/transmuxer.js', | 57 | '../src/transmuxer.js', |
58 | '../src/mp4-generator.js', | 58 | '../src/mp4-generator.js', |
59 | '../src/transmuxer.js', | ||
59 | '../tmp/manifests.js', | 60 | '../tmp/manifests.js', |
60 | '../tmp/expected.js', | 61 | '../tmp/expected.js', |
61 | 'tsSegment-bc.js', | 62 | 'tsSegment-bc.js', | ... | ... |
... | @@ -105,8 +105,8 @@ | ... | @@ -105,8 +105,8 @@ |
105 | }; | 105 | }; |
106 | </script> | 106 | </script> |
107 | <script src="../../src/stream.js"></script> | 107 | <script src="../../src/stream.js"></script> |
108 | <script src="../../src/transmuxer.js"></script> | ||
109 | <script src="../../src/mp4-generator.js"></script> | 108 | <script src="../../src/mp4-generator.js"></script> |
109 | <script src="../../src/transmuxer.js"></script> | ||
110 | <script src="js/mp4-inspector.js"></script> | 110 | <script src="js/mp4-inspector.js"></script> |
111 | 111 | ||
112 | <script src="../../src/bin-utils.js"></script> | 112 | <script src="../../src/bin-utils.js"></script> |
... | @@ -153,24 +153,25 @@ | ... | @@ -153,24 +153,25 @@ |
153 | var reader = new FileReader(); | 153 | var reader = new FileReader(); |
154 | reader.addEventListener('loadend', function() { | 154 | reader.addEventListener('loadend', function() { |
155 | var segment = new Uint8Array(reader.result), | 155 | var segment = new Uint8Array(reader.result), |
156 | packetizer = new videojs.mp2t.PacketStream(), | 156 | transmuxer = new videojs.mp2t.Transmuxer(), |
157 | parser = new videojs.mp2t.ParseStream(), | ||
158 | hex = ''; | 157 | hex = ''; |
159 | 158 | ||
160 | packetizer.pipe(parser); | ||
161 | packetizer.push(segment); | ||
162 | 159 | ||
163 | // clear old boxes info | 160 | transmuxer.on('data', function(data) { |
161 | if (data) { | ||
162 | console.log(data); | ||
163 | } | ||
164 | }); | ||
165 | transmuxer.push(segment); | ||
166 | transmuxer.end(); | ||
164 | 167 | ||
165 | // write out the result | 168 | // write out the result |
166 | hex += '<pre>'; | 169 | hex += '<pre>'; |
167 | hex += videojs.Hls.utils.hexDump(videojs.mp4.initSegment()); | 170 | hex += 'nothing to see here'; |
168 | hex += '</pre>'; | 171 | hex += '</pre>'; |
169 | vjsOutput.innerHTML = hex; | 172 | vjsOutput.innerHTML = hex; |
170 | 173 | ||
171 | // XXX media source testing | 174 | vjsBoxes.innerHTML = 'nothing to see here'; |
172 | |||
173 | vjsBoxes.innerHTML = JSON.stringify(videojs.inspectMp4(videojs.mp4.initSegment()), null, ' '); | ||
174 | }); | 175 | }); |
175 | reader.readAsArrayBuffer(this.files[0]); | 176 | reader.readAsArrayBuffer(this.files[0]); |
176 | }, false); | 177 | }, false); | ... | ... |
... | @@ -27,6 +27,8 @@ var | ... | @@ -27,6 +27,8 @@ var |
27 | parseStream, | 27 | parseStream, |
28 | ProgramStream = videojs.mp2t.ProgramStream, | 28 | ProgramStream = videojs.mp2t.ProgramStream, |
29 | programStream, | 29 | programStream, |
30 | Transmuxer = videojs.mp2t.Transmuxer, | ||
31 | transmuxer, | ||
30 | 32 | ||
31 | MP2T_PACKET_LENGTH = videojs.mp2t.MP2T_PACKET_LENGTH, | 33 | MP2T_PACKET_LENGTH = videojs.mp2t.MP2T_PACKET_LENGTH, |
32 | H264_STREAM_TYPE = videojs.mp2t.H264_STREAM_TYPE, | 34 | H264_STREAM_TYPE = videojs.mp2t.H264_STREAM_TYPE, |
... | @@ -473,10 +475,15 @@ packetize = function(data) { | ... | @@ -473,10 +475,15 @@ packetize = function(data) { |
473 | }; | 475 | }; |
474 | 476 | ||
475 | test('parses metadata events from PSI packets', function() { | 477 | test('parses metadata events from PSI packets', function() { |
476 | var metadatas = 0, datas = 0; | 478 | var |
479 | metadatas = [], | ||
480 | datas = 0, | ||
481 | sortById = function(left, right) { | ||
482 | return left.id - right.id; | ||
483 | }; | ||
477 | programStream.on('data', function(data) { | 484 | programStream.on('data', function(data) { |
478 | if (data.type === 'pat' || data.type === 'pmt') { | 485 | if (data.type === 'metadata') { |
479 | metadatas++; | 486 | metadatas.push(data); |
480 | } | 487 | } |
481 | datas++; | 488 | datas++; |
482 | }); | 489 | }); |
... | @@ -484,11 +491,23 @@ test('parses metadata events from PSI packets', function() { | ... | @@ -484,11 +491,23 @@ test('parses metadata events from PSI packets', function() { |
484 | type: 'pat' | 491 | type: 'pat' |
485 | }); | 492 | }); |
486 | programStream.push({ | 493 | programStream.push({ |
487 | type: 'pmt' | 494 | type: 'pmt', |
495 | programMapTable: { | ||
496 | 1: 0x1b, | ||
497 | 2: 0x0f | ||
498 | } | ||
488 | }); | 499 | }); |
489 | 500 | ||
490 | equal(2, datas, 'data fired'); | 501 | equal(1, datas, 'data fired'); |
491 | equal(2, metadatas, 'metadata generated'); | 502 | equal(1, metadatas.length, 'metadata generated'); |
503 | metadatas[0].tracks.sort(sortById); | ||
504 | deepEqual(metadatas[0].tracks, [{ | ||
505 | id: 1, | ||
506 | codec: 'avc' | ||
507 | }, { | ||
508 | id: 2, | ||
509 | codec: 'adts' | ||
510 | }], 'identified two tracks'); | ||
492 | }); | 511 | }); |
493 | 512 | ||
494 | test('parses standalone program stream packets', function() { | 513 | test('parses standalone program stream packets', function() { |
... | @@ -609,4 +628,30 @@ test('flushes the buffered packets when a new one of that type is started', func | ... | @@ -609,4 +628,30 @@ test('flushes the buffered packets when a new one of that type is started', func |
609 | equal(7, packets[2].data.byteLength, 'parsed the audio payload'); | 628 | equal(7, packets[2].data.byteLength, 'parsed the audio payload'); |
610 | }); | 629 | }); |
611 | 630 | ||
631 | module('Transmuxer', { | ||
632 | setup: function() { | ||
633 | transmuxer = new Transmuxer(); | ||
634 | } | ||
635 | }); | ||
636 | |||
637 | test('generates an init segment', function() { | ||
638 | transmuxer.push(packetize(PAT)); | ||
639 | transmuxer.push(packetize(PMT)); | ||
640 | transmuxer.push(packetize(standalonePes)); | ||
641 | |||
642 | ok(transmuxer.initSegment, 'has an init segment'); | ||
643 | }); | ||
644 | |||
645 | test('parses an example mp2t file and generates media segments', function() { | ||
646 | var segments = []; | ||
647 | transmuxer.on('data', function(segment) { | ||
648 | segments.push(segment); | ||
649 | }); | ||
650 | transmuxer.push(window.bcSegment); | ||
651 | transmuxer.end(); | ||
652 | |||
653 | ok(segments.length, 'generated media segments'); | ||
654 | console.log(segments); | ||
655 | }); | ||
656 | |||
612 | })(window, window.videojs); | 657 | })(window, window.videojs); | ... | ... |
... | @@ -43,8 +43,8 @@ | ... | @@ -43,8 +43,8 @@ |
43 | <script src="../src/bin-utils.js"></script> | 43 | <script src="../src/bin-utils.js"></script> |
44 | 44 | ||
45 | <!-- mp4 utilities --> | 45 | <!-- mp4 utilities --> |
46 | <script src="../src/transmuxer.js"></script> | ||
47 | <script src="../src/mp4-generator.js"></script> | 46 | <script src="../src/mp4-generator.js"></script> |
47 | <script src="../src/transmuxer.js"></script> | ||
48 | <script src="muxer/js/mp4-inspector.js"></script> | 48 | <script src="muxer/js/mp4-inspector.js"></script> |
49 | 49 | ||
50 | <!-- Test cases --> | 50 | <!-- Test cases --> | ... | ... |
-
Please register or sign in to post a comment