Commit 9231520e by Oliver Woodman

Some misc cleanup.

- Remove unused method in DashChunkSource.
- Remove inputEncoding parameter for subtitle parsers. We're
  ignoring it in all but one of the parsers, and for the one
  that does use it, it'll only ever receive null, since that's
  all we're passing.
- Make TextTrackRenderer advance to the next subtitle even if
  the current one hasn't finished, in the case that they overlap.
  This shouldn't ever really happen, but it seems best to trust
  the start time of the new sample rather than the last event
  time of the previous one.
parent eb3829c7
...@@ -75,8 +75,6 @@ public class DashChunkSourceTest extends InstrumentationTestCase { ...@@ -75,8 +75,6 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
private static final long AVAILABILITY_CURRENT_TIME_MS = private static final long AVAILABILITY_CURRENT_TIME_MS =
AVAILABILITY_START_TIME_MS + LIVE_TIMESHIFT_BUFFER_DEPTH_MS - AVAILABILITY_REALTIME_OFFSET_MS; AVAILABILITY_START_TIME_MS + LIVE_TIMESHIFT_BUFFER_DEPTH_MS - AVAILABILITY_REALTIME_OFFSET_MS;
private static final long LIVE_SEEK_BEYOND_EDGE_MS = 60000;
private static final int TALL_HEIGHT = 200; private static final int TALL_HEIGHT = 200;
private static final int WIDE_WIDTH = 400; private static final int WIDE_WIDTH = 400;
...@@ -167,7 +165,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { ...@@ -167,7 +165,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
AdaptationSet.TYPE_VIDEO, null, mockDataSource, EVALUATOR); AdaptationSet.TYPE_VIDEO, null, mockDataSource, EVALUATOR);
chunkSource.enable(0); chunkSource.enable(0);
List<MediaChunk> queue = new ArrayList<MediaChunk>(); List<MediaChunk> queue = new ArrayList<>();
ChunkOperationHolder out = new ChunkOperationHolder(); ChunkOperationHolder out = new ChunkOperationHolder();
// request first chunk; should get back initialization chunk // request first chunk; should get back initialization chunk
...@@ -507,7 +505,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { ...@@ -507,7 +505,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
private static MediaPresentationDescription generateMultiPeriodLiveMpdWithTimeline( private static MediaPresentationDescription generateMultiPeriodLiveMpdWithTimeline(
long startTimeMs) { long startTimeMs) {
List<Period> periods = new ArrayList<Period>(); List<Period> periods = new ArrayList<>();
for (int i = 0; i < MULTI_PERIOD_COUNT; i++) { for (int i = 0; i < MULTI_PERIOD_COUNT; i++) {
Representation representation = generateSegmentTimelineRepresentation(0, startTimeMs, Representation representation = generateSegmentTimelineRepresentation(0, startTimeMs,
...@@ -527,7 +525,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { ...@@ -527,7 +525,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
private static MediaPresentationDescription generateMultiPeriodLiveMpdWithTemplate( private static MediaPresentationDescription generateMultiPeriodLiveMpdWithTemplate(
long periodStartTimeMs) { long periodStartTimeMs) {
List<Period> periods = new ArrayList<Period>(); List<Period> periods = new ArrayList<>();
Representation representation1 = generateSegmentTemplateRepresentation(periodStartTimeMs, Representation representation1 = generateSegmentTemplateRepresentation(periodStartTimeMs,
LIVE_DURATION_MS); LIVE_DURATION_MS);
...@@ -556,6 +554,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { ...@@ -556,6 +554,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
AVAILABILITY_CURRENT_TIME_MS + periodStartMs); AVAILABILITY_CURRENT_TIME_MS + periodStartMs);
} }
@SuppressWarnings("unused")
private DashChunkSource setupDashChunkSource(MediaPresentationDescription mpd, long periodStartMs, private DashChunkSource setupDashChunkSource(MediaPresentationDescription mpd, long periodStartMs,
long liveEdgeLatencyMs, long nowUs) { long liveEdgeLatencyMs, long nowUs) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
...@@ -647,7 +646,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase { ...@@ -647,7 +646,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
} }
private void checkSegmentRequestSequenceOnMultiPeriodLive(DashChunkSource chunkSource) { private void checkSegmentRequestSequenceOnMultiPeriodLive(DashChunkSource chunkSource) {
List<MediaChunk> queue = new ArrayList<MediaChunk>(); List<MediaChunk> queue = new ArrayList<>();
ChunkOperationHolder out = new ChunkOperationHolder(); ChunkOperationHolder out = new ChunkOperationHolder();
long seekPositionMs = 0; long seekPositionMs = 0;
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
*/ */
package com.google.android.exoplayer.text.subrip; package com.google.android.exoplayer.text.subrip;
import com.google.android.exoplayer.C;
import android.test.InstrumentationTestCase; import android.test.InstrumentationTestCase;
import java.io.IOException; import java.io.IOException;
...@@ -34,7 +32,7 @@ public final class SubripParserTest extends InstrumentationTestCase { ...@@ -34,7 +32,7 @@ public final class SubripParserTest extends InstrumentationTestCase {
SubripParser parser = new SubripParser(); SubripParser parser = new SubripParser();
InputStream inputStream = InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets().open(EMPTY_SUBRIP_FILE); getInstrumentation().getContext().getResources().getAssets().open(EMPTY_SUBRIP_FILE);
SubripSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME); SubripSubtitle subtitle = parser.parse(inputStream);
// Assert that the subtitle is empty. // Assert that the subtitle is empty.
assertEquals(0, subtitle.getEventTimeCount()); assertEquals(0, subtitle.getEventTimeCount());
assertTrue(subtitle.getCues(0).isEmpty()); assertTrue(subtitle.getCues(0).isEmpty());
...@@ -44,7 +42,7 @@ public final class SubripParserTest extends InstrumentationTestCase { ...@@ -44,7 +42,7 @@ public final class SubripParserTest extends InstrumentationTestCase {
SubripParser parser = new SubripParser(); SubripParser parser = new SubripParser();
InputStream inputStream = InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets().open(TYPICAL_SUBRIP_FILE); getInstrumentation().getContext().getResources().getAssets().open(TYPICAL_SUBRIP_FILE);
SubripSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME); SubripSubtitle subtitle = parser.parse(inputStream);
// Test event count. // Test event count.
assertEquals(4, subtitle.getEventTimeCount()); assertEquals(4, subtitle.getEventTimeCount());
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
*/ */
package com.google.android.exoplayer.text.webvtt; package com.google.android.exoplayer.text.webvtt;
import com.google.android.exoplayer.C;
import android.test.InstrumentationTestCase; import android.test.InstrumentationTestCase;
import java.io.IOException; import java.io.IOException;
...@@ -39,7 +37,7 @@ public class WebvttParserTest extends InstrumentationTestCase { ...@@ -39,7 +37,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
getInstrumentation().getContext().getResources().getAssets().open(EMPTY_WEBVTT_FILE); getInstrumentation().getContext().getResources().getAssets().open(EMPTY_WEBVTT_FILE);
try { try {
parser.parse(inputStream, C.UTF8_NAME); parser.parse(inputStream);
fail("Expected IOException"); fail("Expected IOException");
} catch (IOException expected) { } catch (IOException expected) {
// Do nothing. // Do nothing.
...@@ -50,7 +48,7 @@ public class WebvttParserTest extends InstrumentationTestCase { ...@@ -50,7 +48,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
WebvttParser parser = new WebvttParser(); WebvttParser parser = new WebvttParser();
InputStream inputStream = InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets().open(TYPICAL_WEBVTT_FILE); getInstrumentation().getContext().getResources().getAssets().open(TYPICAL_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME); WebvttSubtitle subtitle = parser.parse(inputStream);
// test event count // test event count
assertEquals(4, subtitle.getEventTimeCount()); assertEquals(4, subtitle.getEventTimeCount());
...@@ -73,7 +71,7 @@ public class WebvttParserTest extends InstrumentationTestCase { ...@@ -73,7 +71,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
InputStream inputStream = InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets() getInstrumentation().getContext().getResources().getAssets()
.open(TYPICAL_WITH_IDS_WEBVTT_FILE); .open(TYPICAL_WITH_IDS_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME); WebvttSubtitle subtitle = parser.parse(inputStream);
// test event count // test event count
assertEquals(4, subtitle.getEventTimeCount()); assertEquals(4, subtitle.getEventTimeCount());
...@@ -96,7 +94,7 @@ public class WebvttParserTest extends InstrumentationTestCase { ...@@ -96,7 +94,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
InputStream inputStream = InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets() getInstrumentation().getContext().getResources().getAssets()
.open(TYPICAL_WITH_TAGS_WEBVTT_FILE); .open(TYPICAL_WITH_TAGS_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME); WebvttSubtitle subtitle = parser.parse(inputStream);
// test event count // test event count
assertEquals(8, subtitle.getEventTimeCount()); assertEquals(8, subtitle.getEventTimeCount());
...@@ -130,7 +128,7 @@ public class WebvttParserTest extends InstrumentationTestCase { ...@@ -130,7 +128,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
WebvttParser parser = new WebvttParser(); WebvttParser parser = new WebvttParser();
InputStream inputStream = InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets().open(LIVE_TYPICAL_WEBVTT_FILE); getInstrumentation().getContext().getResources().getAssets().open(LIVE_TYPICAL_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME); WebvttSubtitle subtitle = parser.parse(inputStream);
// test event count // test event count
long startTimeUs = 0; long startTimeUs = 0;
......
...@@ -855,15 +855,6 @@ public class DashChunkSource implements ChunkSource { ...@@ -855,15 +855,6 @@ public class DashChunkSource implements ChunkSource {
return segmentIndex.getFirstSegmentNum() + segmentNumShift; return segmentIndex.getFirstSegmentNum() + segmentNumShift;
} }
public int getLastAvailableSegmentNum() {
int lastSegmentNum = segmentIndex.getLastSegmentNum();
if (lastSegmentNum == DashSegmentIndex.INDEX_UNBOUNDED) {
return DashSegmentIndex.INDEX_UNBOUNDED;
} else {
return lastSegmentNum + segmentNumShift;
}
}
public RangedUri getSegmentUrl(int segmentNum) { public RangedUri getSegmentUrl(int segmentNum) {
return segmentIndex.getSegmentUrl(segmentNum - segmentNumShift); return segmentIndex.getSegmentUrl(segmentNum - segmentNumShift);
} }
......
...@@ -232,7 +232,7 @@ public class HlsChunkSource { ...@@ -232,7 +232,7 @@ public class HlsChunkSource {
* @return A copy of the provided {@link MediaFormat} with the maximum video dimensions set, or * @return A copy of the provided {@link MediaFormat} with the maximum video dimensions set, or
* the provided format. * the provided format.
*/ */
public MediaFormat getMaxVideoDimensions(MediaFormat format) { public MediaFormat getWithMaxVideoDimensions(MediaFormat format) {
return (maxWidth == -1 || maxHeight == -1) ? format return (maxWidth == -1 || maxHeight == -1) ? format
: format.copyWithMaxVideoDimensions(maxWidth, maxHeight); : format.copyWithMaxVideoDimensions(maxWidth, maxHeight);
} }
......
...@@ -140,7 +140,8 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader, ...@@ -140,7 +140,8 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
for (int i = 0; i < trackCount; i++) { for (int i = 0; i < trackCount; i++) {
mediaFormats[i] = extractor.getMediaFormat(i).copyWithDurationUs(durationUs); mediaFormats[i] = extractor.getMediaFormat(i).copyWithDurationUs(durationUs);
if (MimeTypes.isVideo(mediaFormats[i].mimeType)) { if (MimeTypes.isVideo(mediaFormats[i].mimeType)) {
mediaFormats[i] = chunkSource.getMaxVideoDimensions(mediaFormats[i]).copyAsAdaptive(); mediaFormats[i] = chunkSource.getWithMaxVideoDimensions(mediaFormats[i])
.copyAsAdaptive();
} }
} }
prepared = true; prepared = true;
...@@ -294,7 +295,7 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader, ...@@ -294,7 +295,7 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
MediaFormat mediaFormat = extractor.getMediaFormat(track); MediaFormat mediaFormat = extractor.getMediaFormat(track);
if (mediaFormat != null && !mediaFormat.equals(downstreamMediaFormats[track], true)) { if (mediaFormat != null && !mediaFormat.equals(downstreamMediaFormats[track], true)) {
chunkSource.getMaxVideoDimensions(mediaFormat); mediaFormat = chunkSource.getWithMaxVideoDimensions(mediaFormat);
formatHolder.format = mediaFormat; formatHolder.format = mediaFormat;
downstreamMediaFormats[track] = mediaFormat; downstreamMediaFormats[track] = mediaFormat;
return FORMAT_READ; return FORMAT_READ;
......
...@@ -35,10 +35,9 @@ public interface SubtitleParser { ...@@ -35,10 +35,9 @@ public interface SubtitleParser {
* Parses a {@link Subtitle} from the provided {@link InputStream}. * Parses a {@link Subtitle} from the provided {@link InputStream}.
* *
* @param inputStream The stream from which to parse the subtitle. * @param inputStream The stream from which to parse the subtitle.
* @param inputEncoding The encoding of the input stream.
* @return A parsed representation of the subtitle. * @return A parsed representation of the subtitle.
* @throws IOException If a problem occurred reading from the stream. * @throws IOException If a problem occurred reading from the stream.
*/ */
public Subtitle parse(InputStream inputStream, String inputEncoding) throws IOException; public Subtitle parse(InputStream inputStream) throws IOException;
} }
...@@ -161,7 +161,7 @@ import java.io.InputStream; ...@@ -161,7 +161,7 @@ import java.io.InputStream;
IOException error = null; IOException error = null;
try { try {
InputStream inputStream = new ByteArrayInputStream(holder.data.array(), 0, holder.size); InputStream inputStream = new ByteArrayInputStream(holder.data.array(), 0, holder.size);
parsedSubtitle = parser.parse(inputStream, null); parsedSubtitle = parser.parse(inputStream);
} catch (IOException e) { } catch (IOException e) {
error = e; error = e;
} }
......
...@@ -207,8 +207,8 @@ public final class TextTrackRenderer extends SampleSourceTrackRenderer implement ...@@ -207,8 +207,8 @@ public final class TextTrackRenderer extends SampleSourceTrackRenderer implement
} }
} }
if (subtitleNextEventTimeUs == Long.MAX_VALUE && nextSubtitle != null if (nextSubtitle != null && (subtitleNextEventTimeUs == Long.MAX_VALUE
&& nextSubtitle.startTimeUs <= positionUs) { || nextSubtitle.startTimeUs <= positionUs)) {
// Advance to the next subtitle. Sync the next event index and trigger an update. // Advance to the next subtitle. Sync the next event index and trigger an update.
subtitle = nextSubtitle; subtitle = nextSubtitle;
nextSubtitle = null; nextSubtitle = null;
......
...@@ -50,7 +50,7 @@ public final class SubripParser implements SubtitleParser { ...@@ -50,7 +50,7 @@ public final class SubripParser implements SubtitleParser {
} }
@Override @Override
public SubripSubtitle parse(InputStream inputStream, String inputEncoding) throws IOException { public SubripSubtitle parse(InputStream inputStream) throws IOException {
ArrayList<Cue> cues = new ArrayList<>(); ArrayList<Cue> cues = new ArrayList<>();
LongArray cueTimesUs = new LongArray(); LongArray cueTimesUs = new LongArray();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, C.UTF8_NAME)); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, C.UTF8_NAME));
......
...@@ -84,10 +84,10 @@ public final class TtmlParser implements SubtitleParser { ...@@ -84,10 +84,10 @@ public final class TtmlParser implements SubtitleParser {
} }
/** /**
* @param strictParsing If true, {@link #parse(InputStream, String)} will throw a * @param strictParsing If true, {@link #parse(InputStream)} will throw a {@link ParserException}
* {@link ParserException} if the stream contains invalid data. If false, the parser will * if the stream contains invalid data. If false, the parser will make a best effort to ignore
* make a best effort to ignore minor errors in the stream. Note however that a * minor errors in the stream. Note however that a {@link ParserException} will still be
* {@link ParserException} will still be thrown when this is not possible. * thrown when this is not possible.
*/ */
public TtmlParser(boolean strictParsing) { public TtmlParser(boolean strictParsing) {
this.strictParsing = strictParsing; this.strictParsing = strictParsing;
...@@ -99,10 +99,10 @@ public final class TtmlParser implements SubtitleParser { ...@@ -99,10 +99,10 @@ public final class TtmlParser implements SubtitleParser {
} }
@Override @Override
public Subtitle parse(InputStream inputStream, String inputEncoding) throws IOException { public Subtitle parse(InputStream inputStream) throws IOException {
try { try {
XmlPullParser xmlParser = xmlParserFactory.newPullParser(); XmlPullParser xmlParser = xmlParserFactory.newPullParser();
xmlParser.setInput(inputStream, inputEncoding); xmlParser.setInput(inputStream, null);
TtmlSubtitle ttmlSubtitle = null; TtmlSubtitle ttmlSubtitle = null;
LinkedList<TtmlNode> nodeStack = new LinkedList<>(); LinkedList<TtmlNode> nodeStack = new LinkedList<>();
int unsupportedNodeDepth = 0; int unsupportedNodeDepth = 0;
......
...@@ -32,7 +32,7 @@ import java.io.InputStream; ...@@ -32,7 +32,7 @@ import java.io.InputStream;
public final class Tx3gParser implements SubtitleParser { public final class Tx3gParser implements SubtitleParser {
@Override @Override
public Subtitle parse(InputStream inputStream, String inputEncoding) throws IOException { public Subtitle parse(InputStream inputStream) throws IOException {
DataInputStream dataInputStream = new DataInputStream(inputStream); DataInputStream dataInputStream = new DataInputStream(inputStream);
String cueText = dataInputStream.readUTF(); String cueText = dataInputStream.readUTF();
return new Tx3gSubtitle(new Cue(cueText)); return new Tx3gSubtitle(new Cue(cueText));
......
...@@ -74,10 +74,10 @@ public final class WebvttParser implements SubtitleParser { ...@@ -74,10 +74,10 @@ public final class WebvttParser implements SubtitleParser {
} }
/** /**
* @param strictParsing If true, {@link #parse(InputStream, String)} will throw a * @param strictParsing If true, {@link #parse(InputStream)} will throw a {@link ParserException}
* {@link ParserException} if the stream contains invalid data. If false, the parser will * if the stream contains invalid data. If false, the parser will make a best effort to ignore
* make a best effort to ignore minor errors in the stream. Note however that a * minor errors in the stream. Note however that a {@link ParserException} will still be
* {@link ParserException} will still be thrown when this is not possible. * thrown when this is not possible.
*/ */
public WebvttParser(boolean strictParsing) { public WebvttParser(boolean strictParsing) {
this.strictParsing = strictParsing; this.strictParsing = strictParsing;
...@@ -85,8 +85,7 @@ public final class WebvttParser implements SubtitleParser { ...@@ -85,8 +85,7 @@ public final class WebvttParser implements SubtitleParser {
} }
@Override @Override
public final WebvttSubtitle parse(InputStream inputStream, String inputEncoding) public final WebvttSubtitle parse(InputStream inputStream) throws IOException {
throws IOException {
ArrayList<WebvttCue> subtitles = new ArrayList<>(); ArrayList<WebvttCue> subtitles = new ArrayList<>();
BufferedReader webvttData = new BufferedReader(new InputStreamReader(inputStream, C.UTF8_NAME)); BufferedReader webvttData = new BufferedReader(new InputStreamReader(inputStream, C.UTF8_NAME));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment