Пример #1
0
mtime_t SegmentInformation::getPlaybackTimeBySegmentNumber(uint64_t number) const
{
    SegmentList *segList;
    MediaSegmentTemplate *mediaTemplate;
    mtime_t time = 0;
    if( (mediaTemplate = inheritSegmentTemplate()) )
    {
        uint64_t timescale = mediaTemplate->inheritTimescale();
        if(mediaTemplate->segmentTimeline.Get())
        {
            time = mediaTemplate->segmentTimeline.Get()->
                    getScaledPlaybackTimeByElementNumber(number);
        }
        else
        {
            time = number * mediaTemplate->duration.Get();
        }
        time = CLOCK_FREQ * time / timescale;
    }
    else if ( (segList = inheritSegmentList()) )
    {
        time = segList->getPlaybackTimeBySegmentNumber(number);
    }

    return time;
}
Пример #2
0
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;
}
bool SegmentInformation::getPlaybackTimeDurationBySegmentNumber(uint64_t number,
                                                                mtime_t *time, mtime_t *duration) const
{
    SegmentList *segList;
    MediaSegmentTemplate *mediaTemplate;

    if( (mediaTemplate = inheritSegmentTemplate()) )
    {
        const Timescale timescale = mediaTemplate->inheritTimescale();

        stime_t stime, sduration;
        if(mediaTemplate->segmentTimeline.Get())
        {
            mediaTemplate->segmentTimeline.Get()->
                getScaledPlaybackTimeDurationBySegmentNumber(number, &stime, &sduration);
        }
        else
        {
            stime = number * mediaTemplate->duration.Get();
            sduration = mediaTemplate->duration.Get();
        }
        *time = timescale.ToTime(stime);
        *duration = timescale.ToTime(sduration);
        return true;
    }
    else if ( (segList = inheritSegmentList()) )
    {
        return segList->getPlaybackTimeDurationBySegmentNumber(number, time, duration);
    }
    else
    {
        const Timescale timescale = inheritTimescale();
        const ISegment *segment = getSegment(SegmentInfoType::INFOTYPE_MEDIA, number);
        if( segment )
        {
            *time = timescale.ToTime(segment->startTime.Get());
            *duration = timescale.ToTime(segment->duration.Get());
            return true;
        }
    }

    return false;
}
Пример #4
0
size_t IsoffMainParser::parseSegmentTemplate(Node *templateNode, SegmentInformation *info)
{
    size_t total = 0;
    if (templateNode == NULL || !templateNode->hasAttribute("media"))
        return total;

    std::string mediaurl = templateNode->getAttributeValue("media");
    MediaSegmentTemplate *mediaTemplate = NULL;
    if(mediaurl.empty() || !(mediaTemplate = new (std::nothrow) MediaSegmentTemplate(info)) )
        return total;
    mediaTemplate->setSourceUrl(mediaurl);

    if(templateNode->hasAttribute("startNumber"))
        mediaTemplate->startNumber.Set(Integer<uint64_t>(templateNode->getAttributeValue("startNumber")));

    if(templateNode->hasAttribute("timescale"))
        mediaTemplate->timescale.Set(Integer<uint64_t>(templateNode->getAttributeValue("timescale")));

    if(templateNode->hasAttribute("duration"))
        mediaTemplate->duration.Set(Integer<stime_t>(templateNode->getAttributeValue("duration")));

    InitSegmentTemplate *initTemplate = NULL;

    if(templateNode->hasAttribute("initialization"))
    {
        std::string initurl = templateNode->getAttributeValue("initialization");
        if(!initurl.empty() && (initTemplate = new (std::nothrow) InitSegmentTemplate(info)))
            initTemplate->setSourceUrl(initurl);
    }

    mediaTemplate->initialisationSegment.Set(initTemplate);
    info->setSegmentTemplate(mediaTemplate);

    parseTimeline(DOMHelper::getFirstChildElementByName(templateNode, "SegmentTimeline"), mediaTemplate);

    total += ( mediaTemplate != NULL );

    return total;
}