com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor Java Examples

The following examples show how to use com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor. 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: DefaultHlsExtractorFactory.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private static FragmentedMp4Extractor createFragmentedMp4Extractor(
    TimestampAdjuster timestampAdjuster,
    Format format,
    DrmInitData drmInitData,
    @Nullable List<Format> muxedCaptionFormats) {
  boolean isVariant = false;
  for (int i = 0; i < format.metadata.length(); i++) {
    Metadata.Entry entry = format.metadata.get(i);
    if (entry instanceof HlsTrackMetadataEntry) {
      isVariant = !((HlsTrackMetadataEntry) entry).variantInfos.isEmpty();
      break;
    }
  }
  // Only enable the EMSG TrackOutput if this is the 'variant' track (i.e. the main one) to avoid
  // creating a separate EMSG track for every audio track in a video stream.
  return new FragmentedMp4Extractor(
      /* flags= */ isVariant ? FragmentedMp4Extractor.FLAG_ENABLE_EMSG_TRACK : 0,
      timestampAdjuster,
      /* sideloadedTrack= */ null,
      drmInitData,
      muxedCaptionFormats != null ? muxedCaptionFormats : Collections.emptyList());
}
 
Example #2
Source File: DefaultHlsExtractorFactory.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private static FragmentedMp4Extractor createFragmentedMp4Extractor(
    TimestampAdjuster timestampAdjuster,
    Format format,
    DrmInitData drmInitData,
    @Nullable List<Format> muxedCaptionFormats) {
  boolean isVariant = false;
  for (int i = 0; i < format.metadata.length(); i++) {
    Metadata.Entry entry = format.metadata.get(i);
    if (entry instanceof HlsTrackMetadataEntry) {
      isVariant = !((HlsTrackMetadataEntry) entry).variantInfos.isEmpty();
      break;
    }
  }
  // Only enable the EMSG TrackOutput if this is the 'variant' track (i.e. the main one) to avoid
  // creating a separate EMSG track for every audio track in a video stream.
  return new FragmentedMp4Extractor(
      /* flags= */ isVariant ? FragmentedMp4Extractor.FLAG_ENABLE_EMSG_TRACK : 0,
      timestampAdjuster,
      /* sideloadedTrack= */ null,
      drmInitData,
      muxedCaptionFormats != null ? muxedCaptionFormats : Collections.emptyList());
}
 
Example #3
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 #4
Source File: DefaultExtractorsFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized Extractor[] createExtractors() {
  Extractor[] extractors = new Extractor[FLAC_EXTRACTOR_CONSTRUCTOR == null ? 12 : 13];
  extractors[0] = new MatroskaExtractor(matroskaFlags);
  extractors[1] = new FragmentedMp4Extractor(fragmentedMp4Flags);
  extractors[2] = new Mp4Extractor(mp4Flags);
  extractors[3] = new Mp3Extractor(mp3Flags);
  extractors[4] = new AdtsExtractor();
  extractors[5] = new Ac3Extractor();
  extractors[6] = new TsExtractor(tsMode, tsFlags);
  extractors[7] = new FlvExtractor();
  extractors[8] = new OggExtractor();
  extractors[9] = new PsExtractor();
  extractors[10] = new WavExtractor();
  extractors[11] = new AmrExtractor();
  if (FLAC_EXTRACTOR_CONSTRUCTOR != null) {
    try {
      extractors[12] = FLAC_EXTRACTOR_CONSTRUCTOR.newInstance();
    } catch (Exception e) {
      // Should never happen.
      throw new IllegalStateException("Unexpected error creating FLAC extractor", e);
    }
  }
  return extractors;
}
 
Example #5
Source File: DefaultExtractorsFactory.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public synchronized Extractor[] createExtractors() {
  Extractor[] extractors = new Extractor[FLAC_EXTRACTOR_CONSTRUCTOR == null ? 12 : 13];
  extractors[0] = new MatroskaExtractor(matroskaFlags);
  extractors[1] = new FragmentedMp4Extractor(fragmentedMp4Flags);
  extractors[2] = new Mp4Extractor(mp4Flags);
  extractors[3] = new Mp3Extractor(mp3Flags);
  extractors[4] = new AdtsExtractor();
  extractors[5] = new Ac3Extractor();
  extractors[6] = new TsExtractor(tsMode, tsFlags);
  extractors[7] = new FlvExtractor();
  extractors[8] = new OggExtractor();
  extractors[9] = new PsExtractor();
  extractors[10] = new WavExtractor();
  extractors[11] = new AmrExtractor();
  if (FLAC_EXTRACTOR_CONSTRUCTOR != null) {
    try {
      extractors[12] = FLAC_EXTRACTOR_CONSTRUCTOR.newInstance();
    } catch (Exception e) {
      // Should never happen.
      throw new IllegalStateException("Unexpected error creating FLAC extractor", e);
    }
  }
  return extractors;
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
Source File: DefaultHlsExtractorFactory.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static FragmentedMp4Extractor createFragmentedMp4Extractor(
    TimestampAdjuster timestampAdjuster,
    Format format,
    @Nullable DrmInitData drmInitData,
    @Nullable List<Format> muxedCaptionFormats) {
  // Only enable the EMSG TrackOutput if this is the 'variant' track (i.e. the main one) to avoid
  // creating a separate EMSG track for every audio track in a video stream.
  return new FragmentedMp4Extractor(
      /* flags= */ isFmp4Variant(format) ? FragmentedMp4Extractor.FLAG_ENABLE_EMSG_TRACK : 0,
      timestampAdjuster,
      /* sideloadedTrack= */ null,
      drmInitData,
      muxedCaptionFormats != null ? muxedCaptionFormats : Collections.emptyList());
}
 
Example #16
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 #17
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 #18
Source File: DefaultExtractorsFactory.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized Extractor[] createExtractors() {
  Extractor[] extractors = new Extractor[FLAC_EXTRACTOR_CONSTRUCTOR == null ? 13 : 14];
  extractors[0] = new MatroskaExtractor(matroskaFlags);
  extractors[1] = new FragmentedMp4Extractor(fragmentedMp4Flags);
  extractors[2] = new Mp4Extractor(mp4Flags);
  extractors[3] =
      new Mp3Extractor(
          mp3Flags
              | (constantBitrateSeekingEnabled
                  ? Mp3Extractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
                  : 0));
  extractors[4] =
      new AdtsExtractor(
          adtsFlags
              | (constantBitrateSeekingEnabled
                  ? AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
                  : 0));
  extractors[5] = new Ac3Extractor();
  extractors[6] = new TsExtractor(tsMode, tsFlags);
  extractors[7] = new FlvExtractor();
  extractors[8] = new OggExtractor();
  extractors[9] = new PsExtractor();
  extractors[10] = new WavExtractor();
  extractors[11] =
      new AmrExtractor(
          amrFlags
              | (constantBitrateSeekingEnabled
                  ? AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
                  : 0));
  extractors[12] = new Ac4Extractor();
  if (FLAC_EXTRACTOR_CONSTRUCTOR != null) {
    try {
      extractors[13] = FLAC_EXTRACTOR_CONSTRUCTOR.newInstance();
    } catch (Exception e) {
      // Should never happen.
      throw new IllegalStateException("Unexpected error creating FLAC extractor", e);
    }
  }
  return extractors;
}
 
Example #19
Source File: DefaultHlsExtractorFactory.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
@Override
public Result createExtractor(
    @Nullable Extractor previousExtractor,
    Uri uri,
    Format format,
    @Nullable List<Format> muxedCaptionFormats,
    @Nullable DrmInitData drmInitData,
    TimestampAdjuster timestampAdjuster,
    Map<String, List<String>> responseHeaders,
    ExtractorInput extractorInput)
    throws InterruptedException, IOException {

  if (previousExtractor != null) {
    // A extractor has already been successfully used. Return one of the same type.
    if (isReusable(previousExtractor)) {
      return buildResult(previousExtractor);
    } else {
      Result result =
          buildResultForSameExtractorType(previousExtractor, format, timestampAdjuster);
      if (result == null) {
        throw new IllegalArgumentException(
            "Unexpected previousExtractor type: " + previousExtractor.getClass().getSimpleName());
      }
    }
  }

  // Try selecting the extractor by the file extension.
  Extractor extractorByFileExtension =
      createExtractorByFileExtension(
          uri, format, muxedCaptionFormats, drmInitData, timestampAdjuster);
  extractorInput.resetPeekPosition();
  if (sniffQuietly(extractorByFileExtension, extractorInput)) {
    return buildResult(extractorByFileExtension);
  }

  // We need to manually sniff each known type, without retrying the one selected by file
  // extension.

  if (!(extractorByFileExtension instanceof WebvttExtractor)) {
    WebvttExtractor webvttExtractor = new WebvttExtractor(format.language, timestampAdjuster);
    if (sniffQuietly(webvttExtractor, extractorInput)) {
      return buildResult(webvttExtractor);
    }
  }

  if (!(extractorByFileExtension instanceof AdtsExtractor)) {
    AdtsExtractor adtsExtractor = new AdtsExtractor();
    if (sniffQuietly(adtsExtractor, extractorInput)) {
      return buildResult(adtsExtractor);
    }
  }

  if (!(extractorByFileExtension instanceof Ac3Extractor)) {
    Ac3Extractor ac3Extractor = new Ac3Extractor();
    if (sniffQuietly(ac3Extractor, extractorInput)) {
      return buildResult(ac3Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof Ac4Extractor)) {
    Ac4Extractor ac4Extractor = new Ac4Extractor();
    if (sniffQuietly(ac4Extractor, extractorInput)) {
      return buildResult(ac4Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof Mp3Extractor)) {
    Mp3Extractor mp3Extractor =
        new Mp3Extractor(/* flags= */ 0, /* forcedFirstSampleTimestampUs= */ 0);
    if (sniffQuietly(mp3Extractor, extractorInput)) {
      return buildResult(mp3Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof FragmentedMp4Extractor)) {
    FragmentedMp4Extractor fragmentedMp4Extractor =
        createFragmentedMp4Extractor(timestampAdjuster, format, drmInitData, muxedCaptionFormats);
    if (sniffQuietly(fragmentedMp4Extractor, extractorInput)) {
      return buildResult(fragmentedMp4Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof TsExtractor)) {
    TsExtractor tsExtractor =
        createTsExtractor(
            payloadReaderFactoryFlags,
            exposeCea608WhenMissingDeclarations,
            format,
            muxedCaptionFormats,
            timestampAdjuster);
    if (sniffQuietly(tsExtractor, extractorInput)) {
      return buildResult(tsExtractor);
    }
  }

  // Fall back on the extractor created by file extension.
  return buildResult(extractorByFileExtension);
}
 
Example #20
Source File: DefaultHlsExtractorFactory.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isReusable(Extractor previousExtractor) {
  return previousExtractor instanceof TsExtractor
      || previousExtractor instanceof FragmentedMp4Extractor;
}
 
Example #21
Source File: DefaultHlsExtractorFactory.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Result createExtractor(
    Extractor previousExtractor,
    Uri uri,
    Format format,
    List<Format> muxedCaptionFormats,
    DrmInitData drmInitData,
    TimestampAdjuster timestampAdjuster,
    Map<String, List<String>> responseHeaders,
    ExtractorInput extractorInput)
    throws InterruptedException, IOException {

  if (previousExtractor != null) {
    // A extractor has already been successfully used. Return one of the same type.
    if (isReusable(previousExtractor)) {
      return buildResult(previousExtractor);
    } else {
      Result result =
          buildResultForSameExtractorType(previousExtractor, format, timestampAdjuster);
      if (result == null) {
        throw new IllegalArgumentException(
            "Unexpected previousExtractor type: " + previousExtractor.getClass().getSimpleName());
      }
    }
  }

  // Try selecting the extractor by the file extension.
  Extractor extractorByFileExtension =
      createExtractorByFileExtension(
          uri, format, muxedCaptionFormats, drmInitData, timestampAdjuster);
  extractorInput.resetPeekPosition();
  if (sniffQuietly(extractorByFileExtension, extractorInput)) {
    return buildResult(extractorByFileExtension);
  }

  // We need to manually sniff each known type, without retrying the one selected by file
  // extension.

  if (!(extractorByFileExtension instanceof WebvttExtractor)) {
    WebvttExtractor webvttExtractor = new WebvttExtractor(format.language, timestampAdjuster);
    if (sniffQuietly(webvttExtractor, extractorInput)) {
      return buildResult(webvttExtractor);
    }
  }

  if (!(extractorByFileExtension instanceof AdtsExtractor)) {
    AdtsExtractor adtsExtractor = new AdtsExtractor();
    if (sniffQuietly(adtsExtractor, extractorInput)) {
      return buildResult(adtsExtractor);
    }
  }

  if (!(extractorByFileExtension instanceof Ac3Extractor)) {
    Ac3Extractor ac3Extractor = new Ac3Extractor();
    if (sniffQuietly(ac3Extractor, extractorInput)) {
      return buildResult(ac3Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof Ac4Extractor)) {
    Ac4Extractor ac4Extractor = new Ac4Extractor();
    if (sniffQuietly(ac4Extractor, extractorInput)) {
      return buildResult(ac4Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof Mp3Extractor)) {
    Mp3Extractor mp3Extractor =
        new Mp3Extractor(/* flags= */ 0, /* forcedFirstSampleTimestampUs= */ 0);
    if (sniffQuietly(mp3Extractor, extractorInput)) {
      return buildResult(mp3Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof FragmentedMp4Extractor)) {
    FragmentedMp4Extractor fragmentedMp4Extractor =
        createFragmentedMp4Extractor(timestampAdjuster, format, drmInitData, muxedCaptionFormats);
    if (sniffQuietly(fragmentedMp4Extractor, extractorInput)) {
      return buildResult(fragmentedMp4Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof TsExtractor)) {
    TsExtractor tsExtractor =
        createTsExtractor(
            payloadReaderFactoryFlags,
            exposeCea608WhenMissingDeclarations,
            format,
            muxedCaptionFormats,
            timestampAdjuster);
    if (sniffQuietly(tsExtractor, extractorInput)) {
      return buildResult(tsExtractor);
    }
  }

  // Fall back on the extractor created by file extension.
  return buildResult(extractorByFileExtension);
}
 
Example #22
Source File: DefaultExtractorsFactory.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized Extractor[] createExtractors() {
  Extractor[] extractors = new Extractor[FLAC_EXTRACTOR_CONSTRUCTOR == null ? 13 : 14];
  extractors[0] = new MatroskaExtractor(matroskaFlags);
  extractors[1] = new FragmentedMp4Extractor(fragmentedMp4Flags);
  extractors[2] = new Mp4Extractor(mp4Flags);
  extractors[3] = new OggExtractor();
  extractors[4] =
      new Mp3Extractor(
          mp3Flags
              | (constantBitrateSeekingEnabled
                  ? Mp3Extractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
                  : 0));
  extractors[5] =
      new AdtsExtractor(
          /* firstStreamSampleTimestampUs= */ 0,
          adtsFlags
              | (constantBitrateSeekingEnabled
                  ? AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
                  : 0));
  extractors[6] = new Ac3Extractor();
  extractors[7] = new TsExtractor(tsMode, tsFlags);
  extractors[8] = new FlvExtractor();
  extractors[9] = new PsExtractor();
  extractors[10] = new WavExtractor();
  extractors[11] =
      new AmrExtractor(
          amrFlags
              | (constantBitrateSeekingEnabled
                  ? AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
                  : 0));
  extractors[12] = new Ac4Extractor();
  if (FLAC_EXTRACTOR_CONSTRUCTOR != null) {
    try {
      extractors[13] = FLAC_EXTRACTOR_CONSTRUCTOR.newInstance();
    } catch (Exception e) {
      // Should never happen.
      throw new IllegalStateException("Unexpected error creating FLAC extractor", e);
    }
  }
  return extractors;
}
 
Example #23
Source File: DefaultHlsExtractorFactory.java    From MediaSDK with Apache License 2.0 4 votes vote down vote up
private static boolean isReusable(Extractor previousExtractor) {
  return previousExtractor instanceof TsExtractor
      || previousExtractor instanceof FragmentedMp4Extractor;
}
 
Example #24
Source File: DefaultHlsExtractorFactory.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private static boolean isReusable(Extractor previousExtractor) {
  return previousExtractor instanceof TsExtractor
      || previousExtractor instanceof FragmentedMp4Extractor;
}
 
Example #25
Source File: DefaultHlsExtractorFactory.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Result createExtractor(
    Extractor previousExtractor,
    Uri uri,
    Format format,
    List<Format> muxedCaptionFormats,
    DrmInitData drmInitData,
    TimestampAdjuster timestampAdjuster,
    Map<String, List<String>> responseHeaders,
    ExtractorInput extractorInput)
    throws InterruptedException, IOException {

  if (previousExtractor != null) {
    // A extractor has already been successfully used. Return one of the same type.
    if (isReusable(previousExtractor)) {
      return buildResult(previousExtractor);
    } else {
      Result result =
          buildResultForSameExtractorType(previousExtractor, format, timestampAdjuster);
      if (result == null) {
        throw new IllegalArgumentException(
            "Unexpected previousExtractor type: " + previousExtractor.getClass().getSimpleName());
      }
    }
  }

  // Try selecting the extractor by the file extension.
  Extractor extractorByFileExtension =
      createExtractorByFileExtension(
          uri, format, muxedCaptionFormats, drmInitData, timestampAdjuster);
  extractorInput.resetPeekPosition();
  if (sniffQuietly(extractorByFileExtension, extractorInput)) {
    return buildResult(extractorByFileExtension);
  }

  // We need to manually sniff each known type, without retrying the one selected by file
  // extension.

  if (!(extractorByFileExtension instanceof WebvttExtractor)) {
    WebvttExtractor webvttExtractor = new WebvttExtractor(format.language, timestampAdjuster);
    if (sniffQuietly(webvttExtractor, extractorInput)) {
      return buildResult(webvttExtractor);
    }
  }

  if (!(extractorByFileExtension instanceof AdtsExtractor)) {
    AdtsExtractor adtsExtractor = new AdtsExtractor();
    if (sniffQuietly(adtsExtractor, extractorInput)) {
      return buildResult(adtsExtractor);
    }
  }

  if (!(extractorByFileExtension instanceof Ac3Extractor)) {
    Ac3Extractor ac3Extractor = new Ac3Extractor();
    if (sniffQuietly(ac3Extractor, extractorInput)) {
      return buildResult(ac3Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof Ac4Extractor)) {
    Ac4Extractor ac4Extractor = new Ac4Extractor();
    if (sniffQuietly(ac4Extractor, extractorInput)) {
      return buildResult(ac4Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof Mp3Extractor)) {
    Mp3Extractor mp3Extractor =
        new Mp3Extractor(/* flags= */ 0, /* forcedFirstSampleTimestampUs= */ 0);
    if (sniffQuietly(mp3Extractor, extractorInput)) {
      return buildResult(mp3Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof FragmentedMp4Extractor)) {
    FragmentedMp4Extractor fragmentedMp4Extractor =
        createFragmentedMp4Extractor(timestampAdjuster, format, drmInitData, muxedCaptionFormats);
    if (sniffQuietly(fragmentedMp4Extractor, extractorInput)) {
      return buildResult(fragmentedMp4Extractor);
    }
  }

  if (!(extractorByFileExtension instanceof TsExtractor)) {
    TsExtractor tsExtractor =
        createTsExtractor(
            payloadReaderFactoryFlags,
            exposeCea608WhenMissingDeclarations,
            format,
            muxedCaptionFormats,
            timestampAdjuster);
    if (sniffQuietly(tsExtractor, extractorInput)) {
      return buildResult(tsExtractor);
    }
  }

  // Fall back on the extractor created by file extension.
  return buildResult(extractorByFileExtension);
}
 
Example #26
Source File: DefaultExtractorsFactory.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public synchronized Extractor[] createExtractors() {
  Extractor[] extractors = new Extractor[FLAC_EXTRACTOR_CONSTRUCTOR == null ? 13 : 14];
  extractors[0] = new MatroskaExtractor(matroskaFlags);
  extractors[1] = new FragmentedMp4Extractor(fragmentedMp4Flags);
  extractors[2] = new Mp4Extractor(mp4Flags);
  extractors[3] = new OggExtractor();
  extractors[4] =
      new Mp3Extractor(
          mp3Flags
              | (constantBitrateSeekingEnabled
                  ? Mp3Extractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
                  : 0));
  extractors[5] =
      new AdtsExtractor(
          /* firstStreamSampleTimestampUs= */ 0,
          adtsFlags
              | (constantBitrateSeekingEnabled
                  ? AdtsExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
                  : 0));
  extractors[6] = new Ac3Extractor();
  extractors[7] = new TsExtractor(tsMode, tsFlags);
  extractors[8] = new FlvExtractor();
  extractors[9] = new PsExtractor();
  extractors[10] = new WavExtractor();
  extractors[11] =
      new AmrExtractor(
          amrFlags
              | (constantBitrateSeekingEnabled
                  ? AmrExtractor.FLAG_ENABLE_CONSTANT_BITRATE_SEEKING
                  : 0));
  extractors[12] = new Ac4Extractor();
  if (FLAC_EXTRACTOR_CONSTRUCTOR != null) {
    try {
      extractors[13] = FLAC_EXTRACTOR_CONSTRUCTOR.newInstance();
    } catch (Exception e) {
      // Should never happen.
      throw new IllegalStateException("Unexpected error creating FLAC extractor", e);
    }
  }
  return extractors;
}
 
Example #27
Source File: DefaultExtractorsFactory.java    From Telegram with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets flags for {@link FragmentedMp4Extractor} instances created by the factory.
 *
 * @see FragmentedMp4Extractor#FragmentedMp4Extractor(int)
 * @param flags The flags to use.
 * @return The factory, for convenience.
 */
public synchronized DefaultExtractorsFactory setFragmentedMp4ExtractorFlags(
    @FragmentedMp4Extractor.Flags int flags) {
  this.fragmentedMp4Flags = flags;
  return this;
}
 
Example #28
Source File: DefaultExtractorsFactory.java    From Telegram-FOSS with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets flags for {@link FragmentedMp4Extractor} instances created by the factory.
 *
 * @see FragmentedMp4Extractor#FragmentedMp4Extractor(int)
 * @param flags The flags to use.
 * @return The factory, for convenience.
 */
public synchronized DefaultExtractorsFactory setFragmentedMp4ExtractorFlags(
    @FragmentedMp4Extractor.Flags int flags) {
  this.fragmentedMp4Flags = flags;
  return this;
}
 
Example #29
Source File: DefaultExtractorsFactory.java    From TelePlus-Android with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets flags for {@link FragmentedMp4Extractor} instances created by the factory.
 *
 * @see FragmentedMp4Extractor#FragmentedMp4Extractor(int)
 * @param flags The flags to use.
 * @return The factory, for convenience.
 */
public synchronized DefaultExtractorsFactory setFragmentedMp4ExtractorFlags(
    @FragmentedMp4Extractor.Flags int flags) {
  this.fragmentedMp4Flags = flags;
  return this;
}
 
Example #30
Source File: DefaultExtractorsFactory.java    From MediaSDK with Apache License 2.0 2 votes vote down vote up
/**
 * Sets flags for {@link FragmentedMp4Extractor} instances created by the factory.
 *
 * @see FragmentedMp4Extractor#FragmentedMp4Extractor(int)
 * @param flags The flags to use.
 * @return The factory, for convenience.
 */
public synchronized DefaultExtractorsFactory setFragmentedMp4ExtractorFlags(
    @FragmentedMp4Extractor.Flags int flags) {
  this.fragmentedMp4Flags = flags;
  return this;
}