Skip to content

Commit

Permalink
fix(FEC-11760): ignore cue with wrong start time (#154)
Browse files Browse the repository at this point in the history
If we have a live stream with CEA 608 captions, and we seek from Live Edge to point A to point C to point B,
where [Time A] < [Time B] < [Time C] < [Live Edge],
a bug in hls.js causes the cue created at point C to have the start time of point A, and the text of cue C to be visible at the wrong position.
As a workaround, if after seek we detect a cue in the cues list which has an endTime greater than its next sibling - we remove that cue.
Fixes FEC-11760.
  • Loading branch information
SivanA-Kaltura authored Dec 20, 2021
1 parent f32883b commit 6211f18
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/hls-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
_nativeTextTracksMap = [];
_lastLoadedFragSN: number = -1;
_sameFragSNLoadedCount: number = 0;
_textTrackIndex = -1;
/**
* an object containing all the events we bind and unbind to.
* @member {Object} - _adapterEventsBindings
Expand Down Expand Up @@ -432,6 +433,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._onRecoveredCallback = () => this._onRecovered();
this._onAddTrack = this._onAddTrack.bind(this);
this._eventManager.listen(this._videoElement, 'addtrack', this._onAddTrack);
this._eventManager.listen(this._videoElement, 'seeked', this._onSeeked.bind(this));
this._videoElement.textTracks.onaddtrack = this._onAddTrack;
}

Expand All @@ -448,13 +450,29 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
// parse CEA 608/708 captions that not exposed on hls.subtitleTracks API
const CEATextTrack = this._parseCEATextTrack(event.track);
if (CEATextTrack) {
HlsAdapter._logger.debug('A CEA 608/708 caption has found', CEATextTrack);
HlsAdapter._logger.debug('A CEA 608/708 caption has been found', CEATextTrack);
this._playerTracks.push(CEATextTrack);
this._trigger(EventType.TRACKS_CHANGED, {tracks: this._playerTracks});
}
}
}

_onSeeked() {
const textTrack = this._nativeTextTracksMap[this._textTrackIndex];
if (textTrack) {
// workaround to clear CEA 608 cues which have an incorrect startTime after seek forward
const cues = textTrack.cues;
if (cues && cues.length > 1) {
for (let i = 0; i < cues.length - 1; ++i) {
if (Math.floor(cues[i].endTime) > Math.floor(cues[i + 1].endTime)) {
textTrack.removeCue(cues[i]);
break;
}
}
}
}
}

/**
* attach media - return the media source to handle the video tag
* @public
Expand Down Expand Up @@ -573,6 +591,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
this._nativeTextTracksMap = [];
this._sameFragSNLoadedCount = 0;
this._lastLoadedFragSN = -1;
this._textTrackIndex = -1;
this._reset();
resolve();
},
Expand Down Expand Up @@ -761,6 +780,7 @@ export default class HlsAdapter extends BaseMediaSourceAdapter {
}

_notifyTrackChanged(textTrack: TextTrack): void {
this._textTrackIndex = textTrack.index;
this._onTrackChanged(textTrack);
}

Expand Down

0 comments on commit 6211f18

Please sign in to comment.