Skip to content

Commit b333169

Browse files
committed
Merge branch 'dev-v2' of git://github.com/jcable/ExoPlayer into jcable-dev-v2
2 parents 78e0545 + 402c985 commit b333169

File tree

14 files changed

+577
-44
lines changed

14 files changed

+577
-44
lines changed

library/core/src/androidTest/assets/ssa/empty

Whitespace-only changes.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Script Info]
2+
Title: SomeTitle
3+
4+
[V4+ Styles]
5+
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
6+
Style: Default,Open Sans Semibold,36,&H00FFFFFF,&H000000FF,&H00020713,&H00000000,-1,0,0,0,100,100,0,0,1,1.7,0,2,0,0,28,1
7+
8+
[Events]
9+
Format: Layer, Start, End, Style, Name, Text
10+
Dialogue: 0,Invalid,0:00:01.23,Default,Olly,This is the first subtitle{ignored}.
11+
Dialogue: 0,0:00:02.34,Invalid,Default,Olly,This is the second subtitle \nwith a newline \Nand another.
12+
Dialogue: 0,0:00:04:56,0:00:08:90,Default,Olly,This is the third subtitle, with a comma.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Script Info]
2+
Title: SomeTitle
3+
4+
[V4+ Styles]
5+
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
6+
Style: Default,Open Sans Semibold,36,&H00FFFFFF,&H000000FF,&H00020713,&H00000000,-1,0,0,0,100,100,0,0,1,1.7,0,2,0,0,28,1
7+
8+
[Events]
9+
Format: Layer, Start, End, Style, Name, Text
10+
Dialogue: 0,0:00:00.00, ,Default,Olly,This is the first subtitle.
11+
Dialogue: 0,0:00:02.34, ,Default,Olly,This is the second subtitle \nwith a newline \Nand another.
12+
Dialogue: 0,0:00:04.56, ,Default,Olly,This is the third subtitle, with a comma.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Script Info]
2+
Title: SomeTitle
3+
4+
[V4+ Styles]
5+
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
6+
Style: Default,Open Sans Semibold,36,&H00FFFFFF,&H000000FF,&H00020713,&H00000000,-1,0,0,0,100,100,0,0,1,1.7,0,2,0,0,28,1
7+
8+
[Events]
9+
Format: Layer, Start, End, Style, Name, Text
10+
Dialogue: 0,0:00:00.00,0:00:01.23,Default,Olly,This is the first subtitle{ignored}.
11+
Dialogue: 0,0:00:02.34,0:00:03.45,Default,Olly,This is the second subtitle \nwith a newline \Nand another.
12+
Dialogue: 0,0:00:04:56,0:00:08:90,Default,Olly,This is the third subtitle, with a comma.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Dialogue: 0,0:00:00.00,0:00:01.23,Default,Olly,This is the first subtitle{ignored}.
2+
Dialogue: 0,0:00:02.34,0:00:03.45,Default,Olly,This is the second subtitle \nwith a newline \Nand another.
3+
Dialogue: 0,0:00:04:56,0:00:08:90,Default,Olly,This is the third subtitle, with a comma.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Format: Layer, Start, End, Style, Name, Text
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[Script Info]
2+
Title: SomeTitle
3+
4+
[V4+ Styles]
5+
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
6+
Style: Default,Open Sans Semibold,36,&H00FFFFFF,&H000000FF,&H00020713,&H00000000,-1,0,0,0,100,100,0,0,1,1.7,0,2,0,0,28,1
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright (C) 2016 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.google.android.exoplayer2.text.ssa;
17+
18+
import android.test.InstrumentationTestCase;
19+
import com.google.android.exoplayer2.testutil.TestUtil;
20+
import java.io.IOException;
21+
import java.util.ArrayList;
22+
23+
/**
24+
* Unit test for {@link SsaDecoder}.
25+
*/
26+
public final class SsaDecoderTest extends InstrumentationTestCase {
27+
28+
private static final String EMPTY = "ssa/empty";
29+
private static final String TYPICAL = "ssa/typical";
30+
private static final String TYPICAL_HEADER_ONLY = "ssa/typical_header";
31+
private static final String TYPICAL_DIALOGUE_ONLY = "ssa/typical_dialogue";
32+
private static final String TYPICAL_FORMAT_ONLY = "ssa/typical_format";
33+
private static final String INVALID_TIMECODES = "ssa/invalid_timecodes";
34+
private static final String NO_END_TIMECODES = "ssa/no_end_timecodes";
35+
36+
public void testDecodeEmpty() throws IOException {
37+
SsaDecoder decoder = new SsaDecoder();
38+
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY);
39+
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
40+
41+
assertEquals(0, subtitle.getEventTimeCount());
42+
assertTrue(subtitle.getCues(0).isEmpty());
43+
}
44+
45+
public void testDecodeTypical() throws IOException {
46+
SsaDecoder decoder = new SsaDecoder();
47+
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL);
48+
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
49+
50+
assertEquals(6, subtitle.getEventTimeCount());
51+
assertTypicalCue1(subtitle, 0);
52+
assertTypicalCue2(subtitle, 2);
53+
assertTypicalCue3(subtitle, 4);
54+
}
55+
56+
public void testDecodeTypicalWithInitializationData() throws IOException {
57+
byte[] headerBytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_HEADER_ONLY);
58+
byte[] formatBytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_FORMAT_ONLY);
59+
ArrayList<byte[]> initializationData = new ArrayList<>();
60+
initializationData.add(formatBytes);
61+
initializationData.add(headerBytes);
62+
SsaDecoder decoder = new SsaDecoder(initializationData);
63+
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_DIALOGUE_ONLY);
64+
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
65+
66+
assertEquals(6, subtitle.getEventTimeCount());
67+
assertTypicalCue1(subtitle, 0);
68+
assertTypicalCue2(subtitle, 2);
69+
assertTypicalCue3(subtitle, 4);
70+
}
71+
72+
public void testDecodeInvalidTimecodes() throws IOException {
73+
// Parsing should succeed, parsing the third cue only.
74+
SsaDecoder decoder = new SsaDecoder();
75+
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), INVALID_TIMECODES);
76+
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
77+
78+
assertEquals(2, subtitle.getEventTimeCount());
79+
assertTypicalCue3(subtitle, 0);
80+
}
81+
82+
public void testDecodeNoEndTimecodes() throws IOException {
83+
SsaDecoder decoder = new SsaDecoder();
84+
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES);
85+
SsaSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
86+
87+
assertEquals(3, subtitle.getEventTimeCount());
88+
89+
assertEquals(0, subtitle.getEventTime(0));
90+
assertEquals("This is the first subtitle.",
91+
subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString());
92+
93+
assertEquals(2340000, subtitle.getEventTime(1));
94+
assertEquals("This is the second subtitle \nwith a newline \nand another.",
95+
subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString());
96+
97+
assertEquals(4560000, subtitle.getEventTime(2));
98+
assertEquals("This is the third subtitle, with a comma.",
99+
subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString());
100+
}
101+
102+
private static void assertTypicalCue1(SsaSubtitle subtitle, int eventIndex) {
103+
assertEquals(0, subtitle.getEventTime(eventIndex));
104+
assertEquals("This is the first subtitle.",
105+
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
106+
assertEquals(1230000, subtitle.getEventTime(eventIndex + 1));
107+
}
108+
109+
private static void assertTypicalCue2(SsaSubtitle subtitle, int eventIndex) {
110+
assertEquals(2340000, subtitle.getEventTime(eventIndex));
111+
assertEquals("This is the second subtitle \nwith a newline \nand another.",
112+
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
113+
assertEquals(3450000, subtitle.getEventTime(eventIndex + 1));
114+
}
115+
116+
private static void assertTypicalCue3(SsaSubtitle subtitle, int eventIndex) {
117+
assertEquals(4560000, subtitle.getEventTime(eventIndex));
118+
assertEquals("This is the third subtitle, with a comma.",
119+
subtitle.getCues(subtitle.getEventTime(eventIndex)).get(0).text.toString());
120+
assertEquals(8900000, subtitle.getEventTime(eventIndex + 1));
121+
}
122+
123+
}

library/core/src/androidTest/java/com/google/android/exoplayer2/text/subrip/SubripDecoderTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public void testDecodeEmpty() throws IOException {
3737
SubripDecoder decoder = new SubripDecoder();
3838
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), EMPTY_FILE);
3939
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
40-
// Assert that the subtitle is empty.
40+
4141
assertEquals(0, subtitle.getEventTimeCount());
4242
assertTrue(subtitle.getCues(0).isEmpty());
4343
}
@@ -46,6 +46,7 @@ public void testDecodeTypical() throws IOException {
4646
SubripDecoder decoder = new SubripDecoder();
4747
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_FILE);
4848
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
49+
4950
assertEquals(6, subtitle.getEventTimeCount());
5051
assertTypicalCue1(subtitle, 0);
5152
assertTypicalCue2(subtitle, 2);
@@ -56,6 +57,7 @@ public void testDecodeTypicalWithByteOrderMark() throws IOException {
5657
SubripDecoder decoder = new SubripDecoder();
5758
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_WITH_BYTE_ORDER_MARK);
5859
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
60+
5961
assertEquals(6, subtitle.getEventTimeCount());
6062
assertTypicalCue1(subtitle, 0);
6163
assertTypicalCue2(subtitle, 2);
@@ -66,6 +68,7 @@ public void testDecodeTypicalExtraBlankLine() throws IOException {
6668
SubripDecoder decoder = new SubripDecoder();
6769
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_EXTRA_BLANK_LINE);
6870
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
71+
6972
assertEquals(6, subtitle.getEventTimeCount());
7073
assertTypicalCue1(subtitle, 0);
7174
assertTypicalCue2(subtitle, 2);
@@ -77,6 +80,7 @@ public void testDecodeTypicalMissingTimecode() throws IOException {
7780
SubripDecoder decoder = new SubripDecoder();
7881
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_TIMECODE);
7982
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
83+
8084
assertEquals(4, subtitle.getEventTimeCount());
8185
assertTypicalCue1(subtitle, 0);
8286
assertTypicalCue3(subtitle, 2);
@@ -87,6 +91,7 @@ public void testDecodeTypicalMissingSequence() throws IOException {
8791
SubripDecoder decoder = new SubripDecoder();
8892
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_MISSING_SEQUENCE);
8993
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
94+
9095
assertEquals(4, subtitle.getEventTimeCount());
9196
assertTypicalCue1(subtitle, 0);
9297
assertTypicalCue3(subtitle, 2);
@@ -97,6 +102,7 @@ public void testDecodeTypicalNegativeTimestamps() throws IOException {
97102
SubripDecoder decoder = new SubripDecoder();
98103
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), TYPICAL_NEGATIVE_TIMESTAMPS);
99104
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
105+
100106
assertEquals(2, subtitle.getEventTimeCount());
101107
assertTypicalCue3(subtitle, 0);
102108
}
@@ -106,20 +112,16 @@ public void testDecodeNoEndTimecodes() throws IOException {
106112
byte[] bytes = TestUtil.getByteArray(getInstrumentation(), NO_END_TIMECODES_FILE);
107113
SubripSubtitle subtitle = decoder.decode(bytes, bytes.length, false);
108114

109-
// Test event count.
110115
assertEquals(3, subtitle.getEventTimeCount());
111116

112-
// Test first cue.
113117
assertEquals(0, subtitle.getEventTime(0));
114118
assertEquals("SubRip doesn't technically allow missing end timecodes.",
115119
subtitle.getCues(subtitle.getEventTime(0)).get(0).text.toString());
116120

117-
// Test second cue.
118121
assertEquals(2345000, subtitle.getEventTime(1));
119122
assertEquals("We interpret it to mean that a subtitle extends to the start of the next one.",
120123
subtitle.getCues(subtitle.getEventTime(1)).get(0).text.toString());
121124

122-
// Test third cue.
123125
assertEquals(3456000, subtitle.getEventTime(2));
124126
assertEquals("Or to the end of the media.",
125127
subtitle.getCues(subtitle.getEventTime(2)).get(0).text.toString());

0 commit comments

Comments
 (0)