com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper Java Examples

The following examples show how to use com.google.android.exoplayer2.source.chunk.ChunkExtractorWrapper. 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: 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 #2
Source File: DashUtil.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static void loadInitializationData(DataSource dataSource,
    Representation representation, ChunkExtractorWrapper extractorWrapper, RangedUri requestUri)
    throws IOException, InterruptedException {
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(representation.baseUrl),
      requestUri.start, requestUri.length, representation.getCacheKey());
  InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec,
      representation.format, C.SELECTION_REASON_UNKNOWN, null /* trackSelectionData */,
      extractorWrapper);
  initializationChunk.load();
}
 
Example #3
Source File: DashUtil.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static ChunkExtractorWrapper newWrappedExtractor(int trackType, Format format) {
  String mimeType = format.containerMimeType;
  boolean isWebm =
      mimeType != null
          && (mimeType.startsWith(MimeTypes.VIDEO_WEBM)
              || mimeType.startsWith(MimeTypes.AUDIO_WEBM));
  Extractor extractor = isWebm ? new MatroskaExtractor() : new FragmentedMp4Extractor();
  return new ChunkExtractorWrapper(extractor, trackType, format);
}
 
Example #4
Source File: DefaultSsChunkSource.java    From TelePlus-Android 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.
 * @param trackEncryptionBoxes Track encryption boxes for the stream.
 */
public DefaultSsChunkSource(
    LoaderErrorThrower manifestLoaderErrorThrower,
    SsManifest manifest,
    int streamElementIndex,
    TrackSelection trackSelection,
    DataSource dataSource,
    TrackEncryptionBox[] trackEncryptionBoxes) {
  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];
    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 #5
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private RepresentationHolder(
    long periodDurationUs,
    Representation representation,
    @Nullable ChunkExtractorWrapper extractorWrapper,
    long segmentNumShift,
    @Nullable DashSegmentIndex segmentIndex) {
  this.periodDurationUs = periodDurationUs;
  this.representation = representation;
  this.segmentNumShift = segmentNumShift;
  this.extractorWrapper = extractorWrapper;
  this.segmentIndex = segmentIndex;
}
 
Example #6
Source File: DashUtil.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * Loads initialization data for the {@code representation} and optionally index data then
 * returns a {@link ChunkExtractorWrapper} which contains the output.
 *
 * @param dataSource The source from which the data should be loaded.
 * @param representation The representation which initialization chunk belongs to.
 * @param loadIndex Whether to load index data too.
 * @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
 *     initialization or (if requested) index data exists.
 * @throws IOException Thrown when there is an error while loading.
 * @throws InterruptedException Thrown if the thread was interrupted.
 */
private static ChunkExtractorWrapper loadInitializationData(DataSource dataSource,
    Representation representation, boolean loadIndex)
    throws IOException, InterruptedException {
  RangedUri initializationUri = representation.getInitializationUri();
  if (initializationUri == null) {
    return null;
  }
  ChunkExtractorWrapper extractorWrapper = newWrappedExtractor(representation.format);
  RangedUri requestUri;
  if (loadIndex) {
    RangedUri indexUri = representation.getIndexUri();
    if (indexUri == null) {
      return null;
    }
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrl);
    if (requestUri == null) {
      loadInitializationData(dataSource, representation, extractorWrapper, initializationUri);
      requestUri = indexUri;
    }
  } else {
    requestUri = initializationUri;
  }
  loadInitializationData(dataSource, representation, extractorWrapper, requestUri);
  return extractorWrapper;
}
 
Example #7
Source File: DashUtil.java    From K-Sonic with MIT License 5 votes vote down vote up
private static void loadInitializationData(DataSource dataSource,
    Representation representation, ChunkExtractorWrapper extractorWrapper, RangedUri requestUri)
    throws IOException, InterruptedException {
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(representation.baseUrl),
      requestUri.start, requestUri.length, representation.getCacheKey());
  InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec,
      representation.format, C.SELECTION_REASON_UNKNOWN, null /* trackSelectionData */,
      extractorWrapper);
  initializationChunk.load();
}
 
Example #8
Source File: DashUtil.java    From K-Sonic with MIT License 5 votes vote down vote up
private static ChunkExtractorWrapper newWrappedExtractor(Format format) {
  String mimeType = format.containerMimeType;
  boolean isWebm = mimeType.startsWith(MimeTypes.VIDEO_WEBM)
      || mimeType.startsWith(MimeTypes.AUDIO_WEBM);
  Extractor extractor = isWebm ? new MatroskaExtractor() : new FragmentedMp4Extractor();
  return new ChunkExtractorWrapper(extractor, format);
}
 
