17ec4078 by Tom Johnson

progress update

1 parent ced9b85e
(function(window) {
var M3U8 = window.videojs.hls.M3U8;
var M3U8Parser = window.videojs.hls.M3U8Parser;
var M3U8TagTypes = window.videojs.hls.m3u8TagType;
window.videojs.hls.ManifestController = function(){
......@@ -50,11 +49,3 @@
};
}
})(this);
\ No newline at end of file
/*
mc = new window.videojs.hls.ManifestController('myM3u8.m3u8', {
onData: function(){},
onError: function(){},
onUpdate: function(){}
});
*/
\ No newline at end of file
......
(function(window) {
var SegmentParser = window.videojs.hls.SegmentParser;
window.videojs.hls.SegmentController = function(){
var self = this;
var url;
var parser;
var requestTimestamp;
var responseTimestamp;
var data;
var onDataCallback;
var onErrorCallback;
var onUpdateCallback;
self.loadSegment = function ( segmentUrl, onDataCallback, onErrorCallback, onUpdateCallback ) {
self.url = segmentUrl;
self.onDataCallback = onDataCallback;
self.onErrorCallback = onErrorCallback;
self.onUpdateCallback = onUpdateCallback;
self.requestTimestamp = new Date().getTime();
vjs.get(segmentUrl, self.onSegmentLoadComplete, self.onSegmentLoadError);
};
self.parseSegment = function ( incomingData ) {
// Add David's code later //
self.data = {};
self.data.url = self.url;
self.data.isCached = false;
self.data.requestTimestamp = self.requestTimestamp;
self.data.responseTimestamp = self.responseTimestamp;
self.data.byteLength = incomingData.byteLength;
self.data.isCached = ( parseInt(self.responseTimestamp - self.requestTimestamp) < 75 );
self.data.throughput = self.calculateThroughput(self.data.byteLength, self.requestTimestamp ,self.responseTimestamp)
return self.data;
};
self.calculateThroughput = function(dataAmount, startTime, endTime) {
return Math.round(dataAmount/(endTime-startTime)*1000)*8;
}
self.onSegmentLoadComplete = function(response) {
self.responseTimestamp = new Date().getTime();
var output = self.parseSegment(response);
if(self.onDataCallback != undefined)
{
self.onDataCallback(output);
}
};
self.onSegmentLoadError = function(err) {
if(err)
{
console.log(err.message);
}
if(self.onErrorCallback != undefined)
{
onErrorCallback((err != undefined) ? err : null);
}
};
}
})(this);
......@@ -54,12 +54,9 @@
<script src="manifest/playlistM3U8data.js"></script>
<script src="manifest/brightcove_playlist_m3u8.js"></script>
<!-- M3U8 -->
<!-- an example MPEG2-TS segment -->
<!-- <script src="tsSegment.js"></script> -->
<!-- SEGMENT -->
<script src="tsSegment-bc.js"></script>
<script src="../src/segment-controller.js"></script>
<script src="../src/bin-utils.js"></script>
......@@ -67,9 +64,9 @@
<script src="video-js-hls_test.js"></script>
<script src="exp-golomb_test.js"></script>
<script src="video-js-hls_test.js"></script>
</head>
<body>
<div id="qunit"></div>
......
......@@ -21,6 +21,7 @@
*/
var
manifestController,
segmentController,
m3u8parser,
parser,
......@@ -328,16 +329,57 @@
manifestController.loadManifest(
hermesUrl,
function(responseData){
console.log('got response data');
ok(true);
},
function(errorData){
console.log('got error data')
console.log('got error data');
},
function(updateData){
console.log('got update data')
console.log('got update data');
}
)
});
module('segment controller', {
setup: function() {
segmentController = new window.videojs.hls.SegmentController();
this.vjsget = vjs.get;
vjs.get = function(url, success, error){
console.log('load segment url', url);
success(window.bcSegment);
};
},
teardown: function() {
vjs.get = this.vjsget;
}
});
test('should get a segment data', function() {
ok(true);
var hermesUrl = "http://localhost:7070/test/ts-files/brightcove/s-1.ts";
segmentController.loadSegment(
hermesUrl,
function(responseData){
console.log('got response from segment controller');
ok(true);
},
function(errorData){
console.log('got error data');
},
function(updateData){
console.log('got update data');
}
)
}
)
test('bandwidth calulation test', function() {
var multiSecondData = segmentController.calculateThroughput(10000,1000,2000);
var subSecondData = segmentController.calculateThroughput(10000,1000,1500);
equal(multiSecondData, 80000, 'MULTI-Second bits per second calculation');
equal(subSecondData, 160000, 'SUB-Second bits per second calculation');
})
......