private void handlePeriodPrepared(MediaPeriod period) throws ExoPlaybackException { if (loadingPeriodHolder == null || loadingPeriodHolder.mediaPeriod != period) { // Stale event. return; } loadingPeriodHolder.handlePrepared(loadingPeriodHolder.startPositionUs, loadControl); if (playingPeriodHolder == null) { // This is the first prepared period, so start playing it. readingPeriodHolder = loadingPeriodHolder; setPlayingPeriodHolder(readingPeriodHolder); if (playbackInfo.startPositionUs == C.TIME_UNSET) { // Update the playback info when seeking to a default position. playbackInfo = new PlaybackInfo(playingPeriodHolder.index, playingPeriodHolder.startPositionUs); resetRendererPosition(playbackInfo.startPositionUs); updatePlaybackPositions(); eventHandler.obtainMessage(MSG_POSITION_DISCONTINUITY, playbackInfo).sendToTarget(); } updateTimelineState(); } maybeContinueLoading(); }
public MediaPeriodHolder(Renderer[] renderers, RendererCapabilities[] rendererCapabilities, long rendererPositionOffsetUs, TrackSelector trackSelector, LoadControl loadControl, MediaSource mediaSource, Object periodUid, int index, MediaPeriodInfo info) { this.renderers = renderers; this.rendererCapabilities = rendererCapabilities; this.rendererPositionOffsetUs = rendererPositionOffsetUs; this.trackSelector = trackSelector; this.loadControl = loadControl; this.mediaSource = mediaSource; this.uid = Assertions.checkNotNull(periodUid); this.index = index; this.info = info; sampleStreams = new SampleStream[renderers.length]; mayRetainStreamFlags = new boolean[renderers.length]; MediaPeriod mediaPeriod = mediaSource.createPeriod(info.id, loadControl.getAllocator()); if (info.endPositionUs != C.TIME_END_OF_SOURCE) { ClippingMediaPeriod clippingMediaPeriod = new ClippingMediaPeriod(mediaPeriod, true); clippingMediaPeriod.setClipping(0, info.endPositionUs); mediaPeriod = clippingMediaPeriod; } this.mediaPeriod = mediaPeriod; }
private void handlePeriodPrepared(MediaPeriod period) throws ExoPlaybackException { if (loadingPeriodHolder == null || loadingPeriodHolder.mediaPeriod != period) { // Stale event. return; } loadingPeriodHolder.handlePrepared(); if (playingPeriodHolder == null) { // This is the first prepared period, so start playing it. readingPeriodHolder = loadingPeriodHolder; resetRendererPosition(readingPeriodHolder.startPositionUs); setPlayingPeriodHolder(readingPeriodHolder); } maybeContinueLoading(); }
private void handleContinueLoadingRequested(MediaPeriod period) { if (loadingPeriodHolder == null || loadingPeriodHolder.mediaPeriod != period) { // Stale event. return; } maybeContinueLoading(); }
@Override public MediaPeriod createPeriod(int periodIndex, Allocator allocator, long positionUs) { EventDispatcher periodEventDispatcher = eventDispatcher.copyWithMediaTimeOffsetMs( manifest.getPeriod(periodIndex).startMs); DashMediaPeriod mediaPeriod = new DashMediaPeriod(firstPeriodId + periodIndex, manifest, periodIndex, chunkSourceFactory, minLoadableRetryCount, periodEventDispatcher, elapsedRealtimeOffsetMs, loaderErrorThrower, allocator); periodsById.put(mediaPeriod.id, mediaPeriod); return mediaPeriod; }
@Override public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) { Assertions.checkArgument(index == 0); SsMediaPeriod period = new SsMediaPeriod(manifest, chunkSourceFactory, minLoadableRetryCount, eventDispatcher, manifestLoaderErrorThrower, allocator); mediaPeriods.add(period); return period; }
public MediaPeriodHolder(Renderer[] renderers, RendererCapabilities[] rendererCapabilities, TrackSelector<T> trackSelector, MediaSource mediaSource, MediaPeriod mediaPeriod, Object uid, long positionUs) { this.renderers = renderers; this.rendererCapabilities = rendererCapabilities; this.trackSelector = trackSelector; this.mediaSource = mediaSource; this.mediaPeriod = mediaPeriod; this.uid = Assertions.checkNotNull(uid); sampleStreams = new SampleStream[renderers.length]; mayRetainStreamFlags = new boolean[renderers.length]; startPositionUs = positionUs; }
@Override public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) { DashMediaPeriod mediaPeriod = new DashMediaPeriod(firstPeriodId + index, manifest, index, chunkSourceFactory, minLoadableRetryCount, eventDispatcher, elapsedRealtimeOffsetMs, loader, allocator); periodsById.put(mediaPeriod.id, mediaPeriod); return mediaPeriod; }
@Override public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) { Assertions.checkArgument(index == 0); SsMediaPeriod period = new SsMediaPeriod(manifest, chunkSourceFactory, minLoadableRetryCount, eventDispatcher, manifestLoader, allocator); mediaPeriods.add(period); return period; }
@Override public void onPrepared(MediaPeriod mediaPeriod) { try { initializePlaybackLoop(); } catch (ExoPlaybackException e) { handlePlayerError(e); } }
/** * Calls {@link MediaSource#createPeriod(MediaSource.MediaPeriodId, Allocator)} on the playback * thread, asserting that a non-null {@link MediaPeriod} is returned. * * @param periodId The id of the period to create. * @return The created {@link MediaPeriod}. */ public MediaPeriod createPeriod(final MediaPeriodId periodId) { final MediaPeriod[] holder = new MediaPeriod[1]; runOnPlaybackThread(new Runnable() { @Override public void run() { holder[0] = mediaSource.createPeriod(periodId, allocator); } }); assertNotNull(holder[0]); return holder[0]; }
/** * Calls {@link MediaSource#releasePeriod(MediaPeriod)} on the playback thread. * * @param mediaPeriod The {@link MediaPeriod} to release. */ public void releasePeriod(final MediaPeriod mediaPeriod) { runOnPlaybackThread(new Runnable() { @Override public void run() { mediaSource.releasePeriod(mediaPeriod); } }); }
private void assertPrepareAndReleasePeriod(MediaPeriodId mediaPeriodId) { MediaPeriod mediaPeriod = createPeriod(mediaPeriodId); ConditionVariable preparedCondition = preparePeriod(mediaPeriod, 0); assertTrue(preparedCondition.block(TIMEOUT_MS)); // MediaSource is supposed to support multiple calls to createPeriod with the same id without an // intervening call to releasePeriod. MediaPeriod secondMediaPeriod = createPeriod(mediaPeriodId); ConditionVariable secondPreparedCondition = preparePeriod(secondMediaPeriod, 0); assertTrue(secondPreparedCondition.block(TIMEOUT_MS)); // Release the periods. releasePeriod(mediaPeriod); releasePeriod(secondMediaPeriod); }
@Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) { Assert.assertTrue(preparedSource); Assert.assertFalse(releasedSource); Assertions.checkIndex(id.periodIndex, 0, timeline.getPeriodCount()); FakeMediaPeriod mediaPeriod = createFakeMediaPeriod(id, trackGroupArray, allocator); activeMediaPeriods.add(mediaPeriod); createdMediaPeriods.add(id); return mediaPeriod; }
@Override public void releasePeriod(MediaPeriod mediaPeriod) { Assert.assertTrue(preparedSource); Assert.assertFalse(releasedSource); FakeMediaPeriod fakeMediaPeriod = (FakeMediaPeriod) mediaPeriod; Assert.assertTrue(activeMediaPeriods.remove(fakeMediaPeriod)); fakeMediaPeriod.release(); }
@Override public MediaPeriod createPeriod(MediaPeriodId periodId, Allocator allocator) { int periodIndex = periodId.periodIndex; EventDispatcher periodEventDispatcher = eventDispatcher.copyWithMediaTimeOffsetMs( manifest.getPeriod(periodIndex).startMs); DashMediaPeriod mediaPeriod = new DashMediaPeriod(firstPeriodId + periodIndex, manifest, periodIndex, chunkSourceFactory, minLoadableRetryCount, periodEventDispatcher, elapsedRealtimeOffsetMs, loaderErrorThrower, allocator); periodsById.put(mediaPeriod.id, mediaPeriod); return mediaPeriod; }
private void handlePeriodPrepared(MediaPeriod period) throws ExoPlaybackException { if (loadingPeriodHolder == null || loadingPeriodHolder.mediaPeriod != period) { // Stale event. return; } loadingPeriodHolder.handlePrepared(); if (playingPeriodHolder == null) { // This is the first prepared period, so start playing it. readingPeriodHolder = loadingPeriodHolder; resetRendererPosition(readingPeriodHolder.info.startPositionUs); setPlayingPeriodHolder(readingPeriodHolder); } maybeContinueLoading(); }
@Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) { Assertions.checkArgument(id.periodIndex == 0); SsMediaPeriod period = new SsMediaPeriod(manifest, chunkSourceFactory, minLoadableRetryCount, eventDispatcher, manifestLoaderErrorThrower, allocator); mediaPeriods.add(period); return period; }
@Override public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) { Assertions.checkArgument(index == 0); return new HlsMediaPeriod(playlistTracker, dataSourceFactory, minLoadableRetryCount, eventDispatcher, allocator, positionUs); }
@Override public void releasePeriod(MediaPeriod mediaPeriod) { ((HlsMediaPeriod) mediaPeriod).release(); }
@Override public void onPrepared(MediaPeriod source) { handler.obtainMessage(MSG_PERIOD_PREPARED, source).sendToTarget(); }
@Override public void onContinueLoadingRequested(MediaPeriod source) { handler.obtainMessage(MSG_SOURCE_CONTINUE_LOADING_REQUESTED, source).sendToTarget(); }
@Override public void releasePeriod(MediaPeriod mediaPeriod) { DashMediaPeriod dashMediaPeriod = (DashMediaPeriod) mediaPeriod; dashMediaPeriod.release(); periodsById.remove(dashMediaPeriod.id); }
@Override public void releasePeriod(MediaPeriod period) { ((SsMediaPeriod) period).release(); mediaPeriods.remove(period); }
private void handleContinueLoadingRequested(MediaPeriod period) { if (loadingPeriodHolder == null || loadingPeriodHolder.mediaPeriod != period) { return; } maybeContinueLoading(); }
@Override public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) { Assertions.checkArgument(index == 0); return new HlsMediaPeriod(manifestUri, dataSourceFactory, minLoadableRetryCount, eventDispatcher, sourceListener, allocator, positionUs); }
@Override public MediaPeriod createPeriod(MediaPeriodId id, Allocator allocator) { return adsMediaSource.createPeriod(id, allocator); }
@Override public void releasePeriod(MediaPeriod mediaPeriod) { adsMediaSource.releasePeriod(mediaPeriod); }