Skip to content

Commit

Permalink
Add workaround for unmatched track indices in tkhd and tfhd.
Browse files Browse the repository at this point in the history
If there is only one track, we can assume that both boxes refer to the same track
even if the track indices don't match.

Issue:#4083

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=203485872
tonihei authored and ojw28 committed Jul 23, 2018
1 parent 6ad9840 commit f2f149a
Showing 2 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -18,6 +18,9 @@
* Add workaround for track index mismatches between trex and tkhd boxes in
fragmented MP4 files
([#4477](https://github.com/google/ExoPlayer/issues/4477)).
* Add workaround for track index mismatches between tfhd and tkhd boxes in
fragmented MP4 files
([#4083](https://github.com/google/ExoPlayer/issues/4083)).

### 2.8.2 ###

Original file line number Diff line number Diff line change
@@ -654,7 +654,7 @@ private static void parseMoof(ContainerAtom moof, SparseArray<TrackBundle> track
private static void parseTraf(ContainerAtom traf, SparseArray<TrackBundle> trackBundleArray,
@Flags int flags, byte[] extendedTypeScratch) throws ParserException {
LeafAtom tfhd = traf.getLeafAtomOfType(Atom.TYPE_tfhd);
TrackBundle trackBundle = parseTfhd(tfhd.data, trackBundleArray, flags);
TrackBundle trackBundle = parseTfhd(tfhd.data, trackBundleArray);
if (trackBundle == null) {
return;
}
@@ -805,13 +805,13 @@ private static void parseSaio(ParsableByteArray saio, TrackFragment out) throws
* @return The {@link TrackBundle} to which the {@link TrackFragment} belongs, or null if the tfhd
* does not refer to any {@link TrackBundle}.
*/
private static TrackBundle parseTfhd(ParsableByteArray tfhd,
SparseArray<TrackBundle> trackBundles, int flags) {
private static TrackBundle parseTfhd(
ParsableByteArray tfhd, SparseArray<TrackBundle> trackBundles) {
tfhd.setPosition(Atom.HEADER_SIZE);
int fullAtom = tfhd.readInt();
int atomFlags = Atom.parseFullAtomFlags(fullAtom);
int trackId = tfhd.readInt();
TrackBundle trackBundle = trackBundles.get((flags & FLAG_SIDELOADED) == 0 ? trackId : 0);
TrackBundle trackBundle = getTrackBundle(trackBundles, trackId);
if (trackBundle == null) {
return null;
}
@@ -836,6 +836,17 @@ private static TrackBundle parseTfhd(ParsableByteArray tfhd,
return trackBundle;
}

private static @Nullable TrackBundle getTrackBundle(
SparseArray<TrackBundle> trackBundles, int trackId) {
if (trackBundles.size() == 1) {
// Ignore track id if there is only one track. This is either because we have a side-loaded
// track (flag FLAG_SIDELOADED) or to cope with non-matching track indices (see
// https://github.com/google/ExoPlayer/issues/4083).
return trackBundles.valueAt(/* index= */ 0);
}
return trackBundles.get(trackId);
}

/**
* Parses a tfdt atom (defined in 14496-12).
*

0 comments on commit f2f149a

Please sign in to comment.