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

The following examples show how to use com.google.android.exoplayer2.upstream.Loader. 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: DefaultHlsPlaylistTracker.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<HlsPlaylist> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(
          loadable.type, loadDurationMs, error, errorCount);
  boolean isFatal = retryDelayMs == C.TIME_UNSET;
  eventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      C.DATA_TYPE_MANIFEST,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      isFatal);
  return isFatal
      ? Loader.DONT_RETRY_FATAL
      : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
}
 
Example #2
Source File: DashMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
LoadErrorAction onManifestLoadError(
    ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(
          C.DATA_TYPE_MANIFEST, loadDurationMs, error, errorCount);
  LoadErrorAction loadErrorAction =
      retryDelayMs == C.TIME_UNSET
          ? Loader.DONT_RETRY_FATAL
          : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      !loadErrorAction.isRetry());
  return loadErrorAction;
}
 
Example #3
Source File: DashMediaSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
LoadErrorAction onManifestLoadError(
    ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(
          C.DATA_TYPE_MANIFEST, loadDurationMs, error, errorCount);
  LoadErrorAction loadErrorAction =
      retryDelayMs == C.TIME_UNSET
          ? Loader.DONT_RETRY_FATAL
          : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      !loadErrorAction.isRetry());
  return loadErrorAction;
}
 
Example #4
Source File: SingleSampleMediaPeriod.java    From MediaSDK with Apache License 2.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 #5
Source File: DefaultHlsPlaylistTracker.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<HlsPlaylist> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(
          loadable.type, loadDurationMs, error, errorCount);
  boolean isFatal = retryDelayMs == C.TIME_UNSET;
  eventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      C.DATA_TYPE_MANIFEST,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      isFatal);
  return isFatal
      ? Loader.DONT_RETRY_FATAL
      : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
}
 
Example #6
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 #7
Source File: SingleSampleMediaPeriod.java    From Telegram 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 #8
Source File: SsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<SsManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(
          C.DATA_TYPE_MANIFEST, loadDurationMs, error, errorCount);
  LoadErrorAction loadErrorAction =
      retryDelayMs == C.TIME_UNSET
          ? Loader.DONT_RETRY_FATAL
          : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      !loadErrorAction.isRetry());
  return loadErrorAction;
}
 
Example #9
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<HlsPlaylist> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      playlistLoadErrorHandlingPolicy.getRetryDelayMsFor(
          loadable, loadDurationMs, error, errorCount);
  boolean isFatal = retryDelayMs == C.TIME_UNSET;
  eventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      C.DATA_TYPE_MANIFEST,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      isFatal);
  return isFatal
      ? Loader.DONT_RETRY_FATAL
      : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
}
 
Example #10
Source File: HlsSampleStreamWrapper.java    From K-Sonic with MIT License 6 votes vote down vote up
/**
 * @param trackType The type of the track. One of the {@link C} {@code TRACK_TYPE_*} constants.
 * @param callback A callback for the wrapper.
 * @param chunkSource A {@link HlsChunkSource} from which chunks to load are obtained.
 * @param allocator An {@link Allocator} from which to obtain media buffer allocations.
 * @param positionUs The position from which to start loading media.
 * @param muxedAudioFormat Optional muxed audio {@link Format} as defined by the master playlist.
 * @param minLoadableRetryCount The minimum number of times that the source should retry a load
 *     before propagating an error.
 * @param eventDispatcher A dispatcher to notify of events.
 */
public HlsSampleStreamWrapper(int trackType, Callback callback, HlsChunkSource chunkSource,
    Allocator allocator, long positionUs, Format muxedAudioFormat, int minLoadableRetryCount,
    EventDispatcher eventDispatcher) {
  this.trackType = trackType;
  this.callback = callback;
  this.chunkSource = chunkSource;
  this.allocator = allocator;
  this.muxedAudioFormat = muxedAudioFormat;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  loader = new Loader("Loader:HlsSampleStreamWrapper");
  nextChunkHolder = new HlsChunkSource.HlsChunkHolder();
  sampleQueues = new SparseArray<>();
  mediaChunks = new LinkedList<>();
  maybeFinishPrepareRunnable = new Runnable() {
    @Override
    public void run() {
      maybeFinishPrepare();
    }
  };
  handler = new Handler();
  lastSeekPositionUs = positionUs;
  pendingResetPositionUs = positionUs;
}
 
