com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom Java Examples

The following examples show how to use com.google.android.exoplayer2.extractor.mp4.Atom.ContainerAtom. 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 K-Sonic with MIT License 6 votes vote down vote up
private void processAtomEnded(long atomEndPosition) throws ParserException {
  while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) {
    Atom.ContainerAtom containerAtom = containerAtoms.pop();
    if (containerAtom.type == Atom.TYPE_moov) {
      // We've reached the end of the moov atom. Process it and prepare to read samples.
      processMoovAtom(containerAtom);
      containerAtoms.clear();
      parserState = STATE_READING_SAMPLE;
    } else if (!containerAtoms.isEmpty()) {
      containerAtoms.peek().add(containerAtom);
    }
  }
  if (parserState != STATE_READING_SAMPLE) {
    enterReadingAtomHeaderState();
  }
}
 
Example #2
Source File: Mp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void processAtomEnded(long atomEndPosition) throws ParserException {
  while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) {
    Atom.ContainerAtom containerAtom = containerAtoms.pop();
    if (containerAtom.type == Atom.TYPE_moov) {
      // We've reached the end of the moov atom. Process it and prepare to read samples.
      processMoovAtom(containerAtom);
      containerAtoms.clear();
      parserState = STATE_READING_SAMPLE;
    } else if (!containerAtoms.isEmpty()) {
      containerAtoms.peek().add(containerAtom);
    }
  }
  if (parserState != STATE_READING_SAMPLE) {
    enterReadingAtomHeaderState();
  }
}
 
Example #3
Source File: Mp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void processAtomEnded(long atomEndPosition) throws ParserException {
  while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) {
    Atom.ContainerAtom containerAtom = containerAtoms.pop();
    if (containerAtom.type == Atom.TYPE_moov) {
      // We've reached the end of the moov atom. Process it and prepare to read samples.
      processMoovAtom(containerAtom);
      containerAtoms.clear();
      parserState = STATE_READING_SAMPLE;
    } else if (!containerAtoms.isEmpty()) {
      containerAtoms.peek().add(containerAtom);
    }
  }
  if (parserState != STATE_READING_SAMPLE) {
    enterReadingAtomHeaderState();
  }
}
 
Example #4
Source File: Mp4Extractor.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private void processAtomEnded(long atomEndPosition) throws ParserException {
  while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) {
    ContainerAtom containerAtom = containerAtoms.pop();
    if (containerAtom.type == Atom.TYPE_moov) {
      // We've reached the end of the moov atom. Process it and prepare to read samples.
      processMoovAtom(containerAtom);
      containerAtoms.clear();
      parserState = STATE_READING_SAMPLE;
    } else if (!containerAtoms.isEmpty()) {
      containerAtoms.peek().add(containerAtom);
    }
  }
  if (parserState != STATE_READING_SAMPLE) {
    enterReadingAtomHeaderState();
  }
}
 
Example #5
Source File: Mp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private void processAtomEnded(long atomEndPosition) throws ParserException {
  while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) {
    Atom.ContainerAtom containerAtom = containerAtoms.pop();
    if (containerAtom.type == Atom.TYPE_moov) {
      // We've reached the end of the moov atom. Process it and prepare to read samples.
      processMoovAtom(containerAtom);
      containerAtoms.clear();
      parserState = STATE_READING_SAMPLE;
    } else if (!containerAtoms.isEmpty()) {
      containerAtoms.peek().add(containerAtom);
    }
  }
  if (parserState != STATE_READING_SAMPLE) {
    enterReadingAtomHeaderState();
  }
}
 
Example #6
Source File: Mp4Extractor.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void processAtomEnded(long atomEndPosition) throws ParserException {
  while (!containerAtoms.isEmpty() && containerAtoms.peek().endPosition == atomEndPosition) {
    Atom.ContainerAtom containerAtom = containerAtoms.pop();
    if (containerAtom.type == Atom.TYPE_moov) {
      // We've reached the end of the moov atom. Process it and prepare to read samples.
      processMoovAtom(containerAtom);
      containerAtoms.clear();
      parserState = STATE_READING_SAMPLE;
    } else if (!containerAtoms.isEmpty()) {
      containerAtoms.peek().add(containerAtom);
    }
  }
  if (parserState != STATE_READING_SAMPLE) {
    enterReadingAtomHeaderState();
  }
}
 
Example #7
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static void parseTruns(ContainerAtom traf, TrackBundle trackBundle, long decodeTime,
    @Flags int flags) {
  int trunCount = 0;
  int totalSampleCount = 0;
  List<LeafAtom> leafChildren = traf.leafChildren;
  int leafChildrenSize = leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = leafChildren.get(i);
    if (atom.type == Atom.TYPE_trun) {
      ParsableByteArray trunData = atom.data;
      trunData.setPosition(Atom.FULL_HEADER_SIZE);
      int trunSampleCount = trunData.readUnsignedIntToInt();
      if (trunSampleCount > 0) {
        totalSampleCount += trunSampleCount;
        trunCount++;
      }
    }
  }
  trackBundle.currentTrackRunIndex = 0;
  trackBundle.currentSampleInTrackRun = 0;
  trackBundle.currentSampleIndex = 0;
  trackBundle.fragment.initTables(trunCount, totalSampleCount);

  int trunIndex = 0;
  int trunStartPosition = 0;
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom trun = leafChildren.get(i);
    if (trun.type == Atom.TYPE_trun) {
      trunStartPosition = parseTrun(trackBundle, trunIndex++, decodeTime, flags, trun.data,
          trunStartPosition);
    }
  }
}
 
Example #8
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static void parseMoof(ContainerAtom moof, SparseArray<TrackBundle> trackBundleArray,
    @Flags int flags, byte[] extendedTypeScratch) throws ParserException {
  int moofContainerChildrenSize = moof.containerChildren.size();
  for (int i = 0; i < moofContainerChildrenSize; i++) {
    Atom.ContainerAtom child = moof.containerChildren.get(i);
    // TODO: Support multiple traf boxes per track in a single moof.
    if (child.type == Atom.TYPE_traf) {
      parseTraf(child, trackBundleArray, flags, extendedTypeScratch);
    }
  }
}
 
Example #9
Source File: Mp4Extractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private ArrayList<TrackSampleTable> getTrackSampleTables(
    ContainerAtom moov, GaplessInfoHolder gaplessInfoHolder, boolean ignoreEditLists)
    throws ParserException {
  ArrayList<TrackSampleTable> trackSampleTables = new ArrayList<>();
  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),
            /* duration= */ C.TIME_UNSET,
            /* drmInitData= */ null,
            ignoreEditLists,
            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;
    }
    trackSampleTables.add(trackSampleTable);
  }
  return trackSampleTables;
}
 
Example #10
Source File: FragmentedMp4Extractor.java    From K-Sonic with MIT License 5 votes vote down vote up
private void onContainerAtomRead(ContainerAtom container) throws ParserException {
  if (container.type == Atom.TYPE_moov) {
    onMoovContainerAtomRead(container);
  } else if (container.type == Atom.TYPE_moof) {
    onMoofContainerAtomRead(container);
  } else if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(container);
  }
}
 
Example #11
Source File: FragmentedMp4Extractor.java    From K-Sonic with MIT License 5 votes vote down vote up
private void onMoofContainerAtomRead(ContainerAtom moof) throws ParserException {
  parseMoof(moof, trackBundles, flags, extendedTypeScratch);
  DrmInitData drmInitData = getDrmInitDataFromAtoms(moof.leafChildren);
  if (drmInitData != null) {
    int trackCount = trackBundles.size();
    for (int i = 0; i < trackCount; i++) {
      trackBundles.valueAt(i).updateDrmInitData(drmInitData);
    }
  }
}
 
Example #12
Source File: FragmentedMp4Extractor.java    From K-Sonic with MIT License 5 votes vote down vote up
private static void parseMoof(ContainerAtom moof, SparseArray<TrackBundle> trackBundleArray,
    @Flags int flags, byte[] extendedTypeScratch) throws ParserException {
  int moofContainerChildrenSize = moof.containerChildren.size();
  for (int i = 0; i < moofContainerChildrenSize; i++) {
    Atom.ContainerAtom child = moof.containerChildren.get(i);
    // TODO: Support multiple traf boxes per track in a single moof.
    if (child.type == Atom.TYPE_traf) {
      parseTraf(child, trackBundleArray, flags, extendedTypeScratch);
    }
  }
}
 
