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 {
private static final long AVAILABILITY_CURRENT_TIME_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 WIDE_WIDTH = 400;
......@@ -167,7 +165,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
AdaptationSet.TYPE_VIDEO, null, mockDataSource, EVALUATOR);
chunkSource.enable(0);
List<MediaChunk> queue = new ArrayList<MediaChunk>();
List<MediaChunk> queue = new ArrayList<>();
ChunkOperationHolder out = new ChunkOperationHolder();
// request first chunk; should get back initialization chunk
......@@ -507,7 +505,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
private static MediaPresentationDescription generateMultiPeriodLiveMpdWithTimeline(
long startTimeMs) {
List<Period> periods = new ArrayList<Period>();
List<Period> periods = new ArrayList<>();
for (int i = 0; i < MULTI_PERIOD_COUNT; i++) {
Representation representation = generateSegmentTimelineRepresentation(0, startTimeMs,
......@@ -527,7 +525,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
private static MediaPresentationDescription generateMultiPeriodLiveMpdWithTemplate(
long periodStartTimeMs) {
List<Period> periods = new ArrayList<Period>();
List<Period> periods = new ArrayList<>();
Representation representation1 = generateSegmentTemplateRepresentation(periodStartTimeMs,
LIVE_DURATION_MS);
......@@ -556,6 +554,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
AVAILABILITY_CURRENT_TIME_MS + periodStartMs);
}
@SuppressWarnings("unused")
private DashChunkSource setupDashChunkSource(MediaPresentationDescription mpd, long periodStartMs,
long liveEdgeLatencyMs, long nowUs) {
@SuppressWarnings("unchecked")
......@@ -647,7 +646,7 @@ public class DashChunkSourceTest extends InstrumentationTestCase {
}
private void checkSegmentRequestSequenceOnMultiPeriodLive(DashChunkSource chunkSource) {
List<MediaChunk> queue = new ArrayList<MediaChunk>();
List<MediaChunk> queue = new ArrayList<>();
ChunkOperationHolder out = new ChunkOperationHolder();
long seekPositionMs = 0;
......
......@@ -15,8 +15,6 @@
*/
package com.google.android.exoplayer.text.subrip;
import com.google.android.exoplayer.C;
import android.test.InstrumentationTestCase;
import java.io.IOException;
......@@ -34,7 +32,7 @@ public final class SubripParserTest extends InstrumentationTestCase {
SubripParser parser = new SubripParser();
InputStream inputStream =
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.
assertEquals(0, subtitle.getEventTimeCount());
assertTrue(subtitle.getCues(0).isEmpty());
......@@ -44,7 +42,7 @@ public final class SubripParserTest extends InstrumentationTestCase {
SubripParser parser = new SubripParser();
InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets().open(TYPICAL_SUBRIP_FILE);
SubripSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME);
SubripSubtitle subtitle = parser.parse(inputStream);
// Test event count.
assertEquals(4, subtitle.getEventTimeCount());
......
......@@ -15,8 +15,6 @@
*/
package com.google.android.exoplayer.text.webvtt;
import com.google.android.exoplayer.C;
import android.test.InstrumentationTestCase;
import java.io.IOException;
......@@ -39,7 +37,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
getInstrumentation().getContext().getResources().getAssets().open(EMPTY_WEBVTT_FILE);
try {
parser.parse(inputStream, C.UTF8_NAME);
parser.parse(inputStream);
fail("Expected IOException");
} catch (IOException expected) {
// Do nothing.
......@@ -50,7 +48,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
WebvttParser parser = new WebvttParser();
InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets().open(TYPICAL_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME);
WebvttSubtitle subtitle = parser.parse(inputStream);
// test event count
assertEquals(4, subtitle.getEventTimeCount());
......@@ -73,7 +71,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets()
.open(TYPICAL_WITH_IDS_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME);
WebvttSubtitle subtitle = parser.parse(inputStream);
// test event count
assertEquals(4, subtitle.getEventTimeCount());
......@@ -96,7 +94,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
InputStream inputStream =
getInstrumentation().getContext().getResources().getAssets()
.open(TYPICAL_WITH_TAGS_WEBVTT_FILE);
WebvttSubtitle subtitle = parser.parse(inputStream, C.UTF8_NAME);
WebvttSubtitle subtitle = parser.parse(inputStream);
// test event count
assertEquals(8, subtitle.getEventTimeCount());
......@@ -130,7 +128,7 @@ public class WebvttParserTest extends InstrumentationTestCase {
WebvttParser parser = new WebvttParser();
InputStream inputStream =
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
long startTimeUs = 0;
......
......@@ -855,15 +855,6 @@ public class DashChunkSource implements ChunkSource {
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) {
return segmentIndex.getSegmentUrl(segmentNum - segmentNumShift);
}
......
......@@ -232,7 +232,7 @@ public class HlsChunkSource {
* @return A copy of the provided {@link MediaFormat} with the maximum video dimensions set, or
* the provided format.
*/
public MediaFormat getMaxVideoDimensions(MediaFormat format) {
public MediaFormat getWithMaxVideoDimensions(MediaFormat format) {
return (maxWidth == -1 || maxHeight == -1) ? format
: format.copyWithMaxVideoDimensions(maxWidth, maxHeight);
}
......
......@@ -140,7 +140,8 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
for (int i = 0; i < trackCount; i++) {
mediaFormats[i] = extractor.getMediaFormat(i).copyWithDurationUs(durationUs);
if (MimeTypes.isVideo(mediaFormats[i].mimeType)) {
mediaFormats[i] = chunkSource.getMaxVideoDimensions(mediaFormats[i]).copyAsAdaptive();
mediaFormats[i] = chunkSource.getWithMaxVideoDimensions(mediaFormats[i])
.copyAsAdaptive();
}
}
prepared = true;
......@@ -294,7 +295,7 @@ public final class HlsSampleSource implements SampleSource, SampleSourceReader,
MediaFormat mediaFormat = extractor.getMediaFormat(track);
if (mediaFormat != null && !mediaFormat.equals(downstreamMediaFormats[track], true)) {
chunkSource.getMaxVideoDimensions(mediaFormat);
mediaFormat = chunkSource.getWithMaxVideoDimensions(mediaFormat);
formatHolder.format = mediaFormat;
downstreamMediaFormats[track] = mediaFormat;
return FORMAT_READ;
......
......@@ -35,10 +35,9 @@ public interface SubtitleParser {
* Parses a {@link Subtitle} from the provided {@link InputStream}.
*
* @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.
* @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;
IOException error = null;
try {
InputStream inputStream = new ByteArrayInputStream(holder.data.array(), 0, holder.size);
parsedSubtitle = parser.parse(inputStream, null);
parsedSubtitle = parser.parse(inputStream);
} catch (IOException e) {
error = e;
}
......
......@@ -207,8 +207,8 @@ public final class TextTrackRenderer extends SampleSourceTrackRenderer implement
}
}
if (subtitleNextEventTimeUs == Long.MAX_VALUE && nextSubtitle != null
&& nextSubtitle.startTimeUs <= positionUs) {
if (nextSubtitle != null && (subtitleNextEventTimeUs == Long.MAX_VALUE
|| nextSubtitle.startTimeUs <= positionUs)) {
// Advance to the next subtitle. Sync the next event index and trigger an update.
subtitle = nextSubtitle;
nextSubtitle = null;
......
......@@ -50,7 +50,7 @@ public final class SubripParser implements SubtitleParser {
}
@Override
public SubripSubtitle parse(InputStream inputStream, String inputEncoding) throws IOException {
public SubripSubtitle parse(InputStream inputStream) throws IOException {
ArrayList<Cue> cues = new ArrayList<>();
LongArray cueTimesUs = new LongArray();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, C.UTF8_NAME));
......
......@@ -84,10 +84,10 @@ public final class TtmlParser implements SubtitleParser {
}
/**
* @param strictParsing If true, {@link #parse(InputStream, String)} will throw a
* {@link ParserException} if the stream contains invalid data. If false, the parser will
* make a best effort to ignore minor errors in the stream. Note however that a
* {@link ParserException} will still be thrown when this is not possible.
* @param strictParsing If true, {@link #parse(InputStream)} will throw a {@link ParserException}
* if the stream contains invalid data. If false, the parser will make a best effort to ignore
* minor errors in the stream. Note however that a {@link ParserException} will still be
* thrown when this is not possible.
*/
public TtmlParser(boolean strictParsing) {
this.strictParsing = strictParsing;
......@@ -99,10 +99,10 @@ public final class TtmlParser implements SubtitleParser {
}
@Override
public Subtitle parse(InputStream inputStream, String inputEncoding) throws IOException {
public Subtitle parse(InputStream inputStream) throws IOException {
try {
XmlPullParser xmlParser = xmlParserFactory.newPullParser();
xmlParser.setInput(inputStream, inputEncoding);
xmlParser.setInput(inputStream, null);
TtmlSubtitle ttmlSubtitle = null;
LinkedList<TtmlNode> nodeStack = new LinkedList<>();
int unsupportedNodeDepth = 0;
......
......@@ -32,7 +32,7 @@ import java.io.InputStream;
public final class Tx3gParser implements SubtitleParser {
@Override
public Subtitle parse(InputStream inputStream, String inputEncoding) throws IOException {
public Subtitle parse(InputStream inputStream) throws IOException {
DataInputStream dataInputStream = new DataInputStream(inputStream);
String cueText = dataInputStream.readUTF();
return new Tx3gSubtitle(new Cue(cueText));
......
......@@ -74,10 +74,10 @@ public final class WebvttParser implements SubtitleParser {
}
/**
* @param strictParsing If true, {@link #parse(InputStream, String)} will throw a
* {@link ParserException} if the stream contains invalid data. If false, the parser will
* make a best effort to ignore minor errors in the stream. Note however that a
* {@link ParserException} will still be thrown when this is not possible.
* @param strictParsing If true, {@link #parse(InputStream)} will throw a {@link ParserException}
* if the stream contains invalid data. If false, the parser will make a best effort to ignore
* minor errors in the stream. Note however that a {@link ParserException} will still be
* thrown when this is not possible.
*/
public WebvttParser(boolean strictParsing) {
this.strictParsing = strictParsing;
......@@ -85,8 +85,7 @@ public final class WebvttParser implements SubtitleParser {
}
@Override
public final WebvttSubtitle parse(InputStream inputStream, String inputEncoding)
throws IOException {
public final WebvttSubtitle parse(InputStream inputStream) throws IOException {
ArrayList<WebvttCue> subtitles = new ArrayList<>();
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