Skip to content

Commit

Permalink
Clear out orphaned roll-up captions
Browse files Browse the repository at this point in the history
  • Loading branch information
romsiltp committed Nov 10, 2016
1 parent 2ec71e3 commit 7d37f6f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/utils/cea-608-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,32 @@ class CaptionScreen {
row.setCursor(absPos);
}

setPAC(pacData) {
setPAC(pacData, lastOutputScreen) {
logger.log('INFO', 'pacData = ' + JSON.stringify(pacData));
var newRow = pacData.row - 1;
if (this.nrRollUpRows && newRow < this.nrRollUpRows - 1) {
newRow = this.nrRollUpRows-1;
}

if (this.currRow !== newRow) {
//clear all rows first
for (var i = 0; i < NR_ROWS; i++) {
this.rows[i].clear();
}

//Copy this.nrRollUpRows rows from lastOutputScreen and place it in the newRow location
//topRowIndex - the start of rows to copy (inclusive index)
var topRowIndex = this.currRow + 1 - (this.nrRollUpRows);
//We only copy if the last position was already shown.
//We use the cueStartTime to check this.
var prevLineTime = lastOutputScreen.rows[topRowIndex].cueStartTime;
if(prevLineTime && prevLineTime < logger.time) {
for (i = 0; i < this.nrRollUpRows; i++) {
this.rows[newRow-this.nrRollUpRows+i+1].copy(lastOutputScreen.rows[topRowIndex+i]);
}
}
}

this.currRow = newRow;
var row = this.rows[this.currRow];
if (pacData.indent !== null) {
Expand Down Expand Up @@ -621,7 +641,7 @@ class Cea608Channel
}

setPAC(pacData) {
this.writeScreen.setPAC(pacData);
this.writeScreen.setPAC(pacData, this.lastOutputScreen);
}

setBkgData(bkgData) {
Expand All @@ -639,6 +659,7 @@ class Cea608Channel
} else {
this.writeScreen = this.displayedMemory;
this.writeScreen.reset();
this.lastOutputScreen.reset();
}
if (this.mode !== 'MODE_ROLL-UP') {
this.displayedMemory.nrRollUpRows = null;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/cues.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ var Cues = {
indenting = false;
}
}
//To be used for cleaning-up orphaned roll-up captions
row.cueStartTime = startTime;
cue = new VTTCue(startTime, endTime, text.trim());

if (indent >= 16)
Expand Down

0 comments on commit 7d37f6f

Please sign in to comment.