From ca7675ceae7fde67cfca292ed7c1745a050573f7 Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 15 Jan 2019 15:08:12 +0000 Subject: [PATCH] Fix bug where missing switch adaptation set causes multiple identical track groups. When the extra adaptation set of a switch group isn't defined in the manifest, we currently assume it's the first adaptation group. This either leads to wrong grouping or duplicate track groups. Such a case may easily happen if the manifest is filtered such that only one of the switch adaptation sets will be present in the manifest. PiperOrigin-RevId: 229365379 --- .../source/dash/DashMediaPeriod.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java index d0a12b9688..cba7a9941b 100644 --- a/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java +++ b/library/dash/src/main/java/com/google/android/exoplayer2/source/dash/DashMediaPeriod.java @@ -46,6 +46,7 @@ import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy; import com.google.android.exoplayer2.upstream.LoaderErrorThrower; import com.google.android.exoplayer2.upstream.TransferListener; import com.google.android.exoplayer2.util.MimeTypes; +import com.google.android.exoplayer2.util.Util; import java.io.IOException; import java.lang.annotation.Documented; import java.lang.annotation.Retention; @@ -452,13 +453,22 @@ import java.util.List; if (adaptationSetSwitchingProperty == null) { groupedAdaptationSetIndices[groupCount++] = new int[] {i}; } else { - String[] extraAdaptationSetIds = adaptationSetSwitchingProperty.value.split(","); + String[] extraAdaptationSetIds = Util.split(adaptationSetSwitchingProperty.value, ","); int[] adaptationSetIndices = new int[1 + extraAdaptationSetIds.length]; adaptationSetIndices[0] = i; + int outputIndex = 1; for (int j = 0; j < extraAdaptationSetIds.length; j++) { - int extraIndex = idToIndexMap.get(Integer.parseInt(extraAdaptationSetIds[j])); - adaptationSetUsedFlags[extraIndex] = true; - adaptationSetIndices[1 + j] = extraIndex; + int extraIndex = + idToIndexMap.get( + Integer.parseInt(extraAdaptationSetIds[j]), /* valueIfKeyNotFound= */ -1); + if (extraIndex != -1) { + adaptationSetUsedFlags[extraIndex] = true; + adaptationSetIndices[outputIndex] = extraIndex; + outputIndex++; + } + } + if (outputIndex < adaptationSetIndices.length) { + adaptationSetIndices = Arrays.copyOf(adaptationSetIndices, outputIndex); } groupedAdaptationSetIndices[groupCount++] = adaptationSetIndices; }