mirror of
https://github.com/samsonjs/media.git
synced 2026-04-11 12:15:47 +00:00
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:
parent
84a7ffc12a
commit
8349d7849e
1 changed files with 20 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue