com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement Java Examples

The following examples show how to use com.google.android.exoplayer2.source.smoothstreaming.manifest.SsManifest.StreamElement. 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: SsDownloader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, SsManifest manifest, boolean allowIncompleteList) {
  ArrayList<Segment> segments = new ArrayList<>();
  for (StreamElement streamElement : manifest.streamElements) {
    for (int i = 0; i < streamElement.formats.length; i++) {
      for (int j = 0; j < streamElement.chunkCount; j++) {
        segments.add(
            new Segment(
                streamElement.getStartTimeUs(j),
                new DataSpec(streamElement.buildRequestUri(i, j))));
      }
    }
  }
  return segments;
}
 
Example #2
Source File: SsDownloader.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, SsManifest manifest, boolean allowIncompleteList) {
  ArrayList<Segment> segments = new ArrayList<>();
  for (StreamElement streamElement : manifest.streamElements) {
    for (int i = 0; i < streamElement.formats.length; i++) {
      for (int j = 0; j < streamElement.chunkCount; j++) {
        segments.add(
            new Segment(
                streamElement.getStartTimeUs(j),
                new DataSpec(streamElement.buildRequestUri(i, j))));
      }
    }
  }
  return segments;
}
 
Example #3
Source File: DefaultSsChunkSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[streamElementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #4
Source File: SsManifestParser.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object build() {
  StreamElement[] streamElementArray = new StreamElement[streamElements.size()];
  streamElements.toArray(streamElementArray);
  if (protectionElement != null) {
    DrmInitData drmInitData = new DrmInitData(new SchemeData(protectionElement.uuid,
        MimeTypes.VIDEO_MP4, protectionElement.data));
    for (StreamElement streamElement : streamElementArray) {
      int type = streamElement.type;
      if (type == C.TRACK_TYPE_VIDEO || type == C.TRACK_TYPE_AUDIO) {
        Format[] formats = streamElement.formats;
        for (int i = 0; i < formats.length; i++) {
          formats[i] = formats[i].copyWithDrmInitData(drmInitData);
        }
      }
    }
  }
  return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength,
      lookAheadCount, isLive, protectionElement, streamElementArray);
}
 
Example #5
Source File: SsDownloader.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, SsManifest manifest, boolean allowIncompleteList) {
  ArrayList<Segment> segments = new ArrayList<>();
  for (StreamElement streamElement : manifest.streamElements) {
    for (int i = 0; i < streamElement.formats.length; i++) {
      for (int j = 0; j < streamElement.chunkCount; j++) {
        segments.add(
            new Segment(
                streamElement.getStartTimeUs(j),
                new DataSpec(streamElement.buildRequestUri(i, j))));
      }
    }
  }
  return segments;
}
 
Example #6
Source File: DefaultSsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[streamElementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #7
Source File: SsManifestParser.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object build() {
  StreamElement[] streamElementArray = new StreamElement[streamElements.size()];
  streamElements.toArray(streamElementArray);
  if (protectionElement != null) {
    DrmInitData drmInitData = new DrmInitData(new SchemeData(protectionElement.uuid,
        MimeTypes.VIDEO_MP4, protectionElement.data));
    for (StreamElement streamElement : streamElementArray) {
      int type = streamElement.type;
      if (type == C.TRACK_TYPE_VIDEO || type == C.TRACK_TYPE_AUDIO) {
        Format[] formats = streamElement.formats;
        for (int i = 0; i < formats.length; i++) {
          formats[i] = formats[i].copyWithDrmInitData(drmInitData);
        }
      }
    }
  }
  return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength,
      lookAheadCount, isLive, protectionElement, streamElementArray);
}
 
Example #8
Source File: DefaultSsChunkSource.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[elementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[elementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #9
Source File: DefaultSsChunkSource.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
 * @param manifest The initial manifest.
 * @param elementIndex The index of the stream element in the manifest.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 * @param trackEncryptionBoxes Track encryption boxes for the stream.
 */
public DefaultSsChunkSource(LoaderErrorThrower manifestLoaderErrorThrower, SsManifest manifest,
    int elementIndex, TrackSelection trackSelection, DataSource dataSource,
    TrackEncryptionBox[] trackEncryptionBoxes) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.elementIndex = elementIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;

  StreamElement streamElement = manifest.streamElements[elementIndex];

  extractorWrappers = new ChunkExtractorWrapper[trackSelection.length()];
  for (int i = 0; i < extractorWrappers.length; i++) {
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(i);
    Format format = streamElement.formats[manifestTrackIndex];
    int nalUnitLengthFieldLength = streamElement.type == C.TRACK_TYPE_VIDEO ? 4 : 0;
    Track track = new Track(manifestTrackIndex, streamElement.type, streamElement.timescale,
        C.TIME_UNSET, manifest.durationUs, format, Track.TRANSFORMATION_NONE,
        trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
    FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
        FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
        | FragmentedMp4Extractor.FLAG_WORKAROUND_IGNORE_TFDT_BOX, null, track);
    extractorWrappers[i] = new ChunkExtractorWrapper(extractor, format);
  }
}
 
Example #10
Source File: SsManifestParser.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public Object build() {
  StreamElement[] streamElementArray = new StreamElement[streamElements.size()];
  streamElements.toArray(streamElementArray);
  if (protectionElement != null) {
    DrmInitData drmInitData = new DrmInitData(new SchemeData(protectionElement.uuid,
        MimeTypes.VIDEO_MP4, protectionElement.data));
    for (StreamElement streamElement : streamElementArray) {
      for (int i = 0; i < streamElement.formats.length; i++) {
        streamElement.formats[i] = streamElement.formats[i].copyWithDrmInitData(drmInitData);
      }
    }
  }
  return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength,
      lookAheadCount, isLive, protectionElement, streamElementArray);
}
 
Example #11
Source File: SsManifestParser.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public Object build() {
  StreamElement[] streamElementArray = new StreamElement[streamElements.size()];
  streamElements.toArray(streamElementArray);
  if (protectionElement != null) {
    DrmInitData drmInitData = new DrmInitData(new SchemeData(protectionElement.uuid,
        MimeTypes.VIDEO_MP4, protectionElement.data));
    for (StreamElement streamElement : streamElementArray) {
      int type = streamElement.type;
      if (type == C.TRACK_TYPE_VIDEO || type == C.TRACK_TYPE_AUDIO) {
        Format[] formats = streamElement.formats;
        for (int i = 0; i < formats.length; i++) {
          formats[i] = formats[i].copyWithDrmInitData(drmInitData);
        }
      }
    }
  }
  return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength,
      lookAheadCount, isLive, protectionElement, streamElementArray);
}
 
Example #12
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[streamElementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #13
Source File: SsManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object build() {
  StreamElement[] streamElementArray = new StreamElement[streamElements.size()];
  streamElements.toArray(streamElementArray);
  if (protectionElement != null) {
    DrmInitData drmInitData = new DrmInitData(new SchemeData(protectionElement.uuid,
        MimeTypes.VIDEO_MP4, protectionElement.data));
    for (StreamElement streamElement : streamElementArray) {
      for (int i = 0; i < streamElement.formats.length; i++) {
        streamElement.formats[i] = streamElement.formats[i].copyWithDrmInitData(drmInitData);
      }
    }
  }
  return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength,
      lookAheadCount, isLive, protectionElement, streamElementArray);
}
 
Example #14
Source File: SsDownloader.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, SsManifest manifest, boolean allowIncompleteList) {
  ArrayList<Segment> segments = new ArrayList<>();
  for (StreamElement streamElement : manifest.streamElements) {
    for (int i = 0; i < streamElement.formats.length; i++) {
      for (int j = 0; j < streamElement.chunkCount; j++) {
        segments.add(
            new Segment(
                streamElement.getStartTimeUs(j),
                new DataSpec(streamElement.buildRequestUri(i, j))));
      }
    }
  }
  return segments;
}
 
Example #15
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[streamElementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #16
Source File: DefaultSsChunkSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void updateManifest(SsManifest newManifest) {
  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int currentElementChunkCount = currentElement.chunkCount;
  StreamElement newElement = newManifest.streamElements[streamElementIndex];
  if (currentElementChunkCount == 0 || newElement.chunkCount == 0) {
    // There's no overlap between the old and new elements because at least one is empty.
    currentManifestChunkOffset += currentElementChunkCount;
  } else {
    long currentElementEndTimeUs = currentElement.getStartTimeUs(currentElementChunkCount - 1)
        + currentElement.getChunkDurationUs(currentElementChunkCount - 1);
    long newElementStartTimeUs = newElement.getStartTimeUs(0);
    if (currentElementEndTimeUs <= newElementStartTimeUs) {
      // There's no overlap between the old and new elements.
      currentManifestChunkOffset += currentElementChunkCount;
    } else {
      // The new element overlaps with the old one.
      currentManifestChunkOffset += currentElement.getChunkIndex(newElementStartTimeUs);
    }
  }
  manifest = newManifest;
}
 
Example #17
Source File: SsManifestParser.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object build() {
  StreamElement[] streamElementArray = new StreamElement[streamElements.size()];
  streamElements.toArray(streamElementArray);
  if (protectionElement != null) {
    DrmInitData drmInitData = new DrmInitData(new SchemeData(protectionElement.uuid,
        MimeTypes.VIDEO_MP4, protectionElement.data));
    for (StreamElement streamElement : streamElementArray) {
      for (int i = 0; i < streamElement.formats.length; i++) {
        streamElement.formats[i] = streamElement.formats[i].copyWithDrmInitData(drmInitData);
      }
    }
  }
  return new SsManifest(majorVersion, minorVersion, timescale, duration, dvrWindowLength,
      lookAheadCount, isLive, protectionElement, streamElementArray);
}
 
Example #18
Source File: SsDownloader.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
protected List<Segment> getSegments(
    DataSource dataSource, SsManifest manifest, boolean allowIncompleteList) {
  ArrayList<Segment> segments = new ArrayList<>();
  for (StreamElement streamElement : manifest.streamElements) {
    for (int i = 0; i < streamElement.formats.length; i++) {
      for (int j = 0; j < streamElement.chunkCount; j++) {
        segments.add(
            new Segment(
                streamElement.getStartTimeUs(j),
                new DataSpec(streamElement.buildRequestUri(i, j))));
      }
    }
  }
  return segments;
}
 
Example #19
Source File: SsManifestParser.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public Object build() {
  Format[] formatArray = new Format[formats.size()];
  formats.toArray(formatArray);
  return new StreamElement(baseUri, url, type, subType, timescale, name, maxWidth, maxHeight,
      displayWidth, displayHeight, language, formatArray, startTimes, lastChunkDuration);
}
 
Example #20
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private long resolveTimeToLiveEdgeUs(long playbackPositionUs) {
  if (!manifest.isLive) {
    return C.TIME_UNSET;
  }

  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int lastChunkIndex = currentElement.chunkCount - 1;
  long lastChunkEndTimeUs = currentElement.getStartTimeUs(lastChunkIndex)
      + currentElement.getChunkDurationUs(lastChunkIndex);
  return lastChunkEndTimeUs - playbackPositionUs;
}
 
Example #21
Source File: DefaultSsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private long resolveTimeToLiveEdgeUs(long playbackPositionUs) {
  if (!manifest.isLive) {
    return C.TIME_UNSET;
  }

  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int lastChunkIndex = currentElement.chunkCount - 1;
  long lastChunkEndTimeUs = currentElement.getStartTimeUs(lastChunkIndex)
      + currentElement.getChunkDurationUs(lastChunkIndex);
  return lastChunkEndTimeUs - playbackPositionUs;
}
 
Example #22
Source File: DefaultSsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
 * @param manifest The initial manifest.
 * @param streamElementIndex The index of the stream element in the manifest.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 */
public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    TrackSelection trackSelection,
    DataSource dataSource) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.streamElementIndex = streamElementIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;

  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  extractorWrappers = new ChunkExtractorWrapper[trackSelection.length()];
  for (int i = 0; i < extractorWrappers.length; i++) {
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(i);
    Format format = streamElement.formats[manifestTrackIndex];
    TrackEncryptionBox[] trackEncryptionBoxes =
        format.drmInitData != null ? manifest.protectionElement.trackEncryptionBoxes : null;
    int nalUnitLengthFieldLength = streamElement.type == C.TRACK_TYPE_VIDEO ? 4 : 0;
    Track track = new Track(manifestTrackIndex, streamElement.type, streamElement.timescale,
        C.TIME_UNSET, manifest.durationUs, format, Track.TRANSFORMATION_NONE,
        trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
    FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
        FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
        | FragmentedMp4Extractor.FLAG_WORKAROUND_IGNORE_TFDT_BOX, null, track, null);
    extractorWrappers[i] = new ChunkExtractorWrapper(extractor, streamElement.type, format);
  }
}
 
Example #23
Source File: DefaultSsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  int chunkIndex = streamElement.getChunkIndex(positionUs);
  long firstSyncUs = streamElement.getStartTimeUs(chunkIndex);
  long secondSyncUs =
      firstSyncUs < positionUs && chunkIndex < streamElement.chunkCount - 1
          ? streamElement.getStartTimeUs(chunkIndex + 1)
          : firstSyncUs;
  return Util.resolveSeekPositionUs(positionUs, seekParameters, firstSyncUs, secondSyncUs);
}
 
Example #24
Source File: DefaultSsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
 * @param manifest The initial manifest.
 * @param streamElementIndex The index of the stream element in the manifest.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 */
public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    TrackSelection trackSelection,
    DataSource dataSource) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.streamElementIndex = streamElementIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;

  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  extractorWrappers = new ChunkExtractorWrapper[trackSelection.length()];
  for (int i = 0; i < extractorWrappers.length; i++) {
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(i);
    Format format = streamElement.formats[manifestTrackIndex];
    TrackEncryptionBox[] trackEncryptionBoxes =
        format.drmInitData != null ? manifest.protectionElement.trackEncryptionBoxes : null;
    int nalUnitLengthFieldLength = streamElement.type == C.TRACK_TYPE_VIDEO ? 4 : 0;
    Track track = new Track(manifestTrackIndex, streamElement.type, streamElement.timescale,
        C.TIME_UNSET, manifest.durationUs, format, Track.TRANSFORMATION_NONE,
        trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
    FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
        FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
        | FragmentedMp4Extractor.FLAG_WORKAROUND_IGNORE_TFDT_BOX, null, track, null);
    extractorWrappers[i] = new ChunkExtractorWrapper(extractor, streamElement.type, format);
  }
}
 
Example #25
Source File: SsManifestParser.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Object build() {
  Format[] formatArray = new Format[formats.size()];
  formats.toArray(formatArray);
  return new StreamElement(baseUri, url, type, subType, timescale, name, maxWidth, maxHeight,
      displayWidth, displayHeight, language, formatArray, startTimes, lastChunkDuration);
}
 
Example #26
Source File: DefaultSsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  int chunkIndex = streamElement.getChunkIndex(positionUs);
  long firstSyncUs = streamElement.getStartTimeUs(chunkIndex);
  long secondSyncUs =
      firstSyncUs < positionUs && chunkIndex < streamElement.chunkCount - 1
          ? streamElement.getStartTimeUs(chunkIndex + 1)
          : firstSyncUs;
  return Util.resolveSeekPositionUs(positionUs, seekParameters, firstSyncUs, secondSyncUs);
}
 
