com.google.android.exoplayer2.extractor.ChunkIndex Java Examples

The following examples show how to use com.google.android.exoplayer2.extractor.ChunkIndex. 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: CachedRegionTracker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex) {
  this.cache = cache;
  this.cacheKey = cacheKey;
  this.chunkIndex = chunkIndex;
  this.regions = new TreeSet<>();
  this.lookupRegion = new Region(0, 0);

  synchronized (this) {
    NavigableSet<CacheSpan> cacheSpans = cache.addListener(cacheKey, this);
    // Merge the spans into regions. mergeSpan is more efficient when merging from high to low,
    // which is why a descending iterator is used here.
    Iterator<CacheSpan> spanIterator = cacheSpans.descendingIterator();
    while (spanIterator.hasNext()) {
      CacheSpan span = spanIterator.next();
      mergeSpan(span);
    }
  }
}
 
Example #2
Source File: CachedRegionTracker.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex) {
  this.cache = cache;
  this.cacheKey = cacheKey;
  this.chunkIndex = chunkIndex;
  this.regions = new TreeSet<>();
  this.lookupRegion = new Region(0, 0);

  synchronized (this) {
    NavigableSet<CacheSpan> cacheSpans = cache.addListener(cacheKey, this);
    // Merge the spans into regions. mergeSpan is more efficient when merging from high to low,
    // which is why a descending iterator is used here.
    Iterator<CacheSpan> spanIterator = cacheSpans.descendingIterator();
    while (spanIterator.hasNext()) {
      CacheSpan span = spanIterator.next();
      mergeSpan(span);
    }
  }
}
 
Example #3
Source File: DefaultDashChunkSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #4
Source File: CachedRegionTracker.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex) {
  this.cache = cache;
  this.cacheKey = cacheKey;
  this.chunkIndex = chunkIndex;
  this.regions = new TreeSet<>();
  this.lookupRegion = new Region(0, 0);

  synchronized (this) {
    NavigableSet<CacheSpan> cacheSpans = cache.addListener(cacheKey, this);
    // Merge the spans into regions. mergeSpan is more efficient when merging from high to low,
    // which is why a descending iterator is used here.
    Iterator<CacheSpan> spanIterator = cacheSpans.descendingIterator();
    while (spanIterator.hasNext()) {
      CacheSpan span = spanIterator.next();
      mergeSpan(span);
    }
  }
}
 
Example #5
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #6
Source File: CachedRegionTracker.java    From K-Sonic with MIT License 6 votes vote down vote up
public CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex) {
  this.cache = cache;
  this.cacheKey = cacheKey;
  this.chunkIndex = chunkIndex;
  this.regions = new TreeSet<>();
  this.lookupRegion = new Region(0, 0);

  synchronized (this) {
    NavigableSet<CacheSpan> cacheSpans = cache.addListener(cacheKey, this);
    if (cacheSpans != null) {
      // Merge the spans into regions. mergeSpan is more efficient when merging from high to low,
      // which is why a descending iterator is used here.
      Iterator<CacheSpan> spanIterator = cacheSpans.descendingIterator();
      while (spanIterator.hasNext()) {
        CacheSpan span = spanIterator.next();
        mergeSpan(span);
      }
    }
  }
}
 
Example #7
Source File: DefaultDashChunkSource.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    RepresentationHolder representationHolder =
        representationHolders[trackSelection.indexOf(initializationChunk.trackFormat)];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolder.segmentIndex = new DashWrappingSegmentIndex((ChunkIndex) seekMap);
      }
    }
  }
}
 
Example #8
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #9
Source File: CachedRegionTracker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex) {
  this.cache = cache;
  this.cacheKey = cacheKey;
  this.chunkIndex = chunkIndex;
  this.regions = new TreeSet<>();
  this.lookupRegion = new Region(0, 0);

  synchronized (this) {
    NavigableSet<CacheSpan> cacheSpans = cache.addListener(cacheKey, this);
    // Merge the spans into regions. mergeSpan is more efficient when merging from high to low,
    // which is why a descending iterator is used here.
    Iterator<CacheSpan> spanIterator = cacheSpans.descendingIterator();
    while (spanIterator.hasNext()) {
      CacheSpan span = spanIterator.next();
      mergeSpan(span);
    }
  }
}
 
Example #10
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #11
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void onChunkLoadCompleted(Chunk chunk) {
  if (chunk instanceof InitializationChunk) {
    InitializationChunk initializationChunk = (InitializationChunk) chunk;
    int trackIndex = trackSelection.indexOf(initializationChunk.trackFormat);
    RepresentationHolder representationHolder = representationHolders[trackIndex];
    // The null check avoids overwriting an index obtained from the manifest with one obtained
    // from the stream. If the manifest defines an index then the stream shouldn't, but in cases
    // where it does we should ignore it.
    if (representationHolder.segmentIndex == null) {
      SeekMap seekMap = representationHolder.extractorWrapper.getSeekMap();
      if (seekMap != null) {
        representationHolders[trackIndex] =
            representationHolder.copyWithNewSegmentIndex(
                new DashWrappingSegmentIndex(
                    (ChunkIndex) seekMap,
                    representationHolder.representation.presentationTimeOffsetUs));
      }
    }
  }
  if (playerTrackEmsgHandler != null) {
    playerTrackEmsgHandler.onChunkLoadCompleted(chunk);
  }
}
 
