Commit f04e412a by olly Committed by Oliver Woodman

Improve unsupported edts handling

When the edited sample sequence does not contain any sync sample Exoplayer does not provide
support. This CL changes the ArrayIndexOutOfBoundsException for a more explicative
ParserException.

Issue: #1336
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=117241805
parent f5b7ea67
...@@ -17,6 +17,7 @@ package com.google.android.exoplayer.extractor.mp4; ...@@ -17,6 +17,7 @@ package com.google.android.exoplayer.extractor.mp4;
import com.google.android.exoplayer.C; import com.google.android.exoplayer.C;
import com.google.android.exoplayer.Format; import com.google.android.exoplayer.Format;
import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.extractor.GaplessInfo; import com.google.android.exoplayer.extractor.GaplessInfo;
import com.google.android.exoplayer.util.Ac3Util; import com.google.android.exoplayer.util.Ac3Util;
import com.google.android.exoplayer.util.Assertions; import com.google.android.exoplayer.util.Assertions;
...@@ -82,8 +83,10 @@ import java.util.List; ...@@ -82,8 +83,10 @@ import java.util.List;
* @param track Track to which this sample table corresponds. * @param track Track to which this sample table corresponds.
* @param stblAtom stbl (sample table) atom to parse. * @param stblAtom stbl (sample table) atom to parse.
* @return Sample table described by the stbl atom. * @return Sample table described by the stbl atom.
* @throws ParserException If the resulting sample sequence does not contain a sync sample.
*/ */
public static TrackSampleTable parseStbl(Track track, Atom.ContainerAtom stblAtom) { public static TrackSampleTable parseStbl(Track track, Atom.ContainerAtom stblAtom)
throws ParserException {
// Array of sample sizes. // Array of sample sizes.
ParsableByteArray stsz = stblAtom.getLeafAtomOfType(Atom.TYPE_stsz).data; ParsableByteArray stsz = stblAtom.getLeafAtomOfType(Atom.TYPE_stsz).data;
...@@ -327,6 +330,15 @@ import java.util.List; ...@@ -327,6 +330,15 @@ import java.util.List;
} }
pts += duration; pts += duration;
} }
boolean hasSyncSample = false;
for (int i = 0; i < editedFlags.length && !hasSyncSample; i++) {
hasSyncSample |= (editedFlags[i] & C.SAMPLE_FLAG_SYNC) != 0;
}
if (!hasSyncSample) {
throw new ParserException("The edited sample sequence does not contain a sync sample.");
}
return new TrackSampleTable(editedOffsets, editedSizes, editedMaximumSize, editedTimestamps, return new TrackSampleTable(editedOffsets, editedSizes, editedMaximumSize, editedTimestamps,
editedFlags); editedFlags);
} }
......
...@@ -17,6 +17,7 @@ package com.google.android.exoplayer.extractor.mp4; ...@@ -17,6 +17,7 @@ package com.google.android.exoplayer.extractor.mp4;
import com.google.android.exoplayer.C; import com.google.android.exoplayer.C;
import com.google.android.exoplayer.Format; import com.google.android.exoplayer.Format;
import com.google.android.exoplayer.ParserException;
import com.google.android.exoplayer.extractor.Extractor; import com.google.android.exoplayer.extractor.Extractor;
import com.google.android.exoplayer.extractor.ExtractorInput; import com.google.android.exoplayer.extractor.ExtractorInput;
import com.google.android.exoplayer.extractor.ExtractorOutput; import com.google.android.exoplayer.extractor.ExtractorOutput;
...@@ -247,7 +248,7 @@ public final class Mp4Extractor implements Extractor, SeekMap { ...@@ -247,7 +248,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
return seekRequired && parserState != STATE_READING_SAMPLE; return seekRequired && parserState != STATE_READING_SAMPLE;
} }
private void processAtomEnded(long atomEndPosition) { private void processAtomEnded(long atomEndPosition) throws ParserException {
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) {
...@@ -288,7 +289,7 @@ public final class Mp4Extractor implements Extractor, SeekMap { ...@@ -288,7 +289,7 @@ public final class Mp4Extractor implements Extractor, SeekMap {
/** /**
* Updates the stored track metadata to reflect the contents of the specified moov atom. * Updates the stored track metadata to reflect the contents of the specified moov atom.
*/ */
private void processMoovAtom(ContainerAtom moov) { private void processMoovAtom(ContainerAtom moov) throws ParserException {
long durationUs = C.UNKNOWN_TIME_US; long durationUs = C.UNKNOWN_TIME_US;
List<Mp4Track> tracks = new ArrayList<>(); List<Mp4Track> tracks = new ArrayList<>();
long earliestSampleOffset = Long.MAX_VALUE; long earliestSampleOffset = Long.MAX_VALUE;
......
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