From b3621c26a86897ba80c17b68f316e22aba61b30b Mon Sep 17 00:00:00 2001 From: Maria Maddox Date: Tue, 27 Sep 2022 09:16:58 -0700 Subject: [PATCH 01/13] fix: check for negative rows before moving (#4510) Closes #4508 --- lib/cea/cea608_memory.js | 4 ++ test/cea/cea608_memory_unit.js | 88 ++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/lib/cea/cea608_memory.js b/lib/cea/cea608_memory.js index a30d8e8073..751141a39f 100644 --- a/lib/cea/cea608_memory.js +++ b/lib/cea/cea608_memory.js @@ -184,6 +184,10 @@ shaka.cea.Cea608Memory = class { * @param {number} count Count of rows to move. */ moveRows(dst, src, count) { + if (src < 0 || dst < 0) { + return; + } + if (dst >= src) { for (let i = count-1; i >= 0; i--) { this.rows_[dst + i] = this.rows_[src + i].map((e) => e); diff --git a/test/cea/cea608_memory_unit.js b/test/cea/cea608_memory_unit.js index 4105b0bd41..b7858c414c 100644 --- a/test/cea/cea608_memory_unit.js +++ b/test/cea/cea608_memory_unit.js @@ -295,5 +295,93 @@ describe('Cea608Memory', () => { const caption = memory.forceEmit(startTime, endTime); expect(caption).toEqual(expectedCaption); }); + + it('does not move rows if source row index is negative', () => { + const startTime = 1; + const endTime = 2; + const text = 'test'; + + // Add the text to the buffer, each character on separate rows. + // At this point, the memory looks like: + // [1]: t + // [2]: e + // [3]: s + // [4]: t + for (const c of text) { + memory.addChar(CharSet.BASIC_NORTH_AMERICAN, + c.charCodeAt(0)); + memory.setRow(memory.getRow() + 1); // increment row + } + + const srcRowIdx = -1; + const dstRowIdx = 2; + const rowsToMove = 3; + memory.moveRows(dstRowIdx, srcRowIdx, rowsToMove); + + // Expected text is 't\ne\ns\nt' + const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.nestedCues = [ + CeaUtils.createDefaultCue(startTime, endTime, 't'), + CeaUtils.createLineBreakCue(startTime, endTime), + CeaUtils.createDefaultCue(startTime, endTime, 'e'), + CeaUtils.createLineBreakCue(startTime, endTime), + CeaUtils.createDefaultCue(startTime, endTime, 's'), + CeaUtils.createLineBreakCue(startTime, endTime), + CeaUtils.createDefaultCue(startTime, endTime, 't'), + ]; + + const expectedCaption = { + stream, + cue: topLevelCue, + }; + + // Force out the new memory. + const caption = memory.forceEmit(startTime, endTime); + expect(caption).toEqual(expectedCaption); + }); + + it('does not move rows if destination row index is negative', () => { + const startTime = 1; + const endTime = 2; + const text = 'test'; + + // Add the text to the buffer, each character on separate rows. + // At this point, the memory looks like: + // [1]: t + // [2]: e + // [3]: s + // [4]: t + for (const c of text) { + memory.addChar(CharSet.BASIC_NORTH_AMERICAN, + c.charCodeAt(0)); + memory.setRow(memory.getRow() + 1); // increment row + } + + const srcRowIdx = 1; + const dstRowIdx = -2; + const rowsToMove = 3; + memory.moveRows(dstRowIdx, srcRowIdx, rowsToMove); + + // Expected text is 't\ne\ns\nt' + const topLevelCue = new shaka.text.Cue(startTime, endTime, ''); + topLevelCue.nestedCues = [ + CeaUtils.createDefaultCue(startTime, endTime, 't'), + CeaUtils.createLineBreakCue(startTime, endTime), + CeaUtils.createDefaultCue(startTime, endTime, 'e'), + CeaUtils.createLineBreakCue(startTime, endTime), + CeaUtils.createDefaultCue(startTime, endTime, 's'), + CeaUtils.createLineBreakCue(startTime, endTime), + CeaUtils.createDefaultCue(startTime, endTime, 't'), + ]; + + const expectedCaption = { + stream, + cue: topLevelCue, + }; + + // Force out the new memory. + const caption = memory.forceEmit(startTime, endTime); + expect(caption).toEqual(expectedCaption); + }); }); }); From 32b0a90a8c583bba03a3d7b035a1244d325e3da6 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Tue, 27 Sep 2022 19:51:46 -0700 Subject: [PATCH 02/13] fix(ttml): Default TTML background color to transparent if unspecified (#4496) Closes #4468 --- lib/text/ttml_text_parser.js | 6 ++++ test/test/util/ttml_utils.js | 2 -- test/text/ttml_text_parser_unit.js | 46 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/lib/text/ttml_text_parser.js b/lib/text/ttml_text_parser.js index de34a05241..bf26ec4509 100644 --- a/lib/text/ttml_text_parser.js +++ b/lib/text/ttml_text_parser.js @@ -164,6 +164,12 @@ shaka.text.TtmlTextParser = class { cellResolutionInfo, /* parentCueElement= */ null, /* isContent= */ false); if (cue) { + // According to the TTML spec, backgrounds default to transparent. + // So default the background of the top-level element to transparent. + // Nested elements may override that background color already. + if (!cue.backgroundColor) { + cue.backgroundColor = 'transparent'; + } cues.push(cue); } } diff --git a/test/test/util/ttml_utils.js b/test/test/util/ttml_utils.js index bb7ed09482..a8417bade4 100644 --- a/test/test/util/ttml_utils.js +++ b/test/test/util/ttml_utils.js @@ -51,8 +51,6 @@ shaka.test.TtmlUtils = class { region, nestedCues: jasmine.any(Object), payload: '', - startTime: 0, - endTime: Infinity, isContainer: true, }); Object.assign(containerCue, properties); diff --git a/test/text/ttml_text_parser_unit.js b/test/text/ttml_text_parser_unit.js index 32f4e3353a..a0b09bb0fb 100644 --- a/test/text/ttml_text_parser_unit.js +++ b/test/text/ttml_text_parser_unit.js @@ -1535,6 +1535,52 @@ describe('TtmlTextParser', () => { {startTime: 1, endTime: 2}); }); + // Regression test for #4468 + it('defaults the body background to transparent', () => { + verifyHelper( + // One cue, don't care about the details + [{}], + '' + + '' + + '' + + '