Skip to content

Commit 230f6e0

Browse files
authored
fix(CEA): Offset text CEA-608 that are out of viewport (#7024)
1 parent 516f9f6 commit 230f6e0

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/cea/cea608_memory.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,29 @@ shaka.cea.Cea608Memory = class {
7979
* @return {?shaka.extern.ICaptionDecoder.ClosedCaption}
8080
*/
8181
forceEmit(startTime, endTime) {
82+
const Cea608Memory = shaka.cea.Cea608Memory;
8283
const stream = `CC${((this.fieldNum_<< 1) | this.channelNum_) + 1}`;
8384
const topLevelCue = new shaka.text.Cue(
8485
startTime, endTime, /* payload= */ '');
8586
topLevelCue.lineInterpretation =
8687
shaka.text.Cue.lineInterpretation.PERCENTAGE;
87-
const line = shaka.cea.Cea608Memory.ROW_TO_LINE_CONVERSION_.get(this.row_);
88+
let line = Cea608Memory.ROW_TO_LINE_CONVERSION_.get(this.row_);
8889
if (line) {
8990
topLevelCue.line = line;
9091
}
91-
return shaka.cea.CeaUtils.getParsedCaption(
92+
const ret = shaka.cea.CeaUtils.getParsedCaption(
9293
topLevelCue, stream, this.rows_, startTime, endTime);
94+
// If the text and its lines are larger than what we can show on the
95+
// screen, we move the lines up so that the text does not come out of the
96+
// video.
97+
if (ret && (this.row_ + ret.cue.nestedCues.length - 3) > 15) {
98+
const newLinePosition = this.row_ + 3 - ret.cue.nestedCues.length;
99+
line = Cea608Memory.ROW_TO_LINE_CONVERSION_.get(newLinePosition);
100+
if (line) {
101+
topLevelCue.line = line;
102+
}
103+
}
104+
return ret;
93105
}
94106

95107
/**

0 commit comments

Comments
 (0)