SegmentInfoCommon.cpp 2.66 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*****************************************************************************
 * SegmentInfoCommon.cpp: Implement the common part for both SegmentInfoDefault
 *                        and SegmentInfo
 *****************************************************************************
 * Copyright (C) 1998-2007 VLC authors and VideoLAN
 * $Id$
 *
 * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

25 26 27 28
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

29 30
#include "SegmentInfoCommon.h"

31
using namespace adaptative::playlist;
32

33
SegmentInfoCommon::SegmentInfoCommon( ICanonicalUrl *parent ) :
34
    ICanonicalUrl( parent ), Initializable(), Indexable(),
35
    startIndex( 0 )
36
{
37
    duration.Set(0);
38 39 40
}

SegmentInfoCommon::~SegmentInfoCommon()
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
{
}

int         SegmentInfoCommon::getStartIndex() const
{
    return this->startIndex;
}

void        SegmentInfoCommon::setStartIndex(int startIndex)
{
    if ( startIndex >= 0 )
        this->startIndex = startIndex;
}

void SegmentInfoCommon::appendBaseURL(const std::string &url)
{
    this->baseURLs.push_back( url );
}

60
Url SegmentInfoCommon::getUrlSegment() const
61
{
62
    Url ret = getParentUrlSegment();
63 64 65 66
    if (!baseURLs.empty())
        ret.append(baseURLs.front());
    return ret;
}
67

68 69
bool SegmentInfoCommon::getSegmentNumberByScaledTime(const std::vector<ISegment *> &segments,
                                                      stime_t time, uint64_t *ret)
70
{
71
    if(segments.empty() || (segments.size() > 1 && segments[1]->startTime.Get() == 0) )
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
        return false;

    std::vector<ISegment *>::const_iterator it = segments.begin();
    while(it != segments.end())
    {
        const ISegment *seg = *it;
        if(seg->startTime.Get() > time)
        {
            if(it == segments.begin())
                return false;
            else
                break;
        }

        (*ret)++;
        it++;
    }

    (*ret)--;
    return true;
}