TTML: Remove unused CellResolution.columns and collapse to int rows

PiperOrigin-RevId: 566908824
This commit is contained in:
ibaker 2023-09-20 03:19:23 -07:00 committed by Copybara-Service
parent 3cf9c08dca
commit 134f53bdb2

View File

@ -106,8 +106,7 @@ public final class TtmlParser implements SubtitleParser {
private static final FrameAndTickRate DEFAULT_FRAME_AND_TICK_RATE = private static final FrameAndTickRate DEFAULT_FRAME_AND_TICK_RATE =
new FrameAndTickRate(DEFAULT_FRAME_RATE, 1, 1); new FrameAndTickRate(DEFAULT_FRAME_RATE, 1, 1);
private static final CellResolution DEFAULT_CELL_RESOLUTION = private static final int DEFAULT_CELL_ROWS = 15;
new CellResolution(/* columns= */ 32, /* rows= */ 15);
private final XmlPullParserFactory xmlParserFactory; private final XmlPullParserFactory xmlParserFactory;
@ -153,7 +152,7 @@ public final class TtmlParser implements SubtitleParser {
int unsupportedNodeDepth = 0; int unsupportedNodeDepth = 0;
int eventType = xmlParser.getEventType(); int eventType = xmlParser.getEventType();
FrameAndTickRate frameAndTickRate = DEFAULT_FRAME_AND_TICK_RATE; FrameAndTickRate frameAndTickRate = DEFAULT_FRAME_AND_TICK_RATE;
CellResolution cellResolution = DEFAULT_CELL_RESOLUTION; int cellRows = DEFAULT_CELL_ROWS;
@Nullable TtsExtent ttsExtent = null; @Nullable TtsExtent ttsExtent = null;
while (eventType != XmlPullParser.END_DOCUMENT) { while (eventType != XmlPullParser.END_DOCUMENT) {
@Nullable TtmlNode parent = nodeStack.peek(); @Nullable TtmlNode parent = nodeStack.peek();
@ -162,14 +161,14 @@ public final class TtmlParser implements SubtitleParser {
if (eventType == XmlPullParser.START_TAG) { if (eventType == XmlPullParser.START_TAG) {
if (TtmlNode.TAG_TT.equals(name)) { if (TtmlNode.TAG_TT.equals(name)) {
frameAndTickRate = parseFrameAndTickRates(xmlParser); frameAndTickRate = parseFrameAndTickRates(xmlParser);
cellResolution = parseCellResolution(xmlParser, DEFAULT_CELL_RESOLUTION); cellRows = parseCellRows(xmlParser, DEFAULT_CELL_ROWS);
ttsExtent = parseTtsExtent(xmlParser); ttsExtent = parseTtsExtent(xmlParser);
} }
if (!isSupportedTag(name)) { if (!isSupportedTag(name)) {
Log.i(TAG, "Ignoring unsupported tag: " + xmlParser.getName()); Log.i(TAG, "Ignoring unsupported tag: " + xmlParser.getName());
unsupportedNodeDepth++; unsupportedNodeDepth++;
} else if (TtmlNode.TAG_HEAD.equals(name)) { } else if (TtmlNode.TAG_HEAD.equals(name)) {
parseHeader(xmlParser, globalStyles, cellResolution, ttsExtent, regionMap, imageMap); parseHeader(xmlParser, globalStyles, cellRows, ttsExtent, regionMap, imageMap);
} else { } else {
try { try {
TtmlNode node = parseNode(xmlParser, parent, regionMap, frameAndTickRate); TtmlNode node = parseNode(xmlParser, parent, regionMap, frameAndTickRate);
@ -242,8 +241,7 @@ public final class TtmlParser implements SubtitleParser {
return new FrameAndTickRate(frameRate * frameRateMultiplier, subFrameRate, tickRate); return new FrameAndTickRate(frameRate * frameRateMultiplier, subFrameRate, tickRate);
} }
private static CellResolution parseCellResolution( private static int parseCellRows(XmlPullParser xmlParser, int defaultValue) {
XmlPullParser xmlParser, CellResolution defaultValue) {
String cellResolution = xmlParser.getAttributeValue(TTP, "cellResolution"); String cellResolution = xmlParser.getAttributeValue(TTP, "cellResolution");
if (cellResolution == null) { if (cellResolution == null) {
return defaultValue; return defaultValue;
@ -258,7 +256,7 @@ public final class TtmlParser implements SubtitleParser {
int columns = Integer.parseInt(Assertions.checkNotNull(cellResolutionMatcher.group(1))); int columns = Integer.parseInt(Assertions.checkNotNull(cellResolutionMatcher.group(1)));
int rows = Integer.parseInt(Assertions.checkNotNull(cellResolutionMatcher.group(2))); int rows = Integer.parseInt(Assertions.checkNotNull(cellResolutionMatcher.group(2)));
checkArgument(columns != 0 && rows != 0, "Invalid cell resolution " + columns + " " + rows); checkArgument(columns != 0 && rows != 0, "Invalid cell resolution " + columns + " " + rows);
return new CellResolution(columns, rows); return rows;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.w(TAG, "Ignoring malformed cell resolution: " + cellResolution); Log.w(TAG, "Ignoring malformed cell resolution: " + cellResolution);
return defaultValue; return defaultValue;
@ -291,7 +289,7 @@ public final class TtmlParser implements SubtitleParser {
private static Map<String, TtmlStyle> parseHeader( private static Map<String, TtmlStyle> parseHeader(
XmlPullParser xmlParser, XmlPullParser xmlParser,
Map<String, TtmlStyle> globalStyles, Map<String, TtmlStyle> globalStyles,
CellResolution cellResolution, int cellRows,
@Nullable TtsExtent ttsExtent, @Nullable TtsExtent ttsExtent,
Map<String, TtmlRegion> globalRegions, Map<String, TtmlRegion> globalRegions,
Map<String, String> imageMap) Map<String, String> imageMap)
@ -311,8 +309,7 @@ public final class TtmlParser implements SubtitleParser {
globalStyles.put(styleId, style); globalStyles.put(styleId, style);
} }
} else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_REGION)) { } else if (XmlPullParserUtil.isStartTag(xmlParser, TtmlNode.TAG_REGION)) {
@Nullable @Nullable TtmlRegion ttmlRegion = parseRegionAttributes(xmlParser, cellRows, ttsExtent);
TtmlRegion ttmlRegion = parseRegionAttributes(xmlParser, cellResolution, ttsExtent);
if (ttmlRegion != null) { if (ttmlRegion != null) {
globalRegions.put(ttmlRegion.id, ttmlRegion); globalRegions.put(ttmlRegion.id, ttmlRegion);
} }
@ -347,7 +344,7 @@ public final class TtmlParser implements SubtitleParser {
*/ */
@Nullable @Nullable
private static TtmlRegion parseRegionAttributes( private static TtmlRegion parseRegionAttributes(
XmlPullParser xmlParser, CellResolution cellResolution, @Nullable TtsExtent ttsExtent) { XmlPullParser xmlParser, int cellRows, @Nullable TtsExtent ttsExtent) {
@Nullable String regionId = XmlPullParserUtil.getAttributeValue(xmlParser, TtmlNode.ATTR_ID); @Nullable String regionId = XmlPullParserUtil.getAttributeValue(xmlParser, TtmlNode.ATTR_ID);
if (regionId == null) { if (regionId == null) {
return null; return null;
@ -465,7 +462,7 @@ public final class TtmlParser implements SubtitleParser {
} }
} }
float regionTextHeight = 1.0f / cellResolution.rows; float regionTextHeight = 1.0f / cellRows;
@Cue.VerticalType int verticalType = Cue.TYPE_UNSET; @Cue.VerticalType int verticalType = Cue.TYPE_UNSET;
@Nullable @Nullable
@ -884,17 +881,6 @@ public final class TtmlParser implements SubtitleParser {
} }
} }
/** Represents the cell resolution for a TTML file. */
private static final class CellResolution {
final int columns;
final int rows;
CellResolution(int columns, int rows) {
this.columns = columns;
this.rows = rows;
}
}
/** Represents the tts:extent for a TTML file. */ /** Represents the tts:extent for a TTML file. */
private static final class TtsExtent { private static final class TtsExtent {
final int width; final int width;