Example #11
Source File: HlsPlaylistTracker.java    From K-Sonic with MIT License 6 votes vote down vote up
@Override
public int onLoadError(ParsingLoadable<HlsPlaylist> loadable, long elapsedRealtimeMs,
    long loadDurationMs, IOException error) {
  boolean isFatal = error instanceof ParserException;
  eventDispatcher.loadError(loadable.dataSpec, C.DATA_TYPE_MANIFEST, elapsedRealtimeMs,
      loadDurationMs, loadable.bytesLoaded(), error, isFatal);
  if (isFatal) {
    return Loader.DONT_RETRY_FATAL;
  }
  boolean shouldRetry = true;
  if (ChunkedTrackBlacklistUtil.shouldBlacklist(error)) {
    blacklistUntilMs =
        SystemClock.elapsedRealtime() + ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS;
    notifyPlaylistBlacklisting(playlistUrl,
        ChunkedTrackBlacklistUtil.DEFAULT_TRACK_BLACKLIST_MS);
    shouldRetry = primaryHlsUrl == playlistUrl && !maybeSelectNewPrimaryUrl();
  }
  return shouldRetry ? Loader.RETRY : Loader.DONT_RETRY;
}
 
Example #12
Source File: SingleSampleMediaPeriod.java    From TelePlus-Android 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,
    int minLoadableRetryCount,
    EventDispatcher eventDispatcher,
    boolean treatLoadErrorsAsEndOfStream) {
  this.dataSpec = dataSpec;
  this.dataSourceFactory = dataSourceFactory;
  this.transferListener = transferListener;
  this.format = format;
  this.durationUs = durationUs;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream;
  tracks = new TrackGroupArray(new TrackGroup(format));
  sampleStreams = new ArrayList<>();
  loader = new Loader("Loader:SingleSampleMediaPeriod");
  eventDispatcher.mediaPeriodCreated();
}
 
Example #13
Source File: DashMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
LoadErrorAction onUtcTimestampLoadError(
    ParsingLoadable<Long> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error) {
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      true);
  onUtcTimestampResolutionError(error);
  return Loader.DONT_RETRY;
}
 
Example #14
Source File: SingleSampleMediaPeriod.java    From TelePlus-Android 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,
    int minLoadableRetryCount,
    EventDispatcher eventDispatcher,
    boolean treatLoadErrorsAsEndOfStream) {
  this.dataSpec = dataSpec;
  this.dataSourceFactory = dataSourceFactory;
  this.transferListener = transferListener;
  this.format = format;
  this.durationUs = durationUs;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.treatLoadErrorsAsEndOfStream = treatLoadErrorsAsEndOfStream;
  tracks = new TrackGroupArray(new TrackGroup(format));
  sampleStreams = new ArrayList<>();
  loader = new Loader("Loader:SingleSampleMediaPeriod");
  eventDispatcher.mediaPeriodCreated();
}
 
Example #15
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
LoadErrorAction onManifestLoadError(
    ParsingLoadable<DashManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error) {
  boolean isFatal = error instanceof ParserException;
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      isFatal);
  return isFatal ? Loader.DONT_RETRY_FATAL : Loader.RETRY;
}
 
Example #16
Source File: DefaultHlsPlaylistTracker.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<HlsPlaylist> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      playlistLoadErrorHandlingPolicy.getRetryDelayMsFor(
          loadable, loadDurationMs, error, errorCount);
  boolean isFatal = retryDelayMs == C.TIME_UNSET;
  eventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      C.DATA_TYPE_MANIFEST,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      isFatal);
  return isFatal
      ? Loader.DONT_RETRY_FATAL
      : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
}
 
Example #17
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<SsManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  boolean isFatal = error instanceof ParserException;
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      isFatal);
  return isFatal ? Loader.DONT_RETRY_FATAL : Loader.RETRY;
}
 
Example #18
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void prepareSourceInternal(
    ExoPlayer player,
    boolean isTopLevelSource,
    @Nullable TransferListener mediaTransferListener) {
  this.mediaTransferListener = mediaTransferListener;
  if (sideloadedManifest) {
    manifestLoaderErrorThrower = new LoaderErrorThrower.Dummy();
    processManifest();
  } else {
    manifestDataSource = manifestDataSourceFactory.createDataSource();
    manifestLoader = new Loader("Loader:Manifest");
    manifestLoaderErrorThrower = manifestLoader;
    manifestRefreshHandler = new Handler();
    startLoadingManifest();
  }
}
 
Example #19
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void prepareSourceInternal(
    ExoPlayer player,
    boolean isTopLevelSource,
    @Nullable TransferListener mediaTransferListener) {
  this.mediaTransferListener = mediaTransferListener;
  if (sideloadedManifest) {
    manifestLoaderErrorThrower = new LoaderErrorThrower.Dummy();
    processManifest();
  } else {
    manifestDataSource = manifestDataSourceFactory.createDataSource();
    manifestLoader = new Loader("Loader:Manifest");
    manifestLoaderErrorThrower = manifestLoader;
    manifestRefreshHandler = new Handler();
    startLoadingManifest();
  }
}
 
Example #20
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
LoadErrorAction onUtcTimestampLoadError(
    ParsingLoadable<Long> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error) {
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      true);
  onUtcTimestampResolutionError(error);
  return Loader.DONT_RETRY;
}
 
Example #21
Source File: DefaultHlsPlaylistTracker.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<HlsPlaylist> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(
          loadable.type, loadDurationMs, error, errorCount);
  boolean isFatal = retryDelayMs == C.TIME_UNSET;
  eventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      C.DATA_TYPE_MANIFEST,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      isFatal);
  return isFatal
      ? Loader.DONT_RETRY_FATAL
      : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
}
 
Example #22
Source File: SsMediaSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ParsingLoadable<SsManifest> loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(
          C.DATA_TYPE_MANIFEST, loadDurationMs, error, errorCount);
  LoadErrorAction loadErrorAction =
      retryDelayMs == C.TIME_UNSET
          ? Loader.DONT_RETRY_FATAL
          : Loader.createRetryAction(/* resetErrorCount= */ false, retryDelayMs);
  manifestEventDispatcher.loadError(
      loadable.dataSpec,
      loadable.getUri(),
      loadable.getResponseHeaders(),
      loadable.type,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.bytesLoaded(),
      error,
      !loadErrorAction.isRetry());
  return loadErrorAction;
}
 
Example #23
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepareSourceInternal(
    ExoPlayer player,
    boolean isTopLevelSource,
    @Nullable TransferListener mediaTransferListener) {
  this.mediaTransferListener = mediaTransferListener;
  if (sideloadedManifest) {
    processManifest(false);
  } else {
    dataSource = manifestDataSourceFactory.createDataSource();
    loader = new Loader("Loader:DashMediaSource");
    handler = new Handler();
    startLoadingManifest();
  }
}
 
Example #24
Source File: SsMediaSource.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public int onLoadError(ParsingLoadable<SsManifest> loadable, long elapsedRealtimeMs,
    long loadDurationMs, IOException error) {
  boolean isFatal = error instanceof ParserException;
  eventDispatcher.loadError(loadable.dataSpec, loadable.type, elapsedRealtimeMs, loadDurationMs,
      loadable.bytesLoaded(), error, isFatal);
  return isFatal ? Loader.DONT_RETRY_FATAL : Loader.RETRY;
}
 
Example #25
Source File: ProgressiveMediaPeriod.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ExtractingLoadable loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  copyLengthFromLoader(loadable);
  LoadErrorAction loadErrorAction;
  long retryDelayMs =
      loadErrorHandlingPolicy.getRetryDelayMsFor(dataType, loadDurationMs, error, errorCount);
  if (retryDelayMs == C.TIME_UNSET) {
    loadErrorAction = Loader.DONT_RETRY_FATAL;
  } else /* the load should be retried */ {
    int extractedSamplesCount = getExtractedSamplesCount();
    boolean madeProgress = extractedSamplesCount > extractedSamplesCountAtStartOfLoad;
    loadErrorAction =
        configureRetry(loadable, extractedSamplesCount)
            ? Loader.createRetryAction(/* resetErrorCount= */ madeProgress, retryDelayMs)
            : Loader.DONT_RETRY;
  }

  eventDispatcher.loadError(
      loadable.dataSpec,
      loadable.dataSource.getLastOpenedUri(),
      loadable.dataSource.getLastResponseHeaders(),
      C.DATA_TYPE_MEDIA,
      C.TRACK_TYPE_UNKNOWN,
      /* trackFormat= */ null,
      C.SELECTION_REASON_UNKNOWN,
      /* trackSelectionData= */ null,
      /* mediaStartTimeUs= */ loadable.seekTimeUs,
      durationUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.dataSource.getBytesRead(),
      error,
      !loadErrorAction.isRetry());
  return loadErrorAction;
}
 
Example #26
Source File: DefaultHlsPlaylistTracker.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public MediaPlaylistBundle(Uri playlistUrl) {
  this.playlistUrl = playlistUrl;
  mediaPlaylistLoader = new Loader("DefaultHlsPlaylistTracker:MediaPlaylist");
  mediaPlaylistLoadable =
      new ParsingLoadable<>(
          dataSourceFactory.createDataSource(C.DATA_TYPE_MANIFEST),
          playlistUrl,
          C.DATA_TYPE_MANIFEST,
          mediaPlaylistParser);
}
 
Example #27
Source File: HlsSampleStreamWrapper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param trackType The type of the track. One of the {@link C} {@code TRACK_TYPE_*} constants.
 * @param callback A callback for the wrapper.
 * @param chunkSource A {@link HlsChunkSource} from which chunks to load are obtained.
 * @param overridingDrmInitData Overriding {@link DrmInitData}, keyed by protection scheme type
 *     (i.e. {@link DrmInitData#schemeType}). If the stream has {@link DrmInitData} and uses a
 *     protection scheme type for which overriding {@link DrmInitData} is provided, then the
 *     stream's {@link DrmInitData} will be overridden.
 * @param allocator An {@link Allocator} from which to obtain media buffer allocations.
 * @param positionUs The position from which to start loading media.
 * @param muxedAudioFormat Optional muxed audio {@link Format} as defined by the master playlist.
 * @param loadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy}.
 * @param eventDispatcher A dispatcher to notify of events.
 */
public HlsSampleStreamWrapper(
    int trackType,
    Callback callback,
    HlsChunkSource chunkSource,
    Map<String, DrmInitData> overridingDrmInitData,
    Allocator allocator,
    long positionUs,
    Format muxedAudioFormat,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    EventDispatcher eventDispatcher,
    @HlsMetadataType int metadataType) {
  this.trackType = trackType;
  this.callback = callback;
  this.chunkSource = chunkSource;
  this.overridingDrmInitData = overridingDrmInitData;
  this.allocator = allocator;
  this.muxedAudioFormat = muxedAudioFormat;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.eventDispatcher = eventDispatcher;
  this.metadataType = metadataType;
  loader = new Loader("Loader:HlsSampleStreamWrapper");
  nextChunkHolder = new HlsChunkSource.HlsChunkHolder();
  sampleQueueTrackIds = new int[0];
  sampleQueueMappingDoneByType = new HashSet<>(MAPPABLE_TYPES.size());
  sampleQueueIndicesByType = new SparseIntArray(MAPPABLE_TYPES.size());
  sampleQueues = new SampleQueue[0];
  sampleQueueIsAudioVideoFlags = new boolean[0];
  sampleQueuesEnabledStates = new boolean[0];
  mediaChunks = new ArrayList<>();
  readOnlyMediaChunks = Collections.unmodifiableList(mediaChunks);
  hlsSampleStreams = new ArrayList<>();
  maybeFinishPrepareRunnable = this::maybeFinishPrepare;
  onTracksEndedRunnable = this::onTracksEnded;
  handler = new Handler();
  lastSeekPositionUs = positionUs;
  pendingResetPositionUs = positionUs;
}
 
Example #28
Source File: ChunkSampleStream.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public int onLoadError(Chunk loadable, long elapsedRealtimeMs, long loadDurationMs,
    IOException error) {
  long bytesLoaded = loadable.bytesLoaded();
  boolean isMediaChunk = isMediaChunk(loadable);
  boolean cancelable = !isMediaChunk || bytesLoaded == 0 || mediaChunks.size() > 1;
  boolean canceled = false;
  if (chunkSource.onChunkLoadError(loadable, cancelable, error)) {
    canceled = true;
    if (isMediaChunk) {
      BaseMediaChunk removed = mediaChunks.removeLast();
      Assertions.checkState(removed == loadable);
      primarySampleQueue.discardUpstreamSamples(removed.getFirstSampleIndex(0));
      for (int i = 0; i < embeddedSampleQueues.length; i++) {
        embeddedSampleQueues[i].discardUpstreamSamples(removed.getFirstSampleIndex(i + 1));
      }
      if (mediaChunks.isEmpty()) {
        pendingResetPositionUs = lastSeekPositionUs;
      }
    }
  }
  eventDispatcher.loadError(loadable.dataSpec, loadable.type, primaryTrackType,
      loadable.trackFormat, loadable.trackSelectionReason, loadable.trackSelectionData,
      loadable.startTimeUs, loadable.endTimeUs, elapsedRealtimeMs, loadDurationMs, bytesLoaded,
      error, canceled);
  if (canceled) {
    callback.onContinueLoadingRequested(this);
    return Loader.DONT_RETRY;
  } else {
    return Loader.RETRY;
  }
}
 
Example #29
Source File: ExtractorMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public LoadErrorAction onLoadError(
    ExtractingLoadable loadable,
    long elapsedRealtimeMs,
    long loadDurationMs,
    IOException error,
    int errorCount) {
  copyLengthFromLoader(loadable);
  LoadErrorAction retryAction;
  if (isLoadableExceptionFatal(error)) {
    retryAction = Loader.DONT_RETRY_FATAL;
  } else {
    int extractedSamplesCount = getExtractedSamplesCount();
    boolean madeProgress = extractedSamplesCount > extractedSamplesCountAtStartOfLoad;
    retryAction =
        configureRetry(loadable, extractedSamplesCount)
            ? (madeProgress ? Loader.RETRY_RESET_ERROR_COUNT : Loader.RETRY)
            : Loader.DONT_RETRY;
  }
  boolean wasCanceled =
      retryAction == Loader.DONT_RETRY || retryAction == Loader.DONT_RETRY_FATAL;
  eventDispatcher.loadError(
      loadable.dataSpec,
      loadable.dataSource.getLastOpenedUri(),
      C.DATA_TYPE_MEDIA,
      C.TRACK_TYPE_UNKNOWN,
      /* trackFormat= */ null,
      C.SELECTION_REASON_UNKNOWN,
      /* trackSelectionData= */ null,
      /* mediaStartTimeUs= */ loadable.seekTimeUs,
      durationUs,
      elapsedRealtimeMs,
      loadDurationMs,
      loadable.dataSource.getBytesRead(),
      error,
      wasCanceled);
  return retryAction;
}
 
Example #30
Source File: ExtractorMediaPeriod.java    From K-Sonic with MIT License 5 votes vote down vote up
/**
 * @param uri The {@link Uri} of the media stream.
 * @param dataSource The data source to read the media.
 * @param extractors The extractors to use to read the data source.
 * @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 sourceListener A listener to notify when the timeline has been loaded.
 * @param allocator An {@link Allocator} from which to obtain media buffer allocations.
 * @param customCacheKey A custom key that uniquely identifies the original stream. Used for cache
 *     indexing. May be null.
 */
public ExtractorMediaPeriod(Uri uri, DataSource dataSource, Extractor[] extractors,
    int minLoadableRetryCount, Handler eventHandler,
    ExtractorMediaSource.EventListener eventListener, MediaSource.Listener sourceListener,
    Allocator allocator, String customCacheKey) {
  this.uri = uri;
  this.dataSource = dataSource;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventHandler = eventHandler;
  this.eventListener = eventListener;
  this.sourceListener = sourceListener;
  this.allocator = allocator;
  this.customCacheKey = customCacheKey;
  loader = new Loader("Loader:ExtractorMediaPeriod");
  extractorHolder = new ExtractorHolder(extractors, this);
  loadCondition = new ConditionVariable();
  maybeFinishPrepareRunnable = new Runnable() {
    @Override
    public void run() {
      maybeFinishPrepare();
    }
  };
  onContinueLoadingRequestedRunnable = new Runnable() {
    @Override
    public void run() {
      if (!released) {
        callback.onContinueLoadingRequested(ExtractorMediaPeriod.this);
      }
    }
  };
  handler = new Handler();

  pendingResetPositionUs = C.TIME_UNSET;
  sampleQueues = new SparseArray<>();
  length = C.LENGTH_UNSET;
}