10a996a2 by Tom Johnson

Include HLS seeking tests for PTS detection routine

1 parent f914eaeb
...@@ -59,19 +59,6 @@ var ...@@ -59,19 +59,6 @@ var
59 return -1; 59 return -1;
60 60
61 }, 61 },
62 getPtsByTime = function(segmentParser, time) {
63 var index = 0;
64
65 for (index; index<segmentParser.getTags().length; index++) {
66 if(index === segmentParser.getTags().length-1) {
67 return segmentParser.getTags()[index].pts;
68 } else {
69 if (segmentParser.getTags()[index].pts <= time && segmentParser.getTags()[index+1].pts > time) {
70 return segmentParser.getTags()[index].pts;
71 }
72 }
73 }
74 },
75 62
76 /** 63 /**
77 * Calculate the total duration for a playlist based on segment metadata. 64 * Calculate the total duration for a playlist based on segment metadata.
...@@ -167,6 +154,20 @@ var ...@@ -167,6 +154,20 @@ var
167 return 1; // HAVE_METADATA 154 return 1; // HAVE_METADATA
168 }; 155 };
169 156
157 player.hls.getPtsByTime = function(segmentParser, time) {
158 var index = 0;
159
160 for (index; index<segmentParser.getTags().length; index++) {
161 if(index === segmentParser.getTags().length-1) {
162 return segmentParser.getTags()[index].pts;
163 } else {
164 if (segmentParser.getTags()[index].pts <= time && segmentParser.getTags()[index+1].pts > time) {
165 return segmentParser.getTags()[index].pts;
166 }
167 }
168 }
169 };
170
170 player.on('seeking', function() { 171 player.on('seeking', function() {
171 var currentTime = player.currentTime(); 172 var currentTime = player.currentTime();
172 player.hls.mediaIndex = getMediaIndexByTime(player.hls.media, currentTime); 173 player.hls.mediaIndex = getMediaIndexByTime(player.hls.media, currentTime);
...@@ -365,7 +366,7 @@ var ...@@ -365,7 +366,7 @@ var
365 366
366 // handle intra-segment seeking, if requested // 367 // handle intra-segment seeking, if requested //
367 if (offset !== undefined && typeof offset === "number") { 368 if (offset !== undefined && typeof offset === "number") {
368 player.el().querySelector('.vjs-tech').vjs_setProperty('lastSeekedTime', getPtsByTime(segmentParser,offset)/1000); 369 player.el().querySelector('.vjs-tech').vjs_setProperty('lastSeekedTime', player.hls.getPtsByTime(segmentParser,offset)/1000);
369 for (tagIndex = 0; tagIndex < segmentParser.getTags().length; tagIndex++) { 370 for (tagIndex = 0; tagIndex < segmentParser.getTags().length; tagIndex++) {
370 if (segmentParser.getTags()[tagIndex].pts > offset) { 371 if (segmentParser.getTags()[tagIndex].pts > offset) {
371 break; 372 break;
......
...@@ -514,11 +514,43 @@ test('cancels outstanding XHRs when seeking', function() { ...@@ -514,11 +514,43 @@ test('cancels outstanding XHRs when seeking', function() {
514 strictEqual(1, opened, 'opened new XHR'); 514 strictEqual(1, opened, 'opened new XHR');
515 }); 515 });
516 516
517 test('gets the correct PTS on seek', function() {
518 var
519 ptsByTime = -1,
520 seekTime = 5.123,
521 segmentParser = new window.videojs.hls.SegmentParser();
522 segmentParser.getTags = function() {
523 return [
524 {pts:1},
525 {pts:2},
526 {pts:3},
527 {pts:4},
528 {pts:5},
529 {pts:6}
530 ];
531 };
532
533 player.hls('manifest/media.m3u8');
534
535 videojs.mediaSources[player.currentSrc()].trigger({
536 type: 'sourceopen'
537 });
538
539 player.on('seeked', function() {
540 ptsByTime = player.hls.getPtsByTime(segmentParser,seekTime);
541 });
542
543 player.trigger('seeked');
544
545 notEqual(ptsByTime, -1, 'PTS Should be set on seek');
546 strictEqual(ptsByTime, 5, 'PTS should be closest');
547 ok(ptsByTime<=seekTime, 'PTS should be less than or equal to seek time');
548 });
549
517 550
518 module('segment controller', { 551 module('segment controller', {
519 setup: function() { 552 setup: function() {
520 segmentController = new window.videojs.hls.SegmentController(); 553 segmentController = new window.videojs.hls.SegmentController();
521
522 }, 554 },
523 teardown: function() { 555 teardown: function() {
524 window.videojs.get = this.vjsget; 556 window.videojs.get = this.vjsget;
......