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

The following examples show how to use com.google.android.exoplayer2.upstream.Allocator. 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: HlsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  Assertions.checkArgument(id.periodIndex == 0);
  EventDispatcher eventDispatcher = createEventDispatcher(id);
  return new HlsMediaPeriod(
      extractorFactory,
      playlistTracker,
      dataSourceFactory,
      mediaTransferListener,
      chunkLoadErrorHandlingPolicy,
      minLoadableRetryCount,
      eventDispatcher,
      allocator,
      compositeSequenceableLoaderFactory,
      allowChunklessPreparation);
}
 
Example #2
Source File: DashMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(
    MediaPeriodId periodId, Allocator allocator, long startPositionUs) {
  int periodIndex = (Integer) periodId.periodUid - firstPeriodId;
  EventDispatcher periodEventDispatcher =
      createEventDispatcher(periodId, manifest.getPeriod(periodIndex).startMs);
  DashMediaPeriod mediaPeriod =
      new DashMediaPeriod(
          firstPeriodId + periodIndex,
          manifest,
          periodIndex,
          chunkSourceFactory,
          mediaTransferListener,
          drmSessionManager,
          loadErrorHandlingPolicy,
          periodEventDispatcher,
          elapsedRealtimeOffsetMs,
          manifestLoadErrorThrower,
          allocator,
          compositeSequenceableLoaderFactory,
          playerEmsgCallback);
  periodsById.put(mediaPeriod.id, mediaPeriod);
  return mediaPeriod;
}
 
Example #3
Source File: ConcatenatingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  int mediaSourceHolderIndex = findMediaSourceHolderByPeriodIndex(id.periodIndex);
  MediaSourceHolder holder = mediaSourceHolders.get(mediaSourceHolderIndex);
  DeferredMediaPeriod mediaPeriod = new DeferredMediaPeriod(holder.mediaSource, id, allocator);
  mediaSourceByMediaPeriod.put(mediaPeriod, holder);
  holder.activeMediaPeriods.add(mediaPeriod);
  if (!holder.hasStartedPreparing) {
    holder.hasStartedPreparing = true;
    prepareChildSource(holder, holder.mediaSource);
  } else if (holder.isPrepared) {
    MediaPeriodId idInSource =
        id.copyWithPeriodIndex(id.periodIndex - holder.firstPeriodIndexInChild);
    mediaPeriod.createPeriod(idInSource);
  }
  return mediaPeriod;
}
 
Example #4
Source File: ExtractorMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  Assertions.checkArgument(id.periodIndex == 0);
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new ExtractorMediaPeriod(
      uri,
      dataSource,
      extractorsFactory.createExtractors(),
      minLoadableRetryCount,
      createEventDispatcher(id),
      this,
      allocator,
      customCacheKey,
      continueLoadingCheckIntervalBytes);
}
 
Example #5
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId periodId, Allocator allocator) {
  int periodIndex = periodId.periodIndex;
  EventDispatcher periodEventDispatcher =
      createEventDispatcher(periodId, manifest.getPeriod(periodIndex).startMs);
  DashMediaPeriod mediaPeriod =
      new DashMediaPeriod(
          firstPeriodId + periodIndex,
          manifest,
          periodIndex,
          chunkSourceFactory,
          mediaTransferListener,
          minLoadableRetryCount,
          periodEventDispatcher,
          elapsedRealtimeOffsetMs,
          manifestLoadErrorThrower,
          allocator,
          compositeSequenceableLoaderFactory,
          playerEmsgCallback);
  periodsById.put(mediaPeriod.id, mediaPeriod);
  return mediaPeriod;
}
 
Example #6
Source File: ExtractorMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  Assertions.checkArgument(id.periodIndex == 0);
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new ExtractorMediaPeriod(
      uri,
      dataSource,
      extractorsFactory.createExtractors(),
      minLoadableRetryCount,
      createEventDispatcher(id),
      this,
      allocator,
      customCacheKey,
      continueLoadingCheckIntervalBytes);
}
 
Example #7
Source File: ProgressiveMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
  DataSource dataSource = dataSourceFactory.createDataSource();
  if (transferListener != null) {
    dataSource.addTransferListener(transferListener);
  }
  return new ProgressiveMediaPeriod(
      uri,
      dataSource,
      extractorsFactory.createExtractors(),
      drmSessionManager,
      loadableLoadErrorHandlingPolicy,
      createEventDispatcher(id),
      this,
      allocator,
      customCacheKey,
      continueLoadingCheckIntervalBytes);
}
 
Example #8
Source File: MaskingMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public MaskingMediaPeriod createPeriod(
    MediaPeriodId id, Allocator allocator, long startPositionUs) {
  MaskingMediaPeriod mediaPeriod =
      new MaskingMediaPeriod(mediaSource, id, allocator, startPositionUs);
  if (isPrepared) {
    MediaPeriodId idInSource = id.copyWithPeriodUid(getInternalPeriodUid(id.periodUid));
    mediaPeriod.createPeriod(idInSource);
  } else {
    // We should have at most one media period while source is unprepared because the duration is
    // unset and we don't load beyond periods with unset duration. We need to figure out how to
    // handle the prepare positions of multiple deferred media periods, should that ever change.
    unpreparedMaskingMediaPeriod = mediaPeriod;
    unpreparedMaskingMediaPeriodEventDispatcher =
        createEventDispatcher(/* windowIndex= */ 0, id, /* mediaTimeOffsetMs= */ 0);
    unpreparedMaskingMediaPeriodEventDispatcher.mediaPeriodCreated();
    if (!hasStartedPreparing) {
      hasStartedPreparing = true;
      prepareChildSource(/* id= */ null, mediaSource);
    }
  }
  return mediaPeriod;
}
 
Example #9
Source File: SsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
  EventDispatcher eventDispatcher = createEventDispatcher(id);
  SsMediaPeriod period =
      new SsMediaPeriod(
          manifest,
          chunkSourceFactory,
          mediaTransferListener,
          compositeSequenceableLoaderFactory,
          drmSessionManager,
          loadErrorHandlingPolicy,
          eventDispatcher,
          manifestLoaderErrorThrower,
          allocator);
  mediaPeriods.add(period);
  return period;
}
 
Example #10
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  Assertions.checkArgument(id.periodIndex == 0);
  EventDispatcher eventDispatcher = createEventDispatcher(id);
  SsMediaPeriod period =
      new SsMediaPeriod(
          manifest,
          chunkSourceFactory,
          mediaTransferListener,
          compositeSequenceableLoaderFactory,
          minLoadableRetryCount,
          eventDispatcher,
          manifestLoaderErrorThrower,
          allocator);
  mediaPeriods.add(period);
  return period;
}
 
Example #11
Source File: SsMediaPeriod.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
public SsMediaPeriod(
    SsManifest manifest,
    SsChunkSource.Factory chunkSourceFactory,
    @Nullable TransferListener transferListener,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    DrmSessionManager<?> drmSessionManager,
    LoadErrorHandlingPolicy loadErrorHandlingPolicy,
    EventDispatcher eventDispatcher,
    LoaderErrorThrower manifestLoaderErrorThrower,
    Allocator allocator) {
  this.manifest = manifest;
  this.chunkSourceFactory = chunkSourceFactory;
  this.transferListener = transferListener;
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.drmSessionManager = drmSessionManager;
  this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
  this.eventDispatcher = eventDispatcher;
  this.allocator = allocator;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  trackGroups = buildTrackGroups(manifest, drmSessionManager);
  sampleStreams = newSampleStreamArray(0);
  compositeSequenceableLoader =
      compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(sampleStreams);
  eventDispatcher.mediaPeriodCreated();
}
 
Example #12
Source File: DashMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId periodId, Allocator allocator) {
  int periodIndex = periodId.periodIndex;
  EventDispatcher periodEventDispatcher =
      createEventDispatcher(periodId, manifest.getPeriod(periodIndex).startMs);
  DashMediaPeriod mediaPeriod =
      new DashMediaPeriod(
          firstPeriodId + periodIndex,
          manifest,
          periodIndex,
          chunkSourceFactory,
          mediaTransferListener,
          minLoadableRetryCount,
          periodEventDispatcher,
          elapsedRealtimeOffsetMs,
          manifestLoadErrorThrower,
          allocator,
          compositeSequenceableLoaderFactory,
          playerEmsgCallback);
  periodsById.put(mediaPeriod.id, mediaPeriod);
  return mediaPeriod;
}
 
Example #13
Source File: ConcatenatingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  int mediaSourceHolderIndex = findMediaSourceHolderByPeriodIndex(id.periodIndex);
  MediaSourceHolder holder = mediaSourceHolders.get(mediaSourceHolderIndex);
  DeferredMediaPeriod mediaPeriod = new DeferredMediaPeriod(holder.mediaSource, id, allocator);
  mediaSourceByMediaPeriod.put(mediaPeriod, holder);
  holder.activeMediaPeriods.add(mediaPeriod);
  if (!holder.hasStartedPreparing) {
    holder.hasStartedPreparing = true;
    prepareChildSource(holder, holder.mediaSource);
  } else if (holder.isPrepared) {
    MediaPeriodId idInSource =
        id.copyWithPeriodIndex(id.periodIndex - holder.firstPeriodIndexInChild);
    mediaPeriod.createPeriod(idInSource);
  }
  return mediaPeriod;
}
 
Example #14
Source File: MediaPeriodHolder.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new holder with information required to play it as part of a timeline.
 *
 * @param rendererCapabilities The renderer capabilities.
 * @param rendererPositionOffsetUs The renderer time of the start of the period, in microseconds.
 * @param trackSelector The track selector.
 * @param allocator The allocator.
 * @param mediaSource The media source that produced the media period.
 * @param info Information used to identify this media period in its timeline period.
 * @param emptyTrackSelectorResult A {@link TrackSelectorResult} with empty selections for each
 *     renderer.
 */
public MediaPeriodHolder(
    RendererCapabilities[] rendererCapabilities,
    long rendererPositionOffsetUs,
    TrackSelector trackSelector,
    Allocator allocator,
    MediaSource mediaSource,
    MediaPeriodInfo info,
    TrackSelectorResult emptyTrackSelectorResult) {
  this.rendererCapabilities = rendererCapabilities;
  this.rendererPositionOffsetUs = rendererPositionOffsetUs;
  this.trackSelector = trackSelector;
  this.mediaSource = mediaSource;
  this.uid = info.id.periodUid;
  this.info = info;
  this.trackGroups = TrackGroupArray.EMPTY;
  this.trackSelectorResult = emptyTrackSelectorResult;
  sampleStreams = new SampleStream[rendererCapabilities.length];
  mayRetainStreamFlags = new boolean[rendererCapabilities.length];
  mediaPeriod =
      createMediaPeriod(
          info.id, mediaSource, allocator, info.startPositionUs, info.endPositionUs);
}
 
Example #15
Source File: HlsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  Assertions.checkArgument(id.periodIndex == 0);
  EventDispatcher eventDispatcher = createEventDispatcher(id);
  return new HlsMediaPeriod(
      extractorFactory,
      playlistTracker,
      dataSourceFactory,
      mediaTransferListener,
      chunkLoadErrorHandlingPolicy,
      minLoadableRetryCount,
      eventDispatcher,
      allocator,
      compositeSequenceableLoaderFactory,
      allowChunklessPreparation);
}
 
Example #16
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 #17
Source File: HlsMediaSource.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
  EventDispatcher eventDispatcher = createEventDispatcher(id);
  return new HlsMediaPeriod(
      extractorFactory,
      playlistTracker,
      dataSourceFactory,
      mediaTransferListener,
      drmSessionManager,
      loadErrorHandlingPolicy,
      eventDispatcher,
      allocator,
      compositeSequenceableLoaderFactory,
      allowChunklessPreparation,
      metadataType,
      useSessionKeys);
}
 
Example #18
Source File: DashMediaPeriod.java    From K-Sonic with MIT License 6 votes vote down vote up
public DashMediaPeriod(int id, DashManifest manifest, int periodIndex,
    DashChunkSource.Factory chunkSourceFactory,  int minLoadableRetryCount,
    EventDispatcher eventDispatcher, long elapsedRealtimeOffset,
    LoaderErrorThrower manifestLoaderErrorThrower, Allocator allocator) {
  this.id = id;
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  this.chunkSourceFactory = chunkSourceFactory;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.elapsedRealtimeOffset = elapsedRealtimeOffset;
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.allocator = allocator;
  sampleStreams = newSampleStreamArray(0);
  sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
  adaptationSets = manifest.getPeriod(periodIndex).adaptationSets;
  Pair<TrackGroupArray, EmbeddedTrackInfo[]> result = buildTrackGroups(adaptationSets);
  trackGroups = result.first;
  embeddedTrackInfos = result.second;
}
 
Example #19
Source File: SsMediaPeriod.java    From K-Sonic with MIT License 6 votes vote down vote up
public SsMediaPeriod(SsManifest manifest, SsChunkSource.Factory chunkSourceFactory,
    int minLoadableRetryCount, EventDispatcher eventDispatcher,
    LoaderErrorThrower manifestLoaderErrorThrower, Allocator allocator) {
  this.chunkSourceFactory = chunkSourceFactory;
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.allocator = allocator;

  trackGroups = buildTrackGroups(manifest);
  ProtectionElement protectionElement = manifest.protectionElement;
  if (protectionElement != null) {
    byte[] keyId = getProtectionElementKeyId(protectionElement.data);
    trackEncryptionBoxes = new TrackEncryptionBox[] {
        new TrackEncryptionBox(true, INITIALIZATION_VECTOR_SIZE, keyId)};
  } else {
    trackEncryptionBoxes = null;
  }
  this.manifest = manifest;
  sampleStreams = newSampleStreamArray(0);
  sequenceableLoader = new CompositeSequenceableLoader(sampleStreams);
}
 
Example #20
Source File: SsMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  Assertions.checkArgument(id.periodIndex == 0);
  EventDispatcher eventDispatcher = createEventDispatcher(id);
  SsMediaPeriod period =
      new SsMediaPeriod(
          manifest,
          chunkSourceFactory,
          mediaTransferListener,
          compositeSequenceableLoaderFactory,
          minLoadableRetryCount,
          eventDispatcher,
          manifestLoaderErrorThrower,
          allocator);
  mediaPeriods.add(period);
  return period;
}
 
Example #21
Source File: HlsSampleStreamWrapper.java    From TelePlus-Android 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 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 chunkLoadErrorHandlingPolicy The {@link LoadErrorHandlingPolicy} for chunk loads.
 * @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,
    LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy,
    int minLoadableRetryCount,
    EventDispatcher eventDispatcher) {
  this.trackType = trackType;
  this.callback = callback;
  this.chunkSource = chunkSource;
  this.allocator = allocator;
  this.muxedAudioFormat = muxedAudioFormat;
  this.chunkLoadErrorHandlingPolicy = chunkLoadErrorHandlingPolicy;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  loader = new Loader("Loader:HlsSampleStreamWrapper");
  nextChunkHolder = new HlsChunkSource.HlsChunkHolder();
  sampleQueueTrackIds = new int[0];
  audioSampleQueueIndex = C.INDEX_UNSET;
  videoSampleQueueIndex = C.INDEX_UNSET;
  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 #22
Source File: ConcatenatingMediaSource.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
  int sourceIndex = timeline.getSourceIndexForPeriod(index);
  int periodIndexInSource = index - timeline.getFirstPeriodIndexInSource(sourceIndex);
  MediaPeriod mediaPeriod = mediaSources[sourceIndex].createPeriod(periodIndexInSource, allocator,
      positionUs);
  sourceIndexByMediaPeriod.put(mediaPeriod, sourceIndex);
  return mediaPeriod;
}
 
Example #23
Source File: LoopingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  return loopCount != Integer.MAX_VALUE
      ? childSource.createPeriod(id.copyWithPeriodIndex(id.periodIndex % childPeriodCount),
          allocator)
      : childSource.createPeriod(id, allocator);
}
 
Example #24
Source File: MergingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  MediaPeriod[] periods = new MediaPeriod[mediaSources.length];
  for (int i = 0; i < periods.length; i++) {
    periods[i] = mediaSources[i].createPeriod(id, allocator);
  }
  return new MergingMediaPeriod(compositeSequenceableLoaderFactory, periods);
}
 
Example #25
Source File: DashMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public DashMediaPeriod(
    int id,
    DashManifest manifest,
    int periodIndex,
    DashChunkSource.Factory chunkSourceFactory,
    @Nullable TransferListener transferListener,
    int minLoadableRetryCount,
    EventDispatcher eventDispatcher,
    long elapsedRealtimeOffset,
    LoaderErrorThrower manifestLoaderErrorThrower,
    Allocator allocator,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    PlayerEmsgCallback playerEmsgCallback) {
  this.id = id;
  this.manifest = manifest;
  this.periodIndex = periodIndex;
  this.chunkSourceFactory = chunkSourceFactory;
  this.transferListener = transferListener;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.elapsedRealtimeOffset = elapsedRealtimeOffset;
  this.manifestLoaderErrorThrower = manifestLoaderErrorThrower;
  this.allocator = allocator;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  playerEmsgHandler = new PlayerEmsgHandler(manifest, playerEmsgCallback, allocator);
  sampleStreams = newSampleStreamArray(0);
  eventSampleStreams = new EventSampleStream[0];
  trackEmsgHandlerBySampleStream = new IdentityHashMap<>();
  compositeSequenceableLoader =
      compositeSequenceableLoaderFactory.createCompositeSequenceableLoader(sampleStreams);
  Period period = manifest.getPeriod(periodIndex);
  eventStreams = period.eventStreams;
  Pair<TrackGroupArray, TrackGroupInfo[]> result = buildTrackGroups(period.adaptationSets,
      eventStreams);
  trackGroups = result.first;
  trackGroupInfos = result.second;
  eventDispatcher.mediaPeriodCreated();
}
 
Example #26
Source File: HlsMediaPeriod.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates an HLS media period.
 *
 * @param extractorFactory An {@link HlsExtractorFactory} for {@link Extractor}s for the segments.
 * @param playlistTracker A tracker for HLS playlists.
 * @param dataSourceFactory An {@link HlsDataSourceFactory} for {@link DataSource}s for segments
 *     and keys.
 * @param mediaTransferListener The transfer listener to inform of any media data transfers. May
 *     be null if no listener is available.
 * @param chunkLoadErrorHandlingPolicy A {@link LoadErrorHandlingPolicy} for chunk loads.
 * @param minLoadableRetryCount The minimum number of times to retry if a loading error occurs.
 * @param eventDispatcher A dispatcher to notify of events.
 * @param allocator An {@link Allocator} from which to obtain media buffer allocations.
 * @param compositeSequenceableLoaderFactory A factory to create composite {@link
 *     SequenceableLoader}s for when this media source loads data from multiple streams.
 * @param allowChunklessPreparation Whether chunkless preparation is allowed.
 */
public HlsMediaPeriod(
    HlsExtractorFactory extractorFactory,
    HlsPlaylistTracker playlistTracker,
    HlsDataSourceFactory dataSourceFactory,
    @Nullable TransferListener mediaTransferListener,
    LoadErrorHandlingPolicy<Chunk> chunkLoadErrorHandlingPolicy,
    int minLoadableRetryCount,
    EventDispatcher eventDispatcher,
    Allocator allocator,
    CompositeSequenceableLoaderFactory compositeSequenceableLoaderFactory,
    boolean allowChunklessPreparation) {
  this.extractorFactory = extractorFactory;
  this.playlistTracker = playlistTracker;
  this.dataSourceFactory = dataSourceFactory;
  this.mediaTransferListener = mediaTransferListener;
  this.chunkLoadErrorHandlingPolicy = chunkLoadErrorHandlingPolicy;
  this.minLoadableRetryCount = minLoadableRetryCount;
  this.eventDispatcher = eventDispatcher;
  this.allocator = allocator;
  this.compositeSequenceableLoaderFactory = compositeSequenceableLoaderFactory;
  this.allowChunklessPreparation = allowChunklessPreparation;
  compositeSequenceableLoader =
      compositeSequenceableLoaderFactory.createCompositeSequenceableLoader();
  streamWrapperIndices = new IdentityHashMap<>();
  timestampAdjusterProvider = new TimestampAdjusterProvider();
  sampleStreamWrappers = new HlsSampleStreamWrapper[0];
  enabledSampleStreamWrappers = new HlsSampleStreamWrapper[0];
  eventDispatcher.mediaPeriodCreated();
}
 
Example #27
Source File: ClippingMediaSource.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) {
  ClippingMediaPeriod mediaPeriod =
      new ClippingMediaPeriod(
          mediaSource.createPeriod(id, allocator),
          enableInitialDiscontinuity,
          periodStartUs,
          periodEndUs);
  mediaPeriods.add(mediaPeriod);
  return mediaPeriod;
}
 
Example #28
Source File: SampleQueue.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param allocator An {@link Allocator} from which allocations for sample data can be obtained.
 */
public SampleQueue(Allocator allocator) {
  this.allocator = allocator;
  allocationLength = allocator.getIndividualAllocationLength();
  metadataQueue = new SampleMetadataQueue();
  extrasHolder = new SampleExtrasHolder();
  scratch = new ParsableByteArray(INITIAL_SCRATCH_SIZE);
  firstAllocationNode = new AllocationNode(0, allocationLength);
  readAllocationNode = firstAllocationNode;
  writeAllocationNode = firstAllocationNode;
}
 
Example #29
Source File: ExtractorMediaSource.java    From K-Sonic with MIT License 5 votes vote down vote up
@Override
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
  Assertions.checkArgument(index == 0);
  return new ExtractorMediaPeriod(uri, dataSourceFactory.createDataSource(),
      extractorsFactory.createExtractors(), minLoadableRetryCount, eventHandler, eventListener,
      this, allocator, customCacheKey);
}
 
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;
}