Commit 72d42fbc by Oliver Woodman

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.
parent 31e5e0ed
...@@ -297,7 +297,7 @@ public final class WebmExtractor implements Extractor { ...@@ -297,7 +297,7 @@ public final class WebmExtractor implements Extractor {
throws ParserException { throws ParserException {
switch (id) { switch (id) {
case ID_SEGMENT: case ID_SEGMENT:
if (segmentContentPosition != UNKNOWN) { if (segmentContentPosition != UNKNOWN && segmentContentPosition != contentPosition) {
throw new ParserException("Multiple Segment elements not supported"); throw new ParserException("Multiple Segment elements not supported");
} }
segmentContentPosition = contentPosition; segmentContentPosition = contentPosition;
......
...@@ -92,6 +92,21 @@ public final class WebmExtractorTest extends InstrumentationTestCase { ...@@ -92,6 +92,21 @@ public final class WebmExtractorTest extends InstrumentationTestCase {
assertIndex(new IndexPoint(0, 0, TEST_DURATION_US)); 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 { public void testPrepareOpus() throws IOException, InterruptedException {
byte[] data = new StreamBuilder() byte[] data = new StreamBuilder()
.setHeader(WEBM_DOC_TYPE) .setHeader(WEBM_DOC_TYPE)
......
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