Skip to content

Commit

Permalink
Add some simple FLV transmuxer smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrivera committed Nov 5, 2015
1 parent 18a72dc commit cb4836d
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lib/flv/transmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ VideoSegmentStream = function(track) {
h264Frame.startNalUnit();
h264Frame.writeBytes(currentNal.data);
}
if (h264Frame) {
this.finishFrame(tags, h264Frame);
}

this.trigger('data', {track: track, tags: tags});

Expand Down
2 changes: 2 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<script src="../lib/m2ts/caption-stream.js"></script>
<script src="../lib/m2ts/metadata-stream.js"></script>
<script src="../lib/mp4/transmuxer.js"></script>
<script src="../lib/flv/flv-tag.js"></script>
<script src="../lib/flv/transmuxer.js"></script>

<!-- test helpers -->
<script src="test-segment.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions test/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ module.exports = function(config) {
'../lib/m2ts/caption-stream.js',
'../lib/m2ts/metadata-stream.js',
'../lib/mp4/transmuxer.js',
'../lib/flv/flv-tag.js',
'../lib/flv/transmuxer.js',

'sintel-captions.js',
'test-segment.js',
Expand Down
110 changes: 108 additions & 2 deletions test/transmuxer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var
AacStream = muxjs.codecs.AacStream,
aacStream,
Transmuxer = muxjs.mp4.Transmuxer,
FlvTransmuxer = muxjs.flv.Transmuxer,
transmuxer,
NalByteStream = muxjs.codecs.NalByteStream,
nalByteStream,
Expand Down Expand Up @@ -1731,7 +1732,7 @@ test('can specify that we want to generate separate audio and video segments', f
equal('mdat', boxes[3].type, 'generated a mdat box');
});

module('Transmuxer', {
module('MP4 - Transmuxer', {
setup: function() {
transmuxer = new Transmuxer();
}
Expand Down Expand Up @@ -1792,7 +1793,7 @@ test('generates an audio init segment', function() {
equal('moov', boxes[1].type, 'generated a moov box');
});

test('buffers video samples until ended', function() {
test('buffers video samples until flushed', function() {
var samples = [], offset, boxes;
transmuxer.on('data', function(data) {
samples.push(data);
Expand Down Expand Up @@ -2195,4 +2196,109 @@ test('parses nal units split across multiple packets', function(){
deepEqual(nalUnits[0], new Uint8Array([0x09, 0xFF, 0x12, 0xDD]), 'has the proper payload');
});

module('FLV - Transmuxer', {
setup: function() {
transmuxer = new FlvTransmuxer();
}
});

test('generates video tags', function() {
var segments = [], boxes;
transmuxer.on('data', function(segment) {
segments.push(segment);
});
transmuxer.push(packetize(PAT));
transmuxer.push(packetize(generatePMT({
hasVideo: true
})));

transmuxer.push(packetize(videoPes([
0x09, 0x01 // access_unit_delimiter
], true)));
transmuxer.push(packetize(videoPes([
0x09, 0x01 // access_unit_delimiter
], true)));

transmuxer.flush();

equal(segments[0].tags.audioTags.length, 0, 'generated no audio tags');
equal(segments[0].tags.videoTags.length, 2, 'generated a two video tags');
});

test('drops nalUnits at the start of a segment not preceeded by an access_unit_delimiter_rbsp', function() {
var segments = [], boxes;
transmuxer.on('data', function(segment) {
segments.push(segment);
});
transmuxer.push(packetize(PAT));
transmuxer.push(packetize(generatePMT({
hasVideo: true
})));

transmuxer.push(packetize(videoPes([
0x08, 0x01 // pic_parameter_set_rbsp
], true)));
transmuxer.push(packetize(videoPes([
0x07, // seq_parameter_set_rbsp
0x27, 0x42, 0xe0, 0x0b,
0xa9, 0x18, 0x60, 0x9d,
0x80, 0x53, 0x06, 0x01,
0x06, 0xb6, 0xc2, 0xb5,
0xef, 0x7c, 0x04
], false)));
transmuxer.push(packetize(videoPes([
0x09, 0x01 // access_unit_delimiter
], true)));

transmuxer.flush();

equal(segments[0].tags.audioTags.length, 0, 'generated no audio tags');
equal(segments[0].tags.videoTags.length, 1, 'generated a single video tag');
});

test('generates an audio tags', function() {
var segments = [], boxes;
transmuxer.on('data', function(segment) {
segments.push(segment);
});
transmuxer.push(packetize(PAT));
transmuxer.push(packetize(generatePMT({
hasAudio: true
})));
transmuxer.push(packetize(audioPes([
0x19, 0x47
], true)));

transmuxer.flush();

equal(segments[0].tags.audioTags.length, 3, 'generated three audio tags');
equal(segments[0].tags.videoTags.length, 0, 'generated no video tags');
});

test('buffers video samples until flushed', function() {
var segments = [], offset, boxes;
transmuxer.on('data', function(data) {
segments.push(data);
});
transmuxer.push(packetize(PAT));
transmuxer.push(packetize(generatePMT({
hasVideo: true
})));

// buffer a NAL
transmuxer.push(packetize(videoPes([0x09, 0x01], true)));
transmuxer.push(packetize(videoPes([0x00, 0x02])));

// add an access_unit_delimiter_rbsp
transmuxer.push(packetize(videoPes([0x09, 0x03])));
transmuxer.push(packetize(videoPes([0x00, 0x04])));
transmuxer.push(packetize(videoPes([0x00, 0x05])));

// flush everything
transmuxer.flush();

equal(segments[0].tags.audioTags.length, 0, 'generated no audio tags');
equal(segments[0].tags.videoTags.length, 2, 'generated two video tags');
});

})(window, window.muxjs);

0 comments on commit cb4836d

Please sign in to comment.