Java Code Examples for com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom#getLeafAtomOfType()

The following examples show how to use com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom#getLeafAtomOfType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Mp4Extractor.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the stored track metadata to reflect the contents of the specified moov atom.
 */
private void processMoovAtom(ContainerAtom moov) throws ParserException {
  int firstVideoTrackIndex = C.INDEX_UNSET;
  long durationUs = C.TIME_UNSET;
  List<Mp4Track> tracks = new ArrayList<>();

  // Process metadata.
  Metadata udtaMetadata = null;
  GaplessInfoHolder gaplessInfoHolder = new GaplessInfoHolder();
  Atom.LeafAtom udta = moov.getLeafAtomOfType(Atom.TYPE_udta);
  if (udta != null) {
    udtaMetadata = AtomParsers.parseUdta(udta, isQuickTime);
    if (udtaMetadata != null) {
      gaplessInfoHolder.setFromMetadata(udtaMetadata);
    }
  }
  Metadata mdtaMetadata = null;
  ContainerAtom meta = moov.getContainerAtomOfType(Atom.TYPE_meta);
  if (meta != null) {
    mdtaMetadata = AtomParsers.parseMdtaFromMeta(meta);
  }

  boolean ignoreEditLists = (flags & FLAG_WORKAROUND_IGNORE_EDIT_LISTS) != 0;
  ArrayList<TrackSampleTable> trackSampleTables =
      getTrackSampleTables(moov, gaplessInfoHolder, ignoreEditLists);

  int trackCount = trackSampleTables.size();
  for (int i = 0; i < trackCount; i++) {
    TrackSampleTable trackSampleTable = trackSampleTables.get(i);
    Track track = trackSampleTable.track;
    long trackDurationUs =
        track.durationUs != C.TIME_UNSET ? track.durationUs : trackSampleTable.durationUs;
    durationUs = Math.max(durationUs, trackDurationUs);
    Mp4Track mp4Track = new Mp4Track(track, trackSampleTable,
        extractorOutput.track(i, track.type));

    // Each sample has up to three bytes of overhead for the start code that replaces its length.
    // Allow ten source samples per output sample, like the platform extractor.
    int maxInputSize = trackSampleTable.maximumSize + 3 * 10;
    Format format = track.format.copyWithMaxInputSize(maxInputSize);
    if (track.type == C.TRACK_TYPE_VIDEO
        && trackDurationUs > 0
        && trackSampleTable.sampleCount > 1) {
      float frameRate = trackSampleTable.sampleCount / (trackDurationUs / 1000000f);
      format = format.copyWithFrameRate(frameRate);
    }
    format =
        MetadataUtil.getFormatWithMetadata(
            track.type, format, udtaMetadata, mdtaMetadata, gaplessInfoHolder);
    mp4Track.trackOutput.format(format);

    if (track.type == C.TRACK_TYPE_VIDEO && firstVideoTrackIndex == C.INDEX_UNSET) {
      firstVideoTrackIndex = tracks.size();
    }
    tracks.add(mp4Track);
  }
  this.firstVideoTrackIndex = firstVideoTrackIndex;
  this.durationUs = durationUs;
  this.tracks = tracks.toArray(new Mp4Track[0]);
  accumulatedSampleSizes = calculateAccumulatedSampleSizes(this.tracks);

  extractorOutput.endTracks();
  extractorOutput.seekMap(this);
}
 
Example 2
Source File: FragmentedMp4Extractor.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
/**
 * Parses a traf atom (defined in 14496-12).
 */
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);
  if (trackBundle == null) {
    return;
  }

  TrackFragment fragment = trackBundle.fragment;
  long decodeTime = fragment.nextFragmentDecodeTime;
  trackBundle.reset();

  LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
  if (tfdtAtom != null && (flags & FLAG_WORKAROUND_IGNORE_TFDT_BOX) == 0) {
    decodeTime = parseTfdt(traf.getLeafAtomOfType(Atom.TYPE_tfdt).data);
  }

  parseTruns(traf, trackBundle, decodeTime, flags);

  TrackEncryptionBox encryptionBox = trackBundle.track
      .getSampleDescriptionEncryptionBox(fragment.header.sampleDescriptionIndex);

  LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
  if (saiz != null) {
    parseSaiz(encryptionBox, saiz.data, fragment);
  }

  LeafAtom saio = traf.getLeafAtomOfType(Atom.TYPE_saio);
  if (saio != null) {
    parseSaio(saio.data, fragment);
  }

  LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
  if (senc != null) {
    parseSenc(senc.data, fragment);
  }

  LeafAtom sbgp = traf.getLeafAtomOfType(Atom.TYPE_sbgp);
  LeafAtom sgpd = traf.getLeafAtomOfType(Atom.TYPE_sgpd);
  if (sbgp != null && sgpd != null) {
    parseSgpd(sbgp.data, sgpd.data, encryptionBox != null ? encryptionBox.schemeType : null,
        fragment);
  }

  int leafChildrenSize = traf.leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = traf.leafChildren.get(i);
    if (atom.type == Atom.TYPE_uuid) {
      parseUuid(atom.data, fragment, extendedTypeScratch);
    }
  }
}
 
Example 3
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a traf atom (defined in 14496-12).
 */
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);
  if (trackBundle == null) {
    return;
  }

  TrackFragment fragment = trackBundle.fragment;
  long decodeTime = fragment.nextFragmentDecodeTime;
  trackBundle.reset();

  LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
  if (tfdtAtom != null && (flags & FLAG_WORKAROUND_IGNORE_TFDT_BOX) == 0) {
    decodeTime = parseTfdt(traf.getLeafAtomOfType(Atom.TYPE_tfdt).data);
  }

  parseTruns(traf, trackBundle, decodeTime, flags);

  TrackEncryptionBox encryptionBox = trackBundle.track
      .getSampleDescriptionEncryptionBox(fragment.header.sampleDescriptionIndex);

  LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
  if (saiz != null) {
    parseSaiz(encryptionBox, saiz.data, fragment);
  }

  LeafAtom saio = traf.getLeafAtomOfType(Atom.TYPE_saio);
  if (saio != null) {
    parseSaio(saio.data, fragment);
  }

  LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
  if (senc != null) {
    parseSenc(senc.data, fragment);
  }

  LeafAtom sbgp = traf.getLeafAtomOfType(Atom.TYPE_sbgp);
  LeafAtom sgpd = traf.getLeafAtomOfType(Atom.TYPE_sgpd);
  if (sbgp != null && sgpd != null) {
    parseSgpd(sbgp.data, sgpd.data, encryptionBox != null ? encryptionBox.schemeType : null,
        fragment);
  }

  int leafChildrenSize = traf.leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = traf.leafChildren.get(i);
    if (atom.type == Atom.TYPE_uuid) {
      parseUuid(atom.data, fragment, extendedTypeScratch);
    }
  }
}
 
Example 4
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a traf atom (defined in 14496-12).
 */
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);
  if (trackBundle == null) {
    return;
  }

  TrackFragment fragment = trackBundle.fragment;
  long decodeTime = fragment.nextFragmentDecodeTime;
  trackBundle.reset();

  LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
  if (tfdtAtom != null && (flags & FLAG_WORKAROUND_IGNORE_TFDT_BOX) == 0) {
    decodeTime = parseTfdt(traf.getLeafAtomOfType(Atom.TYPE_tfdt).data);
  }

  parseTruns(traf, trackBundle, decodeTime, flags);

  TrackEncryptionBox encryptionBox = trackBundle.track
      .getSampleDescriptionEncryptionBox(fragment.header.sampleDescriptionIndex);

  LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
  if (saiz != null) {
    parseSaiz(encryptionBox, saiz.data, fragment);
  }

  LeafAtom saio = traf.getLeafAtomOfType(Atom.TYPE_saio);
  if (saio != null) {
    parseSaio(saio.data, fragment);
  }

  LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
  if (senc != null) {
    parseSenc(senc.data, fragment);
  }

  LeafAtom sbgp = traf.getLeafAtomOfType(Atom.TYPE_sbgp);
  LeafAtom sgpd = traf.getLeafAtomOfType(Atom.TYPE_sgpd);
  if (sbgp != null && sgpd != null) {
    parseSgpd(sbgp.data, sgpd.data, encryptionBox != null ? encryptionBox.schemeType : null,
        fragment);
  }

  int leafChildrenSize = traf.leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = traf.leafChildren.get(i);
    if (atom.type == Atom.TYPE_uuid) {
      parseUuid(atom.data, fragment, extendedTypeScratch);
    }
  }
}
 
