Commit f75f3d75 by olly Committed by Oliver Woodman

Fix sideloaded subtitles

- Fix NPE issue in SingleSampleMediaPeriod.
- Delay handling of EOS in TextRenderer until the last
  subtitle is fully played out.

Issue: #1882

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=134979286
parent 37806ee7
...@@ -41,7 +41,7 @@ import java.util.Arrays; ...@@ -41,7 +41,7 @@ import java.util.Arrays;
/** /**
* The initial size of the allocation used to hold the sample data. * The initial size of the allocation used to hold the sample data.
*/ */
private static final int INITIAL_SAMPLE_SIZE = 1; private static final int INITIAL_SAMPLE_SIZE = 1024;
private final Uri uri; private final Uri uri;
private final DataSource.Factory dataSourceFactory; private final DataSource.Factory dataSourceFactory;
...@@ -71,7 +71,6 @@ import java.util.Arrays; ...@@ -71,7 +71,6 @@ import java.util.Arrays;
tracks = new TrackGroupArray(new TrackGroup(format)); tracks = new TrackGroupArray(new TrackGroup(format));
sampleStreams = new ArrayList<>(); sampleStreams = new ArrayList<>();
loader = new Loader("Loader:SingleSampleMediaPeriod"); loader = new Loader("Loader:SingleSampleMediaPeriod");
sampleData = new byte[INITIAL_SAMPLE_SIZE];
} }
public void release() { public void release() {
...@@ -269,7 +268,9 @@ import java.util.Arrays; ...@@ -269,7 +268,9 @@ import java.util.Arrays;
int result = 0; int result = 0;
while (result != C.RESULT_END_OF_INPUT) { while (result != C.RESULT_END_OF_INPUT) {
sampleSize += result; sampleSize += result;
if (sampleSize == sampleData.length) { if (sampleData == null) {
sampleData = new byte[INITIAL_SAMPLE_SIZE];
} else if (sampleSize == sampleData.length) {
sampleData = Arrays.copyOf(sampleData, sampleData.length * 2); sampleData = Arrays.copyOf(sampleData, sampleData.length * 2);
} }
result = dataSource.read(sampleData, sampleSize, sampleData.length - sampleSize); result = dataSource.read(sampleData, sampleSize, sampleData.length - sampleSize);
......
...@@ -160,21 +160,27 @@ public final class TextRenderer extends BaseRenderer implements Callback { ...@@ -160,21 +160,27 @@ public final class TextRenderer extends BaseRenderer implements Callback {
} }
} }
if (nextSubtitle != null && nextSubtitle.timeUs <= positionUs) { if (nextSubtitle != null) {
// Advance to the next subtitle. Sync the next event index and trigger an update. if (nextSubtitle.isEndOfStream()) {
if (subtitle != null) { if (!textRendererNeedsUpdate && getNextEventTime() == Long.MAX_VALUE) {
subtitle.release(); if (subtitle != null) {
} subtitle.release();
subtitle = nextSubtitle; subtitle = null;
nextSubtitle = null; }
if (subtitle.isEndOfStream()) { nextSubtitle.release();
outputStreamEnded = true; nextSubtitle = null;
subtitle.release(); outputStreamEnded = true;
subtitle = null; }
return; } else if (nextSubtitle.timeUs <= positionUs) {
// Advance to the next subtitle. Sync the next event index and trigger an update.
if (subtitle != null) {
subtitle.release();
}
subtitle = nextSubtitle;
nextSubtitle = null;
nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs);
textRendererNeedsUpdate = true;
} }
nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs);
textRendererNeedsUpdate = true;
} }
if (textRendererNeedsUpdate) { if (textRendererNeedsUpdate) {
......
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