From 47224ff081fa7b022b8e013becab62b60a814143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Fri, 25 Aug 2023 06:52:44 +0200 Subject: [PATCH] feat(CEA): Add support to vertical position in CEA-608 (#5531) Related to https://github.com/shaka-project/shaka-player/issues/2940 --- lib/cea/cea608_memory.js | 4 ++++ test/cea/cea608_memory_unit.js | 24 ++++++++++++++++++++++++ test/cea/cea_decoder_unit.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/lib/cea/cea608_memory.js b/lib/cea/cea608_memory.js index 9a20ba1767..ff1e5a2e98 100644 --- a/lib/cea/cea608_memory.js +++ b/lib/cea/cea608_memory.js @@ -82,6 +82,10 @@ shaka.cea.Cea608Memory = class { const stream = `CC${(this.fieldNum_<< 1) | this.channelNum_ +1}`; const topLevelCue = new shaka.text.Cue( startTime, endTime, /* payload= */ ''); + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; + const maxRows = shaka.cea.Cea608Memory.CC_ROWS + 1; + topLevelCue.line = this.row_ / maxRows * 100; return shaka.cea.CeaUtils.getParsedCaption( topLevelCue, stream, this.rows_, startTime, endTime); } diff --git a/test/cea/cea608_memory_unit.js b/test/cea/cea608_memory_unit.js index b7858c414c..208008786a 100644 --- a/test/cea/cea608_memory_unit.js +++ b/test/cea/cea608_memory_unit.js @@ -31,6 +31,9 @@ describe('Cea608Memory', () => { const caption = memory.forceEmit(startTime, endTime); const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.line = 6.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue(startTime, endTime, text), ]; @@ -79,6 +82,9 @@ describe('Cea608Memory', () => { } const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.line = 6.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue(startTime, endTime, expectedText), ]; @@ -113,6 +119,9 @@ describe('Cea608Memory', () => { } const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.line = 6.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createStyledCue(startTime, endTime, expectedText, /* underline= */ true, @@ -164,6 +173,9 @@ describe('Cea608Memory', () => { // ... // So we expect that test\n\ntest is emitted const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.line = 37.5; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue(startTime, endTime, text), CeaUtils.createLineBreakCue(startTime, endTime), @@ -205,6 +217,9 @@ describe('Cea608Memory', () => { memory.eraseChar(); // Erase the last 't' from 'testt' const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.line = 6.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue(startTime, endTime, expectedText), ]; @@ -276,6 +291,9 @@ describe('Cea608Memory', () => { // Expected text is 's\nt\nt\ne' const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.line = 31.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue(startTime, endTime, 's'), CeaUtils.createLineBreakCue(startTime, endTime), @@ -320,6 +338,9 @@ describe('Cea608Memory', () => { // Expected text is 't\ne\ns\nt' const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.line = 31.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue(startTime, endTime, 't'), CeaUtils.createLineBreakCue(startTime, endTime), @@ -364,6 +385,9 @@ describe('Cea608Memory', () => { // Expected text is 't\ne\ns\nt' const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.line = 31.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue(startTime, endTime, 't'), CeaUtils.createLineBreakCue(startTime, endTime), diff --git a/test/cea/cea_decoder_unit.js b/test/cea/cea_decoder_unit.js index 0223c0193a..35c4c84caf 100644 --- a/test/cea/cea_decoder_unit.js +++ b/test/cea/cea_decoder_unit.js @@ -65,6 +65,9 @@ describe('CeaDecoder', () => { const topLevelCue = new shaka.text.Cue( startTimeCaption1, startTimeCaption2, ''); + topLevelCue.line = 81.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createStyledCue( startTimeCaption1, startTimeCaption2, expectedText, @@ -110,6 +113,9 @@ 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.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue( @@ -160,6 +166,9 @@ describe('CeaDecoder', () => { // A single nested cue containing yellow, italicized text. const topLevelCue = new shaka.text.Cue(startTimeCaption1, startTimeCaption2, ''); + topLevelCue.line = 12.5; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createStyledCue( startTimeCaption1, startTimeCaption2, expectedText, @@ -199,6 +208,9 @@ describe('CeaDecoder', () => { const topLevelCue = new shaka.text.Cue(startTimeCaption1, startTimeCaption2, ''); + topLevelCue.line = 6.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue( startTimeCaption1, startTimeCaption2, expectedText), @@ -231,6 +243,9 @@ describe('CeaDecoder', () => { const topLevelCue = new shaka.text.Cue(startTimeCaption1, startTimeCaption2, ''); + topLevelCue.line = 6.25; + topLevelCue.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue.nestedCues = [ CeaUtils.createDefaultCue( startTimeCaption1, startTimeCaption2, expectedText), @@ -300,6 +315,9 @@ 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.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue1.nestedCues = [ CeaUtils.createDefaultCue( /* startTime= */ time1, /* endTime= */ time2, /* payload= */ '1.'), @@ -308,6 +326,9 @@ 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.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue2.nestedCues = [ CeaUtils.createDefaultCue( /* startTime= */ time2, /* endTime= */ time3, /* payload= */ '1.'), @@ -322,6 +343,9 @@ 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.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue3.nestedCues = [ CeaUtils.createDefaultCue( /* startTime= */ time3, /* endTime= */ time4, /* payload= */ '2.'), @@ -336,6 +360,9 @@ 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.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue4.nestedCues = [ CeaUtils.createDefaultCue( /* startTime= */ time4, /* endTime= */ time5, /* payload= */ '3.'), @@ -406,6 +433,9 @@ 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.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue1.nestedCues = [ CeaUtils.createDefaultCue( /* startTime= */ 1, /* endTime= */ 2, /* payload= */ '1.'), @@ -414,6 +444,9 @@ 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.lineInterpretation = + shaka.text.Cue.lineInterpretation.PERCENTAGE; topLevelCue2.nestedCues = [ CeaUtils.createDefaultCue( /* startTime= */ 2, /* endTime= */ 3, /* payload= */ '1.'),