Skip to content

Commit bdfe0e0

Browse files
dzianis-dashkevichDzianis Dashkevich
andauthored
fix: use paren media sequence sync for audio and vtt, since they are opt-in features and can be enabled after main init (#1505)
Co-authored-by: Dzianis Dashkevich <ddashkevich@brightcove.com>
1 parent be289f6 commit bdfe0e0

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/sync-controller.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import {sumDurations, getPartsAndSegments} from './playlist';
66
import videojs from 'video.js';
77
import logger from './util/logger';
8-
import MediaSequenceSync from './util/media-sequence-sync';
8+
import {MediaSequenceSync, DependantMediaSequenceSync} from './util/media-sequence-sync';
99

1010
// The maximum gap allowed between two media sequence tags when trying to
1111
// synchronize expired playlist segments.
@@ -233,11 +233,11 @@ export default class SyncController extends videojs.EventTarget {
233233
// For some reason this map helps with syncing between quality switch for MPEG-DASH as well.
234234
// Moreover if we disable this map for MPEG-DASH - quality switch will be broken.
235235
// MPEG-DASH should have its own separate sync strategy
236-
this.mediaSequenceStorage_ = {
237-
main: new MediaSequenceSync(),
238-
audio: new MediaSequenceSync(),
239-
vtt: new MediaSequenceSync()
240-
};
236+
const main = new MediaSequenceSync();
237+
const audio = new DependantMediaSequenceSync(main);
238+
const vtt = new DependantMediaSequenceSync(main);
239+
240+
this.mediaSequenceStorage_ = {main, audio, vtt};
241241
this.logger_ = logger('SyncController');
242242
}
243243

src/util/media-sequence-sync.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ class SyncInfoData {
7979
}
8080
}
8181

82-
export default class MediaSequenceSync {
82+
export class MediaSequenceSync {
8383
constructor() {
8484
/**
8585
* @type {Map<number, SyncInfoData>}
86-
* @private
86+
* @protected
8787
*/
8888
this.storage_ = new Map();
8989
this.diagnostics_ = '';
@@ -160,6 +160,10 @@ export default class MediaSequenceSync {
160160
return null;
161161
}
162162

163+
getSyncInfoForMediaSequence(mediaSequence) {
164+
return this.storage_.get(mediaSequence);
165+
}
166+
163167
updateStorage_(segments, startingMediaSequence, startingTime) {
164168
const newStorage = new Map();
165169
let newDiagnostics = '\n';
@@ -244,3 +248,25 @@ export default class MediaSequenceSync {
244248
return mediaSequence !== undefined && mediaSequence !== null && Array.isArray(segments) && segments.length;
245249
}
246250
}
251+
252+
export class DependantMediaSequenceSync extends MediaSequenceSync {
253+
constructor(parent) {
254+
super();
255+
256+
this.parent_ = parent;
257+
}
258+
259+
calculateBaseTime_(mediaSequence, fallback) {
260+
if (!this.storage_.size) {
261+
const info = this.parent_.getSyncInfoForMediaSequence(mediaSequence);
262+
263+
if (info) {
264+
return info.segmentSyncInfo.start;
265+
}
266+
267+
return 0;
268+
}
269+
270+
return super.calculateBaseTime_(mediaSequence, fallback);
271+
}
272+
}

0 commit comments

Comments
 (0)