92b03b90 by Simeon Bateman Committed by David LaPalomento

setup the generator to separate audio and video init files.

1 parent a545f184
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
2 'use strict'; 2 'use strict';
3 3
4 var box, dinf, ftyp, minf, moof, moov, mvex, mvhd, trak, tkhd, mdia, mdhd, hdlr, stbl, 4 var box, dinf, ftyp, minf, moof, moov, mvex, mvhd, trak, tkhd, mdia, mdhd, hdlr, stbl,
5 stsd, types, MAJOR_BRAND, MINOR_VERSION, VIDEO_HDLR, VMHD, DREF, STCO, STSC, STSZ, STTS, TREX, 5 stsd, styp, types, MAJOR_BRAND, MINOR_VERSION, VIDEO_HDLR, AUDIO_HDLR, HDLR_TYPES, VMHD, DREF, STCO, STSC, STSZ, STTS, TREX,
6 Uint8Array, DataView; 6 Uint8Array, DataView;
7 7
8 Uint8Array = window.Uint8Array; 8 Uint8Array = window.Uint8Array;
...@@ -72,7 +72,7 @@ DataView = window.DataView; ...@@ -72,7 +72,7 @@ DataView = window.DataView;
72 0x6f, 0x48, 0x61, 0x6e, 72 0x6f, 0x48, 0x61, 0x6e,
73 0x64, 0x6c, 0x65, 0x72, 0x00 // name: 'VideoHandler' 73 0x64, 0x6c, 0x65, 0x72, 0x00 // name: 'VideoHandler'
74 ]); 74 ]);
75 SOUND_HDLR = new Uint8Array([ 75 AUDIO_HDLR = new Uint8Array([
76 0x00, // version 0 76 0x00, // version 0
77 0x00, 0x00, 0x00, // flags 77 0x00, 0x00, 0x00, // flags
78 0x00, 0x00, 0x00, 0x00, // pre_defined 78 0x00, 0x00, 0x00, 0x00, // pre_defined
...@@ -80,10 +80,14 @@ DataView = window.DataView; ...@@ -80,10 +80,14 @@ DataView = window.DataView;
80 0x00, 0x00, 0x00, 0x00, // reserved 80 0x00, 0x00, 0x00, 0x00, // reserved
81 0x00, 0x00, 0x00, 0x00, // reserved 81 0x00, 0x00, 0x00, 0x00, // reserved
82 0x00, 0x00, 0x00, 0x00, // reserved 82 0x00, 0x00, 0x00, 0x00, // reserved
83 0x56, 0x69, 0x64, 0x65, 83 0x53, 0x6f, 0x75, 0x6e,
84 0x6f, 0x48, 0x61, 0x6e, 84 0x64, 0x48, 0x61, 0x6e,
85 0x73, 0x6f, 0x75, 0x6e, 0x00 // name: 'VideoHandler' 85 0x64, 0x6c, 0x65, 0x72, 0x00 // name: 'SoundHandler'
86 ]); 86 ]);
87 HDLR_TYPES = {
88 "video":VIDEO_HDLR,
89 "audio": AUDIO_HDLR
90 };
87 DREF = new Uint8Array([ 91 DREF = new Uint8Array([
88 0x00, // version 0 92 0x00, // version 0
89 0x00, 0x00, 0x00, // flags 93 0x00, 0x00, 0x00, // flags
...@@ -158,8 +162,8 @@ ftyp = function() { ...@@ -158,8 +162,8 @@ ftyp = function() {
158 return box(types.ftyp, MAJOR_BRAND, MINOR_VERSION, MAJOR_BRAND); 162 return box(types.ftyp, MAJOR_BRAND, MINOR_VERSION, MAJOR_BRAND);
159 }; 163 };
160 164
161 hdlr = function() { 165 hdlr = function(type) {
162 return box(types.hdlr, VIDEO_HDLR); 166 return box(types.hdlr, HDLR_TYPES[type]);
163 }; 167 };
164 mdhd = function(duration) { 168 mdhd = function(duration) {
165 return box(types.mdhd, new Uint8Array([ 169 return box(types.mdhd, new Uint8Array([
...@@ -177,8 +181,8 @@ mdhd = function(duration) { ...@@ -177,8 +181,8 @@ mdhd = function(duration) {
177 0x00, 0x00 181 0x00, 0x00
178 ])); 182 ]));
179 }; 183 };
180 mdia = function(duration, width, height) { 184 mdia = function(duration, width, height, type) {
181 return box(types.mdia, mdhd(duration), hdlr(), minf(width, height)); 185 return box(types.mdia, mdhd(duration), hdlr(type), minf(width, height));
182 }; 186 };
183 minf = function(width, height) { 187 minf = function(width, height) {
184 return box(types.minf, box(types.vmhd, VMHD), dinf(), stbl(width, height)); 188 return box(types.minf, box(types.vmhd, VMHD), dinf(), stbl(width, height));
...@@ -203,8 +207,8 @@ moof = function(tracks) { ...@@ -203,8 +207,8 @@ moof = function(tracks) {
203 box(types.mfhd), 207 box(types.mfhd),
204 box.apply(null, trafCall)); 208 box.apply(null, trafCall));
205 }; 209 };
206 moov = function(duration, width, height) { 210 moov = function(duration, width, height, type) {
207 return box(types.moov, mvhd(duration), trak(duration, width, height), mvex()); 211 return box(types.moov, mvhd(duration), trak(duration, width, height, type), mvex());
208 }; 212 };
209 mvex = function() { 213 mvex = function() {
210 return box(types.mvex, box(types.trex, TREX)); 214 return box(types.mvex, box(types.trex, TREX));
...@@ -349,8 +353,8 @@ tkhd = function(duration, width, height) { ...@@ -349,8 +353,8 @@ tkhd = function(duration, width, height) {
349 ])); 353 ]));
350 }; 354 };
351 355
352 trak = function(duration, width, height) { 356 trak = function(duration, width, height, type) {
353 return box(types.trak, tkhd(duration, width, height), mdia(duration, width, height)); 357 return box(types.trak, tkhd(duration, width, height), mdia(duration, width, height, type));
354 }; 358 };
355 359
356 window.videojs.mp4 = { 360 window.videojs.mp4 = {
...@@ -360,7 +364,7 @@ window.videojs.mp4 = { ...@@ -360,7 +364,7 @@ window.videojs.mp4 = {
360 initSegment: function() { 364 initSegment: function() {
361 var 365 var
362 fileType = ftyp(), 366 fileType = ftyp(),
363 movie = moov(0xffffffff, 1280, 720), 367 movie = moov(0xffffffff, 1280, 720, "video"),
364 result = new Uint8Array(fileType.byteLength + movie.byteLength); 368 result = new Uint8Array(fileType.byteLength + movie.byteLength);
365 369
366 result.set(fileType); 370 result.set(fileType);
......
...@@ -41,7 +41,7 @@ test('generates a BSMFF ftyp', function() { ...@@ -41,7 +41,7 @@ test('generates a BSMFF ftyp', function() {
41 41
42 test('generates a moov', function() { 42 test('generates a moov', function() {
43 var boxes, mvhd, tkhd, mdhd, hdlr, minf, mvex, 43 var boxes, mvhd, tkhd, mdhd, hdlr, minf, mvex,
44 data = mp4.moov(100, 600, 300); 44 data = mp4.moov(100, 600, 300, "video");
45 45
46 ok(data, 'box is not null'); 46 ok(data, 'box is not null');
47 47
...@@ -204,6 +204,34 @@ test('generates a moov', function() { ...@@ -204,6 +204,34 @@ test('generates a moov', function() {
204 }, mvex, 'writes a movie extends box'); 204 }, mvex, 'writes a movie extends box');
205 }); 205 });
206 206
207 test('generates a sound hdlr', function() {
208 var boxes, hdlr,
209 data = mp4.moov(100, 600, 300, "audio");
210
211 ok(data, 'box is not null');
212
213 boxes = inspectMp4(data);
214
215 hdlr = boxes[0].boxes[1].boxes[1].boxes[1];
216 equal(hdlr.type, 'hdlr', 'generate an hdlr type');
217 equal(hdlr.handlerType, 'soun', 'wrote a sound handler');
218 equal(hdlr.name, 'SoundHandler', 'wrote the handler name');
219 });
220
221 test('generates a video hdlr', function() {
222 var boxes, hdlr,
223 data = mp4.moov(100, 600, 300, "video");
224
225 ok(data, 'box is not null');
226
227 boxes = inspectMp4(data);
228
229 hdlr = boxes[0].boxes[1].boxes[1].boxes[1];
230 equal(hdlr.type, 'hdlr', 'generate an hdlr type');
231 equal(hdlr.handlerType, 'vide', 'wrote a video handler');
232 equal(hdlr.name, 'VideoHandler', 'wrote the handler name');
233 });
234
207 test('generates an initialization segment', function() { 235 test('generates an initialization segment', function() {
208 var 236 var
209 data = mp4.initSegment(), 237 data = mp4.initSegment(),
......