Example 5
Source File: Mp4Extractor.java    From K-Sonic with MIT License 4 votes vote down vote up
/**
 * Updates the stored track metadata to reflect the contents of the specified moov atom.
 */
private void processMoovAtom(ContainerAtom moov) throws ParserException {
  long durationUs = C.TIME_UNSET;
  List<Mp4Track> tracks = new ArrayList<>();
  long earliestSampleOffset = Long.MAX_VALUE;

  Metadata metadata = null;
  GaplessInfoHolder gaplessInfoHolder = new GaplessInfoHolder();
  Atom.LeafAtom udta = moov.getLeafAtomOfType(Atom.TYPE_udta);
  if (udta != null) {
    metadata = AtomParsers.parseUdta(udta, isQuickTime);
    if (metadata != null) {
      gaplessInfoHolder.setFromMetadata(metadata);
    }
  }

  for (int i = 0; i < moov.containerChildren.size(); i++) {
    Atom.ContainerAtom atom = moov.containerChildren.get(i);
    if (atom.type != Atom.TYPE_trak) {
      continue;
    }

    Track track = AtomParsers.parseTrak(atom, moov.getLeafAtomOfType(Atom.TYPE_mvhd),
        C.TIME_UNSET, null, isQuickTime);
    if (track == null) {
      continue;
    }

    Atom.ContainerAtom stblAtom = atom.getContainerAtomOfType(Atom.TYPE_mdia)
        .getContainerAtomOfType(Atom.TYPE_minf).getContainerAtomOfType(Atom.TYPE_stbl);
    TrackSampleTable trackSampleTable = AtomParsers.parseStbl(track, stblAtom, gaplessInfoHolder);
    if (trackSampleTable.sampleCount == 0) {
      continue;
    }

    Mp4Track mp4Track = new Mp4Track(track, trackSampleTable,
        extractorOutput.track(i, track.type));
    // Each sample has up to three bytes of overhead for the start code that replaces its length.
    // Allow ten source samples per output sample, like the platform extractor.
    int maxInputSize = trackSampleTable.maximumSize + 3 * 10;
    Format format = track.format.copyWithMaxInputSize(maxInputSize);
    if (track.type == C.TRACK_TYPE_AUDIO) {
      if (gaplessInfoHolder.hasGaplessInfo()) {
        format = format.copyWithGaplessInfo(gaplessInfoHolder.encoderDelay,
            gaplessInfoHolder.encoderPadding);
      }
      if (metadata != null) {
        format = format.copyWithMetadata(metadata);
      }
    }
    mp4Track.trackOutput.format(format);

    durationUs = Math.max(durationUs, track.durationUs);
    tracks.add(mp4Track);

    long firstSampleOffset = trackSampleTable.offsets[0];
    if (firstSampleOffset < earliestSampleOffset) {
      earliestSampleOffset = firstSampleOffset;
    }
  }
  this.durationUs = durationUs;
  this.tracks = tracks.toArray(new Mp4Track[tracks.size()]);
  extractorOutput.endTracks();
  extractorOutput.seekMap(this);
}
 
