Skip to content

Commit

Permalink
Make OggSeeker.startSeek take a granule rather than a time
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 261102180
  • Loading branch information
ojw28 committed Aug 1, 2019
1 parent 7405021 commit 520275e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ public long read(ExtractorInput input) throws IOException, InterruptedException
}

@Override
public long startSeek(long timeUs) {
public void startSeek(long targetGranule) {
Assertions.checkArgument(state == STATE_IDLE || state == STATE_SEEK);
targetGranule = timeUs == 0 ? 0 : streamReader.convertTimeToGranule(timeUs);
this.targetGranule = targetGranule;
state = STATE_SEEK;
resetSeeking();
return targetGranule;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,9 @@ public long read(ExtractorInput input) throws IOException, InterruptedException
}

@Override
public long startSeek(long timeUs) {
long granule = convertTimeToGranule(timeUs);
int index = Util.binarySearchFloor(seekPointGranules, granule, true, true);
public void startSeek(long targetGranule) {
int index = Util.binarySearchFloor(seekPointGranules, targetGranule, true, true);
pendingSeekGranule = seekPointGranules[index];
return granule;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@
SeekMap createSeekMap();

/**
* Initializes a seek operation.
* Starts a seek operation.
*
* @param timeUs The seek position in microseconds.
* @return The granule position targeted by the seek.
* @param targetGranule The target granule position.
*/
long startSeek(long timeUs);
void startSeek(long targetGranule);

/**
* Reads data from the {@link ExtractorInput} to build the {@link SeekMap} or to continue a
* progressive seek.
* Reads data from the {@link ExtractorInput} to build the {@link SeekMap} or to continue a seek.
* <p/>
* If more data is required or if the position of the input needs to be modified then a position
* from which data should be provided is returned. Else a negative value is returned. If a seek
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ final void seek(long position, long timeUs) {
reset(!seekMapSet);
} else {
if (state != STATE_READ_HEADERS) {
targetGranule = oggSeeker.startSeek(timeUs);
targetGranule = convertTimeToGranule(timeUs);
oggSeeker.startSeek(targetGranule);
state = STATE_READ_PAYLOAD;
}
}
Expand Down Expand Up @@ -248,13 +249,13 @@ protected void onSeekEnd(long currentGranule) {
private static final class UnseekableOggSeeker implements OggSeeker {

@Override
public long read(ExtractorInput input) throws IOException, InterruptedException {
public long read(ExtractorInput input) {
return -1;
}

@Override
public long startSeek(long timeUs) {
return 0;
public void startSeek(long targetGranule) {
// Do nothing.
}

@Override
Expand Down

0 comments on commit 520275e

Please sign in to comment.