Search in sources :

Example 6 with LiveConfiguration

use of com.google.android.exoplayer2.MediaItem.LiveConfiguration in project ExoPlayer by google.

the class DashMediaSourceTest method prepare_withCompleteServiceDescription_usesManifestValue.

@Test
public void prepare_withCompleteServiceDescription_usesManifestValue() throws InterruptedException {
    DashMediaSource mediaSource = new DashMediaSource.Factory(() -> createSampleMpdDataSource(SAMPLE_MPD_LIVE_WITH_COMPLETE_SERVICE_DESCRIPTION)).setFallbackTargetLiveOffsetMs(1234L).createMediaSource(MediaItem.fromUri(Uri.EMPTY));
    MediaItem.LiveConfiguration liveConfiguration = prepareAndWaitForTimelineRefresh(mediaSource).liveConfiguration;
    assertThat(liveConfiguration.targetOffsetMs).isEqualTo(4_000L);
    assertThat(liveConfiguration.minOffsetMs).isEqualTo(2_000L);
    assertThat(liveConfiguration.maxOffsetMs).isEqualTo(6_000L);
    assertThat(liveConfiguration.minPlaybackSpeed).isEqualTo(0.96f);
    assertThat(liveConfiguration.maxPlaybackSpeed).isEqualTo(1.04f);
}
Also used : LiveConfiguration(com.google.android.exoplayer2.MediaItem.LiveConfiguration) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 7 with LiveConfiguration

use of com.google.android.exoplayer2.MediaItem.LiveConfiguration in project ExoPlayer by google.

the class DashMediaSource method processManifest.

private void processManifest(boolean scheduleRefresh) {
    // Update any periods.
    for (int i = 0; i < periodsById.size(); i++) {
        int id = periodsById.keyAt(i);
        if (id >= firstPeriodId) {
            periodsById.valueAt(i).updateManifest(manifest, id - firstPeriodId);
        } else {
        // This period has been removed from the manifest so it doesn't need to be updated.
        }
    }
    // Update the window.
    Period firstPeriod = manifest.getPeriod(0);
    int lastPeriodIndex = manifest.getPeriodCount() - 1;
    Period lastPeriod = manifest.getPeriod(lastPeriodIndex);
    long lastPeriodDurationUs = manifest.getPeriodDurationUs(lastPeriodIndex);
    long nowUnixTimeUs = Util.msToUs(Util.getNowUnixTimeMs(elapsedRealtimeOffsetMs));
    long windowStartTimeInManifestUs = getAvailableStartTimeInManifestUs(firstPeriod, manifest.getPeriodDurationUs(0), nowUnixTimeUs);
    long windowEndTimeInManifestUs = getAvailableEndTimeInManifestUs(lastPeriod, lastPeriodDurationUs, nowUnixTimeUs);
    boolean windowChangingImplicitly = manifest.dynamic && !isIndexExplicit(lastPeriod);
    if (windowChangingImplicitly && manifest.timeShiftBufferDepthMs != C.TIME_UNSET) {
        // Update the available start time to reflect the manifest's time shift buffer depth.
        long timeShiftBufferStartTimeInManifestUs = windowEndTimeInManifestUs - Util.msToUs(manifest.timeShiftBufferDepthMs);
        windowStartTimeInManifestUs = max(windowStartTimeInManifestUs, timeShiftBufferStartTimeInManifestUs);
    }
    long windowDurationUs = windowEndTimeInManifestUs - windowStartTimeInManifestUs;
    long windowStartUnixTimeMs = C.TIME_UNSET;
    long windowDefaultPositionUs = 0;
    if (manifest.dynamic) {
        checkState(manifest.availabilityStartTimeMs != C.TIME_UNSET);
        long nowInWindowUs = nowUnixTimeUs - Util.msToUs(manifest.availabilityStartTimeMs) - windowStartTimeInManifestUs;
        updateLiveConfiguration(nowInWindowUs, windowDurationUs);
        windowStartUnixTimeMs = manifest.availabilityStartTimeMs + Util.usToMs(windowStartTimeInManifestUs);
        windowDefaultPositionUs = nowInWindowUs - Util.msToUs(liveConfiguration.targetOffsetMs);
        long minimumWindowDefaultPositionUs = min(MIN_LIVE_DEFAULT_START_POSITION_US, windowDurationUs / 2);
        if (windowDefaultPositionUs < minimumWindowDefaultPositionUs) {
            // The default position is too close to the start of the live window. Set it to the minimum
            // default position provided the window is at least twice as big. Else set it to the middle
            // of the window.
            windowDefaultPositionUs = minimumWindowDefaultPositionUs;
        }
    }
    long offsetInFirstPeriodUs = windowStartTimeInManifestUs - Util.msToUs(firstPeriod.startMs);
    DashTimeline timeline = new DashTimeline(manifest.availabilityStartTimeMs, windowStartUnixTimeMs, elapsedRealtimeOffsetMs, firstPeriodId, offsetInFirstPeriodUs, windowDurationUs, windowDefaultPositionUs, manifest, mediaItem, manifest.dynamic ? liveConfiguration : null);
    refreshSourceInfo(timeline);
    if (!sideloadedManifest) {
        // Remove any pending simulated refresh.
        handler.removeCallbacks(simulateManifestRefreshRunnable);
        // If the window is changing implicitly, post a simulated manifest refresh to update it.
        if (windowChangingImplicitly) {
            handler.postDelayed(simulateManifestRefreshRunnable, getIntervalUntilNextManifestRefreshMs(manifest, Util.getNowUnixTimeMs(elapsedRealtimeOffsetMs)));
        }
        if (manifestLoadPending) {
            startLoadingManifest();
        } else if (scheduleRefresh && manifest.dynamic && manifest.minUpdatePeriodMs != C.TIME_UNSET) {
            // Schedule an explicit refresh if needed.
            long minUpdatePeriodMs = manifest.minUpdatePeriodMs;
            if (minUpdatePeriodMs == 0) {
                // TODO: This is a temporary hack to avoid constantly refreshing the MPD in cases where
                // minimumUpdatePeriod is set to 0. In such cases we shouldn't refresh unless there is
                // explicit signaling in the stream, according to:
                // http://azure.microsoft.com/blog/2014/09/13/dash-live-streaming-with-azure-media-service
                minUpdatePeriodMs = 5000;
            }
            long nextLoadTimestampMs = manifestLoadStartTimestampMs + minUpdatePeriodMs;
            long delayUntilNextLoadMs = max(0, nextLoadTimestampMs - SystemClock.elapsedRealtime());
            scheduleManifestRefresh(delayUntilNextLoadMs);
        }
    }
}
Also used : MediaPeriod(com.google.android.exoplayer2.source.MediaPeriod) Period(com.google.android.exoplayer2.source.dash.manifest.Period)