Example 6
Source File: FragmentedMp4Extractor.java    From K-Sonic with MIT License 4 votes vote down vote up
/**
 * Parses a traf atom (defined in 14496-12).
 */
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);
  if (trackBundle == null) {
    return;
  }

  TrackFragment fragment = trackBundle.fragment;
  long decodeTime = fragment.nextFragmentDecodeTime;
  trackBundle.reset();

  LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
  if (tfdtAtom != null && (flags & FLAG_WORKAROUND_IGNORE_TFDT_BOX) == 0) {
    decodeTime = parseTfdt(traf.getLeafAtomOfType(Atom.TYPE_tfdt).data);
  }

  parseTruns(traf, trackBundle, decodeTime, flags);

  LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
  if (saiz != null) {
    TrackEncryptionBox trackEncryptionBox = trackBundle.track
        .sampleDescriptionEncryptionBoxes[fragment.header.sampleDescriptionIndex];
    parseSaiz(trackEncryptionBox, saiz.data, fragment);
  }

  LeafAtom saio = traf.getLeafAtomOfType(Atom.TYPE_saio);
  if (saio != null) {
    parseSaio(saio.data, fragment);
  }

  LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
  if (senc != null) {
    parseSenc(senc.data, fragment);
  }

  LeafAtom sbgp = traf.getLeafAtomOfType(Atom.TYPE_sbgp);
  LeafAtom sgpd = traf.getLeafAtomOfType(Atom.TYPE_sgpd);
  if (sbgp != null && sgpd != null) {
    parseSgpd(sbgp.data, sgpd.data, fragment);
  }

  int leafChildrenSize = traf.leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = traf.leafChildren.get(i);
    if (atom.type == Atom.TYPE_uuid) {
      parseUuid(atom.data, fragment, extendedTypeScratch);
    }
  }
}
 
Example 7
Source File: Mp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Updates the stored track metadata to reflect the contents of the specified moov atom.
 */
private void processMoovAtom(ContainerAtom moov) throws ParserException {
  int firstVideoTrackIndex = C.INDEX_UNSET;
  long durationUs = C.TIME_UNSET;
  List<Mp4Track> tracks = new ArrayList<>();

  // Process metadata.
  Metadata udtaMetadata = null;
  GaplessInfoHolder gaplessInfoHolder = new GaplessInfoHolder();
  Atom.LeafAtom udta = moov.getLeafAtomOfType(Atom.TYPE_udta);
  if (udta != null) {
    udtaMetadata = AtomParsers.parseUdta(udta, isQuickTime);
    if (udtaMetadata != null) {
      gaplessInfoHolder.setFromMetadata(udtaMetadata);
    }
  }
  Metadata mdtaMetadata = null;
  Atom.ContainerAtom meta = moov.getContainerAtomOfType(Atom.TYPE_meta);
  if (meta != null) {
    mdtaMetadata = AtomParsers.parseMdtaFromMeta(meta);
  }

  boolean ignoreEditLists = (flags & FLAG_WORKAROUND_IGNORE_EDIT_LISTS) != 0;
  ArrayList<TrackSampleTable> trackSampleTables =
      getTrackSampleTables(moov, gaplessInfoHolder, ignoreEditLists);

  int trackCount = trackSampleTables.size();
  for (int i = 0; i < trackCount; i++) {
    TrackSampleTable trackSampleTable = trackSampleTables.get(i);
    Track track = trackSampleTable.track;
    long trackDurationUs =
        track.durationUs != C.TIME_UNSET ? track.durationUs : trackSampleTable.durationUs;
    durationUs = Math.max(durationUs, trackDurationUs);
    Mp4Track mp4Track = new Mp4Track(track, trackSampleTable,
        extractorOutput.track(i, track.type));

    // Each sample has up to three bytes of overhead for the start code that replaces its length.
    // Allow ten source samples per output sample, like the platform extractor.
    int maxInputSize = trackSampleTable.maximumSize + 3 * 10;
    Format format = track.format.copyWithMaxInputSize(maxInputSize);
    if (track.type == C.TRACK_TYPE_VIDEO
        && trackDurationUs > 0
        && trackSampleTable.sampleCount > 1) {
      float frameRate = trackSampleTable.sampleCount / (trackDurationUs / 1000000f);
      format = format.copyWithFrameRate(frameRate);
    }
    format =
        MetadataUtil.getFormatWithMetadata(
            track.type, format, udtaMetadata, mdtaMetadata, gaplessInfoHolder);
    mp4Track.trackOutput.format(format);

    if (track.type == C.TRACK_TYPE_VIDEO && firstVideoTrackIndex == C.INDEX_UNSET) {
      firstVideoTrackIndex = tracks.size();
    }
    tracks.add(mp4Track);
  }
  this.firstVideoTrackIndex = firstVideoTrackIndex;
  this.durationUs = durationUs;
  this.tracks = tracks.toArray(new Mp4Track[0]);
  accumulatedSampleSizes = calculateAccumulatedSampleSizes(this.tracks);

  extractorOutput.endTracks();
  extractorOutput.seekMap(this);
}
 
