Skip to content

Commit

Permalink
Merge pull request #255 from mayurk2:use_edts_offset_if_it_is_for_ent…
Browse files Browse the repository at this point in the history
…ire_file

PiperOrigin-RevId: 513213229
  • Loading branch information
tonihei committed Mar 1, 2023
2 parents 3e1f825 + 0761641 commit d2ba290
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,26 @@ private static long parseTfdt(ParsableByteArray tfdt) {
return version == 1 ? tfdt.readUnsignedLongToLong() : tfdt.readUnsignedInt();
}

private static boolean isEdtsListDurationForEntireMediaTimeline(Track track) {
// Currently we only support a single edit that moves the entire media timeline (indicated by
// duration == 0 or (editListDurationUs + editListMediaTimeUs) >= track duration.
// Other uses of edit lists are uncommon and unsupported.
if (track.editListDurations == null
|| track.editListDurations.length != 1
|| track.editListMediaTimes == null) {
return false;
}
if (track.editListDurations[0] == 0) {
return true;
}
long editListEndMediaTimeUs =
Util.scaleLargeTimestamp(
track.editListDurations[0] + track.editListMediaTimes[0],
C.MICROS_PER_SECOND,
track.movieTimescale);
return editListEndMediaTimeUs >= track.durationUs;
}

/**
* Parses a trun atom (defined in 14496-12).
*
Expand Down Expand Up @@ -1015,11 +1035,8 @@ private static int parseTrun(
// ensure that the first frame's presentation timestamp is zero.
long edtsOffset = 0;

// Currently we only support a single edit that moves the entire media timeline (indicated by
// duration == 0). Other uses of edit lists are uncommon and unsupported.
if (track.editListDurations != null
&& track.editListDurations.length == 1
&& track.editListDurations[0] == 0) {
// Currently we only support a single edit that moves the entire media timeline.
if (isEdtsListDurationForEntireMediaTimeline(track)) {
edtsOffset = castNonNull(track.editListMediaTimes)[0];
}

Expand Down

0 comments on commit d2ba290

Please sign in to comment.