Skip to content

Commit 7c000e6

Browse files
toniheicopybara-github
authored andcommitted
Ensure trick play tracks are not merged with incompatible main group
We can only merge groups if they have a clear role flag and language. If the trick play adaptation set differs, don't merge it to avoid logcat warnings about invalid track groups. Issue: #2148 PiperOrigin-RevId: 777539261
1 parent e807fe5 commit 7c000e6

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

RELEASENOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
and preload hints can cause playback to get stuck or freeze
4141
([#2299](https://github.com/androidx/media/issues/2299)).
4242
* DASH extension:
43+
* Fix issue where trick-play adaptation set is merged with its main
44+
adaptation set to form an invalid `TrackGroup`
45+
([#2148](https://github.com/androidx/media/issues/2148)).
4346
* Smooth Streaming extension:
4447
* RTSP extension:
4548
* Add support for RTP Aggregation Packet for H265 in accordance with RFC

libraries/exoplayer_dash/src/main/java/androidx/media3/exoplayer/dash/DashMediaPeriod.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,8 @@ private static int[][] getGroupedAdaptationSetIndices(List<AdaptationSet> adapta
608608
if (trickPlayProperty != null) {
609609
long mainAdaptationSetId = Long.parseLong(trickPlayProperty.value);
610610
@Nullable Integer mainAdaptationSetIndex = adaptationSetIdToIndex.get(mainAdaptationSetId);
611-
if (mainAdaptationSetIndex != null) {
611+
if (mainAdaptationSetIndex != null
612+
&& canMergeAdaptationSets(adaptationSet, adaptationSets.get(mainAdaptationSetIndex))) {
612613
mergedGroupIndex = mainAdaptationSetIndex;
613614
}
614615
}
@@ -663,8 +664,10 @@ private static boolean canMergeAdaptationSets(
663664
}
664665
Format format1 = adaptationSet1.representations.get(0).format;
665666
Format format2 = adaptationSet2.representations.get(0).format;
667+
int format1RoleFlagsExcludingTrickPlay = format1.roleFlags & ~C.ROLE_FLAG_TRICK_PLAY;
668+
int format2RoleFlagsExcludingTrickPlay = format2.roleFlags & ~C.ROLE_FLAG_TRICK_PLAY;
666669
return Objects.equals(format1.language, format2.language)
667-
&& format1.roleFlags == format2.roleFlags;
670+
&& format1RoleFlagsExcludingTrickPlay == format2RoleFlagsExcludingTrickPlay;
668671
}
669672

670673
/**

libraries/exoplayer_dash/src/test/java/androidx/media3/exoplayer/dash/DashMediaPeriodTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,32 @@ public void trickPlayProperty_mergesTrackGroups() throws IOException {
143143
MediaPeriodAsserts.assertTrackGroups(dashMediaPeriod, expectedTrackGroups);
144144
}
145145

146+
@Test
147+
public void trickPlayProperty_withIncompatibleFormats_mergesOnlyCompatibleTrackGroups()
148+
throws IOException {
149+
DashManifest manifest = parseManifest("media/mpd/sample_mpd_trick_play_property_incompatible");
150+
DashMediaPeriod dashMediaPeriod = createDashMediaPeriod(manifest, 0);
151+
List<AdaptationSet> adaptationSets = manifest.getPeriod(0).adaptationSets;
152+
153+
// We expect the trick play adaptation sets to be merged with the ones to which they refer,
154+
// retaining representations in their original order, except when their properties differ.
155+
TrackGroupArray expectedTrackGroups =
156+
new TrackGroupArray(
157+
new TrackGroup(
158+
/* id= */ "3000000000",
159+
adaptationSets.get(0).representations.get(0).format,
160+
adaptationSets.get(0).representations.get(1).format,
161+
adaptationSets.get(1).representations.get(0).format),
162+
new TrackGroup(
163+
/* id= */ "3000000002",
164+
adaptationSets.get(2).representations.get(0).format,
165+
adaptationSets.get(2).representations.get(1).format),
166+
new TrackGroup(
167+
/* id= */ "3000000003", adaptationSets.get(3).representations.get(0).format));
168+
169+
MediaPeriodAsserts.assertTrackGroups(dashMediaPeriod, expectedTrackGroups);
170+
}
171+
146172
@Test
147173
public void adaptationSetSwitchingProperty_andTrickPlayProperty_mergesTrackGroups()
148174
throws IOException {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<MPD availabilityStartTime="2014-06-19T23:07:42" type="dynamic">
3+
<Period start="PT7462826.784S" id="0">
4+
<AdaptationSet id="3000000000" mimeType="video/mp4">
5+
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
6+
<SupplementalProperty
7+
schemeIdUri="http://dashif.org/guidelines/trickmode"
8+
value="3000000001"/>
9+
<Representation id="0" bandwidth="0" codecs="avc1.42c01f"/>
10+
<Representation id="1" bandwidth="1" codecs="avc1.42c01f"/>
11+
</AdaptationSet>
12+
<AdaptationSet id="3000000001" mimeType="video/mp4">
13+
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
14+
<Representation id="11" bandwidth="100" codecs="avc1.42c01f"/>
15+
</AdaptationSet>
16+
<AdaptationSet id="3000000002" mimeType="video/mp4">
17+
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
18+
<Representation id="21" bandwidth="200" codecs="avc1.42c01f"/>
19+
<Representation id="22" bandwidth="201" codecs="avc1.42c01f"/>
20+
</AdaptationSet>
21+
<AdaptationSet id="3000000003" mimeType="video/mp4">
22+
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="alternate"/>
23+
<SupplementalProperty
24+
schemeIdUri="http://dashif.org/guidelines/trickmode"
25+
value="3000000002"/>
26+
<Representation id="31" bandwidth="300" codecs="avc1.42c01f"/>
27+
</AdaptationSet>
28+
</Period>
29+
</MPD>

0 commit comments

Comments
 (0)