Example 8 with LiveConfiguration

use of com.google.android.exoplayer2.MediaItem.LiveConfiguration in project ExoPlayer by google.

the class DashMediaSourceTest method prepare_withMinMaxOffsetOverridesOutsideOfLiveWindow_adjustsOverridesToBeWithinWindow.

@Test
public void prepare_withMinMaxOffsetOverridesOutsideOfLiveWindow_adjustsOverridesToBeWithinWindow() throws Exception {
    MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setMinOffsetMs(0L).setMaxOffsetMs(1_000_000_000L).build()).build();
    DashMediaSource mediaSource = new DashMediaSource.Factory(() -> createSampleMpdDataSource(SAMPLE_MPD_LIVE_WITH_SUGGESTED_PRESENTATION_DELAY_2S_MIN_BUFFER_TIME_500MS)).createMediaSource(mediaItem);
    MediaItem.LiveConfiguration liveConfiguration = prepareAndWaitForTimelineRefresh(mediaSource).liveConfiguration;
    assertThat(liveConfiguration.minOffsetMs).isEqualTo(500L);
    assertThat(liveConfiguration.maxOffsetMs).isEqualTo(58_000L);
}
Also used : LiveConfiguration(com.google.android.exoplayer2.MediaItem.LiveConfiguration) LiveConfiguration(com.google.android.exoplayer2.MediaItem.LiveConfiguration) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 9 with LiveConfiguration

use of com.google.android.exoplayer2.MediaItem.LiveConfiguration in project ExoPlayer by google.

the class DashMediaSourceTest method prepare_withoutLiveConfiguration_withMediaItemSpeedLimits_usesDefaultFallbackValues.

