Skip to content

Commit

Permalink
Merge pull request androidx#487 from vishnuchilakala:allow_unsigned_i…
Browse files Browse the repository at this point in the history
…nt_for_adaptation_set_id

PiperOrigin-RevId: 544601945
  • Loading branch information
microkatz committed Jul 5, 2023
2 parents f2c0eab + 4169386 commit 9513f2c
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import android.util.Pair;
import android.util.SparseArray;
import android.util.SparseIntArray;
import androidx.annotation.IntDef;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
Expand Down Expand Up @@ -58,6 +57,7 @@
import androidx.media3.exoplayer.upstream.CmcdConfiguration;
import androidx.media3.exoplayer.upstream.LoadErrorHandlingPolicy;
import androidx.media3.exoplayer.upstream.LoaderErrorThrower;
import com.google.common.collect.Maps;
import com.google.common.primitives.Ints;
import java.io.IOException;
import java.lang.annotation.Documented;
Expand All @@ -66,6 +66,7 @@
import java.lang.annotation.Target;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -550,7 +551,8 @@ private static Pair<TrackGroupArray, TrackGroupInfo[]> buildTrackGroups(
*/
private static int[][] getGroupedAdaptationSetIndices(List<AdaptationSet> adaptationSets) {
int adaptationSetCount = adaptationSets.size();
SparseIntArray adaptationSetIdToIndex = new SparseIntArray(adaptationSetCount);
HashMap<Long, Integer> adaptationSetIdToIndex =
Maps.newHashMapWithExpectedSize(adaptationSetCount);
List<List<Integer>> adaptationSetGroupedIndices = new ArrayList<>(adaptationSetCount);
SparseArray<List<Integer>> adaptationSetIndexToGroupedIndices =
new SparseArray<>(adaptationSetCount);
Expand Down Expand Up @@ -578,10 +580,9 @@ private static int[][] getGroupedAdaptationSetIndices(List<AdaptationSet> adapta
trickPlayProperty = findTrickPlayProperty(adaptationSet.supplementalProperties);
}
if (trickPlayProperty != null) {
int mainAdaptationSetId = Integer.parseInt(trickPlayProperty.value);
int mainAdaptationSetIndex =
adaptationSetIdToIndex.get(mainAdaptationSetId, /* valueIfKeyNotFound= */ -1);
if (mainAdaptationSetIndex != -1) {
long mainAdaptationSetId = Long.parseLong(trickPlayProperty.value);
@Nullable Integer mainAdaptationSetIndex = adaptationSetIdToIndex.get(mainAdaptationSetId);
if (mainAdaptationSetIndex != null) {
mergedGroupIndex = mainAdaptationSetIndex;
}
}
Expand All @@ -595,11 +596,11 @@ private static int[][] getGroupedAdaptationSetIndices(List<AdaptationSet> adapta
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 = min(mergedGroupIndex, otherAdaptationSetId);
@Nullable
Integer otherAdaptationSetIndex =
adaptationSetIdToIndex.get(Long.parseLong(adaptationSetId));
if (otherAdaptationSetIndex != null) {
mergedGroupIndex = min(mergedGroupIndex, otherAdaptationSetIndex);
}
}
}
Expand Down Expand Up @@ -683,7 +684,7 @@ private static int buildPrimaryAndEmbeddedTrackGroupInfos(
AdaptationSet firstAdaptationSet = adaptationSets.get(adaptationSetIndices[0]);
String trackGroupId =
firstAdaptationSet.id != AdaptationSet.ID_UNSET
? Integer.toString(firstAdaptationSet.id)
? Long.toString(firstAdaptationSet.id)
: ("unset:" + i);
int primaryTrackGroupIndex = trackGroupCount++;
int eventMessageTrackGroupIndex =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
public class AdaptationSet {

/** Value of {@link #id} indicating no value is set.= */
public static final int ID_UNSET = -1;
public static final long ID_UNSET = -1;

/**
* A non-negative identifier for the adaptation set that's unique in the scope of its containing
* period, or {@link #ID_UNSET} if not specified.
*/
public final int id;
public final long id;

/** The {@link C.TrackType track type} of the adaptation set. */
public final @C.TrackType int type;
Expand All @@ -58,7 +58,7 @@ public class AdaptationSet {
* @param supplementalProperties Supplemental properties in the adaptation set.
*/
public AdaptationSet(
int id,
long id,
@C.TrackType int type,
List<Representation> representations,
List<Descriptor> accessibilityDescriptors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ protected AdaptationSet parseAdaptationSet(
long timeShiftBufferDepthMs,
boolean dvbProfileDeclared)
throws XmlPullParserException, IOException {
int id = parseInt(xpp, "id", AdaptationSet.ID_UNSET);
long id = parseLong(xpp, "id", AdaptationSet.ID_UNSET);
@C.TrackType int contentType = parseContentType(xpp);

String mimeType = xpp.getAttributeValue(null, "mimeType");
Expand Down Expand Up @@ -532,7 +532,7 @@ protected AdaptationSet parseAdaptationSet(
}

protected AdaptationSet buildAdaptationSet(
int id,
long id,
@C.TrackType int contentType,
List<Representation> representations,
List<Descriptor> accessibilityDescriptors,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ public void adaptationSetSwitchingProperty_mergesTrackGroups() throws IOExceptio
TrackGroupArray expectedTrackGroups =
new TrackGroupArray(
new TrackGroup(
/* id= */ "0",
/* id= */ "3000000000",
adaptationSets.get(0).representations.get(0).format,
adaptationSets.get(0).representations.get(1).format,
adaptationSets.get(2).representations.get(0).format,
adaptationSets.get(2).representations.get(1).format,
adaptationSets.get(3).representations.get(0).format),
new TrackGroup(/* id= */ "3", adaptationSets.get(1).representations.get(0).format));
new TrackGroup(
/* id= */ "3000000003", adaptationSets.get(1).representations.get(0).format));

MediaPeriodAsserts.assertTrackGroups(dashMediaPeriod, expectedTrackGroups);
}
Expand All @@ -102,12 +103,12 @@ public void trickPlayProperty_mergesTrackGroups() throws IOException {
TrackGroupArray expectedTrackGroups =
new TrackGroupArray(
new TrackGroup(
/* id= */ "0",
/* id= */ "3000000000",
adaptationSets.get(0).representations.get(0).format,
adaptationSets.get(0).representations.get(1).format,
adaptationSets.get(1).representations.get(0).format),
new TrackGroup(
/* id= */ "2",
/* id= */ "3000000002",
adaptationSets.get(2).representations.get(0).format,
adaptationSets.get(2).representations.get(1).format,
adaptationSets.get(3).representations.get(0).format));
Expand All @@ -127,7 +128,7 @@ public void adaptationSetSwitchingProperty_andTrickPlayProperty_mergesTrackGroup
TrackGroupArray expectedTrackGroups =
new TrackGroupArray(
new TrackGroup(
/* id= */ "0",
/* id= */ "3000000000",
adaptationSets.get(0).representations.get(0).format,
adaptationSets.get(0).representations.get(1).format,
adaptationSets.get(1).representations.get(0).format,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<MPD availabilityStartTime="2014-06-19T23:07:42" type="dynamic">
<Period start="PT7462826.784S" id="0">
<AdaptationSet id="0" mimeType="video/mp4">
<AdaptationSet id="3000000000" mimeType="video/mp4">
<SupplementalProperty
schemeIdUri="http://dashif.org/guidelines/trickmode"
value="1"/>
value="3000000001"/>
<Representation id="0" bandwidth="0" codecs="avc1.42c01f"/>
<Representation id="1" bandwidth="1" codecs="avc1.42c01f"/>
</AdaptationSet>
<AdaptationSet id="1" mimeType="video/mp4">
<AdaptationSet id="3000000001" mimeType="video/mp4">
<SupplementalProperty
schemeIdUri="urn:mpeg:dash:adaptation-set-switching:2016"
value="2"/>
value="3000000002"/>
<Representation id="11" bandwidth="100" codecs="avc1.42c01f"/>
</AdaptationSet>
<AdaptationSet id="2" mimeType="video/mp4">
<AdaptationSet id="3000000002" mimeType="video/mp4">
<SupplementalProperty
schemeIdUri="urn:mpeg:dash:adaptation-set-switching:2016"
value="1"/>
value="3000000001"/>
<Representation id="21" bandwidth="200" codecs="avc1.42c01f"/>
<Representation id="22" bandwidth="201" codecs="avc1.42c01f"/>
</AdaptationSet>
<AdaptationSet id="3" mimeType="video/mp4">
<AdaptationSet id="3000000003" mimeType="video/mp4">
<SupplementalProperty
schemeIdUri="http://dashif.org/guidelines/trickmode"
value="2"/>
value="3000000002"/>
<Representation id="31" bandwidth="300" codecs="avc1.42c01f"/>
</AdaptationSet>
</Period>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<MPD availabilityStartTime="2014-06-19T23:07:42" type="dynamic">
<Period start="PT7462826.784S" id="0">
<AdaptationSet id="0" mimeType="video/mp4">
<AdaptationSet id="3000000000" mimeType="video/mp4">
<SupplementalProperty
schemeIdUri="urn:mpeg:dash:adaptation-set-switching:2016"
value="1,2"/>
value="3000000001,3000000002"/>
<Representation id="1" bandwidth="0" codecs="avc1.42c01f"/>
<Representation id="2" bandwidth="1" codecs="avc1.42c01f"/>
</AdaptationSet>
<AdaptationSet id="3" mimeType="video/mp4">
<AdaptationSet id="3000000003" mimeType="video/mp4">
<Representation id="31" bandwidth="300" codecs="avc1.42c01f"/>
</AdaptationSet>
<AdaptationSet id="2" mimeType="video/mp4">
<AdaptationSet id="3000000002" mimeType="video/mp4">
<SupplementalProperty
schemeIdUri="urn:mpeg:dash:adaptation-set-switching:2016"
value="0,1"/>
value="3000000000,3000000001"/>
<Representation id="21" bandwidth="200" codecs="avc1.42c01f"/>
<Representation id="21" bandwidth="201" codecs="avc1.42c01f"/>
</AdaptationSet>
<AdaptationSet id="1" mimeType="video/mp4">
<AdaptationSet id="3000000001" mimeType="video/mp4">
<SupplementalProperty
schemeIdUri="urn:mpeg:dash:adaptation-set-switching:2016"
value="0,2"/>
value="3000000000,3000000002"/>
<Representation id="11" bandwidth="100" codecs="avc1.42c01f"/>
</AdaptationSet>
</Period>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<MPD availabilityStartTime="2014-06-19T23:07:42" type="dynamic">
<Period start="PT7462826.784S" id="0">
<AdaptationSet id="0" mimeType="video/mp4">
<AdaptationSet id="3000000000" mimeType="video/mp4">
<SupplementalProperty
schemeIdUri="http://dashif.org/guidelines/trickmode"
value="1"/>
value="3000000001"/>
<Representation id="0" bandwidth="0" codecs="avc1.42c01f"/>
<Representation id="1" bandwidth="1" codecs="avc1.42c01f"/>
</AdaptationSet>
<AdaptationSet id="1" mimeType="video/mp4">
<AdaptationSet id="3000000001" mimeType="video/mp4">
<Representation id="11" bandwidth="100" codecs="avc1.42c01f"/>
</AdaptationSet>
<AdaptationSet id="2" mimeType="video/mp4">
<AdaptationSet id="3000000002" mimeType="video/mp4">
<Representation id="21" bandwidth="200" codecs="avc1.42c01f"/>
<Representation id="22" bandwidth="201" codecs="avc1.42c01f"/>
</AdaptationSet>
<AdaptationSet id="3" mimeType="video/mp4">
<AdaptationSet id="3000000003" mimeType="video/mp4">
<SupplementalProperty
schemeIdUri="http://dashif.org/guidelines/trickmode"
value="2"/>
value="3000000002"/>
<Representation id="31" bandwidth="300" codecs="avc1.42c01f"/>
</AdaptationSet>
</Period>
Expand Down
4 changes: 2 additions & 2 deletions libraries/test_data/src/test/assets/media/mpd/sample_mpd_vod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
type="static"
mediaPresentationDuration="PT904S">
<Period id="1" duration="PT904S" start="PT0S">
<AdaptationSet id="0" mimeType="video/mp4" contentType="video" segmentAlignment="true" startWithSAP="1">
<AdaptationSet id="3000000000" mimeType="video/mp4" contentType="video" segmentAlignment="true" startWithSAP="1">
<Role schemeIdUri="urn:mpeg:dash:role:2011" value="main"/>
<SegmentTemplate presentationTimeOffset="0" media="video_$Time$_$Bandwidth$.m4s" timescale="1000" >
<SegmentTimeline>
Expand All @@ -20,7 +20,7 @@
<Representation id="3" codecs="avc1.42c00c" width="400" height="224" frameRate="25/2" bandwidth="250000"/>
<Representation id="4" codecs="avc1.42c00b" width="400" height="224" frameRate="5" bandwidth="50000"/>
</AdaptationSet>
<AdaptationSet id="1" lang="fr" mimeType="audio/mp4" contentType="audio" codecs="mp4a.40.2" segmentAlignment="true" startWithSAP="1">
<AdaptationSet id="3000000001" lang="fr" mimeType="audio/mp4" contentType="audio" codecs="mp4a.40.2" segmentAlignment="true" startWithSAP="1">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:mpegB:cicp:ChannelConfiguration" value="2"/>
<SegmentTemplate presentationTimeOffset="0" media="audio_$Time$_$Bandwidth$.m4s" timescale="1000" >
<SegmentTimeline>
Expand Down

0 comments on commit 9513f2c

Please sign in to comment.