Commit 8349d784 by tonihei Committed by Oliver Woodman

Prevent reading into preload parts.

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

Issue: #5011
PiperOrigin-RevId: 344977548
parent 84a7ffc1
......@@ -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;
}
......
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