From 28622287161b50b664cbfe9b5b8b7b1d5f894e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Velad=20Galv=C3=A1n?= Date: Thu, 11 Jan 2024 18:24:05 +0100 Subject: [PATCH] fix(TTML): Clip to video when extent is not present (#6086) Fixes https://github.com/shaka-project/shaka-player/issues/4793 --- lib/text/ttml_text_parser.js | 5 +++++ test/text/ttml_text_parser_unit.js | 32 +++++++++++++++--------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/text/ttml_text_parser.js b/lib/text/ttml_text_parser.js index 10760fcb25..ead042535e 100644 --- a/lib/text/ttml_text_parser.js +++ b/lib/text/ttml_text_parser.js @@ -491,6 +491,11 @@ shaka.text.TtmlTextParser = class { region.viewportAnchorX = region.viewportAnchorX * 100 / globalWidth; } + } else if (!extent) { + region.width = 100 - region.viewportAnchorX; + region.widthUnits = shaka.text.CueRegion.units.PERCENTAGE; + region.height = 100 - region.viewportAnchorY; + region.heightUnits = shaka.text.CueRegion.units.PERCENTAGE; } region.viewportAnchorUnits = percentage || globalWidth != null ? diff --git a/test/text/ttml_text_parser_unit.js b/test/text/ttml_text_parser_unit.js index 686ead9051..ba7b768a5c 100644 --- a/test/text/ttml_text_parser_unit.js +++ b/test/text/ttml_text_parser_unit.js @@ -638,8 +638,8 @@ describe('TtmlTextParser', () => { id: 'subtitleArea', viewportAnchorX: 50, viewportAnchorY: 16, - width: 100, - height: 100, + width: 50, + height: 84, }, startTime: 62.05, endTime: 3723.2, @@ -666,8 +666,8 @@ describe('TtmlTextParser', () => { region: { viewportAnchorX: 50, viewportAnchorY: 16, - width: 100, - height: 100, + width: 50, + height: 84, }, startTime: 62.05, endTime: 3723.2, @@ -694,8 +694,8 @@ describe('TtmlTextParser', () => { region: { viewportAnchorX: 50, viewportAnchorY: 16, - width: 100, - height: 100, + width: 50, + height: 84, }, startTime: 62.05, endTime: 3723.2, @@ -872,8 +872,8 @@ describe('TtmlTextParser', () => { viewportAnchorY: 16, regionAnchorX: 0, regionAnchorY: 0, - width: 100, - height: 100, + width: 50, + height: 84, heightUnits: CueRegion.units.PERCENTAGE, widthUnits: CueRegion.units.PERCENTAGE, viewportAnchorUnits: CueRegion.units.PERCENTAGE, @@ -945,8 +945,8 @@ describe('TtmlTextParser', () => { id: 'subtitleArea', viewportAnchorX: 50, viewportAnchorY: 16, - width: 100, - height: 100, + width: 50, + height: 84, }, startTime: 62.05, endTime: 3723.2, @@ -973,8 +973,8 @@ describe('TtmlTextParser', () => { region: { viewportAnchorX: 50, viewportAnchorY: 16, - width: 100, - height: 100, + width: 50, + height: 84, }, startTime: 62.05, endTime: 3723.2, @@ -1001,8 +1001,8 @@ describe('TtmlTextParser', () => { region: { viewportAnchorX: 50, viewportAnchorY: 16, - width: 100, - height: 100, + width: 50, + height: 84, }, startTime: 62.05, endTime: 3723.2, @@ -1032,8 +1032,8 @@ describe('TtmlTextParser', () => { id: 'subtitleArea', viewportAnchorX: 12.2, viewportAnchorY: 50.005, - width: 100, - height: 100, + width: 87.8, + height: 49.995, }, startTime: 62.05, endTime: 3723.2,