From eff82e920ecf023afce7128b251d40184d5269e8 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Thu, 18 Aug 2016 04:39:59 -0700 Subject: [PATCH] Fix DASH multi-period transitions and manifest updates. Period transitions can either be to new windows (in which case the default position for the new window should be loaded) or to the next period of the current window (in which case the the new period should be played from zero). Fix the logic for calculating the new period index to load to implement this. In processManifest, periodsById may contain periods that have been removed from the manifest, which are still being used by the player (it releases periods on receiving the source info refresh after processManifest returns). Ignore periods that have been removed from the manifest when calling updateManifest. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=130626441 --- .../android/exoplayer2/ExoPlayerImplInternal.java | 4 +++- .../exoplayer2/source/dash/DashMediaSource.java | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java index 129037143b..cfd82968f3 100644 --- a/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java +++ b/library/src/main/java/com/google/android/exoplayer2/ExoPlayerImplInternal.java @@ -906,7 +906,9 @@ import java.io.IOException; mediaSource.maybeThrowSourceInfoRefreshError(); } else { Window window = timeline.getPeriodWindow(newLoadingPeriodIndex); - long startPositionUs = loadingPeriod == null ? playbackInfo.positionUs : C.UNSET_TIME_US; + long startPositionUs = loadingPeriod == null ? playbackInfo.positionUs + : newLoadingPeriodIndex == window.startPeriodIndex ? C.UNSET_TIME_US + : 0; if (startPositionUs == C.UNSET_TIME_US) { // This is the first period of a new window or we don't have a start position, so seek to // the default position for the window. diff --git a/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java b/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java index 4cff6360e5..edf64051e0 100644 --- a/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java +++ b/library/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaSource.java @@ -184,10 +184,7 @@ public final class DashMediaSource implements MediaSource { @Override public void releasePeriod(MediaPeriod mediaPeriod) { - int id = ((DashMediaPeriod) mediaPeriod).id; - if (id >= firstPeriodId) { - periodsById.remove(id); - } + periodsById.remove(((DashMediaPeriod) mediaPeriod).id); } @Override @@ -348,7 +345,12 @@ public final class DashMediaSource implements MediaSource { private void processManifest() { // Update any periods. for (int i = 0; i < periodsById.size(); i++) { - periodsById.valueAt(i).updateManifest(manifest, periodsById.keyAt(i) - firstPeriodId); + 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. + } } // Remove any pending simulated updates. handler.removeCallbacks(simulateManifestRefreshRunnable);