41e190ce by David LaPalomento

Consolidate PTS scanning

Loop through flv tags while intra-segment seeking in one pass. Rely on the SWF to track the seek destination in currentTime instead of manually pushing it through ExternalInterface.
1 parent 19317e79
......@@ -154,20 +154,6 @@ 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);
......@@ -177,18 +163,6 @@ var
fillBuffer(currentTime * 1000);
});
player.on('hls-missing-segment', function() {
//console.log('Missing Segment Triggered');
});
player.on('hls-missing-playlist', function() {
//console.log('Missing Playlist Triggered');
});
player.on('error', function() {
});
/**
* Chooses the appropriate media playlist based on the current
* bandwidth estimate and the player size.
......@@ -337,8 +311,7 @@ var
bufferedTime = 0,
segment = player.hls.media.segments[player.hls.mediaIndex],
segmentUri,
startTime,
tagIndex;
startTime;
// if there is a request already in flight, do nothing
if (segmentXhr) {
......@@ -401,13 +374,11 @@ var
// transmux the segment data from MP2T to FLV
segmentParser.parseSegmentBinaryData(new Uint8Array(this.response));
// handle intra-segment seeking, if requested //
// if we're refilling the buffer after a seek, scan through the muxed
// FLV tags until we find the one that is closest to the desired
// playback time
if (offset !== undefined && typeof offset === "number") {
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;
}
while (segmentParser.getTags()[0].pts < offset) {
// we're seeking past this tag, so ignore it
segmentParser.getNextTag();
}
......
......@@ -186,9 +186,10 @@
test('the flv tags are well-formed', function() {
var
tag,
byte,
tag,
type,
currentPts = 0,
lastTime = 0;
parser.parseSegmentBinaryData(window.bcSegment);
......@@ -196,6 +197,9 @@
tag = parser.getNextTag();
type = tag.bytes[0];
ok(tag.pts >= currentPts, 'presentation time stamps are increasing');
currentPts = tag.pts;
// generic flv headers
ok(type === 8 || type === 9 || type === 18,
'the type field specifies audio, video or script');
......
......@@ -514,39 +514,6 @@ 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');
});
test('playlist 404 should trigger MEDIA_ERR_NETWORK', function() {
var errorTriggered = false;
......