size_t IsoffMainParser::parseSegmentList(Node * segListNode, SegmentInformation *info) { size_t total = 0; mtime_t totaltime = 0; if(segListNode) { std::vector<Node *> segments = DOMHelper::getElementByTagName(segListNode, "SegmentURL", false); SegmentList *list; if((list = new (std::nothrow) SegmentList())) { parseInitSegment(DOMHelper::getFirstChildElementByName(segListNode, "Initialization"), list, info); if(segListNode->hasAttribute("duration")) list->setDuration(Integer<mtime_t>(segListNode->getAttributeValue("duration"))); if(segListNode->hasAttribute("timescale")) list->timescale.Set(Integer<uint64_t>(segListNode->getAttributeValue("timescale"))); std::vector<Node *>::const_iterator it; for(it = segments.begin(); it != segments.end(); ++it) { Node *segmentURL = *it; std::string mediaUrl = segmentURL->getAttributeValue("media"); if(mediaUrl.empty()) continue; Segment *seg = new (std::nothrow) Segment(info); if(!seg) continue; seg->setSourceUrl(segmentURL->getAttributeValue("media")); if(segmentURL->hasAttribute("mediaRange")) { std::string range = segmentURL->getAttributeValue("mediaRange"); size_t pos = range.find("-"); seg->setByteRange(atoi(range.substr(0, pos).c_str()), atoi(range.substr(pos + 1, range.size()).c_str())); } if(totaltime || list->getDuration()) { seg->startTime.Set(totaltime); totaltime += list->getDuration(); } list->addSegment(seg); total++; } info->setSegmentList(list); } } return total; }
mtime_t SegmentInformation::getPlaybackTimeBySegmentNumber(uint64_t number) const { SegmentList *segList; MediaSegmentTemplate *mediaTemplate; uint64_t timescale = 1; mtime_t time = 0; if( (mediaTemplate = inheritSegmentTemplate()) ) { timescale = mediaTemplate->inheritTimescale(); if(mediaTemplate->segmentTimeline.Get()) { time = mediaTemplate->segmentTimeline.Get()-> getScaledPlaybackTimeByElementNumber(number); } else { time = number * mediaTemplate->duration.Get(); } } else if ( (segList = inheritSegmentList()) ) { timescale = segList->inheritTimescale(); time = number * segList->getDuration(); } if(time) time = CLOCK_FREQ * time / timescale; return time; }
bool SegmentInformation::getSegmentNumberByTime(mtime_t time, uint64_t *ret) const { SegmentList *segList; MediaSegmentTemplate *mediaTemplate; uint64_t timescale = 1; mtime_t duration = 0; if( (mediaTemplate = inheritSegmentTemplate()) ) { timescale = mediaTemplate->inheritTimescale(); duration = mediaTemplate->duration.Get(); } else if ( (segList = inheritSegmentList()) ) { timescale = segList->inheritTimescale(); duration = segList->getDuration(); } if(duration) { *ret = time / (CLOCK_FREQ * duration / timescale); return true; } return false; }