Skip to content

Commit

Permalink
Add support for Ogg without flagged last page
Browse files Browse the repository at this point in the history
Such files are slightly off spec but easy to support.

Issue: #1506
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=121927762
  • Loading branch information
[]inger authored and ojw28 committed May 10, 2016
1 parent 91aedbc commit 45e9020
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,9 @@ public long readGranuleOfLastPage(ExtractorInput input)
Assertions.checkArgument(input.getLength() != C.LENGTH_UNBOUNDED); // never read forever!
OggUtil.skipToNextPage(input);
pageHeader.reset();
while ((pageHeader.type & 0x04) != 0x04) {
if (pageHeader.bodySize > 0) {
input.skipFully(pageHeader.bodySize);
}
while ((pageHeader.type & 0x04) != 0x04 && input.getPosition() < input.getLength()) {
OggUtil.populatePageHeader(input, pageHeader, headerArray, false);
input.skipFully(pageHeader.headerSize);
input.skipFully(pageHeader.headerSize + pageHeader.bodySize);
}
return pageHeader.granulePosition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
*/
/* package */ final class VorbisReader extends StreamReader implements SeekMap {

private static final long LARGEST_EXPECTED_PAGE_SIZE = 8000;

private VorbisSetup vorbisSetup;
private int previousPacketBlockSize;
private long elapsedSamples;
Expand Down Expand Up @@ -78,7 +80,7 @@ public int read(ExtractorInput input, PositionHolder seekPosition)
extractorOutput.seekMap(this);
if (inputLength != C.LENGTH_UNBOUNDED) {
// seek to the end just before the last page of stream to get the duration
seekPosition.position = input.getLength() - 8000;
seekPosition.position = Math.max(0, input.getLength() - LARGEST_EXPECTED_PAGE_SIZE);
return Extractor.RESULT_SEEK;
}
}
Expand Down

0 comments on commit 45e9020

Please sign in to comment.