Example #13
Source File: FragmentedMp4Extractor.java    From K-Sonic with MIT License 5 votes vote down vote up
private static void parseTruns(ContainerAtom traf, TrackBundle trackBundle, long decodeTime,
    @Flags int flags) {
  int trunCount = 0;
  int totalSampleCount = 0;
  List<LeafAtom> leafChildren = traf.leafChildren;
  int leafChildrenSize = leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = leafChildren.get(i);
    if (atom.type == Atom.TYPE_trun) {
      ParsableByteArray trunData = atom.data;
      trunData.setPosition(Atom.FULL_HEADER_SIZE);
      int trunSampleCount = trunData.readUnsignedIntToInt();
      if (trunSampleCount > 0) {
        totalSampleCount += trunSampleCount;
        trunCount++;
      }
    }
  }
  trackBundle.currentTrackRunIndex = 0;
  trackBundle.currentSampleInTrackRun = 0;
  trackBundle.currentSampleIndex = 0;
  trackBundle.fragment.initTables(trunCount, totalSampleCount);

  int trunIndex = 0;
  int trunStartPosition = 0;
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom trun = leafChildren.get(i);
    if (trun.type == Atom.TYPE_trun) {
      trunStartPosition = parseTrun(trackBundle, trunIndex++, decodeTime, flags, trun.data,
          trunStartPosition);
    }
  }
}
 
Example #14
Source File: FragmentedMp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static void parseTruns(ContainerAtom traf, TrackBundle trackBundle, long decodeTime,
    @Flags int flags) {
  int trunCount = 0;
  int totalSampleCount = 0;
  List<LeafAtom> leafChildren = traf.leafChildren;
  int leafChildrenSize = leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = leafChildren.get(i);
    if (atom.type == Atom.TYPE_trun) {
      ParsableByteArray trunData = atom.data;
      trunData.setPosition(Atom.FULL_HEADER_SIZE);
      int trunSampleCount = trunData.readUnsignedIntToInt();
      if (trunSampleCount > 0) {
        totalSampleCount += trunSampleCount;
        trunCount++;
      }
    }
  }
  trackBundle.currentTrackRunIndex = 0;
  trackBundle.currentSampleInTrackRun = 0;
  trackBundle.currentSampleIndex = 0;
  trackBundle.fragment.initTables(trunCount, totalSampleCount);

  int trunIndex = 0;
  int trunStartPosition = 0;
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom trun = leafChildren.get(i);
    if (trun.type == Atom.TYPE_trun) {
      trunStartPosition = parseTrun(trackBundle, trunIndex++, decodeTime, flags, trun.data,
          trunStartPosition);
    }
  }
}
 
Example #15
Source File: Mp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private ArrayList<TrackSampleTable> getTrackSampleTables(
    ContainerAtom moov, GaplessInfoHolder gaplessInfoHolder, boolean ignoreEditLists)
    throws ParserException {
  ArrayList<TrackSampleTable> trackSampleTables = new ArrayList<>();
  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),
            /* duration= */ C.TIME_UNSET,
            /* drmInitData= */ null,
            ignoreEditLists,
            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;
    }
    trackSampleTables.add(trackSampleTable);
  }
  return trackSampleTables;
}
 
Example #16
Source File: FragmentedMp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void onContainerAtomRead(ContainerAtom container) throws ParserException {
  if (container.type == Atom.TYPE_moov) {
    onMoovContainerAtomRead(container);
  } else if (container.type == Atom.TYPE_moof) {
    onMoofContainerAtomRead(container);
  } else if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(container);
  }
}
 
Example #17
Source File: FragmentedMp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static void parseMoof(ContainerAtom moof, SparseArray<TrackBundle> trackBundleArray,
    @Flags int flags, byte[] extendedTypeScratch) throws ParserException {
  int moofContainerChildrenSize = moof.containerChildren.size();
  for (int i = 0; i < moofContainerChildrenSize; i++) {
    Atom.ContainerAtom child = moof.containerChildren.get(i);
    // TODO: Support multiple traf boxes per track in a single moof.
    if (child.type == Atom.TYPE_traf) {
      parseTraf(child, trackBundleArray, flags, extendedTypeScratch);
    }
  }
}
 
Example #18
Source File: FragmentedMp4Extractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void onContainerAtomRead(ContainerAtom container) throws ParserException {
  if (container.type == Atom.TYPE_moov) {
    onMoovContainerAtomRead(container);
  } else if (container.type == Atom.TYPE_moof) {
    onMoofContainerAtomRead(container);
  } else if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(container);
  }
}
 