Example #12
Source File: CachedRegionTracker.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
public CachedRegionTracker(Cache cache, String cacheKey, ChunkIndex chunkIndex) {
  this.cache = cache;
  this.cacheKey = cacheKey;
  this.chunkIndex = chunkIndex;
  this.regions = new TreeSet<>();
  this.lookupRegion = new Region(0, 0);

  synchronized (this) {
    NavigableSet<CacheSpan> cacheSpans = cache.addListener(cacheKey, this);
    // Merge the spans into regions. mergeSpan is more efficient when merging from high to low,
    // which is why a descending iterator is used here.
    Iterator<CacheSpan> spanIterator = cacheSpans.descendingIterator();
    while (spanIterator.hasNext()) {
      CacheSpan span = spanIterator.next();
      mergeSpan(span);
    }
  }
}
 
Example #13
Source File: DashDownloader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static @Nullable DashSegmentIndex getSegmentIndex(
    DataSource dataSource, int trackType, Representation representation)
    throws IOException, InterruptedException {
  DashSegmentIndex index = representation.getIndex();
  if (index != null) {
    return index;
  }
  ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation);
  return seekMap == null
      ? null
      : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs);
}
 
Example #14
Source File: MatroskaExtractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];
  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example #15
Source File: FragmentedMp4Extractor.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void onLeafAtomRead(LeafAtom leaf, long inputPosition) throws ParserException {
  if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(leaf);
  } else if (leaf.type == Atom.TYPE_sidx) {
    Pair<Long, ChunkIndex> result = parseSidx(leaf.data, inputPosition);
    segmentIndexEarliestPresentationTimeUs = result.first;
    extractorOutput.seekMap(result.second);
    haveOutputSeekMap = true;
  } else if (leaf.type == Atom.TYPE_emsg) {
    onEmsgLeafAtomRead(leaf.data);
  }
}
 
Example #16
Source File: DashDownloader.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static @Nullable DashSegmentIndex getSegmentIndex(
    DataSource dataSource, int trackType, Representation representation)
    throws IOException, InterruptedException {
  DashSegmentIndex index = representation.getIndex();
  if (index != null) {
    return index;
  }
  ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation);
  return seekMap == null
      ? null
      : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs);
}
 
Example #17
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];
  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example #18
Source File: DashDownloader.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static @Nullable DashSegmentIndex getSegmentIndex(
    DataSource dataSource, int trackType, Representation representation)
    throws IOException, InterruptedException {
  DashSegmentIndex index = representation.getIndex();
  if (index != null) {
    return index;
  }
  ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation);
  return seekMap == null
      ? null
      : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs);
}
 
Example #19
Source File: MatroskaExtractor.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];
  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example #20
Source File: FragmentedMp4Extractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void onLeafAtomRead(LeafAtom leaf, long inputPosition) throws ParserException {
  if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(leaf);
  } else if (leaf.type == Atom.TYPE_sidx) {
    Pair<Long, ChunkIndex> result = parseSidx(leaf.data, inputPosition);
    segmentIndexEarliestPresentationTimeUs = result.first;
    extractorOutput.seekMap(result.second);
    haveOutputSeekMap = true;
  } else if (leaf.type == Atom.TYPE_emsg) {
    onEmsgLeafAtomRead(leaf.data);
  }
}
 
Example #21
Source File: FragmentedMp4Extractor.java    From K-Sonic with MIT License 5 votes vote down vote up
private void onLeafAtomRead(LeafAtom leaf, long inputPosition) throws ParserException {
  if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(leaf);
  } else if (leaf.type == Atom.TYPE_sidx) {
    Pair<Long, ChunkIndex> result = parseSidx(leaf.data, inputPosition);
    segmentIndexEarliestPresentationTimeUs = result.first;
    extractorOutput.seekMap(result.second);
    haveOutputSeekMap = true;
  } else if (leaf.type == Atom.TYPE_emsg) {
    onEmsgLeafAtomRead(leaf.data);
  }
}
 
Example #22
Source File: FragmentedMp4Extractor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private void onLeafAtomRead(LeafAtom leaf, long inputPosition) throws ParserException {
  if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(leaf);
  } else if (leaf.type == Atom.TYPE_sidx) {
    Pair<Long, ChunkIndex> result = parseSidx(leaf.data, inputPosition);
    segmentIndexEarliestPresentationTimeUs = result.first;
    extractorOutput.seekMap(result.second);
    haveOutputSeekMap = true;
  } else if (leaf.type == Atom.TYPE_emsg) {
    onEmsgLeafAtomRead(leaf.data);
  }
}
 
