Skip to content

Commit

Permalink
fix(CEA): Fix positioning in CEA-608 (#5925)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored Nov 27, 2023
1 parent 00ff864 commit 83f6f53
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 deletions.
15 changes: 13 additions & 2 deletions lib/cea/cea608_memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ shaka.cea.Cea608Memory = class {
startTime, endTime, /* payload= */ '');
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
const maxRows = shaka.cea.Cea608Memory.CC_ROWS + 1;
topLevelCue.line = this.row_ / maxRows * 100;
const line = shaka.cea.Cea608Memory.ROW_TO_LINE_CONVERSION_.get(this.row_);
if (line) {
topLevelCue.line = line;
}
return shaka.cea.CeaUtils.getParsedCaption(
topLevelCue, stream, this.rows_, startTime, endTime);
}
Expand Down Expand Up @@ -320,3 +322,12 @@ shaka.cea.Cea608Memory.CharSet.ExtendedPortugueseGerman = new Map([
[0x38, 'Å'], [0x39, 'å'], [0x3a, 'Ø'], [0x3b, 'ø'], [0x3c, '┌'], [0x3d, '┐'],
[0x3e, '└'], [0x3f, '┘'],
]);

/**
* @private @const {!Map<number, number>}
*/
shaka.cea.Cea608Memory.ROW_TO_LINE_CONVERSION_ = new Map([
[1, 10], [2, 15.33], [3, 20.66], [4, 26], [5, 31.33], [6, 36.66], [7, 42],
[8, 47.33], [9, 52.66], [10, 58], [11, 63.33], [12, 68.66], [13, 74],
[14, 79.33], [15, 84.66],
]);
16 changes: 8 additions & 8 deletions test/cea/cea608_memory_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('Cea608Memory', () => {
const caption = memory.forceEmit(startTime, endTime);

const topLevelCue = new shaka.text.Cue(startTime, endTime, '');
topLevelCue.line = 6.25;
topLevelCue.line = 10;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Cea608Memory', () => {
}

const topLevelCue = new shaka.text.Cue(startTime, endTime, '');
topLevelCue.line = 6.25;
topLevelCue.line = 10;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('Cea608Memory', () => {
}

const topLevelCue = new shaka.text.Cue(startTime, endTime, '');
topLevelCue.line = 6.25;
topLevelCue.line = 10;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('Cea608Memory', () => {
// ...
// So we expect that test\n\ntest is emitted
const topLevelCue = new shaka.text.Cue(startTime, endTime, '');
topLevelCue.line = 37.5;
topLevelCue.line = 36.66;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('Cea608Memory', () => {
memory.eraseChar(); // Erase the last 't' from 'testt'

const topLevelCue = new shaka.text.Cue(startTime, endTime, '');
topLevelCue.line = 6.25;
topLevelCue.line = 10;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('Cea608Memory', () => {

// Expected text is 's\nt\nt\ne'
const topLevelCue = new shaka.text.Cue(startTime, endTime, '');
topLevelCue.line = 31.25;
topLevelCue.line = 31.33;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -338,7 +338,7 @@ describe('Cea608Memory', () => {

// Expected text is 't\ne\ns\nt'
const topLevelCue = new shaka.text.Cue(startTime, endTime, '');
topLevelCue.line = 31.25;
topLevelCue.line = 31.33;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -385,7 +385,7 @@ describe('Cea608Memory', () => {

// Expected text is 't\ne\ns\nt'
const topLevelCue = new shaka.text.Cue(startTime, endTime, '');
topLevelCue.line = 31.25;
topLevelCue.line = 31.33;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down
22 changes: 11 additions & 11 deletions test/cea/cea_decoder_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('CeaDecoder', () => {

const topLevelCue = new shaka.text.Cue(
startTimeCaption1, startTimeCaption2, '');
topLevelCue.line = 81.25;
topLevelCue.line = 74;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('CeaDecoder', () => {
// Since there are three style changes, there should be three nested cues.
const topLevelCue = new shaka.text.Cue(
startTimeCaption1, startTimeCaption2, '');
topLevelCue.line = 6.25;
topLevelCue.line = 10;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;

Expand Down Expand Up @@ -166,7 +166,7 @@ describe('CeaDecoder', () => {
// A single nested cue containing yellow, italicized text.
const topLevelCue = new shaka.text.Cue(startTimeCaption1,
startTimeCaption2, '');
topLevelCue.line = 12.5;
topLevelCue.line = 15.33;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -208,7 +208,7 @@ describe('CeaDecoder', () => {

const topLevelCue = new shaka.text.Cue(startTimeCaption1,
startTimeCaption2, '');
topLevelCue.line = 6.25;
topLevelCue.line = 10;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -243,7 +243,7 @@ describe('CeaDecoder', () => {

const topLevelCue = new shaka.text.Cue(startTimeCaption1,
startTimeCaption2, '');
topLevelCue.line = 6.25;
topLevelCue.line = 10;
topLevelCue.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue.nestedCues = [
Expand Down Expand Up @@ -315,7 +315,7 @@ describe('CeaDecoder', () => {
// Top level cue corresponding to the first closed caption.
const topLevelCue1 = new shaka.text.Cue(
/* startTime= */ time1, /* endTime= */ time2, '');
topLevelCue1.line = 93.75;
topLevelCue1.line = 84.66;
topLevelCue1.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue1.nestedCues = [
Expand All @@ -326,7 +326,7 @@ describe('CeaDecoder', () => {
// Top level cue corresponding to the second closed caption.
const topLevelCue2 = new shaka.text.Cue(
/* startTime= */ time2, /* endTime= */ time3, '');
topLevelCue2.line = 93.75;
topLevelCue2.line = 84.66;
topLevelCue2.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue2.nestedCues = [
Expand All @@ -343,7 +343,7 @@ describe('CeaDecoder', () => {
// Top level cue corresponding to the third closed caption.
const topLevelCue3 = new shaka.text.Cue(
/* startTime= */ time3, /* endTime= */ time4, '');
topLevelCue3.line = 93.75;
topLevelCue3.line = 84.66;
topLevelCue3.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue3.nestedCues = [
Expand All @@ -360,7 +360,7 @@ describe('CeaDecoder', () => {
// Top level cue corresponding to the fourth closed caption.
const topLevelCue4 = new shaka.text.Cue(
/* startTime= */ time4, /* endTime= */ time5, '');
topLevelCue4.line = 93.75;
topLevelCue4.line = 84.66;
topLevelCue4.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue4.nestedCues = [
Expand Down Expand Up @@ -433,7 +433,7 @@ describe('CeaDecoder', () => {
// Top level cue corresponding to the first closed caption.
const topLevelCue1 = new shaka.text.Cue(/* startTime= */ 1,
/* endTime= */ 2, '');
topLevelCue1.line = 93.75;
topLevelCue1.line = 84.66;
topLevelCue1.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue1.nestedCues = [
Expand All @@ -444,7 +444,7 @@ describe('CeaDecoder', () => {
// Top level cue corresponding to the second closed caption.
const topLevelCue2 = new shaka.text.Cue(/* startTime= */ 2,
/* endTime= */ 3, '');
topLevelCue2.line = 25;
topLevelCue2.line = 26;
topLevelCue2.lineInterpretation =
shaka.text.Cue.lineInterpretation.PERCENTAGE;
topLevelCue2.nestedCues = [
Expand Down

0 comments on commit 83f6f53

Please sign in to comment.