Example #19
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onContainerAtomRead(ContainerAtom container) throws ParserException {
  if (container.type == Atom.TYPE_moov) {
    onMoovContainerAtomRead(container);
  } else if (container.type == Atom.TYPE_moof) {
    onMoofContainerAtomRead(container);
  } else if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(container);
  }
}
 
Example #20
Source File: Mp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private ArrayList<TrackSampleTable> getTrackSampleTables(
    ContainerAtom moov, GaplessInfoHolder gaplessInfoHolder, boolean ignoreEditLists)
    throws ParserException {
  ArrayList<TrackSampleTable> trackSampleTables = new ArrayList<>();
  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),
            /* duration= */ C.TIME_UNSET,
            /* drmInitData= */ null,
            ignoreEditLists,
            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;
    }
    trackSampleTables.add(trackSampleTable);
  }
  return trackSampleTables;
}
 
Example #21
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static void parseTruns(ContainerAtom traf, TrackBundle trackBundle, long decodeTime,
    @Flags int flags) {
  int trunCount = 0;
  int totalSampleCount = 0;
  List<LeafAtom> leafChildren = traf.leafChildren;
  int leafChildrenSize = leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = leafChildren.get(i);
    if (atom.type == Atom.TYPE_trun) {
      ParsableByteArray trunData = atom.data;
      trunData.setPosition(Atom.FULL_HEADER_SIZE);
      int trunSampleCount = trunData.readUnsignedIntToInt();
      if (trunSampleCount > 0) {
        totalSampleCount += trunSampleCount;
        trunCount++;
      }
    }
  }
  trackBundle.currentTrackRunIndex = 0;
  trackBundle.currentSampleInTrackRun = 0;
  trackBundle.currentSampleIndex = 0;
  trackBundle.fragment.initTables(trunCount, totalSampleCount);

  int trunIndex = 0;
  int trunStartPosition = 0;
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom trun = leafChildren.get(i);
    if (trun.type == Atom.TYPE_trun) {
      trunStartPosition = parseTrun(trackBundle, trunIndex++, decodeTime, flags, trun.data,
          trunStartPosition);
    }
  }
}
 
Example #22
Source File: FragmentedMp4Extractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static void parseMoof(ContainerAtom moof, SparseArray<TrackBundle> trackBundleArray,
    @Flags int flags, byte[] extendedTypeScratch) throws ParserException {
  int moofContainerChildrenSize = moof.containerChildren.size();
  for (int i = 0; i < moofContainerChildrenSize; i++) {
    Atom.ContainerAtom child = moof.containerChildren.get(i);
    // TODO: Support multiple traf boxes per track in a single moof.
    if (child.type == Atom.TYPE_traf) {
      parseTraf(child, trackBundleArray, flags, extendedTypeScratch);
    }
  }
}
 
Example #23
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static void parseMoof(ContainerAtom moof, SparseArray<TrackBundle> trackBundleArray,
    @Flags int flags, byte[] extendedTypeScratch) throws ParserException {
  int moofContainerChildrenSize = moof.containerChildren.size();
  for (int i = 0; i < moofContainerChildrenSize; i++) {
    Atom.ContainerAtom child = moof.containerChildren.get(i);
    // TODO: Support multiple traf boxes per track in a single moof.
    if (child.type == Atom.TYPE_traf) {
      parseTraf(child, trackBundleArray, flags, extendedTypeScratch);
    }
  }
}
 
Example #24
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onContainerAtomRead(ContainerAtom container) throws ParserException {
  if (container.type == Atom.TYPE_moov) {
    onMoovContainerAtomRead(container);
  } else if (container.type == Atom.TYPE_moof) {
    onMoofContainerAtomRead(container);
  } else if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(container);
  }
}
 
Example #25
Source File: Mp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private ArrayList<TrackSampleTable> getTrackSampleTables(
    ContainerAtom moov, GaplessInfoHolder gaplessInfoHolder, boolean ignoreEditLists)
    throws ParserException {
  ArrayList<TrackSampleTable> trackSampleTables = new ArrayList<>();
  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),
            /* duration= */ C.TIME_UNSET,
            /* drmInitData= */ null,
            ignoreEditLists,
            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;
    }
    trackSampleTables.add(trackSampleTable);
  }
  return trackSampleTables;
}
 
