Correct allowTimeBeyondBuffer values for skipToKeyframeBefore calls

The only case where we should pass false is if we want to know
whether the passed time is within the buffered media. This is
relevant within seekTo implementations only.

This is related to (but does not fix) issue #2582

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=151315676
This commit is contained in:
olly 2017-03-27 06:52:34 -07:00 committed by Oliver Woodman
parent abcd177e8a
commit 5ebb3d4481
4 changed files with 10 additions and 20 deletions

View File

@ -227,20 +227,6 @@ public final class DefaultTrackOutput implements TrackOutput {
return infoQueue.getLargestQueuedTimestampUs();
}
/**
* Attempts to skip to the keyframe before or at the specified time. Succeeds only if the buffer
* contains a keyframe with a timestamp of {@code timeUs} or earlier, and if {@code timeUs} falls
* within the currently buffered media.
* <p>
* This method is equivalent to {@code skipToKeyframeBefore(timeUs, false)}.
*
* @param timeUs The seek time.
* @return Whether the skip was successful.
*/
public boolean skipToKeyframeBefore(long timeUs) {
return skipToKeyframeBefore(timeUs, false);
}
/**
* Attempts to skip to the keyframe before or at the specified time. Succeeds only if the buffer
* contains a keyframe with a timestamp of {@code timeUs} or earlier. If

View File

@ -301,7 +301,7 @@ import java.io.IOException;
boolean seekInsideBuffer = !isPendingReset();
for (int i = 0; seekInsideBuffer && i < trackCount; i++) {
if (trackEnabledStates[i]) {
seekInsideBuffer = sampleQueues.valueAt(i).skipToKeyframeBefore(positionUs);
seekInsideBuffer = sampleQueues.valueAt(i).skipToKeyframeBefore(positionUs, false);
}
}
// If we failed to seek within the sample queues, we need to restart.
@ -340,6 +340,10 @@ import java.io.IOException;
loadingFinished, lastSeekPositionUs);
}
/* package */ void skipToKeyframeBefore(int track, long timeUs) {
sampleQueues.valueAt(track).skipToKeyframeBefore(timeUs, true);
}
// Loader.Callback implementation.
@Override
@ -566,7 +570,7 @@ import java.io.IOException;
@Override
public void skipToKeyframeBefore(long timeUs) {
sampleQueues.valueAt(track).skipToKeyframeBefore(timeUs);
ExtractorMediaPeriod.this.skipToKeyframeBefore(track, timeUs);
}
}

View File

@ -193,7 +193,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
// TODO: For this to work correctly, the embedded streams must not discard anything from their
// sample queues beyond the current read position of the primary stream.
for (DefaultTrackOutput embeddedSampleQueue : embeddedSampleQueues) {
embeddedSampleQueue.skipToKeyframeBefore(positionUs);
embeddedSampleQueue.skipToKeyframeBefore(positionUs, true);
}
} else {
// We failed, and need to restart.
@ -252,7 +252,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
@Override
public void skipToKeyframeBefore(long timeUs) {
primarySampleQueue.skipToKeyframeBefore(timeUs);
primarySampleQueue.skipToKeyframeBefore(timeUs, true);
}
// Loader.Callback implementation.
@ -449,7 +449,7 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
@Override
public void skipToKeyframeBefore(long timeUs) {
sampleQueue.skipToKeyframeBefore(timeUs);
sampleQueue.skipToKeyframeBefore(timeUs, true);
}
@Override

View File

@ -313,7 +313,7 @@ import java.util.LinkedList;
}
/* package */ void skipToKeyframeBefore(int group, long timeUs) {
sampleQueues.valueAt(group).skipToKeyframeBefore(timeUs);
sampleQueues.valueAt(group).skipToKeyframeBefore(timeUs, true);
}
private boolean finishedReadingChunk(HlsMediaChunk chunk) {