Streams.hpp 5.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Streams.hpp
 *****************************************************************************
 * Copyright (C) 2014 - VideoLAN authors
 *
 * 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
 * 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
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
20
21
22
#ifndef STREAM_HPP
#define STREAM_HPP

23
24
25
26
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

27
#include <string>
28
#include <list>
29
#include <vlc_common.h>
30
#include <vlc_es.h>
31
#include "StreamsType.hpp"
32
#include "StreamFormat.hpp"
33

34
namespace adaptative
35
{
36
37
    class SegmentTracker;

38
39
40
41
42
43
44
45
46
47
    namespace http
    {
        class HTTPConnectionManager;
    }

    namespace logic
    {
        class AbstractAdaptationLogic;
    }

48
49
50
51
52
    namespace playlist
    {
        class SegmentChunk;
    }

53

54
    class AbstractStreamOutput;
55
    class AbstractStreamOutputFactory;
56

57
58
    using namespace http;
    using namespace logic;
59
    using namespace playlist;
60

61
62
63
    class Stream
    {
    public:
64
        Stream(demux_t *, const StreamType, const StreamFormat &);
65
66
67
        ~Stream();
        bool operator==(const Stream &) const;
        static StreamType mimeToType(const std::string &mime);
68
69
70
        void create(AbstractAdaptationLogic *, SegmentTracker *,
                    const AbstractStreamOutputFactory *);
        void updateFormat(StreamFormat &);
71
72
        bool isEOF() const;
        mtime_t getPCR() const;
73
        mtime_t getFirstDTS() const;
74
75
76
77
        int getGroup() const;
        int esCount() const;
        bool seekAble() const;
        typedef enum {status_eof, status_buffering, status_demuxed} status;
78
        status demux(HTTPConnectionManager *, mtime_t, bool);
79
80
        bool setPosition(mtime_t, bool);
        mtime_t getPosition() const;
81
        void prune();
82
83

    private:
84
        SegmentChunk *getChunk();
85
        size_t read(HTTPConnectionManager *);
86
        demux_t *p_demux;
87
88
89
90
91
        StreamType type;
        StreamFormat format;
        AbstractStreamOutput *output;
        AbstractAdaptationLogic *adaptationLogic;
        SegmentTracker *segmentTracker;
92
        SegmentChunk *currentChunk;
93
        bool eof;
94
95

        const AbstractStreamOutputFactory *streamOutputFactory;
96
97
98
99
100
    };

    class AbstractStreamOutput
    {
    public:
101
        AbstractStreamOutput(demux_t *, const StreamFormat &);
102
103
        virtual ~AbstractStreamOutput();

104
        const StreamFormat & getStreamFormat() const;
105
        virtual void pushBlock(block_t *, bool) = 0;
106
        virtual mtime_t getPCR() const;
107
        virtual mtime_t getFirstDTS() const = 0;
108
109
110
111
112
113
        virtual int getGroup() const;
        virtual int esCount() const = 0;
        virtual bool seekAble() const = 0;
        virtual void setPosition(mtime_t) = 0;
        virtual void sendToDecoder(mtime_t) = 0;
        virtual bool reinitsOnSeek() const = 0;
114
        virtual bool switchAllowed() const = 0;
115
116

    protected:
117
        demux_t  *realdemux;
118
119
        mtime_t   pcr;
        int       group;
120
121
122

    private:
        StreamFormat format;
123
124
125
126
127
    };

    class AbstractStreamOutputFactory
    {
        public:
128
129
            virtual ~AbstractStreamOutputFactory() {}
            virtual AbstractStreamOutput *create(demux_t*, const StreamFormat &) const = 0;
130
131
132
133
134
    };

    class BaseStreamOutput : public AbstractStreamOutput
    {
    public:
135
        BaseStreamOutput(demux_t *, const StreamFormat &, const std::string &);
136
        virtual ~BaseStreamOutput();
137
        virtual void pushBlock(block_t *, bool); /* reimpl */
138
        virtual mtime_t getFirstDTS() const; /* reimpl */
139
140
141
142
143
        virtual int esCount() const; /* reimpl */
        virtual bool seekAble() const; /* reimpl */
        virtual void setPosition(mtime_t); /* reimpl */
        virtual void sendToDecoder(mtime_t); /* reimpl */
        virtual bool reinitsOnSeek() const; /* reimpl */
144
        virtual bool switchAllowed() const; /* reimpl */
145
        void setTimestampOffset(mtime_t);
146
147

    protected:
148
149
150
        es_out_t *fakeesout; /* to intercept/proxy what is sent from demuxstream */
        stream_t *demuxstream;
        bool      seekable;
151
        std::string name;
152
        bool      restarting;
153
        mtime_t   timestamps_offset;
154

155
156
157
158
159
160
        virtual es_out_id_t *esOutAdd(const es_format_t *);
        virtual int esOutSend(es_out_id_t *, block_t *);
        virtual void esOutDel(es_out_id_t *);
        virtual int esOutControl(int, va_list);
        virtual void esOutDestroy();

161
    private:
162
163
164
165
166
167
        /* static callbacks for demuxer */
        static es_out_id_t *esOutAdd_Callback(es_out_t *, const es_format_t *);
        static int esOutSend_Callback(es_out_t *, es_out_id_t *, block_t *);
        static void esOutDel_Callback(es_out_t *, es_out_id_t *);
        static int esOutControl_Callback(es_out_t *, int, va_list);
        static void esOutDestroy_Callback(es_out_t *);
168
169

        class Demuxed
170
        {
171
            friend class BaseStreamOutput;
172
            Demuxed(es_out_id_t *, const es_format_t *);
173
174
175
176
177
            ~Demuxed();
            void drop();
            es_out_id_t *es_id;
            block_t  *p_queue;
            block_t **pp_queue_last;
178
179
            bool recycle;
            es_format_t fmtcpy;
180
        };
181
        std::list<Demuxed *> queues;
182
        bool b_drop;
183
        vlc_mutex_t lock;
184
        void sendToDecoderUnlocked(mtime_t);
185
        bool restart();
186
    };
187

188
189
}
#endif // STREAMS_HPP