demux: adaptive: merge toChunk/getChunk
[vlc.git] / modules / demux / adaptive / playlist / Segment.h
1 /*
2  * Segment.h
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
25 #ifndef SEGMENT_H_
26 #define SEGMENT_H_
27
28 #include <string>
29 #include <sstream>
30 #include <vector>
31 #include "ICanonicalUrl.hpp"
32 #include "../http/Chunk.h"
33 #include "../tools/Properties.hpp"
34 #include "Time.hpp"
35
36 namespace adaptive
37 {
38     namespace http
39     {
40         class HTTPConnectionManager;
41     }
42
43     namespace playlist
44     {
45         class BaseRepresentation;
46         class SubSegment;
47         class SegmentChunk;
48
49         using namespace http;
50
51         class ISegment : public ICanonicalUrl
52         {
53             public:
54                 ISegment(const ICanonicalUrl *parent);
55                 virtual ~ISegment();
56                 /**
57                  *  @return true if the segment should be dropped after being read.
58                  *          That is basically true when using an Url, and false
59                  *          when using an UrlTemplate
60                  */
61                 virtual SegmentChunk*                   toChunk         (size_t, BaseRepresentation *, HTTPConnectionManager *);
62                 virtual void                            setByteRange    (size_t start, size_t end);
63                 virtual void                            setSequenceNumber(uint64_t);
64                 virtual uint64_t                        getSequenceNumber() const;
65                 virtual bool                            isTemplate      () const;
66                 virtual size_t                          getOffset       () const;
67                 virtual std::vector<ISegment*>          subSegments     () = 0;
68                 virtual void                            addSubSegment   (SubSegment *) = 0;
69                 virtual void                            debug           (vlc_object_t *,int = 0) const;
70                 virtual bool                            contains        (size_t byte) const;
71                 virtual int                             compare         (ISegment *) const;
72                 int                                     getClassId      () const;
73                 Property<stime_t>       startTime;
74                 Property<stime_t>       duration;
75                 Property<unsigned>      chunksuse;
76                 bool                    discontinuity;
77
78                 static const int CLASSID_ISEGMENT = 0;
79                 /* callbacks */
80                 virtual void                            onChunkDownload (block_t **, SegmentChunk *, BaseRepresentation *);
81
82             protected:
83                 size_t                  startByte;
84                 size_t                  endByte;
85                 std::string             debugName;
86                 int                     classId;
87                 bool                    templated;
88                 uint64_t                sequence;
89                 static const int        SEQUENCE_INVALID;
90                 static const int        SEQUENCE_FIRST;
91         };
92
93         class Segment : public ISegment
94         {
95             public:
96                 Segment( ICanonicalUrl *parent );
97                 ~Segment();
98                 virtual void setSourceUrl( const std::string &url );
99                 virtual Url getUrlSegment() const; /* impl */
100                 virtual std::vector<ISegment*> subSegments();
101                 virtual void debug(vlc_object_t *,int = 0) const;
102                 virtual void addSubSegment(SubSegment *);
103                 static const int CLASSID_SEGMENT = 1;
104
105             protected:
106                 std::vector<SubSegment *> subsegments;
107                 Url sourceUrl;
108                 int size;
109         };
110
111         class InitSegment : public Segment
112         {
113             public:
114                 InitSegment( ICanonicalUrl *parent );
115                 static const int CLASSID_INITSEGMENT = 2;
116         };
117
118         class IndexSegment : public Segment
119         {
120             public:
121                 IndexSegment( ICanonicalUrl *parent );
122                 static const int CLASSID_INDEXSEGMENT = 3;
123         };
124
125         class SubSegment : public ISegment
126         {
127             public:
128                 SubSegment(ISegment *, size_t start, size_t end);
129                 virtual Url getUrlSegment() const; /* impl */
130                 virtual std::vector<ISegment*> subSegments();
131                 virtual void addSubSegment(SubSegment *);
132                 static const int CLASSID_SUBSEGMENT = 4;
133             private:
134                 ISegment *parent;
135         };
136     }
137 }
138
139 #endif /* SEGMENT_H_ */