17ec4078 by Tom Johnson

progress update

1 parent ced9b85e
1 (function(window) { 1 (function(window) {
2 var M3U8 = window.videojs.hls.M3U8; 2 var M3U8 = window.videojs.hls.M3U8;
3 var M3U8Parser = window.videojs.hls.M3U8Parser; 3 var M3U8Parser = window.videojs.hls.M3U8Parser;
4 var M3U8TagTypes = window.videojs.hls.m3u8TagType;
5 4
6 window.videojs.hls.ManifestController = function(){ 5 window.videojs.hls.ManifestController = function(){
7 6
...@@ -50,11 +49,3 @@ ...@@ -50,11 +49,3 @@
50 }; 49 };
51 } 50 }
52 })(this); 51 })(this);
...\ No newline at end of file ...\ No newline at end of file
53
54 /*
55 mc = new window.videojs.hls.ManifestController('myM3u8.m3u8', {
56 onData: function(){},
57 onError: function(){},
58 onUpdate: function(){}
59 });
60 */
...\ No newline at end of file ...\ No newline at end of file
......
1 (function(window) {
2
3 var SegmentParser = window.videojs.hls.SegmentParser;
4
5 window.videojs.hls.SegmentController = function(){
6
7 var self = this;
8 var url;
9 var parser;
10 var requestTimestamp;
11 var responseTimestamp;
12 var data;
13
14 var onDataCallback;
15 var onErrorCallback;
16 var onUpdateCallback;
17
18 self.loadSegment = function ( segmentUrl, onDataCallback, onErrorCallback, onUpdateCallback ) {
19 self.url = segmentUrl;
20 self.onDataCallback = onDataCallback;
21 self.onErrorCallback = onErrorCallback;
22 self.onUpdateCallback = onUpdateCallback;
23 self.requestTimestamp = new Date().getTime();
24
25 vjs.get(segmentUrl, self.onSegmentLoadComplete, self.onSegmentLoadError);
26 };
27
28 self.parseSegment = function ( incomingData ) {
29 // Add David's code later //
30
31 self.data = {};
32 self.data.url = self.url;
33 self.data.isCached = false;
34 self.data.requestTimestamp = self.requestTimestamp;
35 self.data.responseTimestamp = self.responseTimestamp;
36 self.data.byteLength = incomingData.byteLength;
37 self.data.isCached = ( parseInt(self.responseTimestamp - self.requestTimestamp) < 75 );
38 self.data.throughput = self.calculateThroughput(self.data.byteLength, self.requestTimestamp ,self.responseTimestamp)
39
40 return self.data;
41 };
42
43 self.calculateThroughput = function(dataAmount, startTime, endTime) {
44 return Math.round(dataAmount/(endTime-startTime)*1000)*8;
45 }
46
47 self.onSegmentLoadComplete = function(response) {
48 self.responseTimestamp = new Date().getTime();
49
50 var output = self.parseSegment(response);
51
52 if(self.onDataCallback != undefined)
53 {
54 self.onDataCallback(output);
55 }
56 };
57
58 self.onSegmentLoadError = function(err) {
59 if(err)
60 {
61 console.log(err.message);
62 }
63
64 if(self.onErrorCallback != undefined)
65 {
66 onErrorCallback((err != undefined) ? err : null);
67 }
68 };
69 }
70 })(this);
...@@ -54,12 +54,9 @@ ...@@ -54,12 +54,9 @@
54 <script src="manifest/playlistM3U8data.js"></script> 54 <script src="manifest/playlistM3U8data.js"></script>
55 <script src="manifest/brightcove_playlist_m3u8.js"></script> 55 <script src="manifest/brightcove_playlist_m3u8.js"></script>
56 <!-- M3U8 --> 56 <!-- M3U8 -->
57 57 <!-- SEGMENT -->
58
59 <!-- an example MPEG2-TS segment -->
60 <!-- <script src="tsSegment.js"></script> -->
61 <script src="tsSegment-bc.js"></script> 58 <script src="tsSegment-bc.js"></script>
62 59 <script src="../src/segment-controller.js"></script>
63 60
64 <script src="../src/bin-utils.js"></script> 61 <script src="../src/bin-utils.js"></script>
65 62
...@@ -67,9 +64,9 @@ ...@@ -67,9 +64,9 @@
67 64
68 65
69 66
70
71 <script src="video-js-hls_test.js"></script>
72 <script src="exp-golomb_test.js"></script> 67 <script src="exp-golomb_test.js"></script>
68 <script src="video-js-hls_test.js"></script>
69
73 </head> 70 </head>
74 <body> 71 <body>
75 <div id="qunit"></div> 72 <div id="qunit"></div>
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
21 */ 21 */
22 var 22 var
23 manifestController, 23 manifestController,
24 segmentController,
24 m3u8parser, 25 m3u8parser,
25 parser, 26 parser,
26 27
...@@ -328,16 +329,57 @@ ...@@ -328,16 +329,57 @@
328 manifestController.loadManifest( 329 manifestController.loadManifest(
329 hermesUrl, 330 hermesUrl,
330 function(responseData){ 331 function(responseData){
331 console.log('got response data');
332 ok(true); 332 ok(true);
333 }, 333 },
334 function(errorData){ 334 function(errorData){
335 console.log('got error data') 335 console.log('got error data');
336 }, 336 },
337 function(updateData){ 337 function(updateData){
338 console.log('got update data') 338 console.log('got update data');
339 } 339 }
340 ) 340 )
341 });
342
343 module('segment controller', {
344 setup: function() {
345 segmentController = new window.videojs.hls.SegmentController();
346 this.vjsget = vjs.get;
347 vjs.get = function(url, success, error){
348 console.log('load segment url', url);
349 success(window.bcSegment);
350 };
351 },
352 teardown: function() {
353 vjs.get = this.vjsget;
354 }
355 });
356
357 test('should get a segment data', function() {
358 ok(true);
359 var hermesUrl = "http://localhost:7070/test/ts-files/brightcove/s-1.ts";
360
361 segmentController.loadSegment(
362 hermesUrl,
363 function(responseData){
364 console.log('got response from segment controller');
365 ok(true);
366
367 },
368 function(errorData){
369 console.log('got error data');
370 },
371 function(updateData){
372 console.log('got update data');
373 }
374 )
375 }
376 )
377
378 test('bandwidth calulation test', function() {
379 var multiSecondData = segmentController.calculateThroughput(10000,1000,2000);
380 var subSecondData = segmentController.calculateThroughput(10000,1000,1500);
381 equal(multiSecondData, 80000, 'MULTI-Second bits per second calculation');
382 equal(subSecondData, 160000, 'SUB-Second bits per second calculation');
341 383
342 }) 384 })
343 385
......