Example #9
Source File: DefaultSsChunkSource.java    From K-Sonic with MIT License 5 votes vote down vote up
private static MediaChunk newMediaChunk(Format format, DataSource dataSource, Uri uri,
    String cacheKey, int chunkIndex, long chunkStartTimeUs, long chunkEndTimeUs,
    int trackSelectionReason, Object trackSelectionData, ChunkExtractorWrapper extractorWrapper) {
  DataSpec dataSpec = new DataSpec(uri, 0, C.LENGTH_UNSET, cacheKey);
  // In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk.
  // To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs.
  long sampleOffsetUs = chunkStartTimeUs;
  return new ContainerMediaChunk(dataSource, dataSpec, format, trackSelectionReason,
      trackSelectionData, chunkStartTimeUs, chunkEndTimeUs, chunkIndex, 1, sampleOffsetUs,
      extractorWrapper);
}
 
Example #10
Source File: DefaultDashChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private RepresentationHolder(
    long periodDurationUs,
    Representation representation,
    @Nullable ChunkExtractorWrapper extractorWrapper,
    long segmentNumShift,
    @Nullable DashSegmentIndex segmentIndex) {
  this.periodDurationUs = periodDurationUs;
  this.representation = representation;
  this.segmentNumShift = segmentNumShift;
  this.extractorWrapper = extractorWrapper;
  this.segmentIndex = segmentIndex;
}
 
Example #11
Source File: DashUtil.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads initialization data for the {@code representation} and optionally index data then returns
 * a {@link ChunkExtractorWrapper} which contains the output.
 *
 * @param dataSource The source from which the data should be loaded.
 * @param trackType The type of the representation. Typically one of the {@link
 *     com.google.android.exoplayer2.C} {@code TRACK_TYPE_*} constants.
 * @param representation The representation which initialization chunk belongs to.
 * @param loadIndex Whether to load index data too.
 * @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
 *     initialization or (if requested) index data exists.
 * @throws IOException Thrown when there is an error while loading.
 * @throws InterruptedException Thrown if the thread was interrupted.
 */
private static @Nullable ChunkExtractorWrapper loadInitializationData(
    DataSource dataSource, int trackType, Representation representation, boolean loadIndex)
    throws IOException, InterruptedException {
  RangedUri initializationUri = representation.getInitializationUri();
  if (initializationUri == null) {
    return null;
  }
  ChunkExtractorWrapper extractorWrapper = newWrappedExtractor(trackType, representation.format);
  RangedUri requestUri;
  if (loadIndex) {
    RangedUri indexUri = representation.getIndexUri();
    if (indexUri == null) {
      return null;
    }
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrl);
    if (requestUri == null) {
      loadInitializationData(dataSource, representation, extractorWrapper, initializationUri);
      requestUri = indexUri;
    }
  } else {
    requestUri = initializationUri;
  }
  loadInitializationData(dataSource, representation, extractorWrapper, requestUri);
  return extractorWrapper;
}
 
Example #12
Source File: DefaultSsChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static MediaChunk newMediaChunk(
    Format format,
    DataSource dataSource,
    Uri uri,
    String cacheKey,
    int chunkIndex,
    long chunkStartTimeUs,
    long chunkEndTimeUs,
    long chunkSeekTimeUs,
    int trackSelectionReason,
    Object trackSelectionData,
    ChunkExtractorWrapper extractorWrapper) {
  DataSpec dataSpec = new DataSpec(uri, 0, C.LENGTH_UNSET, cacheKey);
  // In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk.
  // To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs.
  long sampleOffsetUs = chunkStartTimeUs;
  return new ContainerMediaChunk(
      dataSource,
      dataSpec,
      format,
      trackSelectionReason,
      trackSelectionData,
      chunkStartTimeUs,
      chunkEndTimeUs,
      chunkSeekTimeUs,
      chunkIndex,
      /* chunkCount= */ 1,
      sampleOffsetUs,
      extractorWrapper);
}
 
Example #13
Source File: DashUtil.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static ChunkExtractorWrapper newWrappedExtractor(int trackType, Format format) {
  String mimeType = format.containerMimeType;
  boolean isWebm =
      mimeType != null
          && (mimeType.startsWith(MimeTypes.VIDEO_WEBM)
              || mimeType.startsWith(MimeTypes.AUDIO_WEBM));
  Extractor extractor = isWebm ? new MatroskaExtractor() : new FragmentedMp4Extractor();
  return new ChunkExtractorWrapper(extractor, trackType, format);
}
 
