Java Code Examples for com.google.android.exoplayer2.source.dash.manifest.Representation#getIndex()

The following examples show how to use com.google.android.exoplayer2.source.dash.manifest.Representation#getIndex() . 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: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
RepresentationHolder(
    long periodDurationUs,
    int trackType,
    Representation representation,
    boolean enableEventMessageTrack,
    List<Format> closedCaptionFormats,
    @Nullable TrackOutput playerEmsgTrackOutput) {
  this(
      periodDurationUs,
      representation,
      createExtractorWrapper(
          trackType,
          representation,
          enableEventMessageTrack,
          closedCaptionFormats,
          playerEmsgTrackOutput),
      /* segmentNumShift= */ 0,
      representation.getIndex());
}
 
Example 2
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
RepresentationHolder(
    long periodDurationUs,
    int trackType,
    Representation representation,
    boolean enableEventMessageTrack,
    boolean enableCea608Track,
    TrackOutput playerEmsgTrackOutput) {
  this(
      periodDurationUs,
      representation,
      createExtractorWrapper(
          trackType,
          representation,
          enableEventMessageTrack,
          enableCea608Track,
          playerEmsgTrackOutput),
      /* segmentNumShift= */ 0,
      representation.getIndex());
}
 
Example 3
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
RepresentationHolder(
    long periodDurationUs,
    int trackType,
    Representation representation,
    boolean enableEventMessageTrack,
    boolean enableCea608Track,
    TrackOutput playerEmsgTrackOutput) {
  this(
      periodDurationUs,
      representation,
      createExtractorWrapper(
          trackType,
          representation,
          enableEventMessageTrack,
          enableCea608Track,
          playerEmsgTrackOutput),
      /* segmentNumShift= */ 0,
      representation.getIndex());
}
 
Example 4
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
RepresentationHolder(
    long periodDurationUs,
    int trackType,
    Representation representation,
    boolean enableEventMessageTrack,
    List<Format> closedCaptionFormats,
    TrackOutput playerEmsgTrackOutput) {
  this(
      periodDurationUs,
      representation,
      createExtractorWrapper(
          trackType,
          representation,
          enableEventMessageTrack,
          closedCaptionFormats,
          playerEmsgTrackOutput),
      /* segmentNumShift= */ 0,
      representation.getIndex());
}
 
Example 5
Source File: DefaultDashChunkSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
RepresentationHolder(
    long periodDurationUs,
    int trackType,
    Representation representation,
    boolean enableEventMessageTrack,
    List<Format> closedCaptionFormats,
    TrackOutput playerEmsgTrackOutput) {
  this(
      periodDurationUs,
      representation,
      createExtractorWrapper(
          trackType,
          representation,
          enableEventMessageTrack,
          closedCaptionFormats,
          playerEmsgTrackOutput),
      /* segmentNumShift= */ 0,
      representation.getIndex());
}
 
