Segment.h 5.41 KB
Newer Older
Christopher Mueller's avatar
Christopher Mueller committed
1 2 3 4 5 6 7 8 9
/*
 * Segment.h
 *****************************************************************************
 * Copyright (C) 2010 - 2011 Klagenfurt University
 *
 * Created on: Aug 10, 2010
 * Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
 *          Christian Timmerer  <christian.timmerer@itec.uni-klu.ac.at>
 *
10 11
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
Christopher Mueller's avatar
Christopher Mueller committed
12 13 14 15 16
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
Christopher Mueller's avatar
Christopher Mueller committed
19 20
 *
 * You should have received a copy of the GNU Lesser General Public License
21 22
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
Christopher Mueller's avatar
Christopher Mueller committed
23 24 25 26 27 28
 *****************************************************************************/

#ifndef SEGMENT_H_
#define SEGMENT_H_

#include <string>
29 30
#include <sstream>
#include <vector>
31 32 33
#include "ICanonicalUrl.hpp"
#include "../http/Chunk.h"
#include "../tools/Properties.hpp"
34
#include "Time.hpp"
Christopher Mueller's avatar
Christopher Mueller committed
35

36
namespace adaptive
Christopher Mueller's avatar
Christopher Mueller committed
37
{
38 39
    namespace http
    {
40
        class AbstractConnectionManager;
41 42
    }

43
    namespace playlist
Christopher Mueller's avatar
Christopher Mueller committed
44
    {
45
        class BaseRepresentation;
46
        class SubSegment;
47
        class SegmentChunk;
48 49

        using namespace http;
50 51

        class ISegment : public ICanonicalUrl
Christopher Mueller's avatar
Christopher Mueller committed
52 53
        {
            public:
54
                ISegment(const ICanonicalUrl *parent);
55
                virtual ~ISegment();
56 57 58 59 60
                /**
                 *  @return true if the segment should be dropped after being read.
                 *          That is basically true when using an Url, and false
                 *          when using an UrlTemplate
                 */
61
                virtual SegmentChunk*                   toChunk         (size_t, BaseRepresentation *, AbstractConnectionManager *);
62
                virtual void                            setByteRange    (size_t start, size_t end);
63 64
                virtual void                            setSequenceNumber(uint64_t);
                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 74
                Property<stime_t>       startTime;
                Property<stime_t>       duration;
75
                Property<unsigned>      chunksuse;
76
                bool                    discontinuity;
77 78

                static const int CLASSID_ISEGMENT = 0;
79 80
                /* callbacks */
                virtual void                            onChunkDownload (block_t **, SegmentChunk *, BaseRepresentation *);
Christopher Mueller's avatar
Christopher Mueller committed
81

82
            protected:
83 84
                size_t                  startByte;
                size_t                  endByte;
85
                std::string             debugName;
86
                int                     classId;
87
                bool                    templated;
88 89 90
                uint64_t                sequence;
                static const int        SEQUENCE_INVALID;
                static const int        SEQUENCE_FIRST;
91 92 93 94 95
        };

        class Segment : public ISegment
        {
            public:
96
                Segment( ICanonicalUrl *parent );
97 98
                ~Segment();
                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 106

            protected:
                std::vector<SubSegment *> subsegments;
107
                Url sourceUrl;
108 109 110
                int size;
        };

111 112 113
        class InitSegment : public Segment
        {
            public:
114
                InitSegment( ICanonicalUrl *parent );
115
                static const int CLASSID_INITSEGMENT = 2;
116 117 118 119 120
        };

        class IndexSegment : public Segment
        {
            public:
121
                IndexSegment( ICanonicalUrl *parent );
122
                static const int CLASSID_INDEXSEGMENT = 3;
123 124
        };

125 126 127
        class SubSegment : public ISegment
        {
            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;
Christopher Mueller's avatar
Christopher Mueller committed
135 136 137 138 139
        };
    }
}

#endif /* SEGMENT_H_ */