Browse Source

Boilerplate for the mp4 transmuxer

Add stubs for the transmuxer and a new set of qunit tests. Update the muxer mp4 test page to invoke the stubbed object.
pull/6/head
David LaPalomento 11 years ago
parent
commit
bacd3414cd
  1. 19
      src/transmuxer.js
  2. 1
      test/karma.conf.js
  3. 1
      test/localkarma.conf.js
  4. 21
      test/muxer/mp4.html
  5. 40
      test/transmuxer_test.js
  6. 2
      test/videojs-hls.html

19
src/transmuxer.js

@ -0,0 +1,19 @@
/**
* A stream-based mp2t to mp4 converter. This utility is used to
* deliver mp4s to a SourceBuffer on platforms that support native
* Media Source Extensions. The equivalent process for Flash-based
* platforms can be found in segment-parser.js
*/
(function(window, videojs, undefined) {
'use strict';
var Transmuxer = function() {
Transmuxer.prototype.init.call(this);
this.push = function() {
this.mp4 = new Uint8Array();
};
};
Transmuxer.prototype = new videojs.Hls.Stream();
window.videojs.Hls.Transmuxer = Transmuxer;
})(window, window.videojs);

1
test/karma.conf.js

@ -89,6 +89,7 @@ module.exports = function(config) {
'../src/playlist.js',
'../src/playlist-loader.js',
'../src/decrypter.js',
'../src/transmuxer.js',
'../tmp/manifests.js',
'../tmp/expected.js',
'tsSegment-bc.js',

1
test/localkarma.conf.js

@ -54,6 +54,7 @@ module.exports = function(config) {
'../src/playlist.js',
'../src/playlist-loader.js',
'../src/decrypter.js',
'../src/transmuxer.js',
'../tmp/manifests.js',
'../tmp/expected.js',
'tsSegment-bc.js',

21
test/muxer/mp4.html

@ -58,8 +58,8 @@
<h2>Comparison</h2>
<div class="result-wrapper">
<h3>videojs-contrib-hls</h3>
<ol class="vjs-boxes">
</ol>
<pre class="vjs-boxes">
</pre>
</div>
<div class="result-wrapper">
<h3>Working</h3>
@ -104,6 +104,8 @@
Hls: {}
};
</script>
<script src="../../src/stream.js"></script>
<script src="../../src/transmuxer.js"></script>
<script src="js/mp4-inspector.js"></script>
<script src="../../src/bin-utils.js"></script>
@ -129,14 +131,20 @@
original.addEventListener('change', function() {
var reader = new FileReader();
reader.addEventListener('loadend', function() {
var segment = new Uint8Array(reader.result),
transmuxer = new videojs.Hls.Transmuxer(),
hex = '';
var mp2t = new Uint8Array(reader.result);
transmuxer.push(segment);
// clear old boxes info
vjsBoxes.innerHTML = '';
vjsBoxes.innerHTML = JSON.stringify(videojs.inspectMp4(transmuxer.mp4), null, ' ');
// write out the result
// vjsOutput.innerHTML = hex;
hex += '<pre>';
hex += videojs.Hls.utils.hexDump(transmuxer.mp4);
hex += '</pre>';
vjsOutput.innerHTML = hex;
});
reader.readAsArrayBuffer(this.files[0]);
}, false);
@ -144,13 +152,14 @@
working.addEventListener('change', function() {
var reader = new FileReader();
reader.addEventListener('loadend', function() {
var hex = '<pre>',
var hex = '',
bytes = new Uint8Array(reader.result);
// clear old box info
workingBoxes.innerHTML = JSON.stringify(videojs.inspectMp4(bytes), null, ' ');
// output the hex dump
hex += '<pre>';
hex += videojs.Hls.utils.hexDump(bytes);
hex += '</pre>';
workingOutput.innerHTML = hex;

40
test/transmuxer_test.js

@ -0,0 +1,40 @@
(function(window, videojs) {
'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
Transmuxer = videojs.Hls.Transmuxer,
transmuxer;
module('MP4 Transmuxer', {
setup: function() {
transmuxer = new Transmuxer();
}
});
test('can mux an empty mp2t', function() {
transmuxer.push(new Uint8Array());
ok(transmuxer.mp4, 'produced a non-null result');
strictEqual(transmuxer.mp4.byteLength, 0, 'produced an empty mp4');
});
})(window, window.videojs);

2
test/videojs-hls.html

@ -43,6 +43,7 @@
<script src="../src/bin-utils.js"></script>
<!-- mp4 utilities -->
<script src="../src/transmuxer.js"></script>
<script src="muxer/js/mp4-inspector.js"></script>
<!-- Test cases -->
@ -63,6 +64,7 @@
<script src="playlist_test.js"></script>
<script src="playlist-loader_test.js"></script>
<script src="decrypter_test.js"></script>
<script src="transmuxer_test.js"></script>
<script src="mp4-inspector_test.js"></script>
</head>
<body>

Loading…
Cancel
Save