1 /*****************************************************************************
2 * SegmentTimeline.cpp: Implement the SegmentTimeline tag.
3 *****************************************************************************
4 * Copyright (C) 1998-2007 VLC authors and VideoLAN
7 * Authors: Hugo Beauzée-Luyssen <beauze.h@gmail.com>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #include "SegmentTimeline.h"
26 #include <vlc_common.h>
27 #include <vlc_arrays.h>
31 using namespace dash::mpd;
33 SegmentTimeline::SegmentTimeline() :
38 SegmentTimeline::~SegmentTimeline()
40 vlc_delete_all( this->elements );
43 int dash::mpd::SegmentTimeline::getTimescale() const
45 return this->timescale;
48 void dash::mpd::SegmentTimeline::setTimescale(int timescale)
50 this->timescale = timescale;
53 void dash::mpd::SegmentTimeline::addElement(dash::mpd::SegmentTimeline::Element *e)
55 this->elements.push_back( e );
58 const SegmentTimeline::Element* SegmentTimeline::getElement( mtime_t dts ) const
60 if ( this->elements.size() == 0 )
62 int64_t targetT = dts * this->timescale / 1000000;
63 targetT -= this->elements.front()->t;
65 std::list<Element*>::const_iterator it = this->elements.begin();
66 std::list<Element*>::const_iterator end = this->elements.end();
67 const Element* res = NULL;
71 if ( (*it)->t > targetT )
76 std::cerr << "No more element to be used." << std::endl;
80 dash::mpd::SegmentTimeline::Element::Element() :