Example 8
Source File: FragmentedMp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a traf atom (defined in 14496-12).
 */
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);
  if (trackBundle == null) {
    return;
  }

  TrackFragment fragment = trackBundle.fragment;
  long decodeTime = fragment.nextFragmentDecodeTime;
  trackBundle.reset();

  LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
  if (tfdtAtom != null && (flags & FLAG_WORKAROUND_IGNORE_TFDT_BOX) == 0) {
    decodeTime = parseTfdt(traf.getLeafAtomOfType(Atom.TYPE_tfdt).data);
  }

  parseTruns(traf, trackBundle, decodeTime, flags);

  TrackEncryptionBox encryptionBox = trackBundle.track
      .getSampleDescriptionEncryptionBox(fragment.header.sampleDescriptionIndex);

  LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
  if (saiz != null) {
    parseSaiz(encryptionBox, saiz.data, fragment);
  }

  LeafAtom saio = traf.getLeafAtomOfType(Atom.TYPE_saio);
  if (saio != null) {
    parseSaio(saio.data, fragment);
  }

  LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
  if (senc != null) {
    parseSenc(senc.data, fragment);
  }

  LeafAtom sbgp = traf.getLeafAtomOfType(Atom.TYPE_sbgp);
  LeafAtom sgpd = traf.getLeafAtomOfType(Atom.TYPE_sgpd);
  if (sbgp != null && sgpd != null) {
    parseSgpd(sbgp.data, sgpd.data, encryptionBox != null ? encryptionBox.schemeType : null,
        fragment);
  }

  int leafChildrenSize = traf.leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = traf.leafChildren.get(i);
    if (atom.type == Atom.TYPE_uuid) {
      parseUuid(atom.data, fragment, extendedTypeScratch);
    }
  }
}
 
Example 9
Source File: Mp4Extractor.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Updates the stored track metadata to reflect the contents of the specified moov atom.
 */
private void processMoovAtom(ContainerAtom moov) throws ParserException {
  int firstVideoTrackIndex = C.INDEX_UNSET;
  long durationUs = C.TIME_UNSET;
  List<Mp4Track> tracks = new ArrayList<>();

  // Process metadata.
  Metadata udtaMetadata = null;
  GaplessInfoHolder gaplessInfoHolder = new GaplessInfoHolder();
  Atom.LeafAtom udta = moov.getLeafAtomOfType(Atom.TYPE_udta);
  if (udta != null) {
    udtaMetadata = AtomParsers.parseUdta(udta, isQuickTime);
    if (udtaMetadata != null) {
      gaplessInfoHolder.setFromMetadata(udtaMetadata);
    }
  }
  Metadata mdtaMetadata = null;
  Atom.ContainerAtom meta = moov.getContainerAtomOfType(Atom.TYPE_meta);
  if (meta != null) {
    mdtaMetadata = AtomParsers.parseMdtaFromMeta(meta);
  }

  boolean ignoreEditLists = (flags & FLAG_WORKAROUND_IGNORE_EDIT_LISTS) != 0;
  ArrayList<TrackSampleTable> trackSampleTables =
      getTrackSampleTables(moov, gaplessInfoHolder, ignoreEditLists);

  int trackCount = trackSampleTables.size();
  for (int i = 0; i < trackCount; i++) {
    TrackSampleTable trackSampleTable = trackSampleTables.get(i);
    Track track = trackSampleTable.track;
    long trackDurationUs =
        track.durationUs != C.TIME_UNSET ? track.durationUs : trackSampleTable.durationUs;
    durationUs = Math.max(durationUs, trackDurationUs);
    Mp4Track mp4Track = new Mp4Track(track, trackSampleTable,
        extractorOutput.track(i, track.type));

    // Each sample has up to three bytes of overhead for the start code that replaces its length.
    // Allow ten source samples per output sample, like the platform extractor.
    int maxInputSize = trackSampleTable.maximumSize + 3 * 10;
    Format format = track.format.copyWithMaxInputSize(maxInputSize);
    if (track.type == C.TRACK_TYPE_VIDEO
        && trackDurationUs > 0
        && trackSampleTable.sampleCount > 1) {
      float frameRate = trackSampleTable.sampleCount / (trackDurationUs / 1000000f);
      format = format.copyWithFrameRate(frameRate);
    }
    format =
        MetadataUtil.getFormatWithMetadata(
            track.type, format, udtaMetadata, mdtaMetadata, gaplessInfoHolder);
    mp4Track.trackOutput.format(format);

    if (track.type == C.TRACK_TYPE_VIDEO && firstVideoTrackIndex == C.INDEX_UNSET) {
      firstVideoTrackIndex = tracks.size();
    }
    tracks.add(mp4Track);
  }
  this.firstVideoTrackIndex = firstVideoTrackIndex;
  this.durationUs = durationUs;
  this.tracks = tracks.toArray(new Mp4Track[0]);
  accumulatedSampleSizes = calculateAccumulatedSampleSizes(this.tracks);

  extractorOutput.endTracks();
  extractorOutput.seekMap(this);
}
 
Example 10
Source File: FragmentedMp4Extractor.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Parses a traf atom (defined in 14496-12).
 */
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);
  if (trackBundle == null) {
    return;
  }

  TrackFragment fragment = trackBundle.fragment;
  long decodeTime = fragment.nextFragmentDecodeTime;
  trackBundle.reset();

  LeafAtom tfdtAtom = traf.getLeafAtomOfType(Atom.TYPE_tfdt);
  if (tfdtAtom != null && (flags & FLAG_WORKAROUND_IGNORE_TFDT_BOX) == 0) {
    decodeTime = parseTfdt(traf.getLeafAtomOfType(Atom.TYPE_tfdt).data);
  }

  parseTruns(traf, trackBundle, decodeTime, flags);

  TrackEncryptionBox encryptionBox = trackBundle.track
      .getSampleDescriptionEncryptionBox(fragment.header.sampleDescriptionIndex);

  LeafAtom saiz = traf.getLeafAtomOfType(Atom.TYPE_saiz);
  if (saiz != null) {
    parseSaiz(encryptionBox, saiz.data, fragment);
  }

  LeafAtom saio = traf.getLeafAtomOfType(Atom.TYPE_saio);
  if (saio != null) {
    parseSaio(saio.data, fragment);
  }

  LeafAtom senc = traf.getLeafAtomOfType(Atom.TYPE_senc);
  if (senc != null) {
    parseSenc(senc.data, fragment);
  }

  LeafAtom sbgp = traf.getLeafAtomOfType(Atom.TYPE_sbgp);
  LeafAtom sgpd = traf.getLeafAtomOfType(Atom.TYPE_sgpd);
  if (sbgp != null && sgpd != null) {
    parseSgpd(sbgp.data, sgpd.data, encryptionBox != null ? encryptionBox.schemeType : null,
        fragment);
  }

  int leafChildrenSize = traf.leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = traf.leafChildren.get(i);
    if (atom.type == Atom.TYPE_uuid) {
      parseUuid(atom.data, fragment, extendedTypeScratch);
    }
  }
}