mirror of
https://github.com/androidx/media.git
synced 2025-05-12 10:09:55 +08:00
Support negative value of the @r attrbute of S in SegmentTimeline element
This commit is contained in:
parent
b57c556194
commit
b4a1d55fe4
@ -237,7 +237,7 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
seenFirstBaseUrl = true;
|
seenFirstBaseUrl = true;
|
||||||
}
|
}
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "AdaptationSet")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "AdaptationSet")) {
|
||||||
adaptationSets.add(parseAdaptationSet(xpp, baseUrl, segmentBase));
|
adaptationSets.add(parseAdaptationSet(xpp, baseUrl, segmentBase, durationMs));
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "EventStream")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "EventStream")) {
|
||||||
eventStreams.add(parseEventStream(xpp));
|
eventStreams.add(parseEventStream(xpp));
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentBase")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentBase")) {
|
||||||
@ -245,7 +245,7 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentList")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentList")) {
|
||||||
segmentBase = parseSegmentList(xpp, null);
|
segmentBase = parseSegmentList(xpp, null);
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTemplate")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTemplate")) {
|
||||||
segmentBase = parseSegmentTemplate(xpp, null, Collections.emptyList());
|
segmentBase = parseSegmentTemplate(xpp, null, Collections.emptyList(), durationMs);
|
||||||
} else {
|
} else {
|
||||||
maybeSkipTag(xpp);
|
maybeSkipTag(xpp);
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
// AdaptationSet parsing.
|
// AdaptationSet parsing.
|
||||||
|
|
||||||
protected AdaptationSet parseAdaptationSet(
|
protected AdaptationSet parseAdaptationSet(
|
||||||
XmlPullParser xpp, String baseUrl, @Nullable SegmentBase segmentBase)
|
XmlPullParser xpp, String baseUrl, @Nullable SegmentBase segmentBase, long periodDurationMs)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
int id = parseInt(xpp, "id", AdaptationSet.ID_UNSET);
|
int id = parseInt(xpp, "id", AdaptationSet.ID_UNSET);
|
||||||
int contentType = parseContentType(xpp);
|
int contentType = parseContentType(xpp);
|
||||||
@ -328,7 +328,8 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
roleDescriptors,
|
roleDescriptors,
|
||||||
accessibilityDescriptors,
|
accessibilityDescriptors,
|
||||||
supplementalProperties,
|
supplementalProperties,
|
||||||
segmentBase);
|
segmentBase,
|
||||||
|
periodDurationMs);
|
||||||
contentType = checkContentTypeConsistency(contentType,
|
contentType = checkContentTypeConsistency(contentType,
|
||||||
getContentType(representationInfo.format));
|
getContentType(representationInfo.format));
|
||||||
representationInfos.add(representationInfo);
|
representationInfos.add(representationInfo);
|
||||||
@ -338,7 +339,8 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
segmentBase = parseSegmentList(xpp, (SegmentList) segmentBase);
|
segmentBase = parseSegmentList(xpp, (SegmentList) segmentBase);
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTemplate")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTemplate")) {
|
||||||
segmentBase =
|
segmentBase =
|
||||||
parseSegmentTemplate(xpp, (SegmentTemplate) segmentBase, supplementalProperties);
|
parseSegmentTemplate(xpp, (SegmentTemplate) segmentBase, supplementalProperties,
|
||||||
|
periodDurationMs);
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "InbandEventStream")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "InbandEventStream")) {
|
||||||
inbandEventStreams.add(parseDescriptor(xpp, "InbandEventStream"));
|
inbandEventStreams.add(parseDescriptor(xpp, "InbandEventStream"));
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp)) {
|
} else if (XmlPullParserUtil.isStartTag(xpp)) {
|
||||||
@ -492,7 +494,7 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
List<Descriptor> adaptationSetRoleDescriptors,
|
List<Descriptor> adaptationSetRoleDescriptors,
|
||||||
List<Descriptor> adaptationSetAccessibilityDescriptors,
|
List<Descriptor> adaptationSetAccessibilityDescriptors,
|
||||||
List<Descriptor> adaptationSetSupplementalProperties,
|
List<Descriptor> adaptationSetSupplementalProperties,
|
||||||
@Nullable SegmentBase segmentBase)
|
@Nullable SegmentBase segmentBase, long periodDurationMs)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
String id = xpp.getAttributeValue(null, "id");
|
String id = xpp.getAttributeValue(null, "id");
|
||||||
int bandwidth = parseInt(xpp, "bandwidth", Format.NO_VALUE);
|
int bandwidth = parseInt(xpp, "bandwidth", Format.NO_VALUE);
|
||||||
@ -526,7 +528,8 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTemplate")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTemplate")) {
|
||||||
segmentBase =
|
segmentBase =
|
||||||
parseSegmentTemplate(
|
parseSegmentTemplate(
|
||||||
xpp, (SegmentTemplate) segmentBase, adaptationSetSupplementalProperties);
|
xpp, (SegmentTemplate) segmentBase, adaptationSetSupplementalProperties,
|
||||||
|
periodDurationMs);
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "ContentProtection")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "ContentProtection")) {
|
||||||
Pair<String, SchemeData> contentProtection = parseContentProtection(xpp);
|
Pair<String, SchemeData> contentProtection = parseContentProtection(xpp);
|
||||||
if (contentProtection.first != null) {
|
if (contentProtection.first != null) {
|
||||||
@ -735,7 +738,7 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
|
if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
|
||||||
initialization = parseInitialization(xpp);
|
initialization = parseInitialization(xpp);
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTimeline")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTimeline")) {
|
||||||
timeline = parseSegmentTimeline(xpp);
|
timeline = parseSegmentTimeline(xpp,timescale,duration);
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentURL")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentURL")) {
|
||||||
if (segments == null) {
|
if (segments == null) {
|
||||||
segments = new ArrayList<>();
|
segments = new ArrayList<>();
|
||||||
@ -771,7 +774,8 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
protected SegmentTemplate parseSegmentTemplate(
|
protected SegmentTemplate parseSegmentTemplate(
|
||||||
XmlPullParser xpp,
|
XmlPullParser xpp,
|
||||||
@Nullable SegmentTemplate parent,
|
@Nullable SegmentTemplate parent,
|
||||||
List<Descriptor> adaptationSetSupplementalProperties)
|
List<Descriptor> adaptationSetSupplementalProperties,
|
||||||
|
long periodDurationMs)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
|
long timescale = parseLong(xpp, "timescale", parent != null ? parent.timescale : 1);
|
||||||
long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
|
long presentationTimeOffset = parseLong(xpp, "presentationTimeOffset",
|
||||||
@ -794,7 +798,7 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
|
if (XmlPullParserUtil.isStartTag(xpp, "Initialization")) {
|
||||||
initialization = parseInitialization(xpp);
|
initialization = parseInitialization(xpp);
|
||||||
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTimeline")) {
|
} else if (XmlPullParserUtil.isStartTag(xpp, "SegmentTimeline")) {
|
||||||
timeline = parseSegmentTimeline(xpp);
|
timeline = parseSegmentTimeline(xpp,timescale,periodDurationMs);
|
||||||
} else {
|
} else {
|
||||||
maybeSkipTag(xpp);
|
maybeSkipTag(xpp);
|
||||||
}
|
}
|
||||||
@ -989,7 +993,8 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
return new EventMessage(schemeIdUri, value, durationMs, id, messageData);
|
return new EventMessage(schemeIdUri, value, durationMs, id, messageData);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<SegmentTimelineElement> parseSegmentTimeline(XmlPullParser xpp)
|
protected List<SegmentTimelineElement> parseSegmentTimeline(XmlPullParser xpp,long timescale,
|
||||||
|
long periodDurationMs)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
List<SegmentTimelineElement> segmentTimeline = new ArrayList<>();
|
List<SegmentTimelineElement> segmentTimeline = new ArrayList<>();
|
||||||
long elapsedTime = 0;
|
long elapsedTime = 0;
|
||||||
@ -998,7 +1003,12 @@ public class DashManifestParser extends DefaultHandler
|
|||||||
if (XmlPullParserUtil.isStartTag(xpp, "S")) {
|
if (XmlPullParserUtil.isStartTag(xpp, "S")) {
|
||||||
elapsedTime = parseLong(xpp, "t", elapsedTime);
|
elapsedTime = parseLong(xpp, "t", elapsedTime);
|
||||||
long duration = parseLong(xpp, "d", C.TIME_UNSET);
|
long duration = parseLong(xpp, "d", C.TIME_UNSET);
|
||||||
int count = 1 + parseInt(xpp, "r", 0);
|
|
||||||
|
//if repeat is -1 : length of each segment = duration / timescale and
|
||||||
|
// number of segments = periodDuration / length of each segment
|
||||||
|
int repeat = parseInt(xpp,"r",0);
|
||||||
|
int count = repeat != -1? 1 + repeat : (int) (((periodDurationMs / 1000) * timescale) / duration);
|
||||||
|
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
segmentTimeline.add(buildSegmentTimelineElement(elapsedTime, duration));
|
segmentTimeline.add(buildSegmentTimelineElement(elapsedTime, duration));
|
||||||
elapsedTime += duration;
|
elapsedTime += duration;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user