f239b405 by David LaPalomento

Fix up karma configuration and tests

Move dependencies into the right order. Stub out some end-to-end transmuxer tests.
1 parent bed2b294
......@@ -259,6 +259,9 @@ ParseStream.STREAM_TYPES = {
adts: 0x0f
};
/**
* Reconsistutes program stream packets from multiple transport stream packets.
*/
ProgramStream = function() {
var
// PES packet fragments
......@@ -303,7 +306,8 @@ ProgramStream = function() {
this.push = function(data) {
({
pat: function() {
self.trigger('data', data);
// we have to wait for the PMT to arrive as well before we
// have any meaningful metadata
},
pes: function() {
var stream, streamType;
......@@ -328,7 +332,29 @@ ProgramStream = function() {
stream.size += data.data.byteLength;
},
pmt: function() {
self.trigger('data', data);
var
event = {
type: 'metadata',
tracks: []
},
programMapTable = data.programMapTable,
k,
track;
// translate streams to tracks
for (k in programMapTable) {
if (programMapTable.hasOwnProperty(k)) {
track = {};
track.id = +k;
if (programMapTable[k] === H264_STREAM_TYPE) {
track.codec = 'avc';
} else if (programMapTable[k] === ADTS_STREAM_TYPE) {
track.codec = 'adts';
}
event.tracks.push(track);
}
}
self.trigger('data', event);
}
})[data.type]();
};
......@@ -361,6 +387,9 @@ Transmuxer = function() {
packetStream.pipe(parseStream);
parseStream.pipe(programStream);
// generate an init segment
this.initSegment = mp4.initSegment();
programStream.on('data', function(data) {
self.trigger('data', data);
});
......
......@@ -56,6 +56,7 @@ module.exports = function(config) {
'../src/decrypter.js',
'../src/transmuxer.js',
'../src/mp4-generator.js',
'../src/transmuxer.js',
'../tmp/manifests.js',
'../tmp/expected.js',
'tsSegment-bc.js',
......
......@@ -105,8 +105,8 @@
};
</script>
<script src="../../src/stream.js"></script>
<script src="../../src/transmuxer.js"></script>
<script src="../../src/mp4-generator.js"></script>
<script src="../../src/transmuxer.js"></script>
<script src="js/mp4-inspector.js"></script>
<script src="../../src/bin-utils.js"></script>
......@@ -153,24 +153,25 @@
var reader = new FileReader();
reader.addEventListener('loadend', function() {
var segment = new Uint8Array(reader.result),
packetizer = new videojs.mp2t.PacketStream(),
parser = new videojs.mp2t.ParseStream(),
transmuxer = new videojs.mp2t.Transmuxer(),
hex = '';
packetizer.pipe(parser);
packetizer.push(segment);
// clear old boxes info
transmuxer.on('data', function(data) {
if (data) {
console.log(data);
}
});
transmuxer.push(segment);
transmuxer.end();
// write out the result
hex += '<pre>';
hex += videojs.Hls.utils.hexDump(videojs.mp4.initSegment());
hex += 'nothing to see here';
hex += '</pre>';
vjsOutput.innerHTML = hex;
// XXX media source testing
vjsBoxes.innerHTML = JSON.stringify(videojs.inspectMp4(videojs.mp4.initSegment()), null, ' ');
vjsBoxes.innerHTML = 'nothing to see here';
});
reader.readAsArrayBuffer(this.files[0]);
}, false);
......
......@@ -27,6 +27,8 @@ var
parseStream,
ProgramStream = videojs.mp2t.ProgramStream,
programStream,
Transmuxer = videojs.mp2t.Transmuxer,
transmuxer,
MP2T_PACKET_LENGTH = videojs.mp2t.MP2T_PACKET_LENGTH,
H264_STREAM_TYPE = videojs.mp2t.H264_STREAM_TYPE,
......@@ -473,10 +475,15 @@ packetize = function(data) {
};
test('parses metadata events from PSI packets', function() {
var metadatas = 0, datas = 0;
var
metadatas = [],
datas = 0,
sortById = function(left, right) {
return left.id - right.id;
};
programStream.on('data', function(data) {
if (data.type === 'pat' || data.type === 'pmt') {
metadatas++;
if (data.type === 'metadata') {
metadatas.push(data);
}
datas++;
});
......@@ -484,11 +491,23 @@ test('parses metadata events from PSI packets', function() {
type: 'pat'
});
programStream.push({
type: 'pmt'
type: 'pmt',
programMapTable: {
1: 0x1b,
2: 0x0f
}
});
equal(2, datas, 'data fired');
equal(2, metadatas, 'metadata generated');
equal(1, datas, 'data fired');
equal(1, metadatas.length, 'metadata generated');
metadatas[0].tracks.sort(sortById);
deepEqual(metadatas[0].tracks, [{
id: 1,
codec: 'avc'
}, {
id: 2,
codec: 'adts'
}], 'identified two tracks');
});
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
equal(7, packets[2].data.byteLength, 'parsed the audio payload');
});
module('Transmuxer', {
setup: function() {
transmuxer = new Transmuxer();
}
});
test('generates an init segment', function() {
transmuxer.push(packetize(PAT));
transmuxer.push(packetize(PMT));
transmuxer.push(packetize(standalonePes));
ok(transmuxer.initSegment, 'has an init segment');
});
test('parses an example mp2t file and generates media segments', function() {
var segments = [];
transmuxer.on('data', function(segment) {
segments.push(segment);
});
transmuxer.push(window.bcSegment);
transmuxer.end();
ok(segments.length, 'generated media segments');
console.log(segments);
});
})(window, window.videojs);
......
......@@ -43,8 +43,8 @@
<script src="../src/bin-utils.js"></script>
<!-- mp4 utilities -->
<script src="../src/transmuxer.js"></script>
<script src="../src/mp4-generator.js"></script>
<script src="../src/transmuxer.js"></script>
<script src="muxer/js/mp4-inspector.js"></script>
<!-- Test cases -->
......