use of com.att.aro.core.videoanalysis.parsers.segmenttimeline.MPDSegmentTimeline in project VideoOptimzer by attdevsupport.
the class DashSegmentTimelineParser method updateManifest.
@Override
public void updateManifest(MpdBase manifest) {
MPDSegmentTimeline mani = (MPDSegmentTimeline) manifest;
AdaptationSetTL adSet = findAdaptationSet(mani, "video", null);
loadSegments(adSet);
}
use of com.att.aro.core.videoanalysis.parsers.segmenttimeline.MPDSegmentTimeline in project VideoOptimzer by attdevsupport.
the class ManifestBuilderDASH method processSegmentTimeline.
public void processSegmentTimeline(Manifest newManifest, XmlManifestHelper manifestView, String key, boolean isDynamic) {
// DASH SegmentTimeline
newManifest.setVideoType(VideoType.DASH_SEGMENTTIMELINE);
MPDSegmentTimeline mpdSegmentTimeline = (MPDSegmentTimeline) manifestView.getManifest();
long mediaPresentationDuration = isoConvertDurationTime(mpdSegmentTimeline.getMediaPresentationDuration());
Pattern nameRegex = Pattern.compile("\\/([^\\/]*)\\/$");
String[] urlName;
if ((urlName = stringParse.parse(mpdSegmentTimeline.getBaseURL(), nameRegex)) != null) {
newManifest.setUrlName(urlName[0]);
}
List<PeriodST> periods = mpdSegmentTimeline.getPeriod();
if (periods.size() > 1) {
LOG.debug("period count :" + periods.size() + ", " + newManifest.getUriStr());
return;
}
DashSegmentTimelineParser parseDashdynamic = new DashSegmentTimelineParser(mpdSegmentTimeline, newManifest, manifestCollection, childManifest);
List<AdaptationSetTL> adaptationSetList = parseDashdynamic.getAdaptationSet();
for (AdaptationSetTL adaptationSet : adaptationSetList) {
ContentType contentType = manifest.matchContentType(adaptationSet.getContentType());
if (adaptationSet.getContentType().equals("text")) {
// skipping Closed Caption for now
continue;
}
SegmentTemplateST segmentTemplate = adaptationSet.getSegmentTemplate();
SegmentTimeLineST segmentTimelineST = segmentTemplate.getSegmentTimeline();
List<SegmentST> segmentList;
if (segmentTimelineST != null && segmentTimelineST.getSegmentList() != null) {
segmentList = segmentTimelineST.getSegmentList();
} else {
segmentList = new ArrayList<>();
}
// segment 0 'moov'
String initialization = segmentTemplate.getInitialization();
// segment x 'moof'
String media = segmentTemplate.getMedia();
Double presentationTimeOffset = StringParse.stringToDouble(segmentTemplate.getPresentationTimeOffset(), 0);
Double timescale = StringParse.stringToDouble(segmentTemplate.getTimescale(), 1);
boolean manifestLiveUpdate;
if (isDynamic && (lastPresentationTimeOffset == -1D || ((Double.compare(lastPresentationTimeOffset, presentationTimeOffset) != 0)))) {
lastPresentationTimeOffset = presentationTimeOffset;
switchManifestCollection(newManifest, key, manifest.getRequestTime());
manifestLiveUpdate = false;
} else if (isDynamic) {
manifestLiveUpdate = isDynamic;
LOG.info("update manifest");
} else {
switchManifestCollection(newManifest, key, manifest.getRequestTime());
manifestLiveUpdate = false;
}
manifest.setTimeScale(timescale);
Integer qualityID = 0;
for (RepresentationST representation : adaptationSet.getRepresentation()) {
int segmentID = 0;
qualityID++;
String rid = representation.getContentID();
// generate REGEX for locating Byte position
String childUriName = media.replaceAll("\\$(RepresentationID)\\$", rid).replaceAll("\\$(Time)\\$", "(\\\\d+)");
if (manifestLiveUpdate && ((childManifest = manifestCollection.getUriNameChildMap().get(childUriName)) != null)) {
PatriciaTrie<SegmentInfo> segmentInfoList = childManifest.getSegmentInfoTrie();
for (String segmentKey : segmentInfoList.keySet()) {
SegmentInfo segmentInfo = segmentInfoList.get(segmentKey);
int sid = segmentInfo.getSegmentID();
if (segmentID < sid) {
segmentID = sid + 1;
}
}
} else {
// segment 1-end (moof) a regex for all
childManifest = createChildManifest(newManifest, "", childUriName);
childManifest.setPixelHeight(StringParse.stringToDouble(representation.getHeight(), 0).intValue());
childManifest.setPixelWidth(StringParse.stringToDouble(representation.getWidth(), 0).intValue());
childManifest.setBandwidth(StringParse.stringToDouble(representation.getBandwidth(), 0));
childManifest.setQuality(qualityID);
if (!StringUtils.isEmpty(initialization)) {
// segment 0 (moov)
String moovUriName = initialization.replaceAll("\\$(RepresentationID)\\$", rid);
manifestCollection.addToUriNameChildMap(moovUriName, childManifest);
}
manifestCollection.addToSegmentChildManifestTrie(childManifest.getUriName(), childManifest);
}
String segmentUriName;
SegmentInfo segmentInfo;
Double timePos = 0D;
Double duration = 0D;
Double repetition = 0D;
if (segmentList.size() > 0) {
SegmentST segment0 = segmentList.get(0);
timePos = StringParse.stringToDouble(segment0.getStartTime(), 0);
if (childManifest.getInitialStartTime() == -1) {
initialStartTime = timePos;
childManifest.setInitialStartTime(initialStartTime);
}
// segment moov
segmentInfo = genSegmentInfo(contentType, timescale, qualityID, segmentID, timePos - initialStartTime, 0D);
segmentUriName = initialization.replaceAll("\\$(.*)\\$", rid);
LOG.debug(String.format("moov >> %d :%s", segmentID, segmentUriName));
masterManifest.getSegUrlMatchDef().add(defineUrlMatching(segmentUriName));
segmentInfo = childManifest.addSegment(segmentUriName, segmentInfo);
addToSegmentManifestCollectionMap(segmentUriName);
// segments moof
segmentID = 1;
for (SegmentST segment : segmentList) {
duration = StringParse.stringToDouble(segment.getDuration(), 0);
repetition = StringParse.stringToDouble(segment.getRepeat(), 0);
for (Double countdown = repetition; countdown > -1; countdown--) {
segmentInfo = genSegmentInfo(contentType, timescale, qualityID, segmentID, timePos - initialStartTime, duration);
segmentUriName = media.replaceAll("\\$(RepresentationID)\\$", rid).replaceAll("\\$(Time)\\$", String.format("%.0f", timePos));
masterManifest.getSegUrlMatchDef().add(defineUrlMatching(segmentUriName));
addToSegmentManifestCollectionMap(segmentUriName);
LOG.debug(String.format("moof >> %d :%s", segmentID, segmentUriName));
segmentInfo = childManifest.addSegment(segmentUriName, segmentInfo);
timePos += duration;
segmentID = segmentInfo.getSegmentID() + 1;
}
}
}
addToSegmentManifestCollectionMap(childManifest.getUriName());
}
if (getChildManifest() == null) {
childManifest = createChildManifest(newManifest, "", newManifest.getUriStr());
}
if (adaptationSet.getContentType().equals("audio")) {
if (adaptationSet.getAudioChannelConfiguration() != null) {
childManifest.setChannels(adaptationSet.getAudioChannelConfiguration().getValue());
}
}
}
}
Aggregations