]> git.sesse.net Git - vlc/blob - modules/stream_filter/dash/mpd/SegmentTimeline.cpp
dash: Allow SegmentTimeline to be queried for a "S" element.
[vlc] / modules / stream_filter / dash / mpd / SegmentTimeline.cpp
1 /*****************************************************************************
2  * SegmentTimeline.cpp: Implement the SegmentTimeline tag.
3  *****************************************************************************
4  * Copyright (C) 1998-2007 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Hugo BeauzĂ©e-Luyssen <beauze.h@gmail.com>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #include "SegmentTimeline.h"
25
26 #include <vlc_common.h>
27 #include <vlc_arrays.h>
28
29 #include <iostream>
30
31 using namespace dash::mpd;
32
33 SegmentTimeline::SegmentTimeline() :
34     timescale( -1 )
35 {
36 }
37
38 SegmentTimeline::~SegmentTimeline()
39 {
40     vlc_delete_all( this->elements );
41 }
42
43 int dash::mpd::SegmentTimeline::getTimescale() const
44 {
45     return this->timescale;
46 }
47
48 void dash::mpd::SegmentTimeline::setTimescale(int timescale)
49 {
50     this->timescale = timescale;
51 }
52
53 void dash::mpd::SegmentTimeline::addElement(dash::mpd::SegmentTimeline::Element *e)
54 {
55     this->elements.push_back( e );
56 }
57
58 const SegmentTimeline::Element*    SegmentTimeline::getElement( mtime_t dts ) const
59 {
60     if ( this->elements.size() == 0 )
61         return NULL;
62     int64_t     targetT = dts * this->timescale / 1000000;
63     targetT -= this->elements.front()->t;
64
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;
68
69     while ( it != end )
70     {
71         if ( (*it)->t > targetT )
72             return res;
73         res = *it;
74         ++it;
75     }
76     std::cerr << "No more element to be used." << std::endl;
77     return NULL;
78 }
79
80 dash::mpd::SegmentTimeline::Element::Element() :
81     r( 0 )
82 {
83 }