]> git.sesse.net Git - vlc/blob - modules/stream_filter/dash/mpd/Segment.cpp
stream_filter: dash: remove unused segment methods
[vlc] / modules / stream_filter / dash / mpd / Segment.cpp
1 /*
2  * Segment.cpp
3  *****************************************************************************
4  * Copyright (C) 2010 - 2011 Klagenfurt University
5  *
6  * Created on: Aug 10, 2010
7  * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
8  *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
9  *
10  * This program is free software; you can redistribute it and/or modify it
11  * under the terms of the GNU Lesser General Public License as published
12  * by the Free Software Foundation; either version 2.1 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
27
28 #include "Segment.h"
29 #include "Representation.h"
30
31 #include <cassert>
32
33 using namespace dash::mpd;
34 using namespace dash::http;
35
36 Segment::Segment(const Representation *parent) :
37         startByte  (-1),
38         endByte    (-1),
39         parentRepresentation( parent )
40 {
41     assert( parent != NULL );
42     if ( parent->getSegmentInfo() != NULL && parent->getSegmentInfo()->getDuration() >= 0 )
43         this->size = parent->getBandwidth() * parent->getSegmentInfo()->getDuration();
44     else
45         this->size = -1;
46 }
47
48 std::string             Segment::getSourceUrl   () const
49 {
50     return this->sourceUrl;
51 }
52
53 void                    Segment::setSourceUrl   ( const std::string &url )
54 {
55     if ( url.empty() == false )
56         this->sourceUrl = url;
57 }
58 bool                    Segment::isSingleShot   () const
59 {
60     return true;
61 }
62 void                    Segment::done           ()
63 {
64     //Only used for a SegmentTemplate.
65 }
66 void                    Segment::addBaseUrl     (BaseUrl *url)
67 {
68     this->baseUrls.push_back(url);
69 }
70
71 void                    Segment::setByteRange   (int start, int end)
72 {
73     this->startByte = start;
74     this->endByte   = end;
75 }
76
77 dash::http::Chunk*      Segment::toChunk        ()
78 {
79     Chunk *chunk = new Chunk();
80
81     if(this->startByte != -1 && this->endByte != -1)
82     {
83         chunk->setUseByteRange(true);
84         chunk->setStartByte(this->startByte);
85         chunk->setEndByte(this->endByte);
86     }
87
88     if(this->baseUrls.size() > 0)
89     {
90         std::stringstream ss;
91         ss << this->baseUrls.at(0)->getUrl() << this->sourceUrl;
92         chunk->setUrl(ss.str());
93         ss.clear();
94
95         for(size_t i = 1; i < this->baseUrls.size(); i++)
96         {
97             ss << this->baseUrls.at(i)->getUrl() << this->sourceUrl;
98             chunk->addOptionalUrl(ss.str());
99             ss.clear();
100         }
101     }
102     else
103     {
104         chunk->setUrl(this->sourceUrl);
105     }
106
107     chunk->setBitrate(this->parentRepresentation->getBandwidth());
108
109     return chunk;
110 }
111
112 const Representation *Segment::getParentRepresentation() const
113 {
114     return this->parentRepresentation;
115 }