BaseRepresentation.cpp 4.44 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 25 26 27 28 29 30 31 32
/*
 * BaseRepresentation.cpp
 *****************************************************************************
 * Copyright (C) 2010 - 2011 Klagenfurt University
 *
 * Created on: Aug 10, 2010
 * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
 *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
 *
 * 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.
 *****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstdlib>

#include "BaseRepresentation.h"
#include "BaseAdaptationSet.h"
#include "SegmentTemplate.h"
33
#include "SegmentTimeline.h"
34
#include "../ID.hpp"
35

36 37
using namespace adaptive;
using namespace adaptive::playlist;
38

39
BaseRepresentation::BaseRepresentation( BaseAdaptationSet *set ) :
40 41
                SegmentInformation( set ),
                adaptationSet   ( set ),
42
                bandwidth       (0)
43
{
44
    b_consistent = true;
45 46 47 48 49 50
}

BaseRepresentation::~BaseRepresentation ()
{
}

51 52 53 54 55
StreamFormat BaseRepresentation::getStreamFormat() const
{
    return StreamFormat();
}

56 57 58 59 60
BaseAdaptationSet * BaseRepresentation::getAdaptationSet()
{
    return adaptationSet;
}

61 62 63 64 65 66 67 68 69 70
uint64_t     BaseRepresentation::getBandwidth            () const
{
    return bandwidth;
}

void    BaseRepresentation::setBandwidth( uint64_t bandwidth )
{
    this->bandwidth = bandwidth;
}

71 72 73 74 75 76 77 78 79 80
const std::list<std::string> & BaseRepresentation::getCodecs() const
{
    return codecs;
}

void BaseRepresentation::addCodec(const std::string &codec)
{
    codecs.push_back(codec);
}

81 82 83 84 85
bool BaseRepresentation::needsUpdate() const
{
    return false;
}

86 87 88 89 90 91 92 93 94 95
bool BaseRepresentation::runLocalUpdates(mtime_t, uint64_t, bool)
{
    return false;
}

void BaseRepresentation::scheduleNextUpdate(uint64_t)
{

}

96 97 98 99 100
bool BaseRepresentation::consistentSegmentNumber() const
{
    return b_consistent;
}

101 102 103 104 105 106 107
void BaseRepresentation::pruneByPlaybackTime(mtime_t time)
{
    uint64_t num;
    if(getSegmentNumberByTime(time, &num))
        pruneBySegmentNumber(num);
}

108 109 110 111 112 113 114 115
mtime_t BaseRepresentation::getMinAheadTime(uint64_t curnum) const
{
    std::vector<ISegment *> seglist;
    getSegments(INFOTYPE_MEDIA, seglist);

    if(seglist.size() == 1 && seglist.front()->isTemplate())
    {
        const MediaSegmentTemplate *templ = dynamic_cast<MediaSegmentTemplate *>(seglist.front());
116
        if(templ)
117
        {
118
            const Timescale timescale = templ->inheritTimescale();
119
            stime_t i_length = templ->getMinAheadScaledTime(curnum);
120
            return timescale.ToTime(i_length);
121
        }
122 123 124

        /* should not happen */
        return CLOCK_FREQ;
125 126 127
    }

    mtime_t minTime = 0;
128
    const Timescale timescale = inheritTimescale();
129 130 131 132 133
    std::vector<ISegment *>::const_iterator it;
    for(it = seglist.begin(); it != seglist.end(); ++it)
    {
        const ISegment *seg = *it;
        if(seg->getSequenceNumber() > curnum)
134
            minTime += timescale.ToTime(seg->duration.Get());
135 136 137 138 139
    }

    return minTime;
}

140
void BaseRepresentation::debug(vlc_object_t *obj, int indent) const
141 142
{
    std::string text(indent, ' ');
143 144
    text.append("Representation ");
    text.append(id.str());
145
    msg_Dbg(obj, "%s", text.c_str());
146
    std::vector<ISegment *> list;
147
    getAllSegments(list);
148
    std::vector<ISegment *>::const_iterator l;
149
    for(l = list.begin(); l != list.end(); ++l)
150
        (*l)->debug(obj, indent + 1);
151 152 153 154 155 156 157
}

std::string BaseRepresentation::contextualize(size_t, const std::string &component,
                                              const BaseSegmentTemplate *) const
{
    return component;
}
158

159 160 161 162 163 164
bool BaseRepresentation::bwCompare(const BaseRepresentation *a,
                                   const BaseRepresentation *b)
{
    return a->getBandwidth() < b->getBandwidth();
}

165 166 167 168
bool BaseRepresentation::validateCodec(const std::string &) const
{
    return true;
}