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:
parent
37806ee792
commit
f75f3d75b2
@ -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;
|
|||||||
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;
|
|||||||
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,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.
|
// Advance to the next subtitle. Sync the next event index and trigger an update.
|
||||||
if (subtitle != null) {
|
if (subtitle != null) {
|
||||||
subtitle.release();
|
subtitle.release();
|
||||||
}
|
}
|
||||||
subtitle = nextSubtitle;
|
subtitle = nextSubtitle;
|
||||||
nextSubtitle = null;
|
nextSubtitle = null;
|
||||||
if (subtitle.isEndOfStream()) {
|
|
||||||
outputStreamEnded = true;
|
|
||||||
subtitle.release();
|
|
||||||
subtitle = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs);
|
nextSubtitleEventIndex = subtitle.getNextEventTimeIndex(positionUs);
|
||||||
textRendererNeedsUpdate = true;
|
textRendererNeedsUpdate = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (textRendererNeedsUpdate) {
|
if (textRendererNeedsUpdate) {
|
||||||
// textRendererNeedsUpdate is set and we're playing. Update the renderer.
|
// textRendererNeedsUpdate is set and we're playing. Update the renderer.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user