Skip to content

Commit

Permalink
Allow playback of unseekable fmp4 media.
Browse files Browse the repository at this point in the history
This is useful to allow playback of individual segments from a
DASH stream as regular fmp4 files. These segments don't typically
contain a segment index. For playback to start, we need to invoke
seekMap with the UNSEEKABLE index. We do this if we haven't seen
a segment index when we encounter an mdat box (if one were present,
it would have been located earlier than this point).
  • Loading branch information
ojw28 committed Jul 27, 2015
1 parent e89c40c commit 08dc691
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.android.exoplayer.extractor.ExtractorInput;
import com.google.android.exoplayer.extractor.ExtractorOutput;
import com.google.android.exoplayer.extractor.PositionHolder;
import com.google.android.exoplayer.extractor.SeekMap;
import com.google.android.exoplayer.extractor.TrackOutput;
import com.google.android.exoplayer.extractor.mp4.Atom.ContainerAtom;
import com.google.android.exoplayer.extractor.mp4.Atom.LeafAtom;
Expand Down Expand Up @@ -94,6 +95,9 @@ public final class FragmentedMp4Extractor implements Extractor {
private ExtractorOutput extractorOutput;
private TrackOutput trackOutput;

// Whether extractorOutput.seekMap has been invoked.
private boolean haveOutputSeekMap;

public FragmentedMp4Extractor() {
this(0);
}
Expand Down Expand Up @@ -182,6 +186,10 @@ private boolean readAtomHeader(ExtractorInput input) throws IOException, Interru
atomType = atomHeader.readInt();

if (atomType == Atom.TYPE_mdat) {
if (!haveOutputSeekMap) {
extractorOutput.seekMap(SeekMap.UNSEEKABLE);
haveOutputSeekMap = true;
}
if (fragmentRun.sampleEncryptionDataNeedsFill) {
parserState = STATE_READING_ENCRYPTION_DATA;
} else {
Expand Down Expand Up @@ -233,6 +241,7 @@ private void onLeafAtomRead(LeafAtom leaf, long inputPosition) {
} else if (leaf.type == Atom.TYPE_sidx) {
ChunkIndex segmentIndex = parseSidx(leaf.data, inputPosition);
extractorOutput.seekMap(segmentIndex);
haveOutputSeekMap = true;
}
}

Expand Down

0 comments on commit 08dc691

Please sign in to comment.