From 41c4295aeea33e2f1bb1fb5347742217405f9381 Mon Sep 17 00:00:00 2001 From: Oliver Woodman Date: Mon, 16 Jan 2017 00:20:51 +0000 Subject: [PATCH] Fix build break + cleanup --- .../extractor/DefaultTrackOutput.java | 54 +++++++++++-------- .../source/chunk/ChunkSampleStream.java | 4 +- 2 files changed, 35 insertions(+), 23 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/extractor/DefaultTrackOutput.java b/library/src/main/java/com/google/android/exoplayer2/extractor/DefaultTrackOutput.java index bd9076bd5d..75497e59c1 100644 --- a/library/src/main/java/com/google/android/exoplayer2/extractor/DefaultTrackOutput.java +++ b/library/src/main/java/com/google/android/exoplayer2/extractor/DefaultTrackOutput.java @@ -226,29 +226,37 @@ 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, boolean skipToLastKey) { - long nextOffset = infoQueue.skipToKeyframeBefore(timeUs, skipToLastKey); - if (nextOffset == C.POSITION_UNSET) { - return false; - } - dropDownstreamTo(nextOffset); - return true; - } - - /** - * Attempts to skip to the keyframe before the specified time, if it's present in the buffer. + * 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. + *

+ * 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 infoQueue.skipToKeyframeBefore(timeUs, false); + 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 + * {@code allowTimeBeyondBuffer} is {@code false} then it is also required that {@code timeUs} + * falls within the buffer. + * + * @param timeUs The seek time. + * @param allowTimeBeyondBuffer Whether the skip can succeed if {@code timeUs} is beyond the end + * of the buffer. + * @return Whether the skip was successful. + */ + public boolean skipToKeyframeBefore(long timeUs, boolean allowTimeBeyondBuffer) { + long nextOffset = infoQueue.skipToKeyframeBefore(timeUs, allowTimeBeyondBuffer); + if (nextOffset == C.POSITION_UNSET) { + return false; + } + dropDownstreamTo(nextOffset); + return true; } /** @@ -786,18 +794,22 @@ public final class DefaultTrackOutput implements TrackOutput { } /** - * Attempts to locate the keyframe before the specified time, if it's present in the buffer. + * Attempts to locate the keyframe before or at the specified time. If + * {@code allowTimeBeyondBuffer} is {@code false} then it is also required that {@code timeUs} + * falls within the buffer. * * @param timeUs The seek time. + * @param allowTimeBeyondBuffer Whether the skip can succeed if {@code timeUs} is beyond the end + * of the buffer. * @return The offset of the keyframe's data if the keyframe was present. * {@link C#POSITION_UNSET} otherwise. */ - public synchronized long skipToKeyframeBefore(long timeUs, boolean skipToLastKey) { + public synchronized long skipToKeyframeBefore(long timeUs, boolean allowTimeBeyondBuffer) { if (queueSize == 0 || timeUs < timesUs[relativeReadIndex]) { return C.POSITION_UNSET; } - if (timeUs > largestQueuedTimestampUs && !skipToLastKey) { + if (timeUs > largestQueuedTimestampUs && !allowTimeBeyondBuffer) { return C.POSITION_UNSET; } diff --git a/library/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java b/library/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java index 189fcc96f4..3955d64034 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/chunk/ChunkSampleStream.java @@ -122,8 +122,8 @@ public class ChunkSampleStream 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, (positionUs < getNextLoadPositionUs())); + 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