9fa0bf90 by David LaPalomento

Integrate peg-based parser into qunit tests

Add the peg parser generation step to the gruntfile. Include the generated parser in the test harness page. Update many of the m3u8 tests to work with the new parser. There are a number of tests still failing. I believe this is because parts of the grammar are not sufficiently flexible to handle some optional parameters. For instance, #EXT-X-BYTE-RANGE is being glommed incorrectly into the #EXTINF definition and that's throwing off parsing. This commit is a progress checkpoint; things are definitely not working correctly.
1 parent 3f975913
1 'use strict'; 1 'use strict';
2 2
3 var peg = require('pegjs');
4
3 module.exports = function(grunt) { 5 module.exports = function(grunt) {
4 6
5 // Project configuration. 7 // Project configuration.
...@@ -12,7 +14,7 @@ module.exports = function(grunt) { ...@@ -12,7 +14,7 @@ module.exports = function(grunt) {
12 ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n', 14 ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
13 // Task configuration. 15 // Task configuration.
14 clean: { 16 clean: {
15 files: ['dist'] 17 files: ['build', 'dist']
16 }, 18 },
17 concat: { 19 concat: {
18 options: { 20 options: {
...@@ -95,8 +97,19 @@ module.exports = function(grunt) { ...@@ -95,8 +97,19 @@ module.exports = function(grunt) {
95 grunt.loadNpmTasks('grunt-contrib-jshint'); 97 grunt.loadNpmTasks('grunt-contrib-jshint');
96 grunt.loadNpmTasks('grunt-contrib-watch'); 98 grunt.loadNpmTasks('grunt-contrib-watch');
97 99
100 grunt.registerTask('peg', 'generate the manifest parser', function() {
101 var parser = peg.buildParser(grunt.file.read('src/m3u8/m3u8.pegjs'));
102 grunt.file.write('build/m3u8-parser.js',
103 'window.videojs.hls.M3U8Parser = ' + parser.toSource());
104 });
105
98 // Default task. 106 // Default task.
99 grunt.registerTask('default', 107 grunt.registerTask('default',
100 ['jshint', 'qunit', 'clean', 'concat', 'uglify']); 108 ['peg',
109 'jshint',
110 'qunit',
111 'clean',
112 'concat',
113 'uglify']);
101 114
102 }; 115 };
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
15 "grunt-contrib-jshint": "~0.6.0", 15 "grunt-contrib-jshint": "~0.6.0",
16 "grunt-contrib-qunit": "~0.2.0", 16 "grunt-contrib-qunit": "~0.2.0",
17 "grunt-contrib-concat": "~0.3.0", 17 "grunt-contrib-concat": "~0.3.0",
18 "grunt-contrib-nodeunit": "~0.1.2",
18 "grunt-contrib-uglify": "~0.2.0", 19 "grunt-contrib-uglify": "~0.2.0",
19 "grunt-contrib-watch": "~0.4.0", 20 "grunt-contrib-watch": "~0.4.0",
20 "grunt-contrib-clean": "~0.4.0", 21 "grunt-contrib-clean": "~0.4.0",
......
...@@ -269,13 +269,13 @@ number "number" ...@@ -269,13 +269,13 @@ number "number"
269 / parts:(int) _ { return parts; } 269 / parts:(int) _ { return parts; }
270 270
271 resolution 271 resolution
272 = width:int "x" height:int { return {resolution: {width: width, height: height}}; } 272 = width:int "x" height:int { return {width: width, height: height}; }
273 273
274 int 274 int
275 = first:digit19 rest:digits { return parseInt(first + rest.join(''), 10); } 275 = first:digit19 rest:digits { return parseInt(first + rest.join(''), 10); }
276 / digit:digit { return parseInt(digit, 10); } 276 / digit:digit { return parseInt(digit, 10); }
277 / neg:"-" first:digit19 rest:digits { return parseInt(neg + first + rest.join(''), 10); } 277 / neg:"-" first:digit19 rest:digits { return parseInt(neg + first + rest.join(''), 10); }
278 / neg:"-" digit { return parseInt(neg + digit, 10); } 278 / neg:"-" digit:digit { return parseInt(neg + digit, 10); }
279 279
280 hexint 280 hexint
281 = "0x" hexDigits:hexDigit+ { return '0x' + hexDigits.join(''); } 281 = "0x" hexDigits:hexDigit+ { return '0x' + hexDigits.join(''); }
......
1 (function (window) { 1 (function (window) {
2 var 2
3 M3U8Parser = window.videojs.hls.M3U8Parser; 3 var parser = window.videojs.hls.M3U8Parser;
4 4
5 window.videojs.hls.ManifestController = function() { 5 window.videojs.hls.ManifestController = function() {
6 var self = this; 6 var self = this;
...@@ -22,12 +22,8 @@ ...@@ -22,12 +22,8 @@
22 window.vjs.get(manifestUrl, self.onManifestLoadComplete, self.onManifestLoadError); 22 window.vjs.get(manifestUrl, self.onManifestLoadComplete, self.onManifestLoadError);
23 }; 23 };
24 24
25 self.parseManifest = function(dataAsString) { 25 self.parseManifest = function(manifest) {
26 self.parser = new M3U8Parser(); 26 return parser.parse(manifest);
27 self.parser.directory = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(self.url).slice(1)[1];
28 self.data = self.parser.parse(dataAsString);
29
30 return self.data;
31 }; 27 };
32 28
33 self.onManifestLoadComplete = function(response) { 29 self.onManifestLoadComplete = function(response) {
......
...@@ -44,7 +44,7 @@ window.playlistData = '#EXTM3U\n'+ ...@@ -44,7 +44,7 @@ window.playlistData = '#EXTM3U\n'+
44 'hls_450k_video.ts\n' + 44 'hls_450k_video.ts\n' +
45 '#EXTINF:10,\n' + 45 '#EXTINF:10,\n' +
46 '#EXT-X-BYTERANGE:468684@7108092\n' + 46 '#EXT-X-BYTERANGE:468684@7108092\n' +
47 'hls_450k_video.ts' + 47 'hls_450k_video.ts\n' +
48 '#EXTINF:10,\n' + 48 '#EXTINF:10,\n' +
49 '#EXT-X-BYTERANGE:444996@7576776\n' + 49 '#EXT-X-BYTERANGE:444996@7576776\n' +
50 'hls_450k_video.ts\n' + 50 'hls_450k_video.ts\n' +
......
...@@ -46,7 +46,7 @@ window.playlist_byte_range = '#EXTM3U\n'+ ...@@ -46,7 +46,7 @@ window.playlist_byte_range = '#EXTM3U\n'+
46 'hls_450k_video.ts\n' + 46 'hls_450k_video.ts\n' +
47 '#EXTINF:10,\n' + 47 '#EXTINF:10,\n' +
48 '#EXT-X-BYTERANGE:468684@7108092\n' + 48 '#EXT-X-BYTERANGE:468684@7108092\n' +
49 'hls_450k_video.ts' + 49 'hls_450k_video.ts\n' +
50 '#EXTINF:10,\n' + 50 '#EXTINF:10,\n' +
51 '#EXT-X-BYTERANGE:444996@7576776\n' + 51 '#EXT-X-BYTERANGE:444996@7576776\n' +
52 'hls_450k_video.ts\n' + 52 'hls_450k_video.ts\n' +
......
1 var fs = require('fs');
2 var path = require('path');
3 var manifest = fs.readFileSync(__dirname + '/fixtures/prog_index.m3u8').toString();
4 var parser = require('../src/m3u8/m3u8-generated.js');
5 var parsed = parser.parse(manifest);
6 console.log(parsed);
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
24 <!-- M3U8 --> 24 <!-- M3U8 -->
25 <script src="../src/m3u8/m3u8.js"></script> 25 <script src="../src/m3u8/m3u8.js"></script>
26 <script src="../src/m3u8/m3u8-tag-types.js"></script> 26 <script src="../src/m3u8/m3u8-tag-types.js"></script>
27 <script src="../src/m3u8/m3u8-parser.js"></script> 27 <script src="../build/m3u8-parser.js"></script>
28 <script src="../src/manifest-controller.js"></script> 28 <script src="../src/manifest-controller.js"></script>
29 <!-- M3U8 TEST DATA --> 29 <!-- M3U8 TEST DATA -->
30 <script src="manifest/playlistM3U8data.js"></script> 30 <script src="manifest/playlistM3U8data.js"></script>
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
43 43
44 <script src="../src/bin-utils.js"></script> 44 <script src="../src/bin-utils.js"></script>
45 45
46 <!-- Test cases -->
46 <script src="video-js-hls_test.js"></script> 47 <script src="video-js-hls_test.js"></script>
47 <script src="exp-golomb_test.js"></script> 48 <script src="exp-golomb_test.js"></script>
48 <script src="flv-tag_test.js"></script> 49 <script src="flv-tag_test.js"></script>
......