Seek at a chunk level when seeking to chunk start positions
This avoids issues that can arise due to the slight discrepancies between chunk start times (obtained from the manifest of segment index) and the timestamps of the samples contained within those chunks.
This commit is contained in:
parent
03d35e3f43
commit
173dbc87a2
@ -242,6 +242,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
|||||||
return trackGroup;
|
return trackGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Returns if the chunk source has independent segments. */
|
||||||
|
public boolean hasIndependentSegments() {
|
||||||
|
return independentSegments;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the current track selection.
|
* Sets the current track selection.
|
||||||
*
|
*
|
||||||
|
@ -496,8 +496,21 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Detect whether the seek is to the start of a chunk that's at least partially buffered.
|
||||||
|
@Nullable HlsMediaChunk seekToMediaChunk = null;
|
||||||
|
if (chunkSource.hasIndependentSegments()) {
|
||||||
|
for (int i = 0; i < mediaChunks.size(); i++) {
|
||||||
|
HlsMediaChunk mediaChunk = mediaChunks.get(i);
|
||||||
|
long mediaChunkStartTimeUs = mediaChunk.startTimeUs;
|
||||||
|
if (mediaChunkStartTimeUs == positionUs) {
|
||||||
|
seekToMediaChunk = mediaChunk;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If we're not forced to reset, try and seek within the buffer.
|
// If we're not forced to reset, try and seek within the buffer.
|
||||||
if (sampleQueuesBuilt && !forceReset && seekInsideBufferUs(positionUs)) {
|
if (sampleQueuesBuilt && !forceReset && seekInsideBufferUs(positionUs, seekToMediaChunk)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1470,13 +1483,19 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
* Attempts to seek to the specified position within the sample queues.
|
* Attempts to seek to the specified position within the sample queues.
|
||||||
*
|
*
|
||||||
* @param positionUs The seek position in microseconds.
|
* @param positionUs The seek position in microseconds.
|
||||||
|
* @param chunk Optionally the chunk to seek to.
|
||||||
* @return Whether the in-buffer seek was successful.
|
* @return Whether the in-buffer seek was successful.
|
||||||
*/
|
*/
|
||||||
private boolean seekInsideBufferUs(long positionUs) {
|
private boolean seekInsideBufferUs(long positionUs, @Nullable HlsMediaChunk chunk) {
|
||||||
int sampleQueueCount = sampleQueues.length;
|
int sampleQueueCount = sampleQueues.length;
|
||||||
for (int i = 0; i < sampleQueueCount; i++) {
|
for (int i = 0; i < sampleQueueCount; i++) {
|
||||||
SampleQueue sampleQueue = sampleQueues[i];
|
SampleQueue sampleQueue = sampleQueues[i];
|
||||||
boolean seekInsideQueue = sampleQueue.seekTo(positionUs, /* allowTimeBeyondBuffer= */ false);
|
boolean seekInsideQueue;
|
||||||
|
if (chunk != null) {
|
||||||
|
seekInsideQueue = sampleQueue.seekTo(chunk.getFirstSampleIndex(i));
|
||||||
|
} else {
|
||||||
|
seekInsideQueue = sampleQueue.seekTo(positionUs, /* allowTimeBeyondBuffer= */ false);
|
||||||
|
}
|
||||||
// If we have AV tracks then an in-queue seek is successful if the seek into every AV queue
|
// If we have AV tracks then an in-queue seek is successful if the seek into every AV queue
|
||||||
// is successful. We ignore whether seeks within non-AV queues are successful in this case, as
|
// is successful. We ignore whether seeks within non-AV queues are successful in this case, as
|
||||||
// they may be sparse or poorly interleaved. If we only have non-AV tracks then a seek is
|
// they may be sparse or poorly interleaved. If we only have non-AV tracks then a seek is
|
||||||
|
Loading…
x
Reference in New Issue
Block a user