Example #27
Source File: DefaultSsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private long resolveTimeToLiveEdgeUs(long playbackPositionUs) {
  if (!manifest.isLive) {
    return C.TIME_UNSET;
  }

  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int lastChunkIndex = currentElement.chunkCount - 1;
  long lastChunkEndTimeUs = currentElement.getStartTimeUs(lastChunkIndex)
      + currentElement.getChunkDurationUs(lastChunkIndex);
  return lastChunkEndTimeUs - playbackPositionUs;
}
 
Example #28
Source File: DefaultSsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private long resolveTimeToLiveEdgeUs(long playbackPositionUs) {
  if (!manifest.isLive) {
    return C.TIME_UNSET;
  }

  StreamElement currentElement = manifest.streamElements[streamElementIndex];
  int lastChunkIndex = currentElement.chunkCount - 1;
  long lastChunkEndTimeUs = currentElement.getStartTimeUs(lastChunkIndex)
      + currentElement.getChunkDurationUs(lastChunkIndex);
  return lastChunkEndTimeUs - playbackPositionUs;
}
 
Example #29
Source File: DefaultSsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public long getAdjustedSeekPositionUs(long positionUs, SeekParameters seekParameters) {
  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  int chunkIndex = streamElement.getChunkIndex(positionUs);
  long firstSyncUs = streamElement.getStartTimeUs(chunkIndex);
  long secondSyncUs =
      firstSyncUs < positionUs && chunkIndex < streamElement.chunkCount - 1
          ? streamElement.getStartTimeUs(chunkIndex + 1)
          : firstSyncUs;
  return Util.resolveSeekPositionUs(positionUs, seekParameters, firstSyncUs, secondSyncUs);
}
 
Example #30
Source File: DefaultSsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param manifestLoaderErrorThrower Throws errors affecting loading of manifests.
 * @param manifest The initial manifest.
 * @param streamElementIndex The index of the stream element in the manifest.
 * @param trackSelection The track selection.
 * @param dataSource A {@link DataSource} suitable for loading the media data.
 */
public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    TrackSelection trackSelection,
    DataSource dataSource) {
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.manifest = manifest;
  this.streamElementIndex = streamElementIndex;
  this.trackSelection = trackSelection;
  this.dataSource = dataSource;

  StreamElement streamElement = manifest.streamElements[streamElementIndex];
  extractorWrappers = new ChunkExtractorWrapper[trackSelection.length()];
  for (int i = 0; i < extractorWrappers.length; i++) {
    int manifestTrackIndex = trackSelection.getIndexInTrackGroup(i);
    Format format = streamElement.formats[manifestTrackIndex];
    TrackEncryptionBox[] trackEncryptionBoxes =
        format.drmInitData != null ? manifest.protectionElement.trackEncryptionBoxes : null;
    int nalUnitLengthFieldLength = streamElement.type == C.TRACK_TYPE_VIDEO ? 4 : 0;
    Track track = new Track(manifestTrackIndex, streamElement.type, streamElement.timescale,
        C.TIME_UNSET, manifest.durationUs, format, Track.TRANSFORMATION_NONE,
        trackEncryptionBoxes, nalUnitLengthFieldLength, null, null);
    FragmentedMp4Extractor extractor = new FragmentedMp4Extractor(
        FragmentedMp4Extractor.FLAG_WORKAROUND_EVERY_VIDEO_FRAME_IS_SYNC_FRAME
        | FragmentedMp4Extractor.FLAG_WORKAROUND_IGNORE_TFDT_BOX, null, track, null);
    extractorWrappers[i] = new ChunkExtractorWrapper(extractor, streamElement.type, format);
  }
}