Fix empty container box bug

If a container box is empty, it is never removed
from the container box stack, breaking the extractor.

Issue: #1308
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117228211
This commit is contained in:
olly 2016-03-15 05:18:44 -07:00 committed by Oliver Woodman
parent 37e00c8c6f
commit 1ca32cced8

View File

@ -195,7 +195,12 @@ public final class Mp4Extractor implements Extractor, SeekMap {
if (shouldParseContainerAtom(atomType)) { if (shouldParseContainerAtom(atomType)) {
long endPosition = input.getPosition() + atomSize - atomHeaderBytesRead; long endPosition = input.getPosition() + atomSize - atomHeaderBytesRead;
containerAtoms.add(new ContainerAtom(atomType, endPosition)); containerAtoms.add(new ContainerAtom(atomType, endPosition));
enterReadingAtomHeaderState(); if (atomSize == atomHeaderBytesRead) {
processAtomEnded(endPosition);
} else {
// Start reading the first child atom.
enterReadingAtomHeaderState();
}
} else if (shouldParseLeafAtom(atomType)) { } else if (shouldParseLeafAtom(atomType)) {
// We don't support parsing of leaf atoms that define extended atom sizes, or that have // We don't support parsing of leaf atoms that define extended atom sizes, or that have
// lengths greater than Integer.MAX_VALUE. // lengths greater than Integer.MAX_VALUE.
@ -238,7 +243,11 @@ public final class Mp4Extractor implements Extractor, SeekMap {
seekRequired = true; seekRequired = true;
} }
} }
processAtomEnded(atomEndPosition);
return seekRequired && parserState != STATE_READING_SAMPLE;
}
private void processAtomEnded(long atomEndPosition) {
while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) { while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) {
Atom.ContainerAtom containerAtom = containerAtoms.pop(); Atom.ContainerAtom containerAtom = containerAtoms.pop();
if (containerAtom.type == Atom.TYPE_moov) { if (containerAtom.type == Atom.TYPE_moov) {
@ -246,14 +255,13 @@ public final class Mp4Extractor implements Extractor, SeekMap {
processMoovAtom(containerAtom); processMoovAtom(containerAtom);
containerAtoms.clear(); containerAtoms.clear();
parserState = STATE_READING_SAMPLE; parserState = STATE_READING_SAMPLE;
return false;
} else if (!containerAtoms.isEmpty()) { } else if (!containerAtoms.isEmpty()) {
containerAtoms.peek().add(containerAtom); containerAtoms.peek().add(containerAtom);
} }
} }
if (parserState != STATE_READING_SAMPLE) {
enterReadingAtomHeaderState(); enterReadingAtomHeaderState();
return seekRequired; }
} }
/** /**
@ -289,7 +297,6 @@ public final class Mp4Extractor implements Extractor, SeekMap {
if (udta != null) { if (udta != null) {
gaplessInfo = AtomParsers.parseUdta(udta); gaplessInfo = AtomParsers.parseUdta(udta);
} }
for (int i = 0; i < moov.containerChildren.size(); i++) { for (int i = 0; i < moov.containerChildren.size(); i++) {
Atom.ContainerAtom atom = moov.containerChildren.get(i); Atom.ContainerAtom atom = moov.containerChildren.get(i);
if (atom.type != Atom.TYPE_trak) { if (atom.type != Atom.TYPE_trak) {