Example #14
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);
  }
}
 
Example #15
Source File: DefaultSsChunkSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private static MediaChunk newMediaChunk(
    Format format,
    DataSource dataSource,
    Uri uri,
    String cacheKey,
    int chunkIndex,
    long chunkStartTimeUs,
    long chunkEndTimeUs,
    long chunkSeekTimeUs,
    int trackSelectionReason,
    Object trackSelectionData,
    ChunkExtractorWrapper extractorWrapper) {
  DataSpec dataSpec = new DataSpec(uri, 0, C.LENGTH_UNSET, cacheKey);
  // In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk.
  // To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs.
  long sampleOffsetUs = chunkStartTimeUs;
  return new ContainerMediaChunk(
      dataSource,
      dataSpec,
      format,
      trackSelectionReason,
      trackSelectionData,
      chunkStartTimeUs,
      chunkEndTimeUs,
      chunkSeekTimeUs,
      /* clippedEndTimeUs= */ C.TIME_UNSET,
      chunkIndex,
      /* chunkCount= */ 1,
      sampleOffsetUs,
      extractorWrapper);
}
 
Example #16
Source File: DefaultDashChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private RepresentationHolder(
    long periodDurationUs,
    Representation representation,
    @Nullable ChunkExtractorWrapper extractorWrapper,
    long segmentNumShift,
    @Nullable DashSegmentIndex segmentIndex) {
  this.periodDurationUs = periodDurationUs;
  this.representation = representation;
  this.segmentNumShift = segmentNumShift;
  this.extractorWrapper = extractorWrapper;
  this.segmentIndex = segmentIndex;
}
 
Example #17
Source File: DashUtil.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads initialization data for the {@code representation} and optionally index data then returns
 * a {@link ChunkExtractorWrapper} which contains the output.
 *
 * @param dataSource The source from which the data should be loaded.
 * @param trackType The type of the representation. Typically one of the {@link
 *     com.google.android.exoplayer2.C} {@code TRACK_TYPE_*} constants.
 * @param representation The representation which initialization chunk belongs to.
 * @param loadIndex Whether to load index data too.
 * @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
 *     initialization or (if requested) index data exists.
 * @throws IOException Thrown when there is an error while loading.
 * @throws InterruptedException Thrown if the thread was interrupted.
 */
private static @Nullable ChunkExtractorWrapper loadInitializationData(
    DataSource dataSource, int trackType, Representation representation, boolean loadIndex)
    throws IOException, InterruptedException {
  RangedUri initializationUri = representation.getInitializationUri();
  if (initializationUri == null) {
    return null;
  }
  ChunkExtractorWrapper extractorWrapper = newWrappedExtractor(trackType, representation.format);
  RangedUri requestUri;
  if (loadIndex) {
    RangedUri indexUri = representation.getIndexUri();
    if (indexUri == null) {
      return null;
    }
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrl);
    if (requestUri == null) {
      loadInitializationData(dataSource, representation, extractorWrapper, initializationUri);
      requestUri = indexUri;
    }
  } else {
    requestUri = initializationUri;
  }
  loadInitializationData(dataSource, representation, extractorWrapper, requestUri);
  return extractorWrapper;
}
 
Example #18
Source File: DashUtil.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static void loadInitializationData(DataSource dataSource,
    Representation representation, ChunkExtractorWrapper extractorWrapper, RangedUri requestUri)
    throws IOException, InterruptedException {
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(representation.baseUrl),
      requestUri.start, requestUri.length, representation.getCacheKey());
  InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec,
      representation.format, C.SELECTION_REASON_UNKNOWN, null /* trackSelectionData */,
      extractorWrapper);
  initializationChunk.load();
}
 
Example #19
Source File: DashUtil.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static ChunkExtractorWrapper newWrappedExtractor(int trackType, Format format) {
  String mimeType = format.containerMimeType;
  boolean isWebm =
      mimeType != null
          && (mimeType.startsWith(MimeTypes.VIDEO_WEBM)
              || mimeType.startsWith(MimeTypes.AUDIO_WEBM));
  Extractor extractor = isWebm ? new MatroskaExtractor() : new FragmentedMp4Extractor();
  return new ChunkExtractorWrapper(extractor, trackType, format);
}
 
Example #20
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 #21
Source File: DefaultSsChunkSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private static MediaChunk newMediaChunk(
    Format format,
    DataSource dataSource,
    Uri uri,
    String cacheKey,
    int chunkIndex,
    long chunkStartTimeUs,
    long chunkEndTimeUs,
    long chunkSeekTimeUs,
    int trackSelectionReason,
    Object trackSelectionData,
    ChunkExtractorWrapper extractorWrapper) {
  DataSpec dataSpec = new DataSpec(uri, 0, C.LENGTH_UNSET, cacheKey);
  // In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk.
  // To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs.
  long sampleOffsetUs = chunkStartTimeUs;
  return new ContainerMediaChunk(
      dataSource,
      dataSpec,
      format,
      trackSelectionReason,
      trackSelectionData,
      chunkStartTimeUs,
      chunkEndTimeUs,
      chunkSeekTimeUs,
      /* clippedEndTimeUs= */ C.TIME_UNSET,
      chunkIndex,
      /* chunkCount= */ 1,
      sampleOffsetUs,
      extractorWrapper);
}
 
Example #22
Source File: DashUtil.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads initialization data for the {@code representation} and optionally index data then returns
 * a {@link ChunkExtractorWrapper} which contains the output.
 *
 * @param dataSource The source from which the data should be loaded.
 * @param trackType The type of the representation. Typically one of the {@link
 *     com.google.android.exoplayer2.C} {@code TRACK_TYPE_*} constants.
 * @param representation The representation which initialization chunk belongs to.
 * @param loadIndex Whether to load index data too.
 * @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
 *     initialization or (if requested) index data exists.
 * @throws IOException Thrown when there is an error while loading.
 * @throws InterruptedException Thrown if the thread was interrupted.
 */
private static @Nullable ChunkExtractorWrapper loadInitializationData(
    DataSource dataSource, int trackType, Representation representation, boolean loadIndex)
    throws IOException, InterruptedException {
  RangedUri initializationUri = representation.getInitializationUri();
  if (initializationUri == null) {
    return null;
  }
  ChunkExtractorWrapper extractorWrapper = newWrappedExtractor(trackType, representation.format);
  RangedUri requestUri;
  if (loadIndex) {
    RangedUri indexUri = representation.getIndexUri();
    if (indexUri == null) {
      return null;
    }
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrl);
    if (requestUri == null) {
      loadInitializationData(dataSource, representation, extractorWrapper, initializationUri);
      requestUri = indexUri;
    }
  } else {
    requestUri = initializationUri;
  }
  loadInitializationData(dataSource, representation, extractorWrapper, requestUri);
  return extractorWrapper;
}
 
Example #23
Source File: DashUtil.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Loads initialization data for the {@code representation} and optionally index data then returns
 * a {@link ChunkExtractorWrapper} which contains the output.
 *
 * @param dataSource The source from which the data should be loaded.
 * @param trackType The type of the representation. Typically one of the {@link
 *     com.google.android.exoplayer2.C} {@code TRACK_TYPE_*} constants.
 * @param representation The representation which initialization chunk belongs to.
 * @param loadIndex Whether to load index data too.
 * @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
 *     initialization or (if requested) index data exists.
 * @throws IOException Thrown when there is an error while loading.
 * @throws InterruptedException Thrown if the thread was interrupted.
 */
@Nullable
private static ChunkExtractorWrapper loadInitializationData(
    DataSource dataSource, int trackType, Representation representation, boolean loadIndex)
    throws IOException, InterruptedException {
  RangedUri initializationUri = representation.getInitializationUri();
  if (initializationUri == null) {
    return null;
  }
  ChunkExtractorWrapper extractorWrapper = newWrappedExtractor(trackType, representation.format);
  RangedUri requestUri;
  if (loadIndex) {
    RangedUri indexUri = representation.getIndexUri();
    if (indexUri == null) {
      return null;
    }
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrl);
    if (requestUri == null) {
      loadInitializationData(dataSource, representation, extractorWrapper, initializationUri);
      requestUri = indexUri;
    }
  } else {
    requestUri = initializationUri;
  }
  loadInitializationData(dataSource, representation, extractorWrapper, requestUri);
  return extractorWrapper;
}
 
Example #24
Source File: DashUtil.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static void loadInitializationData(DataSource dataSource,
    Representation representation, ChunkExtractorWrapper extractorWrapper, RangedUri requestUri)
    throws IOException, InterruptedException {
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(representation.baseUrl),
      requestUri.start, requestUri.length, representation.getCacheKey());
  InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec,
      representation.format, C.SELECTION_REASON_UNKNOWN, null /* trackSelectionData */,
      extractorWrapper);
  initializationChunk.load();
}
 
Example #25
Source File: DashUtil.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static ChunkExtractorWrapper newWrappedExtractor(int trackType, Format format) {
  String mimeType = format.containerMimeType;
  boolean isWebm =
      mimeType != null
          && (mimeType.startsWith(MimeTypes.VIDEO_WEBM)
              || mimeType.startsWith(MimeTypes.AUDIO_WEBM));
  Extractor extractor = isWebm ? new MatroskaExtractor() : new FragmentedMp4Extractor();
  return new ChunkExtractorWrapper(extractor, trackType, format);
}
 
Example #26
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 #27
Source File: DefaultSsChunkSource.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static MediaChunk newMediaChunk(
    Format format,
    DataSource dataSource,
    Uri uri,
    String cacheKey,
    int chunkIndex,
    long chunkStartTimeUs,
    long chunkEndTimeUs,
    long chunkSeekTimeUs,
    int trackSelectionReason,
    Object trackSelectionData,
    ChunkExtractorWrapper extractorWrapper) {
  DataSpec dataSpec = new DataSpec(uri, 0, C.LENGTH_UNSET, cacheKey);
  // In SmoothStreaming each chunk contains sample timestamps relative to the start of the chunk.
  // To convert them the absolute timestamps, we need to set sampleOffsetUs to chunkStartTimeUs.
  long sampleOffsetUs = chunkStartTimeUs;
  return new ContainerMediaChunk(
      dataSource,
      dataSpec,
      format,
      trackSelectionReason,
      trackSelectionData,
      chunkStartTimeUs,
      chunkEndTimeUs,
      chunkSeekTimeUs,
      /* clippedEndTimeUs= */ C.TIME_UNSET,
      chunkIndex,
      /* chunkCount= */ 1,
      sampleOffsetUs,
      extractorWrapper);
}
 
Example #28
Source File: DefaultDashChunkSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private RepresentationHolder(
    long periodDurationUs,
    Representation representation,
    @Nullable ChunkExtractorWrapper extractorWrapper,
    long segmentNumShift,
    @Nullable DashSegmentIndex segmentIndex) {
  this.periodDurationUs = periodDurationUs;
  this.representation = representation;
  this.segmentNumShift = segmentNumShift;
  this.extractorWrapper = extractorWrapper;
  this.segmentIndex = segmentIndex;
}
 
Example #29
Source File: DashUtil.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads initialization data for the {@code representation} and optionally index data then returns
 * a {@link ChunkExtractorWrapper} which contains the output.
 *
 * @param dataSource The source from which the data should be loaded.
 * @param trackType The type of the representation. Typically one of the {@link
 *     com.google.android.exoplayer2.C} {@code TRACK_TYPE_*} constants.
 * @param representation The representation which initialization chunk belongs to.
 * @param loadIndex Whether to load index data too.
 * @return A {@link ChunkExtractorWrapper} for the {@code representation}, or null if no
 *     initialization or (if requested) index data exists.
 * @throws IOException Thrown when there is an error while loading.
 * @throws InterruptedException Thrown if the thread was interrupted.
 */
private static @Nullable ChunkExtractorWrapper loadInitializationData(
    DataSource dataSource, int trackType, Representation representation, boolean loadIndex)
    throws IOException, InterruptedException {
  RangedUri initializationUri = representation.getInitializationUri();
  if (initializationUri == null) {
    return null;
  }
  ChunkExtractorWrapper extractorWrapper = newWrappedExtractor(trackType, representation.format);
  RangedUri requestUri;
  if (loadIndex) {
    RangedUri indexUri = representation.getIndexUri();
    if (indexUri == null) {
      return null;
    }
    // It's common for initialization and index data to be stored adjacently. Attempt to merge
    // the two requests together to request both at once.
    requestUri = initializationUri.attemptMerge(indexUri, representation.baseUrl);
    if (requestUri == null) {
      loadInitializationData(dataSource, representation, extractorWrapper, initializationUri);
      requestUri = indexUri;
    }
  } else {
    requestUri = initializationUri;
  }
  loadInitializationData(dataSource, representation, extractorWrapper, requestUri);
  return extractorWrapper;
}
 
Example #30
Source File: DashUtil.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static void loadInitializationData(DataSource dataSource,
    Representation representation, ChunkExtractorWrapper extractorWrapper, RangedUri requestUri)
    throws IOException, InterruptedException {
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(representation.baseUrl),
      requestUri.start, requestUri.length, representation.getCacheKey());
  InitializationChunk initializationChunk = new InitializationChunk(dataSource, dataSpec,
      representation.format, C.SELECTION_REASON_UNKNOWN, null /* trackSelectionData */,
      extractorWrapper);
  initializationChunk.load();
}