From 0b6a93b468431bc5064d727471fdf9c57e8ff8cc Mon Sep 17 00:00:00 2001 From: olly Date: Wed, 24 Aug 2016 10:57:44 -0700 Subject: [PATCH] Workaround missing data offsets in FMP4 If they're omitted, it's reasonable to assume it's because they were uninteresting (i.e. sample data always tightly packed at the start of the mdat). This is an issue for some SmoothStreaming streams. We actually already play such streams successfully, but that's only due to another bug to be fixed in a following CL. The same is true for V1, but given the low impact nature, the fix will be V2 only. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=131191975 --- .../exoplayer2/extractor/mp4/FragmentedMp4Extractor.java | 9 ++++++++- .../android/exoplayer2/extractor/mp4/TrackFragment.java | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java b/library/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java index 8487584eb8..451aa41871 100644 --- a/library/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java +++ b/library/src/main/java/com/google/android/exoplayer2/extractor/mp4/FragmentedMp4Extractor.java @@ -246,6 +246,7 @@ public final class FragmentedMp4Extractor implements Extractor { int trackCount = trackBundles.size(); for (int i = 0; i < trackCount; i++) { TrackFragment fragment = trackBundles.valueAt(i).fragment; + fragment.atomPosition = atomPosition; fragment.auxiliaryDataPosition = atomPosition; fragment.dataPosition = atomPosition; } @@ -935,7 +936,13 @@ public final class FragmentedMp4Extractor implements Extractor { // We skip bytes preceding the next sample to read. int bytesToSkip = (int) (nextDataPosition - input.getPosition()); if (bytesToSkip < 0) { - throw new ParserException("Offset to sample data was negative."); + if (nextDataPosition == currentTrackBundle.fragment.atomPosition) { + // Assume the sample data must be contiguous in the mdat with no preceeding data. + Log.w(TAG, "Offset to sample data was missing."); + bytesToSkip = 0; + } else { + throw new ParserException("Offset to sample data was negative."); + } } input.skipFully(bytesToSkip); this.currentTrackBundle = currentTrackBundle; diff --git a/library/src/main/java/com/google/android/exoplayer2/extractor/mp4/TrackFragment.java b/library/src/main/java/com/google/android/exoplayer2/extractor/mp4/TrackFragment.java index 531e26d92a..5ac673d037 100644 --- a/library/src/main/java/com/google/android/exoplayer2/extractor/mp4/TrackFragment.java +++ b/library/src/main/java/com/google/android/exoplayer2/extractor/mp4/TrackFragment.java @@ -28,6 +28,10 @@ import java.io.IOException; * The default values for samples from the track fragment header. */ public DefaultSampleValues header; + /** + * The position (byte offset) of the start of fragment. + */ + public long atomPosition; /** * The position (byte offset) of the start of data contained in the fragment. */