Skip to content

Commit

Permalink
fix(text): Fix timestamp offset of CEA-608 cues
Browse files Browse the repository at this point in the history
When we attach closed-caption cues to the text engine, we apply the
video timestamp offset to the cues, so that they can align with the
start of the stream. However, we previously forgot to apply that
offset to any nested cues.
This did not matter beforehand, since we previously ignored the start
and end times of nested cues. However, recent changes to the UI text
displayer changed that.
So this fixes nested cues to apply video timestamp offset.

Closes shaka-project#3782

Change-Id: I4c9140fcfa9bf94579f8d847e546ee4e2ec5eff4
  • Loading branch information
theodab committed Dec 6, 2021
1 parent 4cc2954 commit b6d7138
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/media/media_source_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ shaka.media.MediaSourceEngine = class {
* @param {!function(!Array.<shaka.extern.ID3Metadata>, number, ?number)=}
* onMetadata
*/
constructor(video, closedCaptionParser, textDisplayer,
onMetadata) {
constructor(video, closedCaptionParser, textDisplayer, onMetadata) {
/** @private {HTMLMediaElement} */
this.video_ = video;

Expand Down
16 changes: 14 additions & 2 deletions lib/text/text_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ shaka.text.TextEngine = class {
return cues;
}

/**
* @param {!shaka.text.Cue} cue the cue to apply the timestamp to recursively
* @param {number} videoTimestampOffset the timestamp offset of the video
* @private
*/
applyVideoTimestampOffsetRecursive_(cue, videoTimestampOffset) {
cue.startTime += videoTimestampOffset;
cue.endTime += videoTimestampOffset;
for (const nested of cue.nestedCues) {
this.applyVideoTimestampOffsetRecursive_(nested, videoTimestampOffset);
}
}

/**
* Store the closed captions in the text engine, and append the cues to the
* text displayer. This is a side-channel used for embedded text only.
Expand Down Expand Up @@ -373,8 +386,7 @@ shaka.text.TextEngine = class {

// Adjust CEA captions with respect to the timestamp offset of the video
// stream in which they were embedded.
cue.startTime += videoTimestampOffset;
cue.endTime += videoTimestampOffset;
this.applyVideoTimestampOffsetRecursive_(cue, videoTimestampOffset);

const keepThisCue =
cue.startTime >= this.appendWindowStart_ &&
Expand Down

0 comments on commit b6d7138

Please sign in to comment.