Commit 41c4295a by Oliver Woodman

Fix build break + cleanup

parent a418b132
...@@ -226,29 +226,37 @@ public final class DefaultTrackOutput implements TrackOutput { ...@@ -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. * 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. * @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. * @return Whether the skip was successful.
*/ */
public boolean skipToKeyframeBefore(long timeUs, boolean skipToLastKey) { public boolean skipToKeyframeBefore(long timeUs) {
long nextOffset = infoQueue.skipToKeyframeBefore(timeUs, skipToLastKey); return skipToKeyframeBefore(timeUs, false);
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. If
* {@code allowTimeBeyondBuffer} is {@code false} then it is also required that {@code timeUs}
* falls within the buffer.
* *
* @param timeUs The seek time. * @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. * @return Whether the skip was successful.
*/ */
public boolean skipToKeyframeBefore(long timeUs) { public boolean skipToKeyframeBefore(long timeUs, boolean allowTimeBeyondBuffer) {
return infoQueue.skipToKeyframeBefore(timeUs, false); 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 { ...@@ -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 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. * @return The offset of the keyframe's data if the keyframe was present.
* {@link C#POSITION_UNSET} otherwise. * {@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]) { if (queueSize == 0 || timeUs < timesUs[relativeReadIndex]) {
return C.POSITION_UNSET; return C.POSITION_UNSET;
} }
if (timeUs > largestQueuedTimestampUs && !skipToLastKey) { if (timeUs > largestQueuedTimestampUs && !allowTimeBeyondBuffer) {
return C.POSITION_UNSET; return C.POSITION_UNSET;
} }
......
...@@ -122,8 +122,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S ...@@ -122,8 +122,8 @@ public class ChunkSampleStream<T extends ChunkSource> implements SampleStream, S
public void seekToUs(long positionUs) { public void seekToUs(long positionUs) {
lastSeekPositionUs = positionUs; lastSeekPositionUs = positionUs;
// If we're not pending a reset, see if we can seek within the sample queue. // If we're not pending a reset, see if we can seek within the sample queue.
boolean seekInsideBuffer = !isPendingReset() && boolean seekInsideBuffer = !isPendingReset()
sampleQueue.skipToKeyframeBefore(positionUs, (positionUs < getNextLoadPositionUs())); && sampleQueue.skipToKeyframeBefore(positionUs, positionUs < getNextLoadPositionUs());
if (seekInsideBuffer) { if (seekInsideBuffer) {
// We succeeded. All we need to do is discard any chunks that we've moved past. // We succeeded. All we need to do is discard any chunks that we've moved past.
while (mediaChunks.size() > 1 while (mediaChunks.size() > 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment