Move positionUs parameter from createPeriod to prepare
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=158494794
This commit is contained in:
parent
047e0eb645
commit
4e006a9616
@ -159,12 +159,12 @@ public final class ImaAdsMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
if (timeline.isPeriodAd(index)) {
|
||||
int adBreakIndex = timeline.getAdBreakIndex(index);
|
||||
int adIndexInAdBreak = timeline.getAdIndexInAdBreak(index);
|
||||
if (adIndexInAdBreak >= adBreakMediaSources[adBreakIndex].length) {
|
||||
DeferredMediaPeriod deferredPeriod = new DeferredMediaPeriod(0, allocator, positionUs);
|
||||
DeferredMediaPeriod deferredPeriod = new DeferredMediaPeriod(0, allocator);
|
||||
if (adIndexInAdBreak >= adBreakDeferredMediaPeriods[adBreakIndex].length) {
|
||||
adBreakDeferredMediaPeriods[adBreakIndex] = Arrays.copyOf(
|
||||
adBreakDeferredMediaPeriods[adBreakIndex], adIndexInAdBreak + 1);
|
||||
@ -174,15 +174,13 @@ public final class ImaAdsMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
MediaSource adBreakMediaSource = adBreakMediaSources[adBreakIndex][adIndexInAdBreak];
|
||||
MediaPeriod adBreakMediaPeriod = adBreakMediaSource.createPeriod(0, allocator, positionUs);
|
||||
MediaPeriod adBreakMediaPeriod = adBreakMediaSource.createPeriod(0, allocator);
|
||||
mediaSourceByMediaPeriod.put(adBreakMediaPeriod, adBreakMediaSource);
|
||||
return adBreakMediaPeriod;
|
||||
} else {
|
||||
long startUs = timeline.getContentStartTimeUs(index);
|
||||
long endUs = timeline.getContentEndTimeUs(index);
|
||||
long contentStartUs = startUs + positionUs;
|
||||
MediaPeriod contentMediaPeriod = contentMediaSource.createPeriod(0, allocator,
|
||||
contentStartUs);
|
||||
MediaPeriod contentMediaPeriod = contentMediaSource.createPeriod(0, allocator);
|
||||
ClippingMediaPeriod clippingPeriod = new ClippingMediaPeriod(contentMediaPeriod);
|
||||
clippingPeriod.setClipping(startUs, endUs == C.TIME_UNSET ? C.TIME_END_OF_SOURCE : endUs);
|
||||
mediaSourceByMediaPeriod.put(contentMediaPeriod, contentMediaSource);
|
||||
@ -436,29 +434,29 @@ public final class ImaAdsMediaSource implements MediaSource {
|
||||
|
||||
private final int index;
|
||||
private final Allocator allocator;
|
||||
private final long positionUs;
|
||||
|
||||
public MediaPeriod mediaPeriod;
|
||||
private MediaPeriod.Callback callback;
|
||||
private long positionUs;
|
||||
|
||||
public DeferredMediaPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public DeferredMediaPeriod(int index, Allocator allocator) {
|
||||
this.index = index;
|
||||
this.allocator = allocator;
|
||||
this.positionUs = positionUs;
|
||||
}
|
||||
|
||||
public void setMediaSource(MediaSource mediaSource) {
|
||||
mediaPeriod = mediaSource.createPeriod(index, allocator, positionUs);
|
||||
mediaPeriod = mediaSource.createPeriod(index, allocator);
|
||||
if (callback != null) {
|
||||
mediaPeriod.prepare(this);
|
||||
mediaPeriod.prepare(this, positionUs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback) {
|
||||
public void prepare(Callback callback, long positionUs) {
|
||||
this.callback = callback;
|
||||
this.positionUs = positionUs;
|
||||
if (mediaPeriod != null) {
|
||||
mediaPeriod.prepare(this);
|
||||
mediaPeriod.prepare(this, positionUs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -535,11 +535,10 @@ public final class ExoPlayerTest extends TestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
Assertions.checkIndex(index, 0, timeline.getPeriodCount());
|
||||
assertTrue(preparedSource);
|
||||
assertFalse(releasedSource);
|
||||
assertEquals(0, positionUs);
|
||||
FakeMediaPeriod mediaPeriod = new FakeMediaPeriod(trackGroupArray);
|
||||
activeMediaPeriods.add(mediaPeriod);
|
||||
return mediaPeriod;
|
||||
@ -583,8 +582,9 @@ public final class ExoPlayerTest extends TestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback) {
|
||||
public void prepare(Callback callback, long positionUs) {
|
||||
assertFalse(preparedPeriod);
|
||||
assertEquals(0, positionUs);
|
||||
preparedPeriod = true;
|
||||
callback.onPrepared(this);
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ public class TimelineTest extends TestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1352,7 +1352,7 @@ import java.io.IOException;
|
||||
loadingPeriodHolder.next = newPeriodHolder;
|
||||
}
|
||||
loadingPeriodHolder = newPeriodHolder;
|
||||
loadingPeriodHolder.mediaPeriod.prepare(this);
|
||||
loadingPeriodHolder.mediaPeriod.prepare(this, newLoadingPeriodStartPositionUs);
|
||||
setIsLoading(true);
|
||||
}
|
||||
|
||||
@ -1528,8 +1528,7 @@ import java.io.IOException;
|
||||
this.startPositionUs = startPositionUs;
|
||||
sampleStreams = new SampleStream[renderers.length];
|
||||
mayRetainStreamFlags = new boolean[renderers.length];
|
||||
mediaPeriod = mediaSource.createPeriod(periodIndex, loadControl.getAllocator(),
|
||||
startPositionUs);
|
||||
mediaPeriod = mediaSource.createPeriod(periodIndex, loadControl.getAllocator());
|
||||
}
|
||||
|
||||
public long toRendererTime(long periodTimeUs) {
|
||||
|
@ -68,9 +68,9 @@ public final class ClippingMediaPeriod implements MediaPeriod, MediaPeriod.Callb
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(MediaPeriod.Callback callback) {
|
||||
public void prepare(MediaPeriod.Callback callback, long positionUs) {
|
||||
this.callback = callback;
|
||||
mediaPeriod.prepare(this);
|
||||
mediaPeriod.prepare(this, startUs + positionUs);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,9 +69,9 @@ public final class ClippingMediaSource implements MediaSource, MediaSource.Liste
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
ClippingMediaPeriod mediaPeriod = new ClippingMediaPeriod(
|
||||
mediaSource.createPeriod(index, allocator, startUs + positionUs));
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
ClippingMediaPeriod mediaPeriod =
|
||||
new ClippingMediaPeriod(mediaSource.createPeriod(index, allocator));
|
||||
mediaPeriods.add(mediaPeriod);
|
||||
mediaPeriod.setClipping(clippingTimeline.startUs, clippingTimeline.endUs);
|
||||
return mediaPeriod;
|
||||
|
@ -91,11 +91,11 @@ public final class ConcatenatingMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
int sourceIndex = timeline.getChildIndexForPeriod(index);
|
||||
int periodIndexInSource = index - timeline.getFirstPeriodIndexInChild(sourceIndex);
|
||||
MediaPeriod mediaPeriod = mediaSources[sourceIndex].createPeriod(periodIndexInSource, allocator,
|
||||
positionUs);
|
||||
MediaPeriod mediaPeriod =
|
||||
mediaSources[sourceIndex].createPeriod(periodIndexInSource, allocator);
|
||||
sourceIndexByMediaPeriod.put(mediaPeriod, sourceIndex);
|
||||
return mediaPeriod;
|
||||
}
|
||||
|
@ -159,7 +159,7 @@ import java.io.IOException;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback) {
|
||||
public void prepare(Callback callback, long positionUs) {
|
||||
this.callback = callback;
|
||||
loadCondition.open();
|
||||
startLoading();
|
||||
|
@ -156,7 +156,7 @@ public final class ExtractorMediaSource implements MediaSource, MediaSource.List
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
Assertions.checkArgument(index == 0);
|
||||
return new ExtractorMediaPeriod(uri, dataSourceFactory.createDataSource(),
|
||||
extractorsFactory.createExtractors(), minLoadableRetryCount, eventHandler, eventListener,
|
||||
|
@ -76,10 +76,10 @@ public final class LoopingMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
return loopCount != Integer.MAX_VALUE
|
||||
? childSource.createPeriod(index % childPeriodCount, allocator, positionUs)
|
||||
: childSource.createPeriod(index, allocator, positionUs);
|
||||
? childSource.createPeriod(index % childPeriodCount, allocator)
|
||||
: childSource.createPeriod(index, allocator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,8 +55,10 @@ public interface MediaPeriod extends SequenceableLoader {
|
||||
*
|
||||
* @param callback Callback to receive updates from this period, including being notified when
|
||||
* preparation completes.
|
||||
* @param positionUs The position in microseconds relative to the start of the period at which to
|
||||
* start loading data.
|
||||
*/
|
||||
void prepare(Callback callback);
|
||||
void prepare(Callback callback, long positionUs);
|
||||
|
||||
/**
|
||||
* Throws an error that's preventing the period from becoming prepared. Does nothing if no such
|
||||
@ -162,9 +164,9 @@ public interface MediaPeriod extends SequenceableLoader {
|
||||
* This method may be called both during and after the period has been prepared.
|
||||
* <p>
|
||||
* A period may call {@link Callback#onContinueLoadingRequested(SequenceableLoader)} on the
|
||||
* {@link Callback} passed to {@link #prepare(Callback)} to request that this method be called
|
||||
* when the period is permitted to continue loading data. A period may do this both during and
|
||||
* after preparation.
|
||||
* {@link Callback} passed to {@link #prepare(Callback, long)} to request that this method be
|
||||
* called when the period is permitted to continue loading data. A period may do this both during
|
||||
* and after preparation.
|
||||
*
|
||||
* @param positionUs The current playback position.
|
||||
* @return True if progress was made, meaning that {@link #getNextLoadPositionUs()} will return
|
||||
|
@ -64,10 +64,9 @@ public interface MediaSource {
|
||||
*
|
||||
* @param index The index of the period.
|
||||
* @param allocator An {@link Allocator} from which to obtain media buffer allocations.
|
||||
* @param positionUs The player's current playback position.
|
||||
* @return A new {@link MediaPeriod}.
|
||||
*/
|
||||
MediaPeriod createPeriod(int index, Allocator allocator, long positionUs);
|
||||
MediaPeriod createPeriod(int index, Allocator allocator);
|
||||
|
||||
/**
|
||||
* Releases the period.
|
||||
|
@ -44,11 +44,11 @@ import java.util.IdentityHashMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback) {
|
||||
public void prepare(Callback callback, long positionUs) {
|
||||
this.callback = callback;
|
||||
pendingChildPrepareCount = periods.length;
|
||||
for (MediaPeriod period : periods) {
|
||||
period.prepare(this);
|
||||
period.prepare(this, positionUs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,10 +116,10 @@ public final class MergingMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
MediaPeriod[] periods = new MediaPeriod[mediaSources.length];
|
||||
for (int i = 0; i < periods.length; i++) {
|
||||
periods[i] = mediaSources[i].createPeriod(index, allocator, positionUs);
|
||||
periods[i] = mediaSources[i].createPeriod(index, allocator);
|
||||
}
|
||||
return new MergingMediaPeriod(periods);
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ import java.util.Arrays;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback) {
|
||||
public void prepare(Callback callback, long positionUs) {
|
||||
callback.onPrepared(this);
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ public final class SingleSampleMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
Assertions.checkArgument(index == 0);
|
||||
return new SingleSampleMediaPeriod(uri, dataSourceFactory, format, minLoadableRetryCount,
|
||||
eventHandler, eventListener, eventSourceId);
|
||||
|
@ -106,7 +106,7 @@ import java.util.List;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback) {
|
||||
public void prepare(Callback callback, long positionUs) {
|
||||
this.callback = callback;
|
||||
callback.onPrepared(this);
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ public final class DashMediaSource implements MediaSource {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int periodIndex, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int periodIndex, Allocator allocator) {
|
||||
EventDispatcher periodEventDispatcher = eventDispatcher.copyWithMediaTimeOffsetMs(
|
||||
manifest.getPeriod(periodIndex).startMs);
|
||||
DashMediaPeriod mediaPeriod = new DashMediaPeriod(firstPeriodId + periodIndex, manifest,
|
||||
|
@ -51,7 +51,6 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
private final IdentityHashMap<SampleStream, Integer> streamWrapperIndices;
|
||||
private final TimestampAdjusterProvider timestampAdjusterProvider;
|
||||
private final Handler continueLoadingHandler;
|
||||
private final long preparePositionUs;
|
||||
|
||||
private Callback callback;
|
||||
private int pendingPrepareCount;
|
||||
@ -62,8 +61,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
private CompositeSequenceableLoader sequenceableLoader;
|
||||
|
||||
public HlsMediaPeriod(HlsPlaylistTracker playlistTracker, HlsDataSourceFactory dataSourceFactory,
|
||||
int minLoadableRetryCount, EventDispatcher eventDispatcher, Allocator allocator,
|
||||
long positionUs) {
|
||||
int minLoadableRetryCount, EventDispatcher eventDispatcher, Allocator allocator) {
|
||||
this.playlistTracker = playlistTracker;
|
||||
this.dataSourceFactory = dataSourceFactory;
|
||||
this.minLoadableRetryCount = minLoadableRetryCount;
|
||||
@ -72,7 +70,6 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
streamWrapperIndices = new IdentityHashMap<>();
|
||||
timestampAdjusterProvider = new TimestampAdjusterProvider();
|
||||
continueLoadingHandler = new Handler();
|
||||
preparePositionUs = positionUs;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
@ -86,10 +83,10 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback) {
|
||||
public void prepare(Callback callback, long positionUs) {
|
||||
playlistTracker.addListener(this);
|
||||
this.callback = callback;
|
||||
buildAndPrepareSampleStreamWrappers();
|
||||
buildAndPrepareSampleStreamWrappers(positionUs);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -285,7 +282,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
|
||||
// Internal methods.
|
||||
|
||||
private void buildAndPrepareSampleStreamWrappers() {
|
||||
private void buildAndPrepareSampleStreamWrappers(long positionUs) {
|
||||
HlsMasterPlaylist masterPlaylist = playlistTracker.getMasterPlaylist();
|
||||
// Build the default stream wrapper.
|
||||
List<HlsUrl> selectedVariants = new ArrayList<>(masterPlaylist.variants);
|
||||
@ -322,7 +319,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
HlsUrl[] variants = new HlsMasterPlaylist.HlsUrl[selectedVariants.size()];
|
||||
selectedVariants.toArray(variants);
|
||||
HlsSampleStreamWrapper sampleStreamWrapper = buildSampleStreamWrapper(C.TRACK_TYPE_DEFAULT,
|
||||
variants, masterPlaylist.muxedAudioFormat, masterPlaylist.muxedCaptionFormats);
|
||||
variants, masterPlaylist.muxedAudioFormat, masterPlaylist.muxedCaptionFormats, positionUs);
|
||||
sampleStreamWrappers[currentWrapperIndex++] = sampleStreamWrapper;
|
||||
sampleStreamWrapper.setIsTimestampMaster(true);
|
||||
sampleStreamWrapper.continuePreparing();
|
||||
@ -332,7 +329,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
// Build audio stream wrappers.
|
||||
for (int i = 0; i < audioRenditions.size(); i++) {
|
||||
sampleStreamWrapper = buildSampleStreamWrapper(C.TRACK_TYPE_AUDIO,
|
||||
new HlsUrl[] {audioRenditions.get(i)}, null, Collections.<Format>emptyList());
|
||||
new HlsUrl[] {audioRenditions.get(i)}, null, Collections.<Format>emptyList(), positionUs);
|
||||
sampleStreamWrappers[currentWrapperIndex++] = sampleStreamWrapper;
|
||||
sampleStreamWrapper.continuePreparing();
|
||||
}
|
||||
@ -341,18 +338,18 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsSampleStreamWrapper
|
||||
for (int i = 0; i < subtitleRenditions.size(); i++) {
|
||||
HlsUrl url = subtitleRenditions.get(i);
|
||||
sampleStreamWrapper = buildSampleStreamWrapper(C.TRACK_TYPE_TEXT, new HlsUrl[] {url}, null,
|
||||
Collections.<Format>emptyList());
|
||||
Collections.<Format>emptyList(), positionUs);
|
||||
sampleStreamWrapper.prepareSingleTrack(url.format);
|
||||
sampleStreamWrappers[currentWrapperIndex++] = sampleStreamWrapper;
|
||||
}
|
||||
}
|
||||
|
||||
private HlsSampleStreamWrapper buildSampleStreamWrapper(int trackType, HlsUrl[] variants,
|
||||
Format muxedAudioFormat, List<Format> muxedCaptionFormats) {
|
||||
Format muxedAudioFormat, List<Format> muxedCaptionFormats, long positionUs) {
|
||||
HlsChunkSource defaultChunkSource = new HlsChunkSource(playlistTracker, variants,
|
||||
dataSourceFactory, timestampAdjusterProvider, muxedCaptionFormats);
|
||||
return new HlsSampleStreamWrapper(trackType, this, defaultChunkSource, allocator,
|
||||
preparePositionUs, muxedAudioFormat, minLoadableRetryCount, eventDispatcher);
|
||||
return new HlsSampleStreamWrapper(trackType, this, defaultChunkSource, allocator, positionUs,
|
||||
muxedAudioFormat, minLoadableRetryCount, eventDispatcher);
|
||||
}
|
||||
|
||||
private void continuePreparingOrLoading() {
|
||||
|
@ -88,10 +88,10 @@ public final class HlsMediaSource implements MediaSource,
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
Assertions.checkArgument(index == 0);
|
||||
return new HlsMediaPeriod(playlistTracker, dataSourceFactory, minLoadableRetryCount,
|
||||
eventDispatcher, allocator, positionUs);
|
||||
eventDispatcher, allocator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,7 +93,7 @@ import java.util.ArrayList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(Callback callback) {
|
||||
public void prepare(Callback callback, long positionUs) {
|
||||
this.callback = callback;
|
||||
callback.onPrepared(this);
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ public final class SsMediaSource implements MediaSource,
|
||||
}
|
||||
|
||||
@Override
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||
public MediaPeriod createPeriod(int index, Allocator allocator) {
|
||||
Assertions.checkArgument(index == 0);
|
||||
SsMediaPeriod period = new SsMediaPeriod(manifest, chunkSourceFactory, minLoadableRetryCount,
|
||||
eventDispatcher, manifestLoaderErrorThrower, allocator);
|
||||
|
Loading…
x
Reference in New Issue
Block a user