/** * Gets correct value of ending point of a temporal interval. * <p><p/> * Note: if both end and dur attributes are specified in the element then ending point is equal to the lesser of the * value of the dur attribute and the difference between the value of the end attribute and the element's begin * time. * * @param begin begin point of a temporal interval * @param end ending point of a temporal interval * @param dur duration of a temporal interval * @return correct value of ending point of a temporal interval */ private static long getEnd(TtmlTimeConverter ttConverter, String begin, String end, String dur) { long b = (begin == null || begin.isEmpty()) ? 0 : ttConverter.parseTimeExpression(begin); long e = (end == null || end.isEmpty()) ? Long.MAX_VALUE : ttConverter.parseTimeExpression(end); long d = (dur == null || dur.isEmpty()) ? Long.MAX_VALUE - b : ttConverter.parseTimeExpression(dur); return Math.min(b + d, e); }
long pB = ttConverter.parseTimeExpression(p.getBegin()); long pE = ttConverter.parseTimeExpression(p.getEnd());
@Test public void offsetTimeMsParsedCorrecly() { /* PREPARATION */ TtmlTimeConverter converter = new TtmlTimeConverter(new TtEltype()); int expectedMs = 10; String timeExpression = String.format("%dms", expectedMs); /* EXECUTION */ long ms = converter.parseTimeExpression(timeExpression); /* VALIDATION */ assertEquals(expectedMs, ms); } }
@Test public void clockTimeWithoutFractionsAndFramesParsedCorrecly() { /* PREPARATION */ TtmlTimeConverter converter = new TtmlTimeConverter(new TtEltype()); int h = 1; int m = 2; int s = 3; String timeExpression = String.format("%02d:%02d:%02d", h, m, s); long expectedMs = (h * 3600 + m * 60 + s) * 1000; /* EXECUTION */ long ms = converter.parseTimeExpression(timeExpression); /* VALIDATION */ assertEquals(expectedMs, ms); }
@Test public void clockTimeWithFramesNonDropParsedCorrecly() { /* PREPARATION */ TtmlTimeConverter converter = new TtmlTimeConverter(new TtEltype()); // default frame rate 30 int h = 1; int m = 2; int s = 3; int f = 10; String timeExpression = String.format("%02d:%02d:%02d:%02d", h, m, s, f); long expectedMs = (h * 3600 + m * 60 + s) * 1000 + (int)((float) f * 1000 / 30); /* EXECUTION */ long ms = converter.parseTimeExpression(timeExpression); /* VALIDATION */ assertEquals(expectedMs, ms); }
TtmlTimeConverter ttConverter = new TtmlTimeConverter(tt); long totalBegin = ttConverter.parseTimeExpression(tt.getBody().getBegin()); DivEltype div = divIt.next(); totalBegin += ttConverter.parseTimeExpression(div.getBegin()); long pBegin = totalBegin + ttConverter.parseTimeExpression(p.getBegin()); long pEnd = totalBegin + getEnd(ttConverter, p.getBegin(), p.getEnd(), p.getDur()); if (pEnd < startMS || pBegin > endMS) { // remove not matched