a02c09db by David LaPalomento

Fix up dist production in Gruntfile and cleanup jshint in test cases

Explicitly list out source files so they are concatenated in the correct order in the final build.
1 parent dd4862c9
...@@ -20,7 +20,19 @@ module.exports = function(grunt) { ...@@ -20,7 +20,19 @@ module.exports = function(grunt) {
20 stripBanners: true 20 stripBanners: true
21 }, 21 },
22 dist: { 22 dist: {
23 src: ['src/*.js'], 23 src: ['src/video-js-hls.js',
24 'src/flv-tag.js',
25 'src/exp-golomb.js',
26 'src/h264-stream.js',
27 'src/aac-stream.js',
28 'src/segment-parser.js',
29 'src/segment-controller.js',
30 'src/m3u8/m3u8.js',
31 'src/m3u8/m3u8-tag-types.js',
32 'src/m3u8/m3u8-parser.js',
33 'src/manifest-controller.js',
34 'src/segment-controller.js',
35 'src/hls-playback-controller.js'],
24 dest: 'dist/videojs.hls.js' 36 dest: 'dist/videojs.hls.js'
25 }, 37 },
26 }, 38 },
...@@ -53,7 +65,7 @@ module.exports = function(grunt) { ...@@ -53,7 +65,7 @@ module.exports = function(grunt) {
53 options: { 65 options: {
54 jshintrc: 'test/.jshintrc' 66 jshintrc: 'test/.jshintrc'
55 }, 67 },
56 src: ['test/**/*.js', '!test/tsSegment.js'] 68 src: ['test/**/*.js', '!test/tsSegment.js', '!test/fixtures/*.js']
57 }, 69 },
58 }, 70 },
59 watch: { 71 watch: {
......
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
21 */ 21 */
22 var 22 var
23 buffer, 23 buffer,
24 expGolomb, 24 expGolomb;
25 view;
26 25
27 module('Exponential Golomb coding'); 26 module('Exponential Golomb coding');
28 27
......
...@@ -6,4 +6,4 @@ window.brightcove_playlist_data = '#EXTM3U\n'+ ...@@ -6,4 +6,4 @@ window.brightcove_playlist_data = '#EXTM3U\n'+
6 '#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=440000,RESOLUTION=396x224\n'+ 6 '#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=440000,RESOLUTION=396x224\n'+
7 'http://c.brightcove.com/services/mobile/streaming/index/rendition.m3u8?assetId=1824686593001&videoId=1824650741001\n'+ 7 'http://c.brightcove.com/services/mobile/streaming/index/rendition.m3u8?assetId=1824686593001&videoId=1824650741001\n'+
8 '#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1928000,RESOLUTION=960x540\n'+ 8 '#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1928000,RESOLUTION=960x540\n'+
9 'http://c.brightcove.com/services/mobile/streaming/index/rendition.m3u8?assetId=1824687660001&videoId=1824650741001'
...\ No newline at end of file ...\ No newline at end of file
9 'http://c.brightcove.com/services/mobile/streaming/index/rendition.m3u8?assetId=1824687660001&videoId=1824650741001';
......
1 (function (window) { 1 (function(window) {
2 /* 2 /*
3 ======== A Handy Little QUnit Reference ======== 3 ======== A Handy Little QUnit Reference ========
4 http://api.qunitjs.com/ 4 http://api.qunitjs.com/
...@@ -34,22 +34,23 @@ ...@@ -34,22 +34,23 @@
34 testScriptTag, 34 testScriptTag,
35 asciiFromBytes, 35 asciiFromBytes,
36 testScriptString, 36 testScriptString,
37 testScriptEcmaArray; 37 testScriptEcmaArray,
38 testNalUnit;
38 39
39 module('environment'); 40 module('environment');
40 41
41 test('is sane', function () { 42 test('is sane', function() {
42 expect(1); 43 expect(1);
43 ok(true); 44 ok(true);
44 }); 45 });
45 46
46 module('segment parser', { 47 module('segment parser', {
47 setup: function () { 48 setup: function() {
48 parser = new window.videojs.hls.SegmentParser(); 49 parser = new window.videojs.hls.SegmentParser();
49 } 50 }
50 }); 51 });
51 52
52 test('creates an flv header', function () { 53 test('creates an flv header', function() {
53 var header = Array.prototype.slice.call(parser.getFlvHeader()); 54 var header = Array.prototype.slice.call(parser.getFlvHeader());
54 ok(header, 'the header is truthy'); 55 ok(header, 'the header is truthy');
55 equal(9 + 4, header.length, 'the header length is correct'); 56 equal(9 + 4, header.length, 'the header length is correct');
...@@ -60,17 +61,13 @@ ...@@ -60,17 +61,13 @@
60 deepEqual(expectedHeader, header, 'the rest of the header is correct'); 61 deepEqual(expectedHeader, header, 'the rest of the header is correct');
61 }); 62 });
62 63
63 test('parses the first bipbop segment', function () { 64 test('parses the first bipbop segment', function() {
64 var tag, bytes, i;
65 parser.parseSegmentBinaryData(window.bcSegment); 65 parser.parseSegmentBinaryData(window.bcSegment);
66 66
67 ok(parser.tagsAvailable(), 'tags are available'); 67 ok(parser.tagsAvailable(), 'tags are available');
68
69 console.log('h264 tags:', parser.stats.h264Tags(),
70 'aac tags:', parser.stats.aacTags());
71 }); 68 });
72 69
73 testAudioTag = function (tag) { 70 testAudioTag = function(tag) {
74 var 71 var
75 byte = tag.bytes[11], 72 byte = tag.bytes[11],
76 format = (byte & 0xF0) >>> 4, 73 format = (byte & 0xF0) >>> 4,
...@@ -93,12 +90,10 @@ ...@@ -93,12 +90,10 @@
93 frameType = (byte & 0xF0) >>> 4, 90 frameType = (byte & 0xF0) >>> 4,
94 codecId = byte & 0x0F, 91 codecId = byte & 0x0F,
95 packetType = tag.bytes[12], 92 packetType = tag.bytes[12],
96 compositionTime = (tag.view.getInt32(13) & 0xFFFFFF00) >> 8, 93 compositionTime = (tag.view.getInt32(13) & 0xFFFFFF00) >> 8;
97 nalHeader;
98 94
99 // payload starts at tag.bytes[16] 95 // payload starts at tag.bytes[16]
100 96
101
102 // XXX: I'm not sure that frame types 3-5 are invalid 97 // XXX: I'm not sure that frame types 3-5 are invalid
103 ok(frameType === 1 || frameType === 2, 98 ok(frameType === 1 || frameType === 2,
104 'the frame type should be valid'); 99 'the frame type should be valid');
...@@ -120,10 +115,10 @@ ...@@ -120,10 +115,10 @@
120 } 115 }
121 }; 116 };
122 117
123 testNalUnit = function (bytes) { 118 testNalUnit = function(bytes) {
124 var 119 var
125 nalHeader = bytes[0], 120 nalHeader = bytes[0];
126 unitType = nalHeader & 0x1F; 121 // unitType = nalHeader & 0x1F;
127 122
128 equal(0, (nalHeader & 0x80) >>> 7, 'the first bit is always 0'); 123 equal(0, (nalHeader & 0x80) >>> 7, 'the first bit is always 0');
129 // equal(90, (nalHeader & 0x60) >>> 5, 'the NAL reference indicator is something'); 124 // equal(90, (nalHeader & 0x60) >>> 5, 'the NAL reference indicator is something');
...@@ -132,7 +127,7 @@ ...@@ -132,7 +127,7 @@
132 }; 127 };
133 128
134 129
135 asciiFromBytes = function (bytes) { 130 asciiFromBytes = function(bytes) {
136 var 131 var
137 string = [], 132 string = [],
138 i = bytes.byteLength; 133 i = bytes.byteLength;
...@@ -143,12 +138,11 @@ ...@@ -143,12 +138,11 @@
143 return string.join(''); 138 return string.join('');
144 }; 139 };
145 140
146 testScriptString = function (tag, offset, expected) { 141 testScriptString = function(tag, offset, expected) {
147 var 142 var
148 type = tag.bytes[offset], 143 type = tag.bytes[offset],
149 stringLength = tag.view.getUint16(offset + 1), 144 stringLength = tag.view.getUint16(offset + 1),
150 string, 145 string;
151 i = expected.length;
152 146
153 equal(2, type, 'the script element is of string type'); 147 equal(2, type, 'the script element is of string type');
154 equal(stringLength, expected.length, 'the script string length is correct'); 148 equal(stringLength, expected.length, 'the script string length is correct');
...@@ -157,7 +151,7 @@ ...@@ -157,7 +151,7 @@
157 equal(expected, string, 'the string value is "' + expected + '"'); 151 equal(expected, string, 'the string value is "' + expected + '"');
158 }; 152 };
159 153
160 testScriptEcmaArray = function (tag, start) { 154 testScriptEcmaArray = function(tag, start) {
161 var 155 var
162 numItems = tag.view.getUint32(start), 156 numItems = tag.view.getUint32(start),
163 i = numItems, 157 i = numItems,
...@@ -191,7 +185,7 @@ ...@@ -191,7 +185,7 @@
191 equal(tag.bytes[offset + 2], 9, 'the property array terminator is valid'); 185 equal(tag.bytes[offset + 2], 9, 'the property array terminator is valid');
192 }; 186 };
193 187
194 testScriptTag = function (tag) { 188 testScriptTag = function(tag) {
195 testScriptString(tag, 11, 'onMetaData'); 189 testScriptString(tag, 11, 'onMetaData');
196 190
197 // the onMetaData object is stored as an 'ecma array', an array with non- 191 // the onMetaData object is stored as an 'ecma array', an array with non-
...@@ -200,7 +194,7 @@ ...@@ -200,7 +194,7 @@
200 testScriptEcmaArray(tag, 25); 194 testScriptEcmaArray(tag, 25);
201 }; 195 };
202 196
203 test('the flv tags are well-formed', function () { 197 test('the flv tags are well-formed', function() {
204 var 198 var
205 tag, 199 tag,
206 byte, 200 byte,
...@@ -242,21 +236,21 @@ ...@@ -242,21 +236,21 @@
242 */ 236 */
243 237
244 module('m3u8 parser', { 238 module('m3u8 parser', {
245 setup: function () { 239 setup: function() {
246 m3u8parser = new window.videojs.hls.M3U8Parser(); 240 m3u8parser = new window.videojs.hls.M3U8Parser();
247 } 241 }
248 }); 242 });
249 243
250 test('should create my parser', function () { 244 test('should create my parser', function() {
251 ok(m3u8parser != undefined); 245 ok(m3u8parser !== undefined);
252 }); 246 });
253 247
254 test('should successfully parse manifest data', function () { 248 test('should successfully parse manifest data', function() {
255 var parsedData = m3u8parser.parse(window.playlistData); 249 var parsedData = m3u8parser.parse(window.playlistData);
256 ok(parsedData); 250 ok(parsedData);
257 }); 251 });
258 252
259 test('test for expected results', function () { 253 test('test for expected results', function() {
260 var data = m3u8parser.parse(window.playlistData); 254 var data = m3u8parser.parse(window.playlistData);
261 255
262 notEqual(data, null, 'data is not NULL'); 256 notEqual(data, null, 'data is not NULL');
...@@ -273,12 +267,12 @@ ...@@ -273,12 +267,12 @@
273 }); 267 });
274 268
275 module('brightcove playlist', { 269 module('brightcove playlist', {
276 setup: function () { 270 setup: function() {
277 m3u8parser = new window.videojs.hls.M3U8Parser(); 271 m3u8parser = new window.videojs.hls.M3U8Parser();
278 } 272 }
279 }); 273 });
280 274
281 test('should parse a brightcove manifest data', function () { 275 test('should parse a brightcove manifest data', function() {
282 var data = m3u8parser.parse(window.brightcove_playlist_data); 276 var data = m3u8parser.parse(window.brightcove_playlist_data);
283 277
284 ok(data); 278 ok(data);
...@@ -292,23 +286,23 @@ ...@@ -292,23 +286,23 @@
292 ); 286 );
293 287
294 module('manifest controller', { 288 module('manifest controller', {
295 setup: function () { 289 setup: function() {
296 manifestController = new window.videojs.hls.ManifestController(); 290 manifestController = new window.videojs.hls.ManifestController();
297 this.vjsget = vjs.get; 291 this.vjsget = window.videojs.get;
298 vjs.get = function (url, success, error) { 292 window.videojs.get = function(url, success) {
299 success(window.brightcove_playlist_data); 293 success(window.brightcove_playlist_data);
300 }; 294 };
301 }, 295 },
302 teardown: function () { 296 teardown: function() {
303 vjs.get = this.vjsget; 297 window.videojs.get = this.vjsget;
304 } 298 }
305 }); 299 });
306 300
307 test('should create', function () { 301 test('should create', function() {
308 ok(manifestController); 302 ok(manifestController);
309 }); 303 });
310 304
311 test('should return a parsed object', function () { 305 test('should return a parsed object', function() {
312 var data = manifestController.parseManifest(window.brightcove_playlist_data); 306 var data = manifestController.parseManifest(window.brightcove_playlist_data);
313 307
314 ok(data); 308 ok(data);
...@@ -319,33 +313,31 @@ ...@@ -319,33 +313,31 @@
319 equal(data.playlistItems[0].resolution.height, 224, 'First rendition index resolution height is correct'); 313 equal(data.playlistItems[0].resolution.height, 224, 'First rendition index resolution height is correct');
320 }); 314 });
321 315
322 test('should get a manifest from hermes', function () { 316 test('should get a manifest from hermes', function() {
323 manifestController.loadManifest('http://example.com/16x9-master.m3u8', 317 manifestController.loadManifest('http://example.com/16x9-master.m3u8',
324 function (responseData) { 318 function(responseData) {
325 ok(responseData); 319 ok(responseData);
326 }, 320 },
327 function (errorData) { 321 function() {
328 ok(false, 'does not error'); 322 ok(false, 'does not error');
329 }, 323 },
330 function (updateData) { 324 function() {});
331 });
332 }); 325 });
333 326
334 module('segment controller', { 327 module('segment controller', {
335 setup: function () { 328 setup: function() {
336 segmentController = new window.videojs.hls.SegmentController(); 329 segmentController = new window.videojs.hls.SegmentController();
337 this.vjsget = vjs.get; 330 this.vjsget = window.videojs.get;
338 vjs.get = function (url, success, error) { 331 window.videojs.get = function(url, success) {
339 console.log('load segment url', url);
340 success(window.bcSegment); 332 success(window.bcSegment);
341 }; 333 };
342 }, 334 },
343 teardown: function () { 335 teardown: function() {
344 vjs.get = this.vjsget; 336 window.videojs.get = this.vjsget;
345 } 337 }
346 }); 338 });
347 339
348 test('bandwidth calulation test', function () { 340 test('bandwidth calulation test', function() {
349 var 341 var
350 multiSecondData = segmentController.calculateThroughput(10000, 1000, 2000), 342 multiSecondData = segmentController.calculateThroughput(10000, 1000, 2000),
351 subSecondData = segmentController.calculateThroughput(10000, 1000, 1500); 343 subSecondData = segmentController.calculateThroughput(10000, 1000, 1500);
......