2d70b254 by David LaPalomento

Remove unused files

Get rid of leftovers from the previous iteration of managing manifest and stream downloading. That logic has been consolidated into the main plugin file.
1 parent 3f87ad97
...@@ -28,11 +28,8 @@ module.exports = function(grunt) { ...@@ -28,11 +28,8 @@ module.exports = function(grunt) {
28 'src/h264-stream.js', 28 'src/h264-stream.js',
29 'src/aac-stream.js', 29 'src/aac-stream.js',
30 'src/segment-parser.js', 30 'src/segment-parser.js',
31 'src/segment-controller.js', 31 'src/m3u8/m3u8-parser.js'
32 'src/m3u8/m3u8-parser.js', 32 ],
33 'src/manifest-controller.js',
34 'src/segment-controller.js',
35 'src/hls-playback-controller.js'],
36 dest: 'dist/videojs.hls.js' 33 dest: 'dist/videojs.hls.js'
37 }, 34 },
38 }, 35 },
......
...@@ -21,14 +21,10 @@ ...@@ -21,14 +21,10 @@
21 <script src="src/h264-stream.js"></script> 21 <script src="src/h264-stream.js"></script>
22 <script src="src/aac-stream.js"></script> 22 <script src="src/aac-stream.js"></script>
23 <script src="src/segment-parser.js"></script> 23 <script src="src/segment-parser.js"></script>
24 <script src="src/segment-controller.js"></script>
25 24
26 <!-- m3u8 handling --> 25 <!-- m3u8 handling -->
27 <script src="src/stream.js"></script> 26 <script src="src/stream.js"></script>
28 <script src="src/m3u8/m3u8-parser.js"></script> 27 <script src="src/m3u8/m3u8-parser.js"></script>
29 <script src="src/manifest-controller.js"></script>
30 <script src="src/segment-controller.js"></script>
31 <script src="src/hls-playback-controller.js"></script>
32 28
33 <!-- example MPEG2-TS segments --> 29 <!-- example MPEG2-TS segments -->
34 <!-- bipbop --> 30 <!-- bipbop -->
......
1 (function(window) {
2 var
3 ManifestController = window.videojs.hls.ManifestController,
4 SegmentController = window.videojs.hls.SegmentController,
5 MediaSource = window.videojs.MediaSource,
6 SegmentParser = window.videojs.hls.SegmentParser;
7
8
9 window.videojs.hls.HLSPlaybackController = function(player) {
10
11 var self = this;
12
13 self.player = player;
14 self.mediaSource = new MediaSource();
15 self.parser = new SegmentParser();
16
17 self.manifestLoaded = false;
18 self.currentSegment = 0;
19
20 // register external callbacks
21 self.rendition = function(rendition) {
22 self.currentRendition = rendition;
23 self.loadManifestWithMediaSources(self.currentRendition.url, self.onM3U8LoadComplete, self.onM3U8LoadError, self.onM3U8Update);
24 };
25
26 self.loadManifestWithMediaSources = function(manifestUrl,onDataCallback) {
27 self.manifestController = new ManifestController();
28 self.manifestController.loadManifest(manifestUrl, self.onM3U8LoadComplete, self.onM3U8LoadError, self.onM3U8Update);
29 if (onDataCallback) {
30 self.manifestLoadCompleteCallback = onDataCallback;
31 }
32 };
33
34 self.loadManifest = function(manifestUrl, onDataCallback) {
35 self.mediaSource.addEventListener('sourceopen', function() {
36 // feed parsed bytes into the player
37 self.sourceBuffer = self.mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"');
38
39 self.parser = new SegmentParser();
40
41 self.sourceBuffer.appendBuffer(self.parser.getFlvHeader(), self.player);
42
43 if (onDataCallback) {
44 self.manifestLoadCompleteCallback = onDataCallback;
45 }
46
47 self.manifestController = new ManifestController();
48 self.manifestController.loadManifest(manifestUrl, self.onM3U8LoadComplete, self.onM3U8LoadError, self.onM3U8Update);
49
50 }, false);
51
52 self.player.src({
53 src: window.videojs.URL.createObjectURL(self.mediaSource),
54 type: "video/flv"
55 });
56 };
57
58 self.onM3U8LoadComplete = function(m3u8) {
59 if (m3u8.invalidReasons.length === 0) {
60 if (m3u8.isPlaylist) {
61 self.currentPlaylist = m3u8;
62 self.rendition(self.currentPlaylist.playlistItems[0]);
63 } else {
64 self.currentManifest = m3u8;
65 self.manifestLoaded = true;
66
67 self.loadSegment(self.currentManifest.mediaItems[0]);
68
69 if (self.manifestLoadCompleteCallback) {
70 self.manifestLoadCompleteCallback(m3u8);
71 }
72 }
73 }
74 };
75
76 self.onM3U8LoadError = function() {};
77 self.onM3U8Update = function() {};
78
79 self.loadSegment = function(segment) {
80 self.segmentController = new SegmentController();
81 self.segmentController.loadSegment(segment.url, self.onSegmentLoadComplete, self.onSegmentLoadError);
82 };
83
84 self.onSegmentLoadComplete = function(segment) {
85 self.parser.parseSegmentBinaryData(segment.binaryData);
86
87 while (self.parser.tagsAvailable()) {
88 self.sourceBuffer.appendBuffer(self.parser.getNextTag().bytes, self.player);
89 }
90
91 if (self.currentSegment < self.currentManifest.mediaItems.length-1) {
92 self.loadNextSegment();
93 }
94 };
95
96 self.loadNextSegment = function() {
97 self.currentSegment++;
98 self.loadSegment(self.currentManifest.mediaItems[self.currentSegment]);
99 };
100
101 self.onSegmentLoadError = function() {};
102
103 };
104 })(this);
1 (function (window) {
2
3 var parser = window.videojs.hls.M3U8Parser;
4
5 window.videojs.hls.ManifestController = function() {
6 var self = this;
7
8 self.loadManifest = function(manifestUrl, onDataCallback, onErrorCallback, onUpdateCallback) {
9 self.url = manifestUrl;
10
11 if (onDataCallback) {
12 self.onDataCallback = onDataCallback;
13 }
14 if (onErrorCallback) {
15 self.onErrorCallback = onErrorCallback;
16 }
17
18 if (onUpdateCallback) {
19 self.onUpdateCallback = onUpdateCallback;
20 }
21
22 window.vjs.get(manifestUrl, self.onManifestLoadComplete, self.onManifestLoadError);
23 };
24
25 self.parseManifest = function(manifest) {
26 return parser.parse(manifest);
27 };
28
29 self.onManifestLoadComplete = function(response) {
30 var output = self.parseManifest(response);
31
32 if (self.onDataCallback !== undefined) {
33 self.onDataCallback(output);
34 }
35 };
36
37 self.onManifestLoadError = function(err) {
38 if (self.onErrorCallback !== undefined) {
39 self.onErrorCallback((err !== undefined) ? err : null);
40 }
41 };
42 };
43 })(this);
1 (function(window) {
2
3 window.videojs.hls.SegmentController = function() {
4 var self = this;
5
6 self.loadSegment = function(segmentUrl, onDataCallback, onErrorCallback, onUpdateCallback) {
7 var request = new XMLHttpRequest();
8
9 self.url = segmentUrl;
10 self.onDataCallback = onDataCallback;
11 self.onErrorCallback = onErrorCallback;
12 self.onUpdateCallback = onUpdateCallback;
13 self.requestTimestamp = +new Date();
14
15 request.open('GET', segmentUrl, true);
16 request.responseType = 'arraybuffer';
17 request.onload = function() {
18 self.onSegmentLoadComplete(new Uint8Array(request.response));
19 };
20
21 request.send(null);
22 };
23
24 self.parseSegment = function(incomingData) {
25 self.data = {};
26 self.data.binaryData = incomingData;
27 self.data.url = self.url;
28 self.data.isCached = false;
29 self.data.requestTimestamp = self.requestTimestamp;
30 self.data.responseTimestamp = self.responseTimestamp;
31 self.data.byteLength = incomingData.byteLength;
32 self.data.isCached = parseInt(self.responseTimestamp - self.requestTimestamp,10) < 75;
33 self.data.throughput = self.calculateThroughput(self.data.byteLength, self.requestTimestamp ,self.responseTimestamp);
34
35 return self.data;
36 };
37
38 self.calculateThroughput = function(dataAmount, startTime, endTime) {
39 return Math.round(dataAmount / (endTime - startTime) * 1000) * 8;
40 };
41
42 self.onSegmentLoadComplete = function(response) {
43 var output;
44
45 self.responseTimestamp = +new Date();
46
47 output = self.parseSegment(response);
48
49 if (self.onDataCallback !== undefined) {
50 self.onDataCallback(output);
51 }
52 };
53
54 self.onSegmentLoadError = function(error) {
55 if (error) {
56 throw error;
57 }
58
59 if (self.onErrorCallback !== undefined) {
60 self.onErrorCallback(error);
61 }
62 };
63 };
64 })(this);
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
22 <!-- M3U8 --> 22 <!-- M3U8 -->
23 <script src="../src/stream.js"></script> 23 <script src="../src/stream.js"></script>
24 <script src="../src/m3u8/m3u8-parser.js"></script> 24 <script src="../src/m3u8/m3u8-parser.js"></script>
25 <script src="../src/manifest-controller.js"></script>
26 <!-- M3U8 TEST DATA --> 25 <!-- M3U8 TEST DATA -->
27 <script src="../tmp/manifests.js"></script> 26 <script src="../tmp/manifests.js"></script>
28 <script src="../tmp/expected.js"></script> 27 <script src="../tmp/expected.js"></script>
...@@ -30,7 +29,6 @@ ...@@ -30,7 +29,6 @@
30 <!-- M3U8 --> 29 <!-- M3U8 -->
31 <!-- SEGMENT --> 30 <!-- SEGMENT -->
32 <script src="tsSegment-bc.js"></script> 31 <script src="tsSegment-bc.js"></script>
33 <script src="../src/segment-controller.js"></script>
34 <script src="../src/bin-utils.js"></script> 32 <script src="../src/bin-utils.js"></script>
35 33
36 <!-- Test cases --> 34 <!-- Test cases -->
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
22 22
23 var 23 var
24 player, 24 player,
25 segmentController,
26 oldFlashSupported, 25 oldFlashSupported,
27 oldXhr, 26 oldXhr,
28 oldSourceBuffer, 27 oldSourceBuffer,
...@@ -721,21 +720,4 @@ test('has no effect if native HLS is available', function() { ...@@ -721,21 +720,4 @@ test('has no effect if native HLS is available', function() {
721 'no media source was opened'); 720 'no media source was opened');
722 }); 721 });
723 722
724 module('segment controller', {
725 setup: function() {
726 segmentController = new window.videojs.hls.SegmentController();
727 },
728 teardown: function() {
729 window.videojs.get = this.vjsget;
730 }
731 });
732
733 test('bandwidth calulation test', function() {
734 var
735 multiSecondData = segmentController.calculateThroughput(10000, 1000, 2000),
736 subSecondData = segmentController.calculateThroughput(10000, 1000, 1500);
737 equal(multiSecondData, 80000, 'MULTI-Second bits per second calculation');
738 equal(subSecondData, 160000, 'SUB-Second bits per second calculation');
739 });
740
741 })(window, window.videojs); 723 })(window, window.videojs);
......