Fix an issue where retrying WebM extraction failed.

The ID_SEGMENT can only be read once, as seeing the element a second time is
assumed to indicate that the file contains multiple segment elements (which is
not supported).

This change allows the element to be read twice if it is at the same position,
so that retrying loading from the start can succeed.
This commit is contained in:
Oliver Woodman 2015-07-15 11:15:21 +01:00
parent 31e5e0edaf
commit 72d42fbc9f
2 changed files with 16 additions and 1 deletions

View File

@ -297,7 +297,7 @@ public final class WebmExtractor implements Extractor {
throws ParserException {
switch (id) {
case ID_SEGMENT:
if (segmentContentPosition != UNKNOWN) {
if (segmentContentPosition != UNKNOWN && segmentContentPosition != contentPosition) {
throw new ParserException("Multiple Segment elements not supported");
}
segmentContentPosition = contentPosition;

View File

@ -92,6 +92,21 @@ public final class WebmExtractorTest extends InstrumentationTestCase {
assertIndex(new IndexPoint(0, 0, TEST_DURATION_US));
}
public void testReadSegmentTwice() throws IOException, InterruptedException {
byte[] data = new StreamBuilder()
.setHeader(WEBM_DOC_TYPE)
.setInfo(DEFAULT_TIMECODE_SCALE, TEST_DURATION_US)
.addVp9Track(TEST_WIDTH, TEST_HEIGHT, null)
.build(1);
TestUtil.consumeTestData(extractor, data);
extractor.seek();
TestUtil.consumeTestData(extractor, data);
assertVp9VideoFormat();
assertIndex(new IndexPoint(0, 0, TEST_DURATION_US));
}
public void testPrepareOpus() throws IOException, InterruptedException {
byte[] data = new StreamBuilder()
.setHeader(WEBM_DOC_TYPE)