Example #23
Source File: MatroskaExtractor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];
  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example #24
Source File: MatroskaExtractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];
  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example #25
Source File: MatroskaExtractor.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a {@link SeekMap} from the recently gathered Cues information.
 *
 * @return The built {@link SeekMap}. The returned {@link SeekMap} may be unseekable if cues
 *     information was missing or incomplete.
 */
private SeekMap buildSeekMap() {
  if (segmentContentPosition == C.POSITION_UNSET || durationUs == C.TIME_UNSET
      || cueTimesUs == null || cueTimesUs.size() == 0
      || cueClusterPositions == null || cueClusterPositions.size() != cueTimesUs.size()) {
    // Cues information is missing or incomplete.
    cueTimesUs = null;
    cueClusterPositions = null;
    return new SeekMap.Unseekable(durationUs);
  }
  int cuePointsSize = cueTimesUs.size();
  int[] sizes = new int[cuePointsSize];
  long[] offsets = new long[cuePointsSize];
  long[] durationsUs = new long[cuePointsSize];
  long[] timesUs = new long[cuePointsSize];
  for (int i = 0; i < cuePointsSize; i++) {
    timesUs[i] = cueTimesUs.get(i);
    offsets[i] = segmentContentPosition + cueClusterPositions.get(i);
  }
  for (int i = 0; i < cuePointsSize - 1; i++) {
    sizes[i] = (int) (offsets[i + 1] - offsets[i]);
    durationsUs[i] = timesUs[i + 1] - timesUs[i];
  }
  sizes[cuePointsSize - 1] =
      (int) (segmentContentPosition + segmentContentSize - offsets[cuePointsSize - 1]);
  durationsUs[cuePointsSize - 1] = durationUs - timesUs[cuePointsSize - 1];

  long lastDurationUs = durationsUs[cuePointsSize - 1];
  if (lastDurationUs <= 0) {
    Log.w(TAG, "Discarding last cue point with unexpected duration: " + lastDurationUs);
    sizes = Arrays.copyOf(sizes, sizes.length - 1);
    offsets = Arrays.copyOf(offsets, offsets.length - 1);
    durationsUs = Arrays.copyOf(durationsUs, durationsUs.length - 1);
    timesUs = Arrays.copyOf(timesUs, timesUs.length - 1);
  }

  cueTimesUs = null;
  cueClusterPositions = null;
  return new ChunkIndex(sizes, offsets, durationsUs, timesUs);
}
 
Example #26
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onLeafAtomRead(LeafAtom leaf, long inputPosition) throws ParserException {
  if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(leaf);
  } else if (leaf.type == Atom.TYPE_sidx) {
    Pair<Long, ChunkIndex> result = parseSidx(leaf.data, inputPosition);
    segmentIndexEarliestPresentationTimeUs = result.first;
    extractorOutput.seekMap(result.second);
    haveOutputSeekMap = true;
  } else if (leaf.type == Atom.TYPE_emsg) {
    onEmsgLeafAtomRead(leaf.data);
  }
}
 
Example #27
Source File: FragmentedMp4Extractor.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onLeafAtomRead(LeafAtom leaf, long inputPosition) throws ParserException {
  if (!containerAtoms.isEmpty()) {
    containerAtoms.peek().add(leaf);
  } else if (leaf.type == Atom.TYPE_sidx) {
    Pair<Long, ChunkIndex> result = parseSidx(leaf.data, inputPosition);
    segmentIndexEarliestPresentationTimeUs = result.first;
    extractorOutput.seekMap(result.second);
    haveOutputSeekMap = true;
  } else if (leaf.type == Atom.TYPE_emsg) {
    onEmsgLeafAtomRead(leaf.data);
  }
}
 
Example #28
Source File: DashDownloader.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static @Nullable DashSegmentIndex getSegmentIndex(
    DataSource dataSource, int trackType, Representation representation)
    throws IOException, InterruptedException {
  DashSegmentIndex index = representation.getIndex();
  if (index != null) {
    return index;
  }
  ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation);
  return seekMap == null
      ? null
      : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs);
}
 
Example #29
Source File: DashDownloader.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static @Nullable DashSegmentIndex getSegmentIndex(
    DataSource dataSource, int trackType, Representation representation)
    throws IOException, InterruptedException {
  DashSegmentIndex index = representation.getIndex();
  if (index != null) {
    return index;
  }
  ChunkIndex seekMap = DashUtil.loadChunkIndex(dataSource, trackType, representation);
  return seekMap == null
      ? null
      : new DashWrappingSegmentIndex(seekMap, representation.presentationTimeOffsetUs);
}
 
Example #30
Source File: DashWrappingSegmentIndex.java    From K-Sonic with MIT License 4 votes vote down vote up
/**
 * @param chunkIndex The {@link ChunkIndex} to wrap.
 */
public DashWrappingSegmentIndex(ChunkIndex chunkIndex) {
  this.chunkIndex = chunkIndex;
}