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;
}