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

fix: use paren media sequence sync for audio and vtt, since they are opt-in features and can be enabled after main init. #1505

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading