Search in sources :

Example 1 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class ConcatenatingMediaSource method addMediaSourceInternal.

private void addMediaSourceInternal(int newIndex, MediaSourceHolder newMediaSourceHolder) {
    if (newIndex > 0) {
        MediaSourceHolder previousHolder = mediaSourceHolders.get(newIndex - 1);
        Timeline previousTimeline = previousHolder.mediaSource.getTimeline();
        newMediaSourceHolder.reset(newIndex, previousHolder.firstWindowIndexInChild + previousTimeline.getWindowCount());
    } else {
        newMediaSourceHolder.reset(newIndex, /* firstWindowIndexInChild= */
        0);
    }
    Timeline newTimeline = newMediaSourceHolder.mediaSource.getTimeline();
    correctOffsets(newIndex, /* childIndexUpdate= */
    1, newTimeline.getWindowCount());
    mediaSourceHolders.add(newIndex, newMediaSourceHolder);
    mediaSourceByUid.put(newMediaSourceHolder.uid, newMediaSourceHolder);
    prepareChildSource(newMediaSourceHolder, newMediaSourceHolder.mediaSource);
    if (isEnabled() && mediaSourceByMediaPeriod.isEmpty()) {
        enabledMediaSourceHolders.add(newMediaSourceHolder);
    } else {
        disableChildSource(newMediaSourceHolder);
    }
}
Also used : Timeline(com.google.android.exoplayer2.Timeline) AbstractConcatenatedTimeline(com.google.android.exoplayer2.AbstractConcatenatedTimeline) MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)

Example 2 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class ConcatenatingMediaSource method createPeriod.

@Override
public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator, long startPositionUs) {
    Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid);
    MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid));
    @Nullable MediaSourceHolder holder = mediaSourceByUid.get(mediaSourceHolderUid);
    if (holder == null) {
        // Stale event. The media source has already been removed.
        holder = new MediaSourceHolder(new FakeMediaSource(), useLazyPreparation);
        holder.isRemoved = true;
        prepareChildSource(holder, holder.mediaSource);
    }
    enableMediaSource(holder);
    holder.activeMediaPeriodIds.add(childMediaPeriodId);
    MediaPeriod mediaPeriod = holder.mediaSource.createPeriod(childMediaPeriodId, allocator, startPositionUs);
    mediaSourceByMediaPeriod.put(mediaPeriod, holder);
    disableUnusedMediaSources();
    return mediaPeriod;
}
Also used : MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder) Nullable(androidx.annotation.Nullable)

Example 3 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class ConcatenatingMediaSource method correctOffsets.

private void correctOffsets(int startIndex, int childIndexUpdate, int windowOffsetUpdate) {
    // the childIndex and firstWindowIndexInChild variables.
    for (int i = startIndex; i < mediaSourceHolders.size(); i++) {
        MediaSourceHolder holder = mediaSourceHolders.get(i);
        holder.childIndex += childIndexUpdate;
        holder.firstWindowIndexInChild += windowOffsetUpdate;
    }
}
Also used : MediaSourceHolder(com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)

Example 4 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class MediaSourceList method prepareChildSource.

private void prepareChildSource(MediaSourceHolder holder) {
    MediaSource mediaSource = holder.mediaSource;
    MediaSource.MediaSourceCaller caller = (source, timeline) -> mediaSourceListInfoListener.onPlaylistUpdateRequested();
    ForwardingEventListener eventListener = new ForwardingEventListener(holder);
    childSources.put(holder, new MediaSourceAndListener(mediaSource, caller, eventListener));
    mediaSource.addEventListener(Util.createHandlerForCurrentOrMainLooper(), eventListener);
    mediaSource.addDrmEventListener(Util.createHandlerForCurrentOrMainLooper(), eventListener);
    mediaSource.prepareSource(caller, mediaTransferListener, playerId);
}
Also used : DefaultShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder.DefaultShuffleOrder) Util(com.google.android.exoplayer2.util.Util) LoadEventInfo(com.google.android.exoplayer2.source.LoadEventInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PlayerId(com.google.android.exoplayer2.analytics.PlayerId) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) Log(com.google.android.exoplayer2.util.Log) Handler(android.os.Handler) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) Map(java.util.Map) ShuffleOrder(com.google.android.exoplayer2.source.ShuffleOrder) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) MediaSource(com.google.android.exoplayer2.source.MediaSource) Allocator(com.google.android.exoplayer2.upstream.Allocator) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) IdentityHashMap(java.util.IdentityHashMap) Iterator(java.util.Iterator) Set(java.util.Set) IOException(java.io.IOException) Math.min(java.lang.Math.min) DrmSession(com.google.android.exoplayer2.drm.DrmSession) List(java.util.List) Nullable(androidx.annotation.Nullable) MaskingMediaPeriod(com.google.android.exoplayer2.source.MaskingMediaPeriod) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) Math.max(java.lang.Math.max) MediaLoadData(com.google.android.exoplayer2.source.MediaLoadData) AnalyticsCollector(com.google.android.exoplayer2.analytics.AnalyticsCollector) Assertions(com.google.android.exoplayer2.util.Assertions) MediaSource(com.google.android.exoplayer2.source.MediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource)

Example 5 with MediaSourceHolder

use of com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder in project ExoPlayer by google.

the class MediaSourceList method createPeriod.

/**
 * Returns a new {@link MediaPeriod} identified by {@code periodId}.
 *
 * @param id The identifier of the period.
 * @param allocator An {@link Allocator} from which to obtain media buffer allocations.
 * @param startPositionUs The expected start position, in microseconds.
 * @return A new {@link MediaPeriod}.
 */
public MediaPeriod createPeriod(MediaSource.MediaPeriodId id, Allocator allocator, long startPositionUs) {
    Object mediaSourceHolderUid = getMediaSourceHolderUid(id.periodUid);
    MediaSource.MediaPeriodId childMediaPeriodId = id.copyWithPeriodUid(getChildPeriodUid(id.periodUid));
    MediaSourceHolder holder = Assertions.checkNotNull(mediaSourceByUid.get(mediaSourceHolderUid));
    enableMediaSource(holder);
    holder.activeMediaPeriodIds.add(childMediaPeriodId);
    MediaPeriod mediaPeriod = holder.mediaSource.createPeriod(childMediaPeriodId, allocator, startPositionUs);
    mediaSourceByMediaPeriod.put(mediaPeriod, holder);
    disableUnusedMediaSources();
    return mediaPeriod;
}
Also used : MediaSource(com.google.android.exoplayer2.source.MediaSource) MaskingMediaSource(com.google.android.exoplayer2.source.MaskingMediaSource) MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) MaskingMediaPeriod(com.google.android.exoplayer2.source.MaskingMediaPeriod)

Aggregations

MediaSourceHolder (com.google.android.exoplayer2.source.ConcatenatingMediaSource.MediaSourceHolder)9 MediaSource (com.google.android.exoplayer2.source.MediaSource)5 ShuffleOrder (com.google.android.exoplayer2.source.ShuffleOrder)4 FakeMediaSource (com.google.android.exoplayer2.testutil.FakeMediaSource)4 FakeShuffleOrder (com.google.android.exoplayer2.testutil.FakeShuffleOrder)4 Nullable (androidx.annotation.Nullable)3 Test (org.junit.Test)3 Handler (android.os.Handler)2 AbstractConcatenatedTimeline (com.google.android.exoplayer2.AbstractConcatenatedTimeline)2 Timeline (com.google.android.exoplayer2.Timeline)2 MaskingMediaPeriod (com.google.android.exoplayer2.source.MaskingMediaPeriod)2 MaskingMediaSource (com.google.android.exoplayer2.source.MaskingMediaSource)2 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)2 ArrayList (java.util.ArrayList)2 GuardedBy (androidx.annotation.GuardedBy)1 AnalyticsCollector (com.google.android.exoplayer2.analytics.AnalyticsCollector)1 PlayerId (com.google.android.exoplayer2.analytics.PlayerId)1 DrmSession (com.google.android.exoplayer2.drm.DrmSession)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 LoadEventInfo (com.google.android.exoplayer2.source.LoadEventInfo)1