Example 6
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 7
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 8
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 9
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 10
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 11
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@CheckResult
/* package */ RepresentationHolder copyWithNewRepresentation(
    long newPeriodDurationUs, Representation newRepresentation)
    throws BehindLiveWindowException {
  DashSegmentIndex oldIndex = representation.getIndex();
  DashSegmentIndex newIndex = newRepresentation.getIndex();

  if (oldIndex == null) {
    // Segment numbers cannot shift if the index isn't defined by the manifest.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, oldIndex);
  }

  if (!oldIndex.isExplicit()) {
    // Segment numbers cannot shift if the index isn't explicit.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  int oldIndexSegmentCount = oldIndex.getSegmentCount(newPeriodDurationUs);
  if (oldIndexSegmentCount == 0) {
    // Segment numbers cannot shift if the old index was empty.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  long oldIndexFirstSegmentNum = oldIndex.getFirstSegmentNum();
  long oldIndexStartTimeUs = oldIndex.getTimeUs(oldIndexFirstSegmentNum);
  long oldIndexLastSegmentNum = oldIndexFirstSegmentNum + oldIndexSegmentCount - 1;
  long oldIndexEndTimeUs =
      oldIndex.getTimeUs(oldIndexLastSegmentNum)
          + oldIndex.getDurationUs(oldIndexLastSegmentNum, newPeriodDurationUs);
  long newIndexFirstSegmentNum = newIndex.getFirstSegmentNum();
  long newIndexStartTimeUs = newIndex.getTimeUs(newIndexFirstSegmentNum);
  long newSegmentNumShift = segmentNumShift;
  if (oldIndexEndTimeUs == newIndexStartTimeUs) {
    // The new index continues where the old one ended, with no overlap.
    newSegmentNumShift += oldIndexLastSegmentNum + 1 - newIndexFirstSegmentNum;
  } else if (oldIndexEndTimeUs < newIndexStartTimeUs) {
    // There's a gap between the old index and the new one which means we've slipped behind the
    // live window and can't proceed.
    throw new BehindLiveWindowException();
  } else if (newIndexStartTimeUs < oldIndexStartTimeUs) {
    // The new index overlaps with (but does not have a start position contained within) the old
    // index. This can only happen if extra segments have been added to the start of the index.
    newSegmentNumShift -=
        newIndex.getSegmentNum(oldIndexStartTimeUs, newPeriodDurationUs)
            - oldIndexFirstSegmentNum;
  } else {
    // The new index overlaps with (and has a start position contained within) the old index.
    newSegmentNumShift +=
        oldIndex.getSegmentNum(newIndexStartTimeUs, newPeriodDurationUs)
            - newIndexFirstSegmentNum;
  }
  return new RepresentationHolder(
      newPeriodDurationUs, newRepresentation, extractorWrapper, newSegmentNumShift, newIndex);
}
 
Example 12
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@CheckResult
/* package */ RepresentationHolder copyWithNewRepresentation(
    long newPeriodDurationUs, Representation newRepresentation)
    throws BehindLiveWindowException {
  DashSegmentIndex oldIndex = representation.getIndex();
  DashSegmentIndex newIndex = newRepresentation.getIndex();

  if (oldIndex == null) {
    // Segment numbers cannot shift if the index isn't defined by the manifest.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, oldIndex);
  }

  if (!oldIndex.isExplicit()) {
    // Segment numbers cannot shift if the index isn't explicit.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  int oldIndexSegmentCount = oldIndex.getSegmentCount(newPeriodDurationUs);
  if (oldIndexSegmentCount == 0) {
    // Segment numbers cannot shift if the old index was empty.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  long oldIndexLastSegmentNum = oldIndex.getFirstSegmentNum() + oldIndexSegmentCount - 1;
  long oldIndexEndTimeUs =
      oldIndex.getTimeUs(oldIndexLastSegmentNum)
          + oldIndex.getDurationUs(oldIndexLastSegmentNum, newPeriodDurationUs);
  long newIndexFirstSegmentNum = newIndex.getFirstSegmentNum();
  long newIndexStartTimeUs = newIndex.getTimeUs(newIndexFirstSegmentNum);
  long newSegmentNumShift = segmentNumShift;
  if (oldIndexEndTimeUs == newIndexStartTimeUs) {
    // The new index continues where the old one ended, with no overlap.
    newSegmentNumShift += oldIndexLastSegmentNum + 1 - newIndexFirstSegmentNum;
  } else if (oldIndexEndTimeUs < newIndexStartTimeUs) {
    // There's a gap between the old index and the new one which means we've slipped behind the
    // live window and can't proceed.
    throw new BehindLiveWindowException();
  } else {
    // The new index overlaps with the old one.
    newSegmentNumShift +=
        oldIndex.getSegmentNum(newIndexStartTimeUs, newPeriodDurationUs)
            - newIndexFirstSegmentNum;
  }
  return new RepresentationHolder(
      newPeriodDurationUs, newRepresentation, extractorWrapper, newSegmentNumShift, newIndex);
}
 
Example 13
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@CheckResult
/* package */ RepresentationHolder copyWithNewRepresentation(
    long newPeriodDurationUs, Representation newRepresentation)
    throws BehindLiveWindowException {
  DashSegmentIndex oldIndex = representation.getIndex();
  DashSegmentIndex newIndex = newRepresentation.getIndex();

  if (oldIndex == null) {
    // Segment numbers cannot shift if the index isn't defined by the manifest.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, oldIndex);
  }

  if (!oldIndex.isExplicit()) {
    // Segment numbers cannot shift if the index isn't explicit.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  int oldIndexSegmentCount = oldIndex.getSegmentCount(newPeriodDurationUs);
  if (oldIndexSegmentCount == 0) {
    // Segment numbers cannot shift if the old index was empty.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  long oldIndexLastSegmentNum = oldIndex.getFirstSegmentNum() + oldIndexSegmentCount - 1;
  long oldIndexEndTimeUs =
      oldIndex.getTimeUs(oldIndexLastSegmentNum)
          + oldIndex.getDurationUs(oldIndexLastSegmentNum, newPeriodDurationUs);
  long newIndexFirstSegmentNum = newIndex.getFirstSegmentNum();
  long newIndexStartTimeUs = newIndex.getTimeUs(newIndexFirstSegmentNum);
  long newSegmentNumShift = segmentNumShift;
  if (oldIndexEndTimeUs == newIndexStartTimeUs) {
    // The new index continues where the old one ended, with no overlap.
    newSegmentNumShift += oldIndexLastSegmentNum + 1 - newIndexFirstSegmentNum;
  } else if (oldIndexEndTimeUs < newIndexStartTimeUs) {
    // There's a gap between the old index and the new one which means we've slipped behind the
    // live window and can't proceed.
    throw new BehindLiveWindowException();
  } else {
    // The new index overlaps with the old one.
    newSegmentNumShift +=
        oldIndex.getSegmentNum(newIndexStartTimeUs, newPeriodDurationUs)
            - newIndexFirstSegmentNum;
  }
  return new RepresentationHolder(
      newPeriodDurationUs, newRepresentation, extractorWrapper, newSegmentNumShift, newIndex);
}
 
Example 14
Source File: DefaultDashChunkSource.java    From K-Sonic with MIT License 4 votes vote down vote up
public void updateRepresentation(long newPeriodDurationUs, Representation newRepresentation)
    throws BehindLiveWindowException{
  DashSegmentIndex oldIndex = representation.getIndex();
  DashSegmentIndex newIndex = newRepresentation.getIndex();

  periodDurationUs = newPeriodDurationUs;
  representation = newRepresentation;
  if (oldIndex == null) {
    // Segment numbers cannot shift if the index isn't defined by the manifest.
    return;
  }

  segmentIndex = newIndex;
  if (!oldIndex.isExplicit()) {
    // Segment numbers cannot shift if the index isn't explicit.
    return;
  }

  int oldIndexSegmentCount = oldIndex.getSegmentCount(periodDurationUs);
  if (oldIndexSegmentCount == 0) {
    // Segment numbers cannot shift if the old index was empty.
    return;
  }

  int oldIndexLastSegmentNum = oldIndex.getFirstSegmentNum() + oldIndexSegmentCount - 1;
  long oldIndexEndTimeUs = oldIndex.getTimeUs(oldIndexLastSegmentNum)
      + oldIndex.getDurationUs(oldIndexLastSegmentNum, periodDurationUs);
  int newIndexFirstSegmentNum = newIndex.getFirstSegmentNum();
  long newIndexStartTimeUs = newIndex.getTimeUs(newIndexFirstSegmentNum);
  if (oldIndexEndTimeUs == newIndexStartTimeUs) {
    // The new index continues where the old one ended, with no overlap.
    segmentNumShift += oldIndexLastSegmentNum + 1 - newIndexFirstSegmentNum;
  } else if (oldIndexEndTimeUs < newIndexStartTimeUs) {
    // There's a gap between the old index and the new one which means we've slipped behind the
    // live window and can't proceed.
    throw new BehindLiveWindowException();
  } else {
    // The new index overlaps with the old one.
    segmentNumShift += oldIndex.getSegmentNum(newIndexStartTimeUs, periodDurationUs)
        - newIndexFirstSegmentNum;
  }
}
 
Example 15
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@CheckResult
/* package */ RepresentationHolder copyWithNewRepresentation(
    long newPeriodDurationUs, Representation newRepresentation)
    throws BehindLiveWindowException {
  DashSegmentIndex oldIndex = representation.getIndex();
  DashSegmentIndex newIndex = newRepresentation.getIndex();

  if (oldIndex == null) {
    // Segment numbers cannot shift if the index isn't defined by the manifest.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, oldIndex);
  }

  if (!oldIndex.isExplicit()) {
    // Segment numbers cannot shift if the index isn't explicit.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  int oldIndexSegmentCount = oldIndex.getSegmentCount(newPeriodDurationUs);
  if (oldIndexSegmentCount == 0) {
    // Segment numbers cannot shift if the old index was empty.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  long oldIndexFirstSegmentNum = oldIndex.getFirstSegmentNum();
  long oldIndexStartTimeUs = oldIndex.getTimeUs(oldIndexFirstSegmentNum);
  long oldIndexLastSegmentNum = oldIndexFirstSegmentNum + oldIndexSegmentCount - 1;
  long oldIndexEndTimeUs =
      oldIndex.getTimeUs(oldIndexLastSegmentNum)
          + oldIndex.getDurationUs(oldIndexLastSegmentNum, newPeriodDurationUs);
  long newIndexFirstSegmentNum = newIndex.getFirstSegmentNum();
  long newIndexStartTimeUs = newIndex.getTimeUs(newIndexFirstSegmentNum);
  long newSegmentNumShift = segmentNumShift;
  if (oldIndexEndTimeUs == newIndexStartTimeUs) {
    // The new index continues where the old one ended, with no overlap.
    newSegmentNumShift += oldIndexLastSegmentNum + 1 - newIndexFirstSegmentNum;
  } else if (oldIndexEndTimeUs < newIndexStartTimeUs) {
    // There's a gap between the old index and the new one which means we've slipped behind the
    // live window and can't proceed.
    throw new BehindLiveWindowException();
  } else if (newIndexStartTimeUs < oldIndexStartTimeUs) {
    // The new index overlaps with (but does not have a start position contained within) the old
    // index. This can only happen if extra segments have been added to the start of the index.
    newSegmentNumShift -=
        newIndex.getSegmentNum(oldIndexStartTimeUs, newPeriodDurationUs)
            - oldIndexFirstSegmentNum;
  } else {
    // The new index overlaps with (and has a start position contained within) the old index.
    newSegmentNumShift +=
        oldIndex.getSegmentNum(newIndexStartTimeUs, newPeriodDurationUs)
            - newIndexFirstSegmentNum;
  }
  return new RepresentationHolder(
      newPeriodDurationUs, newRepresentation, extractorWrapper, newSegmentNumShift, newIndex);
}
 
Example 16
Source File: DefaultDashChunkSource.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@CheckResult
/* package */ RepresentationHolder copyWithNewRepresentation(
    long newPeriodDurationUs, Representation newRepresentation)
    throws BehindLiveWindowException {
  DashSegmentIndex oldIndex = representation.getIndex();
  DashSegmentIndex newIndex = newRepresentation.getIndex();

  if (oldIndex == null) {
    // Segment numbers cannot shift if the index isn't defined by the manifest.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, oldIndex);
  }

  if (!oldIndex.isExplicit()) {
    // Segment numbers cannot shift if the index isn't explicit.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  int oldIndexSegmentCount = oldIndex.getSegmentCount(newPeriodDurationUs);
  if (oldIndexSegmentCount == 0) {
    // Segment numbers cannot shift if the old index was empty.
    return new RepresentationHolder(
        newPeriodDurationUs, newRepresentation, extractorWrapper, segmentNumShift, newIndex);
  }

  long oldIndexFirstSegmentNum = oldIndex.getFirstSegmentNum();
  long oldIndexStartTimeUs = oldIndex.getTimeUs(oldIndexFirstSegmentNum);
  long oldIndexLastSegmentNum = oldIndexFirstSegmentNum + oldIndexSegmentCount - 1;
  long oldIndexEndTimeUs =
      oldIndex.getTimeUs(oldIndexLastSegmentNum)
          + oldIndex.getDurationUs(oldIndexLastSegmentNum, newPeriodDurationUs);
  long newIndexFirstSegmentNum = newIndex.getFirstSegmentNum();
  long newIndexStartTimeUs = newIndex.getTimeUs(newIndexFirstSegmentNum);
  long newSegmentNumShift = segmentNumShift;
  if (oldIndexEndTimeUs == newIndexStartTimeUs) {
    // The new index continues where the old one ended, with no overlap.
    newSegmentNumShift += oldIndexLastSegmentNum + 1 - newIndexFirstSegmentNum;
  } else if (oldIndexEndTimeUs < newIndexStartTimeUs) {
    // There's a gap between the old index and the new one which means we've slipped behind the
    // live window and can't proceed.
    throw new BehindLiveWindowException();
  } else if (newIndexStartTimeUs < oldIndexStartTimeUs) {
    // The new index overlaps with (but does not have a start position contained within) the old
    // index. This can only happen if extra segments have been added to the start of the index.
    newSegmentNumShift -=
        newIndex.getSegmentNum(oldIndexStartTimeUs, newPeriodDurationUs)
            - oldIndexFirstSegmentNum;
  } else {
    // The new index overlaps with (and has a start position contained within) the old index.
    newSegmentNumShift +=
        oldIndex.getSegmentNum(newIndexStartTimeUs, newPeriodDurationUs)
            - newIndexFirstSegmentNum;
  }
  return new RepresentationHolder(
      newPeriodDurationUs, newRepresentation, extractorWrapper, newSegmentNumShift, newIndex);
}