mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Merge pull request #2318 from WeiChungChang/far_seek_improvement
Improve far seek performance of chunkSampleStream
This commit is contained in:
commit
a418b132d9
@ -229,10 +229,11 @@ public final class DefaultTrackOutput implements TrackOutput {
|
||||
* Attempts to skip to the keyframe before the specified time, if it's present in the buffer.
|
||||
*
|
||||
* @param timeUs The seek time.
|
||||
* @param skipToLastKey Skip to last key regardless the seek time is out of range .
|
||||
* @return Whether the skip was successful.
|
||||
*/
|
||||
public boolean skipToKeyframeBefore(long timeUs) {
|
||||
long nextOffset = infoQueue.skipToKeyframeBefore(timeUs);
|
||||
public boolean skipToKeyframeBefore(long timeUs, boolean skipToLastKey) {
|
||||
long nextOffset = infoQueue.skipToKeyframeBefore(timeUs, skipToLastKey);
|
||||
if (nextOffset == C.POSITION_UNSET) {
|
||||
return false;
|
||||
}
|
||||
@ -240,6 +241,16 @@ public final class DefaultTrackOutput implements TrackOutput {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to skip to the keyframe before the specified time, if it's present in the buffer.
|
||||
*
|
||||
* @param timeUs The seek time.
|
||||
* @return Whether the skip was successful.
|
||||
*/
|
||||
public boolean skipToKeyframeBefore(long timeUs) {
|
||||
return infoQueue.skipToKeyframeBefore(timeUs, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to read from the queue.
|
||||
*
|
||||
@ -781,12 +792,12 @@ public final class DefaultTrackOutput implements TrackOutput {
|
||||
* @return The offset of the keyframe's data if the keyframe was present.
|
||||
* {@link C#POSITION_UNSET} otherwise.
|
||||
*/
|
||||
public synchronized long skipToKeyframeBefore(long timeUs) {
|
||||
public synchronized long skipToKeyframeBefore(long timeUs, boolean skipToLastKey) {
|
||||
if (queueSize == 0 || timeUs < timesUs[relativeReadIndex]) {
|
||||
return C.POSITION_UNSET;
|
||||
}
|
||||
|
||||
if (timeUs > largestQueuedTimestampUs) {
|
||||
if (timeUs > largestQueuedTimestampUs && !skipToLastKey) {
|
||||
return C.POSITION_UNSET;
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
|
||||
public void seekToUs(long positionUs) {
|
||||
lastSeekPositionUs = positionUs;
|
||||
// If we're not pending a reset, see if we can seek within the sample queue.
|
||||
boolean seekInsideBuffer = !isPendingReset() && sampleQueue.skipToKeyframeBefore(positionUs);
|
||||
boolean seekInsideBuffer = !isPendingReset() &&
|
||||
sampleQueue.skipToKeyframeBefore(positionUs, (positionUs < getNextLoadPositionUs()));
|
||||
if (seekInsideBuffer) {
|
||||
// We succeeded. All we need to do is discard any chunks that we've moved past.
|
||||
while (mediaChunks.size() > 1
|
||||
|
Loading…
x
Reference in New Issue
Block a user