Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr for media sequence #1204

Merged
merged 12 commits into from
Sep 22, 2021
10 changes: 10 additions & 0 deletions src/sync-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {sumDurations, getPartsAndSegments} from './playlist';
import videojs from 'video.js';
import logger from './util/logger';

// The maximum gap allowed between two media sequence tags when trying to
// synchronize expired playlist segments.
const MAX_MEDIA_SEQUENCE_DIFF_FOR_SYNC = 1000;
jontsnz marked this conversation as resolved.
Show resolved Hide resolved

export const syncPointStrategies = [
// Stategy "VOD": Handle the VOD-case where the sync-point is *always*
// the equivalence display-time 0 === segment-index 0
Expand Down Expand Up @@ -364,6 +368,12 @@ export default class SyncController extends videojs.EventTarget {
saveExpiredSegmentInfo(oldPlaylist, newPlaylist) {
const mediaSequenceDiff = newPlaylist.mediaSequence - oldPlaylist.mediaSequence;

// Ignore large media sequence gaps
if (mediaSequenceDiff > MAX_MEDIA_SEQUENCE_DIFF_FOR_SYNC) {
videojs.log.warn(`Not saving expired segment info. Media sequence gap ${mediaSequenceDiff} is too large.`);
return;
}

// When a segment expires from the playlist and it has a start time
// save that information as a possible sync-point reference in future
for (let i = mediaSequenceDiff - 1; i >= 0; i--) {
Expand Down
18 changes: 18 additions & 0 deletions test/sync-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,24 @@ QUnit.test('saves expired info onto new playlist for sync point', function(asser
);
});

QUnit.test('skips save of expired segment info if media sequence gap too large', function(assert) {
const oldPlaylist = playlistWithDuration(50);
const newPlaylist = playlistWithDuration(50);

oldPlaylist.mediaSequence = 100;
newPlaylist.mediaSequence = 2000;
jontsnz marked this conversation as resolved.
Show resolved Hide resolved

oldPlaylist.segments[0].start = 390;
oldPlaylist.segments[1].start = 400;

this.syncController.saveExpiredSegmentInfo(oldPlaylist, newPlaylist);

assert.strictEqual(
typeof newPlaylist.syncInfo, 'undefined',
'skipped saving sync info onto new playlist'
);
});

QUnit.test('saves segment timing info', function(assert) {
const syncCon = this.syncController;
const playlist = playlistWithDuration(60);
Expand Down