Java Code Examples for com.google.android.exoplayer2.extractor.GaplessInfoHolder#setFromMetadata()

The following examples show how to use com.google.android.exoplayer2.extractor.GaplessInfoHolder#setFromMetadata() . 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: 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 3
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 4
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);
}