@Test
public void prepare_withoutLiveConfiguration_withMediaItemSpeedLimits_usesDefaultFallbackValues() throws InterruptedException {
    DashMediaSource mediaSource = new DashMediaSource.Factory(() -> createSampleMpdDataSource(SAMPLE_MPD_LIVE_WITHOUT_LIVE_CONFIGURATION)).createMediaSource(new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new LiveConfiguration.Builder().setMinPlaybackSpeed(0.95f).build()).build());
    MediaItem.LiveConfiguration liveConfiguration = prepareAndWaitForTimelineRefresh(mediaSource).liveConfiguration;
    assertThat(liveConfiguration.targetOffsetMs).isEqualTo(DashMediaSource.DEFAULT_FALLBACK_TARGET_LIVE_OFFSET_MS);
    assertThat(liveConfiguration.minOffsetMs).isEqualTo(0L);
    assertThat(liveConfiguration.maxOffsetMs).isEqualTo(58_000L);
    assertThat(liveConfiguration.minPlaybackSpeed).isEqualTo(0.95f);
    assertThat(liveConfiguration.maxPlaybackSpeed).isEqualTo(C.RATE_UNSET);
}
Also used : LiveConfiguration(com.google.android.exoplayer2.MediaItem.LiveConfiguration) LiveConfiguration(com.google.android.exoplayer2.MediaItem.LiveConfiguration) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Example 10 with LiveConfiguration

use of com.google.android.exoplayer2.MediaItem.LiveConfiguration in project ExoPlayer by google.

the class DashMediaSourceTest method prepare_withSuggestedPresentationDelayAndMinBufferTime_withMediaItemLiveProperties_usesMediaItem.

@Test
public void prepare_withSuggestedPresentationDelayAndMinBufferTime_withMediaItemLiveProperties_usesMediaItem() throws InterruptedException {
    MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.EMPTY).setLiveConfiguration(new MediaItem.LiveConfiguration.Builder().setTargetOffsetMs(876L).setMinPlaybackSpeed(23f).setMaxPlaybackSpeed(42f).setMinOffsetMs(600L).setMaxOffsetMs(999L).build()).build();
    DashMediaSource mediaSource = new DashMediaSource.Factory(() -> createSampleMpdDataSource(SAMPLE_MPD_LIVE_WITH_SUGGESTED_PRESENTATION_DELAY_2S_MIN_BUFFER_TIME_500MS)).setFallbackTargetLiveOffsetMs(1234L).createMediaSource(mediaItem);
    MediaItem.LiveConfiguration liveConfiguration = prepareAndWaitForTimelineRefresh(mediaSource).liveConfiguration;
    assertThat(liveConfiguration.targetOffsetMs).isEqualTo(876L);
    assertThat(liveConfiguration.minOffsetMs).isEqualTo(600L);
    assertThat(liveConfiguration.maxOffsetMs).isEqualTo(999L);
    assertThat(liveConfiguration.minPlaybackSpeed).isEqualTo(23f);
    assertThat(liveConfiguration.maxPlaybackSpeed).isEqualTo(42f);
}
Also used : LiveConfiguration(com.google.android.exoplayer2.MediaItem.LiveConfiguration) MediaItem(com.google.android.exoplayer2.MediaItem) Test(org.junit.Test)

Aggregations

MediaItem (com.google.android.exoplayer2.MediaItem)11 LiveConfiguration (com.google.android.exoplayer2.MediaItem.LiveConfiguration)10 Test (org.junit.Test)10 Nullable (androidx.annotation.Nullable)1 Format (com.google.android.exoplayer2.Format)1 DefaultExtractorsFactory (com.google.android.exoplayer2.extractor.DefaultExtractorsFactory)1 Extractor (com.google.android.exoplayer2.extractor.Extractor)1 ExtractorsFactory (com.google.android.exoplayer2.extractor.ExtractorsFactory)1 MediaPeriod (com.google.android.exoplayer2.source.MediaPeriod)1 AdsMediaSource (com.google.android.exoplayer2.source.ads.AdsMediaSource)1 Period (com.google.android.exoplayer2.source.dash.manifest.Period)1 SubtitleExtractor (com.google.android.exoplayer2.text.SubtitleExtractor)1