Example #26
Source File: FragmentedMp4Extractor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static void parseTruns(ContainerAtom traf, TrackBundle trackBundle, long decodeTime,
    @Flags int flags) {
  int trunCount = 0;
  int totalSampleCount = 0;
  List<LeafAtom> leafChildren = traf.leafChildren;
  int leafChildrenSize = leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = leafChildren.get(i);
    if (atom.type == Atom.TYPE_trun) {
      ParsableByteArray trunData = atom.data;
      trunData.setPosition(Atom.FULL_HEADER_SIZE);
      int trunSampleCount = trunData.readUnsignedIntToInt();
      if (trunSampleCount > 0) {
        totalSampleCount += trunSampleCount;
        trunCount++;
      }
    }
  }
  trackBundle.currentTrackRunIndex = 0;
  trackBundle.currentSampleInTrackRun = 0;
  trackBundle.currentSampleIndex = 0;
  trackBundle.fragment.initTables(trunCount, totalSampleCount);

  int trunIndex = 0;
  int trunStartPosition = 0;
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom trun = leafChildren.get(i);
    if (trun.type == Atom.TYPE_trun) {
      trunStartPosition = parseTrun(trackBundle, trunIndex++, decodeTime, flags, trun.data,
          trunStartPosition);
    }
  }
}
 
Example #27
Source File: FragmentedMp4Extractor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static void parseMoof(ContainerAtom moof, SparseArray<TrackBundle> trackBundleArray,
    @Flags int flags, byte[] extendedTypeScratch) throws ParserException {
  int moofContainerChildrenSize = moof.containerChildren.size();
  for (int i = 0; i < moofContainerChildrenSize; i++) {
    ContainerAtom child = moof.containerChildren.get(i);
    // TODO: Support multiple traf boxes per track in a single moof.
    if (child.type == Atom.TYPE_traf) {
      parseTraf(child, trackBundleArray, flags, extendedTypeScratch);
    }
  }
}
 
Example #28
Source File: FragmentedMp4Extractor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void onContainerAtomRead(ContainerAtom container) throws ParserException {
  if (container.type == Atom.TYPE_moov) {
    onMoovContainerAtomRead(container);
  } else if (container.type == Atom.TYPE_moof) {
    onMoofContainerAtomRead(container);
  } else if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(container);
  }
}
 
Example #29
Source File: Mp4Extractor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private ArrayList<TrackSampleTable> getTrackSampleTables(
    ContainerAtom moov, GaplessInfoHolder gaplessInfoHolder, boolean ignoreEditLists)
    throws ParserException {
  ArrayList<TrackSampleTable> trackSampleTables = new ArrayList<>();
  for (int i = 0; i < moov.containerChildren.size(); i++) {
    ContainerAtom atom = moov.containerChildren.get(i);
    if (atom.type != Atom.TYPE_trak) {
      continue;
    }
    Track track =
        AtomParsers.parseTrak(
            atom,
            moov.getLeafAtomOfType(Atom.TYPE_mvhd),
            /* duration= */ C.TIME_UNSET,
            /* drmInitData= */ null,
            ignoreEditLists,
            isQuickTime);
    if (track == null) {
      continue;
    }
    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;
    }
    trackSampleTables.add(trackSampleTable);
  }
  return trackSampleTables;
}
 
Example #30
Source File: FragmentedMp4Extractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static void parseTruns(ContainerAtom traf, TrackBundle trackBundle, long decodeTime,
    @Flags int flags) {
  int trunCount = 0;
  int totalSampleCount = 0;
  List<LeafAtom> leafChildren = traf.leafChildren;
  int leafChildrenSize = leafChildren.size();
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom atom = leafChildren.get(i);
    if (atom.type == Atom.TYPE_trun) {
      ParsableByteArray trunData = atom.data;
      trunData.setPosition(Atom.FULL_HEADER_SIZE);
      int trunSampleCount = trunData.readUnsignedIntToInt();
      if (trunSampleCount > 0) {
        totalSampleCount += trunSampleCount;
        trunCount++;
      }
    }
  }
  trackBundle.currentTrackRunIndex = 0;
  trackBundle.currentSampleInTrackRun = 0;
  trackBundle.currentSampleIndex = 0;
  trackBundle.fragment.initTables(trunCount, totalSampleCount);

  int trunIndex = 0;
  int trunStartPosition = 0;
  for (int i = 0; i < leafChildrenSize; i++) {
    LeafAtom trun = leafChildren.get(i);
    if (trun.type == Atom.TYPE_trun) {
      trunStartPosition = parseTrun(trackBundle, trunIndex++, decodeTime, flags, trun.data,
          trunStartPosition);
    }
  }
}