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
This commit is contained in:
olly 2016-10-03 06:55:41 -07:00 committed by Oliver Woodman
parent 37806ee792
commit f75f3d75b2
2 changed files with 24 additions and 17 deletions

View File

@ -41,7 +41,7 @@ import java.util.Arrays;
/**
* 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 DataSource.Factory dataSourceFactory;
@ -71,7 +71,6 @@ import java.util.Arrays;
tracks = new TrackGroupArray(new TrackGroup(format));
sampleStreams = new ArrayList<>();
loader = new Loader("Loader:SingleSampleMediaPeriod");
sampleData = new byte[INITIAL_SAMPLE_SIZE];
}
public void release() {
@ -269,7 +268,9 @@ import java.util.Arrays;
int result = 0;
while (result != C.RESULT_END_OF_INPUT) {
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);
}
result = dataSource.read(sampleData, sampleSize, sampleData.length - sampleSize);

View File

@ -160,22 +160,28 @@ public final class TextRenderer extends BaseRenderer implements Callback {
}
}
if (nextSubtitle != null && nextSubtitle.timeUs <= positionUs) {
if (nextSubtitle != null) {
if (nextSubtitle.isEndOfStream()) {
if (!textRendererNeedsUpdate && getNextEventTime() == Long.MAX_VALUE) {
if (subtitle != null) {
subtitle.release();
subtitle = null;
}
nextSubtitle.release();
nextSubtitle = null;
outputStreamEnded = true;
}
} 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;
if (subtitle.isEndOfStream()) {
outputStreamEnded = true;
subtitle.release();
subtitle = null;
return;
}
nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs);
textRendererNeedsUpdate = true;
}
}
if (textRendererNeedsUpdate) {
// textRendererNeedsUpdate is set and we're playing. Update the renderer.