Skip to content

Commit

Permalink
fix: use paren media sequence sync for audio and vtt, since they are …
Browse files Browse the repository at this point in the history
…opt-in features and can be enabled after main init (#1505)

Co-authored-by: Dzianis Dashkevich <[email protected]>
  • Loading branch information
dzianis-dashkevich and Dzianis Dashkevich authored Apr 22, 2024
1 parent be289f6 commit bdfe0e0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/sync-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import {sumDurations, getPartsAndSegments} from './playlist';
import videojs from 'video.js';
import logger from './util/logger';
import MediaSequenceSync from './util/media-sequence-sync';
import {MediaSequenceSync, DependantMediaSequenceSync} from './util/media-sequence-sync';

// The maximum gap allowed between two media sequence tags when trying to
// synchronize expired playlist segments.
Expand Down Expand Up @@ -233,11 +233,11 @@ export default class SyncController extends videojs.EventTarget {
// For some reason this map helps with syncing between quality switch for MPEG-DASH as well.
// Moreover if we disable this map for MPEG-DASH - quality switch will be broken.
// MPEG-DASH should have its own separate sync strategy
this.mediaSequenceStorage_ = {
main: new MediaSequenceSync(),
audio: new MediaSequenceSync(),
vtt: new MediaSequenceSync()
};
const main = new MediaSequenceSync();
const audio = new DependantMediaSequenceSync(main);
const vtt = new DependantMediaSequenceSync(main);

this.mediaSequenceStorage_ = {main, audio, vtt};
this.logger_ = logger('SyncController');
}

Expand Down
30 changes: 28 additions & 2 deletions src/util/media-sequence-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ class SyncInfoData {
}
}

export default class MediaSequenceSync {
export class MediaSequenceSync {
constructor() {
/**
* @type {Map<number, SyncInfoData>}
* @private
* @protected
*/
this.storage_ = new Map();
this.diagnostics_ = '';
Expand Down Expand Up @@ -160,6 +160,10 @@ export default class MediaSequenceSync {
return null;
}

getSyncInfoForMediaSequence(mediaSequence) {
return this.storage_.get(mediaSequence);
}

updateStorage_(segments, startingMediaSequence, startingTime) {
const newStorage = new Map();
let newDiagnostics = '\n';
Expand Down Expand Up @@ -244,3 +248,25 @@ export default class MediaSequenceSync {
return mediaSequence !== undefined && mediaSequence !== null && Array.isArray(segments) && segments.length;
}
}

export class DependantMediaSequenceSync extends MediaSequenceSync {
constructor(parent) {
super();

this.parent_ = parent;
}

calculateBaseTime_(mediaSequence, fallback) {
if (!this.storage_.size) {
const info = this.parent_.getSyncInfoForMediaSequence(mediaSequence);

if (info) {
return info.segmentSyncInfo.start;
}

return 0;
}

return super.calculateBaseTime_(mediaSequence, fallback);
}
}

0 comments on commit bdfe0e0

Please sign in to comment.