Prevent reading into preload parts.

This is to ensure we can still discard the data if needed.

Issue: #5011
PiperOrigin-RevId: 344977548
This commit is contained in:
tonihei 2020-12-01 10:02:49 +00:00 committed by Oliver Woodman
parent 84a7ffc12a
commit 8349d7849e

View file

@ -596,6 +596,11 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
downstreamTrackFormat = trackFormat;
}
if (!mediaChunks.isEmpty() && !mediaChunks.get(0).isPublished()) {
// Don't read into preload chunks until we can be sure they are permanently published.
return C.RESULT_NOTHING_READ;
}
int result =
sampleQueues[sampleQueueIndex].read(formatHolder, buffer, requireFormat, loadingFinished);
if (result == C.RESULT_FORMAT_READ) {
@ -625,6 +630,21 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
SampleQueue sampleQueue = sampleQueues[sampleQueueIndex];
int skipCount = sampleQueue.getSkipCount(positionUs, loadingFinished);
// Ensure we don't skip into preload chunks until we can be sure they are permanently published.
int readIndex = sampleQueue.getReadIndex();
for (int i = 0; i < mediaChunks.size(); i++) {
HlsMediaChunk mediaChunk = mediaChunks.get(i);
int firstSampleIndex = mediaChunks.get(i).getFirstSampleIndex(sampleQueueIndex);
if (readIndex + skipCount <= firstSampleIndex) {
break;
}
if (!mediaChunk.isPublished()) {
skipCount = firstSampleIndex - readIndex;
break;
}
}
sampleQueue.skip(skipCount);
return skipCount;
}