e13e2ae8 by Gary Katsevman

initial plugin->tech conversion

1 parent fafd0563
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 <link href="node_modules/video.js/dist/video-js/video-js.css" rel="stylesheet"> 7 <link href="node_modules/video.js/dist/video-js/video-js.css" rel="stylesheet">
8 8
9 <!-- video.js --> 9 <!-- video.js -->
10 <script src="node_modules/video.js/dist/video-js/video.js"></script> 10 <script src="node_modules/video.js/dist/video-js/video.dev.js"></script>
11 11
12 <!-- Media Sources plugin --> 12 <!-- Media Sources plugin -->
13 <script src="node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script> 13 <script src="node_modules/videojs-contrib-media-sources/src/videojs-media-sources.js"></script>
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
31 <!-- bipbop --> 31 <!-- bipbop -->
32 <!-- <script src="test/tsSegment.js"></script> --> 32 <!-- <script src="test/tsSegment.js"></script> -->
33 <!-- bunnies --> 33 <!-- bunnies -->
34 <script src="test/tsSegment-bc.js"></script> 34 <!--<script src="test/tsSegment-bc.js"></script>-->
35 35
36 <style> 36 <style>
37 body { 37 body {
...@@ -63,10 +63,12 @@ ...@@ -63,10 +63,12 @@
63 <script> 63 <script>
64 videojs.options.flash.swf = 'node_modules/video.js/dist/video-js/video-js.swf'; 64 videojs.options.flash.swf = 'node_modules/video.js/dist/video-js/video-js.swf';
65 // initialize the player 65 // initialize the player
66 var player = videojs('video'); 66 var player = videojs('video', {
67 techOrder: ['hls']
68 });
67 69
68 // initialize the plugin 70 // initialize the plugin
69 player.hls(); 71 //player.hls()
70 </script> 72 </script>
71 </body> 73 </body>
72 </html> 74 </html>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
8 8
9 (function(window) { 9 (function(window) {
10 var 10 var
11 FlvTag = window.videojs.hls.FlvTag, 11 FlvTag = window.videojs.Hls.FlvTag,
12 adtsSampleingRates = [ 12 adtsSampleingRates = [
13 96000, 88200, 13 96000, 88200,
14 64000, 48000, 14 64000, 48000,
...@@ -17,7 +17,7 @@ var ...@@ -17,7 +17,7 @@ var
17 16000, 12000 17 16000, 12000
18 ]; 18 ];
19 19
20 window.videojs.hls.AacStream = function() { 20 window.videojs.Hls.AacStream = function() {
21 var 21 var
22 next_pts, // :uint 22 next_pts, // :uint
23 pts_offset, // :int 23 pts_offset, // :int
......
...@@ -29,5 +29,5 @@ ...@@ -29,5 +29,5 @@
29 } 29 }
30 }; 30 };
31 31
32 window.videojs.hls.utils = module; 32 window.videojs.Hls.utils = module;
33 })(this); 33 })(this);
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
4 * Parser for exponential Golomb codes, a variable-bitwidth number encoding 4 * Parser for exponential Golomb codes, a variable-bitwidth number encoding
5 * scheme used by h264. 5 * scheme used by h264.
6 */ 6 */
7 window.videojs.hls.ExpGolomb = function(workingData) { 7 window.videojs.Hls.ExpGolomb = function(workingData) {
8 var 8 var
9 // the number of bytes left to examine in workingData 9 // the number of bytes left to examine in workingData
10 workingBytesAvailable = workingData.byteLength, 10 workingBytesAvailable = workingData.byteLength,
......
1 (function(window) { 1 (function(window) {
2 2
3 window.videojs = window.videojs || {}; 3 window.videojs = window.videojs || {};
4 window.videojs.hls = window.videojs.hls || {}; 4 window.videojs.Hls = window.videojs.Hls || {};
5 5
6 var hls = window.videojs.hls; 6 var hls = window.videojs.Hls;
7 7
8 // (type:uint, extraData:Boolean = false) extends ByteArray 8 // (type:uint, extraData:Boolean = false) extends ByteArray
9 hls.FlvTag = function(type, extraData) { 9 hls.FlvTag = function(type, extraData) {
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
8 8
9 (function(window) { 9 (function(window) {
10 var 10 var
11 ExpGolomb = window.videojs.hls.ExpGolomb, 11 ExpGolomb = window.videojs.Hls.ExpGolomb,
12 FlvTag = window.videojs.hls.FlvTag, 12 FlvTag = window.videojs.Hls.FlvTag,
13 13
14 H264ExtraData = function() { 14 H264ExtraData = function() {
15 this.sps = []; // :Array 15 this.sps = []; // :Array
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
234 * an h264 stream. Exactly one byte. 234 * an h264 stream. Exactly one byte.
235 */ 235 */
236 // incomplete, see Table 7.1 of ITU-T H.264 for 12-32 236 // incomplete, see Table 7.1 of ITU-T H.264 for 12-32
237 window.videojs.hls.NALUnitType = NALUnitType = { 237 window.videojs.Hls.NALUnitType = NALUnitType = {
238 unspecified: 0, 238 unspecified: 0,
239 slice_layer_without_partitioning_rbsp_non_idr: 1, 239 slice_layer_without_partitioning_rbsp_non_idr: 1,
240 slice_data_partition_a_layer_rbsp: 2, 240 slice_data_partition_a_layer_rbsp: 2,
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
249 end_of_stream_rbsp: 11 249 end_of_stream_rbsp: 11
250 }; 250 };
251 251
252 window.videojs.hls.H264Stream = function() { 252 window.videojs.Hls.H264Stream = function() {
253 var 253 var
254 next_pts, // :uint; 254 next_pts, // :uint;
255 next_dts, // :uint; 255 next_dts, // :uint;
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
32 } 32 }
33 return result; 33 return result;
34 }, 34 },
35 Stream = videojs.hls.Stream, 35 Stream = videojs.Hls.Stream,
36 LineStream, 36 LineStream,
37 ParseStream, 37 ParseStream,
38 Parser; 38 Parser;
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
5 (function(window, videojs) { 5 (function(window, videojs) {
6 'use strict'; 6 'use strict';
7 var 7 var
8 resolveUrl = videojs.hls.resolveUrl, 8 resolveUrl = videojs.Hls.resolveUrl,
9 xhr = videojs.hls.xhr, 9 xhr = videojs.Hls.xhr,
10 10
11 /** 11 /**
12 * Returns a new master playlist that is the result of merging an 12 * Returns a new master playlist that is the result of merging an
...@@ -231,7 +231,7 @@ ...@@ -231,7 +231,7 @@
231 return loader.trigger('loadedmetadata'); 231 return loader.trigger('loadedmetadata');
232 }); 232 });
233 }; 233 };
234 PlaylistLoader.prototype = new videojs.hls.Stream(); 234 PlaylistLoader.prototype = new videojs.Hls.Stream();
235 235
236 videojs.hls.PlaylistLoader = PlaylistLoader; 236 videojs.Hls.PlaylistLoader = PlaylistLoader;
237 })(window, window.videojs); 237 })(window, window.videojs);
......
1 (function(window) { 1 (function(window) {
2 var 2 var
3 videojs = window.videojs, 3 videojs = window.videojs,
4 FlvTag = videojs.hls.FlvTag, 4 FlvTag = videojs.Hls.FlvTag,
5 H264Stream = videojs.hls.H264Stream, 5 H264Stream = videojs.Hls.H264Stream,
6 AacStream = videojs.hls.AacStream, 6 AacStream = videojs.Hls.AacStream,
7 MP2T_PACKET_LENGTH, 7 MP2T_PACKET_LENGTH,
8 STREAM_TYPES; 8 STREAM_TYPES;
9 9
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
11 * An object that incrementally transmuxes MPEG2 Trasport Stream 11 * An object that incrementally transmuxes MPEG2 Trasport Stream
12 * chunks into an FLV. 12 * chunks into an FLV.
13 */ 13 */
14 videojs.hls.SegmentParser = function() { 14 videojs.Hls.SegmentParser = function() {
15 var 15 var
16 self = this, 16 self = this,
17 parseTSPacket, 17 parseTSPacket,
...@@ -432,8 +432,8 @@ ...@@ -432,8 +432,8 @@
432 }; 432 };
433 433
434 // MPEG2-TS constants 434 // MPEG2-TS constants
435 videojs.hls.SegmentParser.MP2T_PACKET_LENGTH = MP2T_PACKET_LENGTH = 188; 435 videojs.Hls.SegmentParser.MP2T_PACKET_LENGTH = MP2T_PACKET_LENGTH = 188;
436 videojs.hls.SegmentParser.STREAM_TYPES = STREAM_TYPES = { 436 videojs.Hls.SegmentParser.STREAM_TYPES = STREAM_TYPES = {
437 h264: 0x1b, 437 h264: 0x1b,
438 adts: 0x0f 438 adts: 0x0f
439 }; 439 };
......
...@@ -65,5 +65,5 @@ ...@@ -65,5 +65,5 @@
65 }); 65 });
66 }; 66 };
67 67
68 videojs.hls.Stream = Stream; 68 videojs.Hls.Stream = Stream;
69 })(window.videojs); 69 })(window.videojs);
......
...@@ -8,28 +8,6 @@ ...@@ -8,28 +8,6 @@
8 8
9 (function(window, videojs, document, undefined) { 9 (function(window, videojs, document, undefined) {
10 10
11 videojs.hls = {
12 /**
13 * Whether the browser has built-in HLS support.
14 */
15 supportsNativeHls: (function() {
16 var
17 video = document.createElement('video'),
18 xMpegUrl,
19 vndMpeg;
20
21 // native HLS is definitely not supported if HTML5 video isn't
22 if (!videojs.Html5.isSupported()) {
23 return false;
24 }
25
26 xMpegUrl = video.canPlayType('application/x-mpegURL');
27 vndMpeg = video.canPlayType('application/vnd.apple.mpegURL');
28 return (/probably|maybe/).test(xMpegUrl) ||
29 (/probably|maybe/).test(vndMpeg);
30 })()
31 };
32
33 var 11 var
34 12
35 // the desired length of video to maintain in the buffer, in seconds 13 // the desired length of video to maintain in the buffer, in seconds
...@@ -95,60 +73,7 @@ var ...@@ -95,60 +73,7 @@ var
95 } 73 }
96 }, 74 },
97 75
98 /** 76 xhr,
99 * Creates and sends an XMLHttpRequest.
100 * @param options {string | object} if this argument is a string, it
101 * is intrepreted as a URL and a simple GET request is
102 * inititated. If it is an object, it should contain a `url`
103 * property that indicates the URL to request and optionally a
104 * `method` which is the type of HTTP request to send.
105 * @param callback (optional) {function} a function to call when the
106 * request completes. If the request was not successful, the first
107 * argument will be falsey.
108 * @return {object} the XMLHttpRequest that was initiated.
109 */
110 xhr = videojs.hls.xhr = function(url, callback) {
111 var
112 options = {
113 method: 'GET'
114 },
115 request;
116
117 if (typeof callback !== 'function') {
118 callback = function() {};
119 }
120
121 if (typeof url === 'object') {
122 options = videojs.util.mergeOptions(options, url);
123 url = options.url;
124 }
125
126 request = new window.XMLHttpRequest();
127 request.open(options.method, url);
128
129 if (options.responseType) {
130 request.responseType = options.responseType;
131 }
132 if (options.withCredentials) {
133 request.withCredentials = true;
134 }
135
136 request.onreadystatechange = function() {
137 // wait until the request completes
138 if (this.readyState !== 4) {
139 return;
140 }
141
142 // request error
143 if (this.status >= 400 || this.status === 0) {
144 return callback.call(this, true, url);
145 }
146
147 return callback.call(this, false, url);
148 };
149 request.send(null);
150 return request;
151 },
152 77
153 /** 78 /**
154 * TODO - Document this great feature. 79 * TODO - Document this great feature.
...@@ -247,44 +172,7 @@ var ...@@ -247,44 +172,7 @@ var
247 return duration; 172 return duration;
248 }, 173 },
249 174
250 /** 175 resolveUrl,
251 * Constructs a new URI by interpreting a path relative to another
252 * URI.
253 * @param basePath {string} a relative or absolute URI
254 * @param path {string} a path part to combine with the base
255 * @return {string} a URI that is equivalent to composing `base`
256 * with `path`
257 * @see http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue
258 */
259 resolveUrl = videojs.hls.resolveUrl = function(basePath, path) {
260 // use the base element to get the browser to handle URI resolution
261 var
262 oldBase = document.querySelector('base'),
263 docHead = document.querySelector('head'),
264 a = document.createElement('a'),
265 base = oldBase,
266 oldHref,
267 result;
268
269 // prep the document
270 if (oldBase) {
271 oldHref = oldBase.href;
272 } else {
273 base = docHead.appendChild(document.createElement('base'));
274 }
275
276 base.href = basePath;
277 a.href = path;
278 result = a.href;
279
280 // clean up
281 if (oldBase) {
282 oldBase.href = oldHref;
283 } else {
284 docHead.removeChild(base);
285 }
286 return result;
287 },
288 176
289 /** 177 /**
290 * Initializes the HLS plugin. 178 * Initializes the HLS plugin.
...@@ -293,7 +181,7 @@ var ...@@ -293,7 +181,7 @@ var
293 init = function(options) { 181 init = function(options) {
294 var 182 var
295 mediaSource = new videojs.MediaSource(), 183 mediaSource = new videojs.MediaSource(),
296 segmentParser = new videojs.hls.SegmentParser(), 184 segmentParser = new videojs.Hls.SegmentParser(),
297 player = this, 185 player = this,
298 srcUrl, 186 srcUrl,
299 187
...@@ -303,7 +191,7 @@ var ...@@ -303,7 +191,7 @@ var
303 updateDuration; 191 updateDuration;
304 192
305 // if the video element supports HLS natively, do nothing 193 // if the video element supports HLS natively, do nothing
306 if (videojs.hls.supportsNativeHls) { 194 if (videojs.Hls.supportsNativeHls) {
307 return; 195 return;
308 } 196 }
309 197
...@@ -346,13 +234,13 @@ var ...@@ -346,13 +234,13 @@ var
346 } 234 }
347 235
348 // do nothing if the source is handled by one of the standard techs 236 // do nothing if the source is handled by one of the standard techs
349 for (j in player.options().techOrder) { 237 //for (j in player.options().techOrder) {
350 techName = player.options().techOrder[j]; 238 //techname = player.options().techorder[j];
351 techName = techName[0].toUpperCase() + techName.substring(1); 239 //techname = techname[0].touppercase() + techname.substring(1);
352 if (videojs[techName].canPlaySource({ type: sources[i].type })) { 240 //if (videojs[techname].canplaysource({ type: sources[i].type })) {
353 return; 241 //return;
354 } 242 //}
355 } 243 //}
356 244
357 // use the plugin if the MIME type specifies HLS 245 // use the plugin if the MIME type specifies HLS
358 if ((/application\/x-mpegURL/).test(sources[i].type) || 246 if ((/application\/x-mpegURL/).test(sources[i].type) ||
...@@ -638,28 +526,158 @@ var ...@@ -638,28 +526,158 @@ var
638 oldMediaPlaylist = updatedPlaylist; 526 oldMediaPlaylist = updatedPlaylist;
639 }); 527 });
640 }); 528 });
641 player.src([{
642 src: videojs.URL.createObjectURL(mediaSource),
643 type: "video/flv"
644 }]);
645 529
646 if (player.options().autoplay) { 530 //player.src([{
647 player.play(); 531 //src: videojs.URL.createObjectURL(mediaSource),
648 } 532 //type: "video/flv"
533 //}]);
534
535 //if (player.options().autoplay) {
536 //player.play();
537 //}
649 }; 538 };
650 539
651 videojs.plugin('hls', function() { 540 var mpegurlRE = /^application\/(?:x-|vnd\.apple\.)mpegurl/i;
652 if (typeof Uint8Array === 'undefined') { 541
653 return; 542 videojs.Hls = videojs.Flash.extend({
543 init: function(player, options, ready) {
544 videojs.Flash.call(this, player, options, ready);
545 player.hls = {};
546 this.ready(function() {
547 console.log('ready!');
548 //init.call(player, options);
549 });
654 } 550 }
551 });
655 552
656 var initialize = function() { 553 //for (var prop in videojs.Flash) {
657 return function() { 554 //videojs.Hls[prop] = videojs.Flash[prop];
658 this.hls = initialize(); 555 //}
659 init.apply(this, arguments); 556 //for (prop in videojs.Flash.prototype) {
660 }; 557 //videojs.Hls.prototype[prop] = videojs.Flash[prop];
558 //}
559
560 videojs.Hls.isSupported = function() {
561 return videojs.Flash.isSupported() && videojs.MediaSource;
562 }
563
564 videojs.Hls.canPlaySource = function(srcObj) {
565 return mpegurlRE.test(srcObj.type) || videojs.Flash.canPlaySource.call(this, srcObj);
566 };
567
568 videojs.Hls.supportsNativeHls = (function() {
569 var
570 video = document.createElement('video'),
571 xMpegUrl,
572 vndMpeg;
573
574 // native HLS is definitely not supported if HTML5 video isn't
575 if (!videojs.Html5.isSupported()) {
576 return false;
577 }
578
579 xMpegUrl = video.canPlayType('application/x-mpegURL');
580 vndMpeg = video.canPlayType('application/vnd.apple.mpegURL');
581 return (/probably|maybe/).test(xMpegUrl) ||
582 (/probably|maybe/).test(vndMpeg);
583 })();
584
585 /**
586 * Creates and sends an XMLHttpRequest.
587 * @param options {string | object} if this argument is a string, it
588 * is intrepreted as a URL and a simple GET request is
589 * inititated. If it is an object, it should contain a `url`
590 * property that indicates the URL to request and optionally a
591 * `method` which is the type of HTTP request to send.
592 * @param callback (optional) {function} a function to call when the
593 * request completes. If the request was not successful, the first
594 * argument will be falsey.
595 * @return {object} the XMLHttpRequest that was initiated.
596 */
597 xhr = videojs.Hls.xhr = function(url, callback) {
598 var
599 options = {
600 method: 'GET'
601 },
602 request;
603
604 if (typeof callback !== 'function') {
605 callback = function() {};
606 }
607
608 if (typeof url === 'object') {
609 options = videojs.util.mergeOptions(options, url);
610 url = options.url;
611 }
612
613 request = new window.XMLHttpRequest();
614 request.open(options.method, url);
615
616 if (options.responseType) {
617 request.responseType = options.responseType;
618 }
619 if (options.withCredentials) {
620 request.withCredentials = true;
621 }
622
623 request.onreadystatechange = function() {
624 // wait until the request completes
625 if (this.readyState !== 4) {
626 return;
627 }
628
629 // request error
630 if (this.status >= 400 || this.status === 0) {
631 return callback.call(this, true, url);
632 }
633
634 return callback.call(this, false, url);
661 }; 635 };
662 initialize().apply(this, arguments); 636 request.send(null);
663 }); 637 return request;
638 };
639
640 /**
641 * Constructs a new URI by interpreting a path relative to another
642 * URI.
643 * @param basePath {string} a relative or absolute URI
644 * @param path {string} a path part to combine with the base
645 * @return {string} a URI that is equivalent to composing `base`
646 * with `path`
647 * @see http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue
648 */
649 resolveUrl = videojs.Hls.resolveUrl = function(basePath, path) {
650 // use the base element to get the browser to handle URI resolution
651 var
652 oldBase = document.querySelector('base'),
653 docHead = document.querySelector('head'),
654 a = document.createElement('a'),
655 base = oldBase,
656 oldHref,
657 result;
658
659 // prep the document
660 if (oldBase) {
661 oldHref = oldBase.href;
662 } else {
663 base = docHead.appendChild(document.createElement('base'));
664 }
665
666 base.href = basePath;
667 a.href = path;
668 result = a.href;
669
670 // clean up
671 if (oldBase) {
672 oldBase.href = oldHref;
673 } else {
674 docHead.removeChild(base);
675 }
676 return result;
677 };
678
679 //videojs.Hls.onReady = videojs.Flash.onReady;
680 //videojs.Hls.onEvent = videojs.Flash.onEvent;
681 //videojs.Hls.onError = videojs.Flash.onError;
664 682
665 })(window, window.videojs, document); 683 })(window, window.videojs, document);
......