10a996a2 by Tom Johnson

Include HLS seeking tests for PTS detection routine

1 parent f914eaeb
......@@ -59,19 +59,6 @@ var
return -1;
},
getPtsByTime = function(segmentParser, time) {
var index = 0;
for (index; index<segmentParser.getTags().length; index++) {
if(index === segmentParser.getTags().length-1) {
return segmentParser.getTags()[index].pts;
} else {
if (segmentParser.getTags()[index].pts <= time && segmentParser.getTags()[index+1].pts > time) {
return segmentParser.getTags()[index].pts;
}
}
}
},
/**
* Calculate the total duration for a playlist based on segment metadata.
......@@ -167,6 +154,20 @@ var
return 1; // HAVE_METADATA
};
player.hls.getPtsByTime = function(segmentParser, time) {
var index = 0;
for (index; index<segmentParser.getTags().length; index++) {
if(index === segmentParser.getTags().length-1) {
return segmentParser.getTags()[index].pts;
} else {
if (segmentParser.getTags()[index].pts <= time && segmentParser.getTags()[index+1].pts > time) {
return segmentParser.getTags()[index].pts;
}
}
}
};
player.on('seeking', function() {
var currentTime = player.currentTime();
player.hls.mediaIndex = getMediaIndexByTime(player.hls.media, currentTime);
......@@ -365,7 +366,7 @@ var
// handle intra-segment seeking, if requested //
if (offset !== undefined && typeof offset === "number") {
player.el().querySelector('.vjs-tech').vjs_setProperty('lastSeekedTime', getPtsByTime(segmentParser,offset)/1000);
player.el().querySelector('.vjs-tech').vjs_setProperty('lastSeekedTime', player.hls.getPtsByTime(segmentParser,offset)/1000);
for (tagIndex = 0; tagIndex < segmentParser.getTags().length; tagIndex++) {
if (segmentParser.getTags()[tagIndex].pts > offset) {
break;
......
......@@ -514,11 +514,43 @@ test('cancels outstanding XHRs when seeking', function() {
strictEqual(1, opened, 'opened new XHR');
});
test('gets the correct PTS on seek', function() {
var
ptsByTime = -1,
seekTime = 5.123,
segmentParser = new window.videojs.hls.SegmentParser();
segmentParser.getTags = function() {
return [
{pts:1},
{pts:2},
{pts:3},
{pts:4},
{pts:5},
{pts:6}
];
};
player.hls('manifest/media.m3u8');
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
player.on('seeked', function() {
ptsByTime = player.hls.getPtsByTime(segmentParser,seekTime);
});
player.trigger('seeked');
notEqual(ptsByTime, -1, 'PTS Should be set on seek');
strictEqual(ptsByTime, 5, 'PTS should be closest');
ok(ptsByTime<=seekTime, 'PTS should be less than or equal to seek time');
});
module('segment controller', {
setup: function() {
segmentController = new window.videojs.hls.SegmentController();
},
teardown: function() {
window.videojs.get = this.vjsget;
......