com.google.android.exoplayer2.upstream.DataSource Java Examples

The following examples show how to use com.google.android.exoplayer2.upstream.DataSource. 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: DashMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance to play the manifest at a given {@link Uri}, which may be dynamic or
 * static.
 *
 * @param manifestUri The manifest {@link Uri}.
 * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used
 *     to load (and refresh) the manifest.
 * @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the
 *     default start position should precede the end of the live window. Use {@link
 *     #DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS} to use the value specified by the
 *     manifest, if present.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
@SuppressWarnings("deprecation")
public DashMediaSource(
    Uri manifestUri,
    DataSource.Factory manifestDataSourceFactory,
    DashChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    long livePresentationDelayMs,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(
      manifestUri,
      manifestDataSourceFactory,
      new DashManifestParser(),
      chunkSourceFactory,
      minLoadableRetryCount,
      livePresentationDelayMs,
      eventHandler,
      eventListener);
}
 
Example #2
Source File: DefaultDashChunkSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
protected Chunk newInitializationChunk(
    RepresentationHolder representationHolder,
    DataSource dataSource,
    Format trackFormat,
    int trackSelectionReason,
    Object trackSelectionData,
    RangedUri initializationUri,
    RangedUri indexUri) {
  RangedUri requestUri;
  String baseUrl = representationHolder.representation.baseUrl;
  if (initializationUri != 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, baseUrl);
    if (requestUri == null) {
      requestUri = initializationUri;
    }
  } else {
    requestUri = indexUri;
  }
  DataSpec dataSpec = new DataSpec(requestUri.resolveUri(baseUrl), requestUri.start,
      requestUri.length, representationHolder.representation.getCacheKey());
  return new InitializationChunk(dataSource, dataSpec, trackFormat,
      trackSelectionReason, trackSelectionData, representationHolder.extractorWrapper);
}
 
Example #3
Source File: MediaSourceBuilder.java    From ARVI with Apache License 2.0 6 votes vote down vote up
@NonNull @Override
public MediaSource buildMediaSource(@NonNull Context context,
                                    @NonNull Uri fileUri,
                                    @Nullable String fileExtension,
                                    @Nullable Handler handler,
                                    @NonNull DataSource.Factory manifestDataSourceFactory,
                                    @NonNull DataSource.Factory mediaDataSourceFactory,
                                    @Nullable MediaSourceEventListener eventListener) {
    return new LoopingMediaSource(DEFAULT.buildMediaSource(
        context,
        fileUri,
        fileExtension,
        handler,
        manifestDataSourceFactory,
        mediaDataSourceFactory,
        eventListener
    ));
}
 
Example #4
Source File: SingleSampleMediaChunk.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param dataSource The source from which the data should be loaded.
 * @param dataSpec Defines the data to be loaded.
 * @param trackFormat See {@link #trackFormat}.
 * @param trackSelectionReason See {@link #trackSelectionReason}.
 * @param trackSelectionData See {@link #trackSelectionData}.
 * @param startTimeUs The start time of the media contained by the chunk, in microseconds.
 * @param endTimeUs The end time of the media contained by the chunk, in microseconds.
 * @param chunkIndex The index of the chunk, or {@link C#INDEX_UNSET} if it is not known.
 * @param trackType The type of the chunk. Typically one of the {@link C} {@code TRACK_TYPE_*}
 *     constants.
 * @param sampleFormat The {@link Format} of the sample in the chunk.
 */
public SingleSampleMediaChunk(
    DataSource dataSource,
    DataSpec dataSpec,
    Format trackFormat,
    int trackSelectionReason,
    Object trackSelectionData,
    long startTimeUs,
    long endTimeUs,
    long chunkIndex,
    int trackType,
    Format sampleFormat) {
  super(
      dataSource,
      dataSpec,
      trackFormat,
      trackSelectionReason,
      trackSelectionData,
      startTimeUs,
      endTimeUs,
      /* clippedStartTimeUs= */ C.TIME_UNSET,
      /* clippedEndTimeUs= */ C.TIME_UNSET,
      chunkIndex);
  this.trackType = trackType;
  this.sampleFormat = sampleFormat;
}
 
Example #5
Source File: PlayerTextureView.java    From Mp4Composer-android with MIT License 6 votes vote down vote up
public PlayerTextureView(Context context, String path) {
    super(context, null, 0);

    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "yourApplicationName"));

    // This is the MediaSource representing the media to be played.
    MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
            .createMediaSource(Uri.parse(path));

    LoopingMediaSource loopingMediaSource = new LoopingMediaSource(videoSource);


    // SimpleExoPlayer
    player = ExoPlayerFactory.newSimpleInstance(context);
    // Prepare the player with the source.
    player.prepare(loopingMediaSource);
    player.addVideoListener(this);

    setSurfaceTextureListener(this);
}
 
Example #6
Source File: Chunk.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * @param dataSource The source from which the data should be loaded.
 * @param dataSpec Defines the data to be loaded.
 * @param type See {@link #type}.
 * @param trackFormat See {@link #trackFormat}.
 * @param trackSelectionReason See {@link #trackSelectionReason}.
 * @param trackSelectionData See {@link #trackSelectionData}.
 * @param startTimeUs See {@link #startTimeUs}.
 * @param endTimeUs See {@link #endTimeUs}.
 */
public Chunk(
    DataSource dataSource,
    DataSpec dataSpec,
    int type,
    Format trackFormat,
    int trackSelectionReason,
    @Nullable Object trackSelectionData,
    long startTimeUs,
    long endTimeUs) {
  this.dataSource = new StatsDataSource(dataSource);
  this.dataSpec = Assertions.checkNotNull(dataSpec);
  this.type = type;
  this.trackFormat = trackFormat;
  this.trackSelectionReason = trackSelectionReason;
  this.trackSelectionData = trackSelectionData;
  this.startTimeUs = startTimeUs;
  this.endTimeUs = endTimeUs;
}
 
Example #7
Source File: SingleSampleMediaChunk.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param dataSource The source from which the data should be loaded.
 * @param dataSpec Defines the data to be loaded.
 * @param trackFormat See {@link #trackFormat}.
 * @param trackSelectionReason See {@link #trackSelectionReason}.
 * @param trackSelectionData See {@link #trackSelectionData}.
 * @param startTimeUs The start time of the media contained by the chunk, in microseconds.
 * @param endTimeUs The end time of the media contained by the chunk, in microseconds.
 * @param chunkIndex The index of the chunk, or {@link C#INDEX_UNSET} if it is not known.
 * @param trackType The type of the chunk. Typically one of the {@link C} {@code TRACK_TYPE_*}
 *     constants.
 * @param sampleFormat The {@link Format} of the sample in the chunk.
 */
public SingleSampleMediaChunk(
    DataSource dataSource,
    DataSpec dataSpec,
    Format trackFormat,
    int trackSelectionReason,
    Object trackSelectionData,
    long startTimeUs,
    long endTimeUs,
    long chunkIndex,
    int trackType,
    Format sampleFormat) {
  super(
      dataSource,
      dataSpec,
      trackFormat,
      trackSelectionReason,
      trackSelectionData,
      startTimeUs,
      endTimeUs,
      /* clippedStartTimeUs= */ C.TIME_UNSET,
      /* clippedEndTimeUs= */ C.TIME_UNSET,
      chunkIndex);
  this.trackType = trackType;
  this.sampleFormat = sampleFormat;
}
 
Example #8
Source File: DownloaderConstructorHelper.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a new {@link CacheDataSource} instance. If {@code offline} is true, it can only read
 * data from the cache.
 */
public CacheDataSource buildCacheDataSource(boolean offline) {
  DataSource cacheReadDataSource = cacheReadDataSourceFactory != null
      ? cacheReadDataSourceFactory.createDataSource() : new FileDataSource();
  if (offline) {
    return new CacheDataSource(cache, DummyDataSource.INSTANCE,
        cacheReadDataSource, null, CacheDataSource.FLAG_BLOCK_ON_CACHE, null);
  } else {
    DataSink cacheWriteDataSink = cacheWriteDataSinkFactory != null
        ? cacheWriteDataSinkFactory.createDataSink()
        : new CacheDataSink(cache, CacheDataSource.DEFAULT_MAX_CACHE_FILE_SIZE);
    DataSource upstream = upstreamDataSourceFactory.createDataSource();
    upstream = priorityTaskManager == null ? upstream
        : new PriorityDataSource(upstream, priorityTaskManager, C.PRIORITY_DOWNLOAD);
    return new CacheDataSource(cache, upstream, cacheReadDataSource,
        cacheWriteDataSink, CacheDataSource.FLAG_BLOCK_ON_CACHE, null);
  }
}
 
Example #9
Source File: SingleSampleMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public SingleSampleMediaPeriod(
    DataSpec dataSpec,
    DataSource.Factory dataSourceFactory,
    @Nullable TransferListener transferListener,
    Format format,
    long durationUs,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    EventDispatcher eventDispatcher,
    boolean treatLoadErrorsAsEndOfStream) {
  this.dataSpec = dataSpec;
  this.dataSourceFactory = dataSourceFactory;
  this.transferListener = transferListener;
  this.format = format;
  this.durationUs = durationUs;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.eventDispatcher = eventDispatcher;
  this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream;
  tracks = new TrackGroupArray(new TrackGroup(format));
  sampleStreams = new ArrayList<>();
  loader = new Loader("Loader:SingleSampleMediaPeriod");
  eventDispatcher.mediaPeriodCreated();
}
 
Example #10
Source File: ExtractorMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  progressiveMediaSource =
      new ProgressiveMediaSource(
          uri,
          dataSourceFactory,
          extractorsFactory,
          DrmSessionManager.getDummyDrmSessionManager(),
          loadableLoadErrorHandlingPolicy,
          customCacheKey,
          continueLoadingCheckIntervalBytes,
          tag);
}
 
Example #11
Source File: CacheDataSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance with arbitrary {@link DataSource} and {@link DataSink} instances for
 * reading and writing the cache. One use of this constructor is to allow data to be transformed
 * before it is written to disk.
 *
 * @param cache The cache.
 * @param upstream A {@link DataSource} for reading data not in the cache.
 * @param cacheReadDataSource A {@link DataSource} for reading data from the cache.
 * @param cacheWriteDataSink A {@link DataSink} for writing data to the cache. If null, cache is
 *     accessed read-only.
 * @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR}
 *     and {@link #FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}, or 0.
 * @param eventListener An optional {@link EventListener} to receive events.
 * @param cacheKeyFactory An optional factory for cache keys.
 */
public CacheDataSource(
    Cache cache,
    DataSource upstream,
    DataSource cacheReadDataSource,
    @Nullable DataSink cacheWriteDataSink,
    @Flags int flags,
    @Nullable EventListener eventListener,
    @Nullable CacheKeyFactory cacheKeyFactory) {
  this.cache = cache;
  this.cacheReadDataSource = cacheReadDataSource;
  this.cacheKeyFactory =
      cacheKeyFactory != null ? cacheKeyFactory : CacheUtil.DEFAULT_CACHE_KEY_FACTORY;
  this.blockOnCache = (flags & FLAG_BLOCK_ON_CACHE) != 0;
  this.ignoreCacheOnError = (flags & FLAG_IGNORE_CACHE_ON_ERROR) != 0;
  this.ignoreCacheForUnsetLengthRequests =
      (flags & FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS) != 0;
  this.upstreamDataSource = upstream;
  if (cacheWriteDataSink != null) {
    this.cacheWriteDataSource = new TeeDataSource(upstream, cacheWriteDataSink);
  } else {
    this.cacheWriteDataSource = null;
  }
  this.eventListener = eventListener;
}
 
Example #12
Source File: ExtractorMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory A factory for {@link DataSource}s to read the media.
 * @param extractorsFactory A factory for {@link Extractor}s to process the media stream. If the
 *     possible formats are known, pass a factory that instantiates extractors for those formats.
 *     Otherwise, pass a {@link DefaultExtractorsFactory} to use default extractors.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 * @param continueLoadingCheckIntervalBytes The number of bytes that should be loaded between each
 *     invocation of {@link MediaPeriod.Callback#onContinueLoadingRequested(SequenceableLoader)}.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public ExtractorMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    Handler eventHandler,
    EventListener eventListener,
    String customCacheKey,
    int continueLoadingCheckIntervalBytes) {
  this(
      uri,
      dataSourceFactory,
      extractorsFactory,
      new DefaultLoadErrorHandlingPolicy(),
      customCacheKey,
      continueLoadingCheckIntervalBytes,
      /* tag= */ null);
  if (eventListener != null && eventHandler != null) {
    addEventListener(eventHandler, new EventListenerWrapper(eventListener));
  }
}
 
Example #13
Source File: SingleSampleMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSourceFactory The factory from which the {@link DataSource} to read the media will
 *     be obtained.
 * @param format The {@link Format} associated with the output track.
 * @param durationUs The duration of the media stream in microseconds.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @param eventSourceId An identifier that gets passed to {@code eventListener} methods.
 * @param treatLoadErrorsAsEndOfStream If true, load errors will not be propagated by sample
 *     streams, treating them as ended instead. If false, load errors will be propagated normally
 *     by {@link SampleStream#maybeThrowError()}.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public SingleSampleMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    Format format,
    long durationUs,
    int minLoadableRetryCount,
    Handler eventHandler,
    EventListener eventListener,
    int eventSourceId,
    boolean treatLoadErrorsAsEndOfStream) {
  this(
      uri,
      dataSourceFactory,
      format,
      durationUs,
      minLoadableRetryCount,
      treatLoadErrorsAsEndOfStream,
      /* tag= */ null);
  if (eventHandler != null && eventListener != null) {
    addEventListener(eventHandler, new EventListenerWrapper(eventListener, eventSourceId));
  }
}
 
Example #14
Source File: CacheDataSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance with arbitrary {@link DataSource} and {@link DataSink} instances for
 * reading and writing the cache. One use of this constructor is to allow data to be transformed
 * before it is written to disk.
 *
 * @param cache The cache.
 * @param upstream A {@link DataSource} for reading data not in the cache.
 * @param cacheReadDataSource A {@link DataSource} for reading data from the cache.
 * @param cacheWriteDataSink A {@link DataSink} for writing data to the cache. If null, cache is
 *     accessed read-only.
 * @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR}
 *     and {@link #FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}, or 0.
 * @param eventListener An optional {@link EventListener} to receive events.
 */
public CacheDataSource(
    Cache cache,
    DataSource upstream,
    DataSource cacheReadDataSource,
    @Nullable DataSink cacheWriteDataSink,
    @Flags int flags,
    @Nullable EventListener eventListener) {
  this(
      cache,
      upstream,
      cacheReadDataSource,
      cacheWriteDataSink,
      flags,
      eventListener,
      /* cacheKeyFactory= */ null);
}
 
Example #15
Source File: ProgressiveMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
ProgressiveMediaSource(
    Uri uri,
    DataSource.Factory dataSourceFactory,
    ExtractorsFactory extractorsFactory,
    LoadErrorHandlingPolicy loadableLoadErrorHandlingPolicy,
    @Nullable String customCacheKey,
    int continueLoadingCheckIntervalBytes,
    @Nullable Object tag) {
  this.uri = uri;
  this.dataSourceFactory = dataSourceFactory;
  this.extractorsFactory = extractorsFactory;
  this.loadableLoadErrorHandlingPolicy = loadableLoadErrorHandlingPolicy;
  this.customCacheKey = customCacheKey;
  this.continueLoadingCheckIntervalBytes = continueLoadingCheckIntervalBytes;
  this.timelineDurationUs = C.TIME_UNSET;
  this.tag = tag;
}
 
Example #16
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 #17
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 #18
Source File: Chunk.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @param dataSource The source from which the data should be loaded.
 * @param dataSpec Defines the data to be loaded.
 * @param type See {@link #type}.
 * @param trackFormat See {@link #trackFormat}.
 * @param trackSelectionReason See {@link #trackSelectionReason}.
 * @param trackSelectionData See {@link #trackSelectionData}.
 * @param startTimeUs See {@link #startTimeUs}.
 * @param endTimeUs See {@link #endTimeUs}.
 */
public Chunk(
    DataSource dataSource,
    DataSpec dataSpec,
    int type,
    Format trackFormat,
    int trackSelectionReason,
    @Nullable Object trackSelectionData,
    long startTimeUs,
    long endTimeUs) {
  this.dataSource = new StatsDataSource(dataSource);
  this.dataSpec = Assertions.checkNotNull(dataSpec);
  this.type = type;
  this.trackFormat = trackFormat;
  this.trackSelectionReason = trackSelectionReason;
  this.trackSelectionData = trackSelectionData;
  this.startTimeUs = startTimeUs;
  this.endTimeUs = endTimeUs;
}
 
Example #19
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs an instance to play the manifest at a given {@link Uri}, which may be dynamic or
 * static.
 *
 * @param manifestUri The manifest {@link Uri}.
 * @param manifestDataSourceFactory A factory for {@link DataSource} instances that will be used
 *     to load (and refresh) the manifest.
 * @param chunkSourceFactory A factory for {@link DashChunkSource} instances.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param livePresentationDelayMs For live playbacks, the duration in milliseconds by which the
 *     default start position should precede the end of the live window. Use {@link
 *     #DEFAULT_LIVE_PRESENTATION_DELAY_PREFER_MANIFEST_MS} to use the value specified by the
 *     manifest, if present.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A listener of events. May be null if delivery of events is not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
@SuppressWarnings("deprecation")
public DashMediaSource(
    Uri manifestUri,
    DataSource.Factory manifestDataSourceFactory,
    DashChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount,
    long livePresentationDelayMs,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(
      manifestUri,
      manifestDataSourceFactory,
      new DashManifestParser(),
      chunkSourceFactory,
      minLoadableRetryCount,
      livePresentationDelayMs,
      eventHandler,
      eventListener);
}
 
Example #20
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/** @deprecated Use {@link #forDash(Context, Uri, Factory, RenderersFactory)} */
@Deprecated
public static DownloadHelper forDash(
    Uri uri, DataSource.Factory dataSourceFactory, RenderersFactory renderersFactory) {
  return forDash(
      uri,
      dataSourceFactory,
      renderersFactory,
      /* drmSessionManager= */ null,
      DEFAULT_TRACK_SELECTOR_PARAMETERS_WITHOUT_VIEWPORT);
}
 
Example #21
Source File: ContainerMediaChunk.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param dataSource The source from which the data should be loaded.
 * @param dataSpec Defines the data to be loaded.
 * @param trackFormat See {@link #trackFormat}.
 * @param trackSelectionReason See {@link #trackSelectionReason}.
 * @param trackSelectionData See {@link #trackSelectionData}.
 * @param startTimeUs The start time of the media contained by the chunk, in microseconds.
 * @param endTimeUs The end time of the media contained by the chunk, in microseconds.
 * @param seekTimeUs The media time from which output will begin, or {@link C#TIME_UNSET} if the
 *     whole chunk should be output.
 * @param chunkIndex The index of the chunk, or {@link C#INDEX_UNSET} if it is not known.
 * @param chunkCount The number of chunks in the underlying media that are spanned by this
 *     instance. Normally equal to one, but may be larger if multiple chunks as defined by the
 *     underlying media are being merged into a single load.
 * @param sampleOffsetUs An offset to add to the sample timestamps parsed by the extractor.
 * @param extractorWrapper A wrapped extractor to use for parsing the data.
 */
public ContainerMediaChunk(
    DataSource dataSource,
    DataSpec dataSpec,
    Format trackFormat,
    int trackSelectionReason,
    Object trackSelectionData,
    long startTimeUs,
    long endTimeUs,
    long seekTimeUs,
    long chunkIndex,
    int chunkCount,
    long sampleOffsetUs,
    ChunkExtractorWrapper extractorWrapper) {
  super(
      dataSource,
      dataSpec,
      trackFormat,
      trackSelectionReason,
      trackSelectionData,
      startTimeUs,
      endTimeUs,
      seekTimeUs,
      chunkIndex);
  this.chunkCount = chunkCount;
  this.sampleOffsetUs = sampleOffsetUs;
  this.extractorWrapper = extractorWrapper;
}
 
Example #22
Source File: HlsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param manifestUri The {@link Uri} of the HLS manifest.
 * @param dataSourceFactory An {@link HlsDataSourceFactory} for {@link DataSource}s for manifests,
 *     segments and keys.
 * @param eventHandler A handler for events. May be null if delivery of events is not required.
 * @param eventListener A {@link MediaSourceEventListener}. May be null if delivery of events is
 *     not required.
 * @deprecated Use {@link Factory} instead.
 */
@Deprecated
public HlsMediaSource(
    Uri manifestUri,
    DataSource.Factory dataSourceFactory,
    Handler eventHandler,
    MediaSourceEventListener eventListener) {
  this(manifestUri, dataSourceFactory, DEFAULT_MIN_LOADABLE_RETRY_COUNT, eventHandler,
      eventListener);
}
 
Example #23
Source File: DownloadManager.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link DownloadManager}.
 *
 * @param cache Cache instance to be used to store downloaded data.
 * @param upstreamDataSourceFactory A {@link DataSource.Factory} for creating data sources for
 *     downloading upstream data.
 * @param actionSaveFile File to save active actions.
 * @param deserializers Used to deserialize {@link DownloadAction}s. If empty, {@link
 *     DownloadAction#getDefaultDeserializers()} is used instead.
 */
public DownloadManager(
    Cache cache,
    DataSource.Factory upstreamDataSourceFactory,
    File actionSaveFile,
    Deserializer... deserializers) {
  this(
      new DownloaderConstructorHelper(cache, upstreamDataSourceFactory),
      actionSaveFile,
      deserializers);
}
 
Example #24
Source File: ExtractorMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public ExtractingLoadable(Uri uri, DataSource dataSource, ExtractorHolder extractorHolder,
    ConditionVariable loadCondition) {
  this.uri = Assertions.checkNotNull(uri);
  this.dataSource = new StatsDataSource(dataSource);
  this.extractorHolder = Assertions.checkNotNull(extractorHolder);
  this.loadCondition = loadCondition;
  this.positionHolder = new PositionHolder();
  this.pendingExtractorSeek = true;
  this.length = C.LENGTH_UNSET;
  dataSpec = new DataSpec(uri, positionHolder.position, C.LENGTH_UNSET, customCacheKey);
}
 
Example #25
Source File: HlsMediaChunk.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * If the segment is fully encrypted, returns an {@link Aes128DataSource} that wraps the original
 * in order to decrypt the loaded data. Else returns the original.
 */
private static DataSource buildDataSource(DataSource dataSource, byte[] fullSegmentEncryptionKey,
    byte[] encryptionIv) {
  if (fullSegmentEncryptionKey != null) {
    return new Aes128DataSource(dataSource, fullSegmentEncryptionKey, encryptionIv);
  }
  return dataSource;
}
 
Example #26
Source File: BaseMeter.java    From ARVI with Apache License 2.0 5 votes vote down vote up
@Override
public final void onTransferEnd(DataSource dataSource,
                                DataSpec dataSpec,
                                boolean isNetwork) {
    this.transferListener.onTransferEnd(
        dataSource,
        dataSpec,
        isNetwork
    );
}
 
Example #27
Source File: DownloadHelper.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link DownloadHelper} for HLS streams.
 *
 * @param context Any {@link Context}.
 * @param uri A playlist {@link Uri}.
 * @param dataSourceFactory A {@link DataSource.Factory} used to load the playlist.
 * @param renderersFactory A {@link RenderersFactory} creating the renderers for which tracks are
 *     selected.
 * @return A {@link DownloadHelper} for HLS streams.
 * @throws IllegalStateException If the HLS module is missing.
 */
public static DownloadHelper forHls(
    Context context,
    Uri uri,
    DataSource.Factory dataSourceFactory,
    RenderersFactory renderersFactory) {
  return forHls(
      uri,
      dataSourceFactory,
      renderersFactory,
      /* drmSessionManager= */ null,
      getDefaultTrackSelectorParameters(context));
}
 
Example #28
Source File: ExtendedDefaultDataSource.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private DataSource getEncryptedFileDataSource() {
    if (encryptedFileDataSource == null) {
        encryptedFileDataSource = new EncryptedFileDataSource();
        addListenersToDataSource(encryptedFileDataSource);
    }
    return encryptedFileDataSource;
}
 
Example #29
Source File: CacheDataSource.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs an instance with default {@link DataSource} and {@link DataSink} instances for
 * reading and writing the cache.
 *
 * @param cache The cache.
 * @param upstream A {@link DataSource} for reading data not in the cache.
 * @param flags A combination of {@link #FLAG_BLOCK_ON_CACHE}, {@link #FLAG_IGNORE_CACHE_ON_ERROR}
 *     and {@link #FLAG_IGNORE_CACHE_FOR_UNSET_LENGTH_REQUESTS}, or 0.
 */
public CacheDataSource(Cache cache, DataSource upstream, @Flags int flags) {
  this(
      cache,
      upstream,
      new FileDataSource(),
      new CacheDataSink(cache, CacheDataSink.DEFAULT_FRAGMENT_SIZE),
      flags,
      /* eventListener= */ null);
}
 
Example #30
Source File: Chunk.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * @param dataSource The source from which the data should be loaded.
 * @param dataSpec Defines the data to be loaded.
 * @param type See {@link #type}.
 * @param trackFormat See {@link #trackFormat}.
 * @param trackSelectionReason See {@link #trackSelectionReason}.
 * @param trackSelectionData See {@link #trackSelectionData}.
 * @param startTimeUs See {@link #startTimeUs}.
 * @param endTimeUs See {@link #endTimeUs}.
 */
public Chunk(DataSource dataSource, DataSpec dataSpec, int type, Format trackFormat,
    int trackSelectionReason, Object trackSelectionData, long startTimeUs, long endTimeUs) {
  this.dataSource = Assertions.checkNotNull(dataSource);
  this.dataSpec = Assertions.checkNotNull(dataSpec);
  this.type = type;
  this.trackFormat = trackFormat;
  this.trackSelectionReason = trackSelectionReason;
  this.trackSelectionData = trackSelectionData;
  this.startTimeUs = startTimeUs;
  this.endTimeUs = endTimeUs;
}