Skip to content

Commit

Permalink
Fix sideloaded subtitles
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ojw28 committed Oct 3, 2016
1 parent 37806ee commit f75f3d7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
/**
* 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;
Expand Down Expand Up @@ -71,7 +71,6 @@ public SingleSampleMediaPeriod(Uri uri, DataSource.Factory dataSourceFactory, Fo
tracks = new TrackGroupArray(new TrackGroup(format));
sampleStreams = new ArrayList<>();
loader = new Loader("Loader:SingleSampleMediaPeriod");
sampleData = new byte[INITIAL_SAMPLE_SIZE];
}

public void release() {
Expand Down Expand Up @@ -269,7 +268,9 @@ public void load() throws IOException, InterruptedException {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,27 @@ public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackEx
}
}

if (nextSubtitle != null && 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;
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;
nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs);
textRendererNeedsUpdate = true;
}
nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs);
textRendererNeedsUpdate = true;
}

if (textRendererNeedsUpdate) {
Expand Down

0 comments on commit f75f3d7

Please sign in to comment.