3 *****************************************************************************
4 * Copyright (C) 2010 - 2011 Klagenfurt University
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>
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.
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.
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 #define __STDC_CONSTANT_MACROS
31 #include "Representation.h"
33 #include "mp4/AtomsReader.hpp"
37 using namespace dash::mpd;
38 using namespace dash::http;
40 ISegment::ISegment(const ICanonicalUrl *parent):
41 ICanonicalUrl( parent ),
45 debugName = "Segment";
46 classId = CLASSID_ISEGMENT;
47 startTime.Set(VLC_TS_INVALID);
51 dash::http::Chunk * ISegment::getChunk(const std::string &url)
53 return new (std::nothrow) SegmentChunk(this, url);
56 dash::http::Chunk* ISegment::toChunk(size_t index, Representation *ctxrep)
61 chunk = getChunk(getUrlSegment().toString(index, ctxrep));
70 if(startByte != endByte)
72 chunk->setStartByte(startByte);
73 chunk->setEndByte(endByte);
79 bool ISegment::isSingleShot() const
85 //Only used for a SegmentTemplate.
88 void ISegment::setByteRange(size_t start, size_t end)
94 size_t ISegment::getOffset() const
99 std::string ISegment::toString(int indent) const
101 std::stringstream ss;
102 ss << std::string(indent, ' ') << debugName << " url=" << getUrlSegment().toString();
103 if(startByte!=endByte)
104 ss << " @" << startByte << ".." << endByte;
108 bool ISegment::contains(size_t byte) const
110 if (startByte == endByte)
112 return (byte >= startByte &&
113 (!endByte || byte <= endByte) );
116 int ISegment::getClassId() const
121 ISegment::SegmentChunk::SegmentChunk(ISegment *segment_, const std::string &url) :
122 dash::http::Chunk(url)
127 void ISegment::SegmentChunk::onDownload(void *, size_t)
132 Segment::Segment(ICanonicalUrl *parent) :
136 classId = CLASSID_SEGMENT;
139 void Segment::addSubSegment(SubSegment *subsegment)
141 subsegments.push_back(subsegment);
146 std::vector<SubSegment*>::iterator it;
147 for(it=subsegments.begin();it!=subsegments.end();it++)
151 void Segment::setSourceUrl ( const std::string &url )
153 if ( url.empty() == false )
154 this->sourceUrl = url;
157 std::string Segment::toString(int indent) const
159 if (subsegments.empty())
161 return ISegment::toString(indent);
166 std::vector<SubSegment *>::const_iterator l;
167 for(l = subsegments.begin(); l != subsegments.end(); l++)
169 ret.append( (*l)->toString(indent + 1) );
175 Url Segment::getUrlSegment() const
177 Url ret = getParentUrlSegment();
178 if (!sourceUrl.empty())
179 ret.append(sourceUrl);
183 dash::http::Chunk* Segment::toChunk(size_t index, Representation *ctxrep)
185 Chunk *chunk = ISegment::toChunk(index, ctxrep);
187 chunk->setBitrate(ctxrep->getBandwidth());
191 std::vector<ISegment*> Segment::subSegments()
193 std::vector<ISegment*> list;
194 if(!subsegments.empty())
196 std::vector<SubSegment*>::iterator it;
197 for(it=subsegments.begin();it!=subsegments.end();it++)
202 list.push_back(this);
207 InitSegment::InitSegment(ICanonicalUrl *parent) :
210 debugName = "InitSegment";
211 classId = CLASSID_INITSEGMENT;
214 IndexSegment::IndexSegment(ICanonicalUrl *parent) :
217 debugName = "IndexSegment";
218 classId = CLASSID_INDEXSEGMENT;
221 dash::http::Chunk* IndexSegment::toChunk(size_t index, Representation *ctxrep)
223 IndexSegmentChunk *chunk = dynamic_cast<IndexSegmentChunk *>(Segment::toChunk(index, ctxrep));
224 chunk->setIndexRepresentation(ctxrep);
228 dash::http::Chunk * IndexSegment::getChunk(const std::string &url)
230 return new IndexSegmentChunk(this, url);
233 IndexSegment::IndexSegmentChunk::IndexSegmentChunk(ISegment *segment, const std::string &url)
234 : SegmentChunk(segment, url)
239 void IndexSegment::IndexSegmentChunk::setIndexRepresentation(Representation *rep_)
244 void IndexSegment::IndexSegmentChunk::onDownload(void *buffer, size_t size)
249 dash::mp4::AtomsReader br(rep->getMPD()->getVLCObject());
250 br.parseBlock(buffer, size, rep);
253 SubSegment::SubSegment(Segment *main, size_t start, size_t end) :
254 ISegment(main), parent(main)
256 setByteRange(start, end);
257 debugName = "SubSegment";
258 classId = CLASSID_SUBSEGMENT;
261 Url SubSegment::getUrlSegment() const
263 return getParentUrlSegment();
266 std::vector<ISegment*> SubSegment::subSegments()
268 std::vector<ISegment*> list;
269 list.push_back(this);