bacd3414 by David LaPalomento

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.
1 parent 5e95014b
1 /**
2 * A stream-based mp2t to mp4 converter. This utility is used to
3 * deliver mp4s to a SourceBuffer on platforms that support native
4 * Media Source Extensions. The equivalent process for Flash-based
5 * platforms can be found in segment-parser.js
6 */
7 (function(window, videojs, undefined) {
8 'use strict';
9
10 var Transmuxer = function() {
11 Transmuxer.prototype.init.call(this);
12 this.push = function() {
13 this.mp4 = new Uint8Array();
14 };
15 };
16 Transmuxer.prototype = new videojs.Hls.Stream();
17
18 window.videojs.Hls.Transmuxer = Transmuxer;
19 })(window, window.videojs);
...@@ -89,6 +89,7 @@ module.exports = function(config) { ...@@ -89,6 +89,7 @@ module.exports = function(config) {
89 '../src/playlist.js', 89 '../src/playlist.js',
90 '../src/playlist-loader.js', 90 '../src/playlist-loader.js',
91 '../src/decrypter.js', 91 '../src/decrypter.js',
92 '../src/transmuxer.js',
92 '../tmp/manifests.js', 93 '../tmp/manifests.js',
93 '../tmp/expected.js', 94 '../tmp/expected.js',
94 'tsSegment-bc.js', 95 'tsSegment-bc.js',
......
...@@ -54,6 +54,7 @@ module.exports = function(config) { ...@@ -54,6 +54,7 @@ module.exports = function(config) {
54 '../src/playlist.js', 54 '../src/playlist.js',
55 '../src/playlist-loader.js', 55 '../src/playlist-loader.js',
56 '../src/decrypter.js', 56 '../src/decrypter.js',
57 '../src/transmuxer.js',
57 '../tmp/manifests.js', 58 '../tmp/manifests.js',
58 '../tmp/expected.js', 59 '../tmp/expected.js',
59 'tsSegment-bc.js', 60 'tsSegment-bc.js',
......
...@@ -58,8 +58,8 @@ ...@@ -58,8 +58,8 @@
58 <h2>Comparison</h2> 58 <h2>Comparison</h2>
59 <div class="result-wrapper"> 59 <div class="result-wrapper">
60 <h3>videojs-contrib-hls</h3> 60 <h3>videojs-contrib-hls</h3>
61 <ol class="vjs-boxes"> 61 <pre class="vjs-boxes">
62 </ol> 62 </pre>
63 </div> 63 </div>
64 <div class="result-wrapper"> 64 <div class="result-wrapper">
65 <h3>Working</h3> 65 <h3>Working</h3>
...@@ -104,6 +104,8 @@ ...@@ -104,6 +104,8 @@
104 Hls: {} 104 Hls: {}
105 }; 105 };
106 </script> 106 </script>
107 <script src="../../src/stream.js"></script>
108 <script src="../../src/transmuxer.js"></script>
107 <script src="js/mp4-inspector.js"></script> 109 <script src="js/mp4-inspector.js"></script>
108 110
109 <script src="../../src/bin-utils.js"></script> 111 <script src="../../src/bin-utils.js"></script>
...@@ -129,14 +131,20 @@ ...@@ -129,14 +131,20 @@
129 original.addEventListener('change', function() { 131 original.addEventListener('change', function() {
130 var reader = new FileReader(); 132 var reader = new FileReader();
131 reader.addEventListener('loadend', function() { 133 reader.addEventListener('loadend', function() {
134 var segment = new Uint8Array(reader.result),
135 transmuxer = new videojs.Hls.Transmuxer(),
136 hex = '';
132 137
133 var mp2t = new Uint8Array(reader.result); 138 transmuxer.push(segment);
134 139
135 // clear old boxes info 140 // clear old boxes info
136 vjsBoxes.innerHTML = ''; 141 vjsBoxes.innerHTML = JSON.stringify(videojs.inspectMp4(transmuxer.mp4), null, ' ');
137 142
138 // write out the result 143 // write out the result
139 // vjsOutput.innerHTML = hex; 144 hex += '<pre>';
145 hex += videojs.Hls.utils.hexDump(transmuxer.mp4);
146 hex += '</pre>';
147 vjsOutput.innerHTML = hex;
140 }); 148 });
141 reader.readAsArrayBuffer(this.files[0]); 149 reader.readAsArrayBuffer(this.files[0]);
142 }, false); 150 }, false);
...@@ -144,13 +152,14 @@ ...@@ -144,13 +152,14 @@
144 working.addEventListener('change', function() { 152 working.addEventListener('change', function() {
145 var reader = new FileReader(); 153 var reader = new FileReader();
146 reader.addEventListener('loadend', function() { 154 reader.addEventListener('loadend', function() {
147 var hex = '<pre>', 155 var hex = '',
148 bytes = new Uint8Array(reader.result); 156 bytes = new Uint8Array(reader.result);
149 157
150 // clear old box info 158 // clear old box info
151 workingBoxes.innerHTML = JSON.stringify(videojs.inspectMp4(bytes), null, ' '); 159 workingBoxes.innerHTML = JSON.stringify(videojs.inspectMp4(bytes), null, ' ');
152 160
153 // output the hex dump 161 // output the hex dump
162 hex += '<pre>';
154 hex += videojs.Hls.utils.hexDump(bytes); 163 hex += videojs.Hls.utils.hexDump(bytes);
155 hex += '</pre>'; 164 hex += '</pre>';
156 workingOutput.innerHTML = hex; 165 workingOutput.innerHTML = hex;
......
1 (function(window, videojs) {
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 var
24 Transmuxer = videojs.Hls.Transmuxer,
25 transmuxer;
26
27 module('MP4 Transmuxer', {
28 setup: function() {
29 transmuxer = new Transmuxer();
30 }
31 });
32
33 test('can mux an empty mp2t', function() {
34 transmuxer.push(new Uint8Array());
35
36 ok(transmuxer.mp4, 'produced a non-null result');
37 strictEqual(transmuxer.mp4.byteLength, 0, 'produced an empty mp4');
38 });
39
40 })(window, window.videojs);
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
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>
46 <script src="muxer/js/mp4-inspector.js"></script> 47 <script src="muxer/js/mp4-inspector.js"></script>
47 48
48 <!-- Test cases --> 49 <!-- Test cases -->
...@@ -63,6 +64,7 @@ ...@@ -63,6 +64,7 @@
63 <script src="playlist_test.js"></script> 64 <script src="playlist_test.js"></script>
64 <script src="playlist-loader_test.js"></script> 65 <script src="playlist-loader_test.js"></script>
65 <script src="decrypter_test.js"></script> 66 <script src="decrypter_test.js"></script>
67 <script src="transmuxer_test.js"></script>
66 <script src="mp4-inspector_test.js"></script> 68 <script src="mp4-inspector_test.js"></script>
67 </head> 69 </head>
68 <body> 70 <body>
......