Skip to content

Commit

Permalink
Correct allowTimeBeyondBuffer values for skipToKeyframeBefore calls
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ojw28 committed Mar 31, 2017
1 parent abcd177 commit 5ebb3d4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,6 @@ public long getLargestQueuedTimestampUs() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public long seekToUs(long positionUs) {
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.
Expand Down Expand Up @@ -340,6 +340,10 @@ public long seekToUs(long positionUs) {
loadingFinished, lastSeekPositionUs);
}

/* package */ void skipToKeyframeBefore(int track, long timeUs) {
sampleQueues.valueAt(track).skipToKeyframeBefore(timeUs, true);
}

// Loader.Callback implementation.

@Override
Expand Down Expand Up @@ -566,7 +570,7 @@ public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer,

@Override
public void skipToKeyframeBefore(long timeUs) {
sampleQueues.valueAt(track).skipToKeyframeBefore(timeUs);
ExtractorMediaPeriod.this.skipToKeyframeBefore(track, timeUs);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void seekToUs(long positionUs) {
// 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.
Expand Down Expand Up @@ -252,7 +252,7 @@ public int readData(FormatHolder formatHolder, DecoderInputBuffer buffer,

@Override
public void skipToKeyframeBefore(long timeUs) {
primarySampleQueue.skipToKeyframeBefore(timeUs);
primarySampleQueue.skipToKeyframeBefore(timeUs, true);
}

// Loader.Callback implementation.
Expand Down Expand Up @@ -449,7 +449,7 @@ public boolean isReady() {

@Override
public void skipToKeyframeBefore(long timeUs) {
sampleQueue.skipToKeyframeBefore(timeUs);
sampleQueue.skipToKeyframeBefore(timeUs, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public void onPlaylistBlacklisted(HlsUrl url, long blacklistMs) {
}

/* package */ void skipToKeyframeBefore(int group, long timeUs) {
sampleQueues.valueAt(group).skipToKeyframeBefore(timeUs);
sampleQueues.valueAt(group).skipToKeyframeBefore(timeUs, true);
}

private boolean finishedReadingChunk(HlsMediaChunk chunk) {
Expand Down

0 comments on commit 5ebb3d4

Please sign in to comment.