Commit fea43767 by olly Committed by Oliver Woodman

Merge trick play tracks into main track groups

Issue: #6054
PiperOrigin-RevId: 307285068
parent 8ea33e23
...@@ -97,6 +97,11 @@ ...@@ -97,6 +97,11 @@
* Remove generics from DRM components. * Remove generics from DRM components.
* Downloads: Merge downloads in `SegmentDownloader` to improve overall * Downloads: Merge downloads in `SegmentDownloader` to improve overall
download speed ([#5978](https://github.com/google/ExoPlayer/issues/5978)). download speed ([#5978](https://github.com/google/ExoPlayer/issues/5978)).
* DASH:
* Merge trick play adaptation sets (i.e., adaptation sets marked with
`http://dashif.org/guidelines/trickmode`) into the same `TrackGroup` as
the main adaptation sets to which they refer. Trick play tracks are
marked with the `C.ROLE_FLAG_TRICK_PLAY` flag.
* MP3: Add `IndexSeeker` for accurate seeks in VBR streams * MP3: Add `IndexSeeker` for accurate seeks in VBR streams
([#6787](https://github.com/google/ExoPlayer/issues/6787)). This seeker is ([#6787](https://github.com/google/ExoPlayer/issues/6787)). This seeker is
enabled by passing `FLAG_ENABLE_INDEX_SEEKING` to the `Mp3Extractor`. It may enabled by passing `FLAG_ENABLE_INDEX_SEEKING` to the `Mp3Extractor`. It may
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
package com.google.android.exoplayer2.source.dash; package com.google.android.exoplayer2.source.dash;
import android.util.Pair; import android.util.Pair;
import android.util.SparseArray;
import android.util.SparseIntArray; import android.util.SparseIntArray;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
...@@ -516,51 +517,94 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -516,51 +517,94 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
return Pair.create(new TrackGroupArray(trackGroups), trackGroupInfos); return Pair.create(new TrackGroupArray(trackGroups), trackGroupInfos);
} }
/**
* Groups adaptation sets. Two adaptations sets belong to the same group if either:
*
* <ul>
* <li>One is a trick-play adaptation set and uses a {@code
* http://dashif.org/guidelines/trickmode} essential or supplemental property to indicate
* that the other is the main adaptation set to which it corresponds.
* <li>The two adaptation sets are marked as safe for switching using {@code
* urn:mpeg:dash:adaptation-set-switching:2016} supplemental properties.
* </ul>
*
* @param adaptationSets The adaptation sets to merge.
* @return An array of groups, where each group is an array of adaptation set indices.
*/
private static int[][] getGroupedAdaptationSetIndices(List<AdaptationSet> adaptationSets) { private static int[][] getGroupedAdaptationSetIndices(List<AdaptationSet> adaptationSets) {
int adaptationSetCount = adaptationSets.size(); int adaptationSetCount = adaptationSets.size();
SparseIntArray idToIndexMap = new SparseIntArray(adaptationSetCount); SparseIntArray adaptationSetIdToIndex = new SparseIntArray(adaptationSetCount);
List<List<Integer>> adaptationSetGroupedIndices = new ArrayList<>(adaptationSetCount);
SparseArray<List<Integer>> adaptationSetIndexToGroupedIndices =
new SparseArray<>(adaptationSetCount);
// Initially make each adaptation set belong to its own group. Also build the
// adaptationSetIdToIndex map.
for (int i = 0; i < adaptationSetCount; i++) { for (int i = 0; i < adaptationSetCount; i++) {
idToIndexMap.put(adaptationSets.get(i).id, i); adaptationSetIdToIndex.put(adaptationSets.get(i).id, i);
List<Integer> initialGroup = new ArrayList<>();
initialGroup.add(i);
adaptationSetGroupedIndices.add(initialGroup);
adaptationSetIndexToGroupedIndices.put(i, initialGroup);
} }
int[][] groupedAdaptationSetIndices = new int[adaptationSetCount][]; // Merge adaptation set groups.
boolean[] adaptationSetUsedFlags = new boolean[adaptationSetCount];
int groupCount = 0;
for (int i = 0; i < adaptationSetCount; i++) { for (int i = 0; i < adaptationSetCount; i++) {
if (adaptationSetUsedFlags[i]) { int mergedGroupIndex = i;
// This adaptation set has already been included in a group. AdaptationSet adaptationSet = adaptationSets.get(i);
continue;
} // Trick-play adaptation sets are merged with their corresponding main adaptation sets.
adaptationSetUsedFlags[i] = true;
@Nullable @Nullable
Descriptor adaptationSetSwitchingProperty = Descriptor trickPlayProperty = findTrickPlayProperty(adaptationSet.essentialProperties);
findAdaptationSetSwitchingProperty(adaptationSets.get(i).supplementalProperties); if (trickPlayProperty == null) {
if (adaptationSetSwitchingProperty == null) { // Trick-play can also be specified using a supplemental property.
groupedAdaptationSetIndices[groupCount++] = new int[] {i}; trickPlayProperty = findTrickPlayProperty(adaptationSet.supplementalProperties);
} else { }
String[] extraAdaptationSetIds = Util.split(adaptationSetSwitchingProperty.value, ","); if (trickPlayProperty != null) {
int[] adaptationSetIndices = new int[1 + extraAdaptationSetIds.length]; int mainAdaptationSetId = Integer.parseInt(trickPlayProperty.value);
adaptationSetIndices[0] = i; int mainAdaptationSetIndex =
int outputIndex = 1; adaptationSetIdToIndex.get(mainAdaptationSetId, /* valueIfKeyNotFound= */ -1);
for (String adaptationSetId : extraAdaptationSetIds) { if (mainAdaptationSetIndex != -1) {
int extraIndex = mergedGroupIndex = mainAdaptationSetIndex;
idToIndexMap.get(Integer.parseInt(adaptationSetId), /* valueIfKeyNotFound= */ -1);
if (extraIndex != -1) {
adaptationSetUsedFlags[extraIndex] = true;
adaptationSetIndices[outputIndex] = extraIndex;
outputIndex++;
}
} }
if (outputIndex < adaptationSetIndices.length) { }
adaptationSetIndices = Arrays.copyOf(adaptationSetIndices, outputIndex);
// Adaptation sets that are safe for switching are merged, using the smallest index for the
// merged group.
if (mergedGroupIndex == i) {
@Nullable
Descriptor adaptationSetSwitchingProperty =
findAdaptationSetSwitchingProperty(adaptationSet.supplementalProperties);
if (adaptationSetSwitchingProperty != null) {
String[] otherAdaptationSetIds = Util.split(adaptationSetSwitchingProperty.value, ",");
for (String adaptationSetId : otherAdaptationSetIds) {
int otherAdaptationSetId =
adaptationSetIdToIndex.get(
Integer.parseInt(adaptationSetId), /* valueIfKeyNotFound= */ -1);
if (otherAdaptationSetId != -1) {
mergedGroupIndex = Math.min(mergedGroupIndex, otherAdaptationSetId);
}
}
} }
groupedAdaptationSetIndices[groupCount++] = adaptationSetIndices; }
// Merge the groups if necessary.
if (mergedGroupIndex != i) {
List<Integer> thisGroup = adaptationSetIndexToGroupedIndices.get(i);
List<Integer> mergedGroup = adaptationSetIndexToGroupedIndices.get(mergedGroupIndex);
mergedGroup.addAll(thisGroup);
adaptationSetIndexToGroupedIndices.put(i, mergedGroup);
adaptationSetGroupedIndices.remove(thisGroup);
} }
} }
return groupCount < adaptationSetCount int[][] groupedAdaptationSetIndices = new int[adaptationSetGroupedIndices.size()][];
? Arrays.copyOf(groupedAdaptationSetIndices, groupCount) : groupedAdaptationSetIndices; for (int i = 0; i < groupedAdaptationSetIndices.length; i++) {
groupedAdaptationSetIndices[i] = Util.toArray(adaptationSetGroupedIndices.get(i));
// Restore the original adaptation set order within each group.
Arrays.sort(groupedAdaptationSetIndices[i]);
}
return groupedAdaptationSetIndices;
} }
/** /**
...@@ -747,9 +791,19 @@ import org.checkerframework.checker.nullness.compatqual.NullableType; ...@@ -747,9 +791,19 @@ import org.checkerframework.checker.nullness.compatqual.NullableType;
@Nullable @Nullable
private static Descriptor findAdaptationSetSwitchingProperty(List<Descriptor> descriptors) { private static Descriptor findAdaptationSetSwitchingProperty(List<Descriptor> descriptors) {
return findDescriptor(descriptors, "urn:mpeg:dash:adaptation-set-switching:2016");
}
@Nullable
private static Descriptor findTrickPlayProperty(List<Descriptor> descriptors) {
return findDescriptor(descriptors, "http://dashif.org/guidelines/trickmode");
}
@Nullable
private static Descriptor findDescriptor(List<Descriptor> descriptors, String schemeIdUri) {
for (int i = 0; i < descriptors.size(); i++) { for (int i = 0; i < descriptors.size(); i++) {
Descriptor descriptor = descriptors.get(i); Descriptor descriptor = descriptors.get(i);
if ("urn:mpeg:dash:adaptation-set-switching:2016".equals(descriptor.schemeIdUri)) { if (schemeIdUri.equals(descriptor.schemeIdUri)) {
return descriptor; return descriptor;
} }
} }
......
...@@ -55,6 +55,17 @@ public final class MediaPeriodAsserts { ...@@ -55,6 +55,17 @@ public final class MediaPeriodAsserts {
private MediaPeriodAsserts() {} private MediaPeriodAsserts() {}
/** /**
* Prepares the {@link MediaPeriod} and asserts that it provides the specified track groups.
*
* @param mediaPeriod The {@link MediaPeriod} to test.
* @param expectedGroups The expected track groups.
*/
public static void assertTrackGroups(MediaPeriod mediaPeriod, TrackGroupArray expectedGroups) {
TrackGroupArray actualGroups = prepareAndGetTrackGroups(mediaPeriod);
assertThat(actualGroups).isEqualTo(expectedGroups);
}
/**
* Asserts that the values returns by {@link MediaPeriod#getStreamKeys(List)} are compatible with * Asserts that the values returns by {@link MediaPeriod#getStreamKeys(List)} are compatible with
* a {@link FilterableManifest} using these stream keys. * a {@link FilterableManifest} using these stream keys.
* *
...@@ -85,7 +96,7 @@ public final class MediaPeriodAsserts { ...@@ -85,7 +96,7 @@ public final class MediaPeriodAsserts {
int periodIndex, int periodIndex,
@Nullable String ignoredMimeType) { @Nullable String ignoredMimeType) {
MediaPeriod mediaPeriod = mediaPeriodFactory.createMediaPeriod(manifest, periodIndex); MediaPeriod mediaPeriod = mediaPeriodFactory.createMediaPeriod(manifest, periodIndex);
TrackGroupArray trackGroupArray = getTrackGroups(mediaPeriod); TrackGroupArray trackGroupArray = prepareAndGetTrackGroups(mediaPeriod);
// Create test vector of query test selections: // Create test vector of query test selections:
// - One selection with one track per group, two tracks or all tracks. // - One selection with one track per group, two tracks or all tracks.
...@@ -146,7 +157,7 @@ public final class MediaPeriodAsserts { ...@@ -146,7 +157,7 @@ public final class MediaPeriodAsserts {
// The filtered manifest should only have one period left. // The filtered manifest should only have one period left.
MediaPeriod filteredMediaPeriod = MediaPeriod filteredMediaPeriod =
mediaPeriodFactory.createMediaPeriod(filteredManifest, /* periodIndex= */ 0); mediaPeriodFactory.createMediaPeriod(filteredManifest, /* periodIndex= */ 0);
TrackGroupArray filteredTrackGroupArray = getTrackGroups(filteredMediaPeriod); TrackGroupArray filteredTrackGroupArray = prepareAndGetTrackGroups(filteredMediaPeriod);
for (TrackSelection trackSelection : testSelection) { for (TrackSelection trackSelection : testSelection) {
if (ignoredMimeType != null if (ignoredMimeType != null
&& ignoredMimeType.equals(trackSelection.getFormat(0).sampleMimeType)) { && ignoredMimeType.equals(trackSelection.getFormat(0).sampleMimeType)) {
...@@ -186,7 +197,7 @@ public final class MediaPeriodAsserts { ...@@ -186,7 +197,7 @@ public final class MediaPeriodAsserts {
return true; return true;
} }
private static TrackGroupArray getTrackGroups(MediaPeriod mediaPeriod) { private static TrackGroupArray prepareAndGetTrackGroups(MediaPeriod mediaPeriod) {
AtomicReference<TrackGroupArray> trackGroupArray = new AtomicReference<>(); AtomicReference<TrackGroupArray> trackGroupArray = new AtomicReference<>();
DummyMainThread dummyMainThread = new DummyMainThread(); DummyMainThread dummyMainThread = new DummyMainThread();
ConditionVariable preparedCondition = new ConditionVariable(); ConditionVariable preparedCondition = new ConditionVariable();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment