Streams.hpp 6.47 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 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
        void setLanguage(const std::string &);
72
        void setDescription(const std::string &);
73 74
        bool isEOF() const;
        mtime_t getPCR() const;
75
        mtime_t getFirstDTS() const;
76 77 78
        int getGroup() const;
        int esCount() const;
        bool seekAble() const;
79
        bool isSelected() const;
80 81
        bool reactivate(mtime_t);
        bool isDisabled() const;
82
        typedef enum {status_eof, status_eop, status_buffering, status_demuxed} status;
83
        status demux(HTTPConnectionManager *, mtime_t, bool);
84 85
        bool setPosition(mtime_t, bool);
        mtime_t getPosition() const;
86
        void prune();
87 88

    private:
89
        SegmentChunk *getChunk();
90
        size_t read(HTTPConnectionManager *);
91
        demux_t *p_demux;
92 93 94 95 96
        StreamType type;
        StreamFormat format;
        AbstractStreamOutput *output;
        AbstractAdaptationLogic *adaptationLogic;
        SegmentTracker *segmentTracker;
97
        SegmentChunk *currentChunk;
98
        bool disabled;
99
        bool eof;
100
        std::string language;
101
        std::string description;
102 103

        const AbstractStreamOutputFactory *streamOutputFactory;
104 105 106 107 108
    };

    class AbstractStreamOutput
    {
    public:
109
        AbstractStreamOutput(demux_t *, const StreamFormat &);
110 111
        virtual ~AbstractStreamOutput();

112
        void setLanguage(const std::string &);
113
        void setDescription(const std::string &);
114
        const StreamFormat & getStreamFormat() const;
115
        virtual void pushBlock(block_t *, bool) = 0;
116
        virtual mtime_t getPCR() const;
117
        virtual mtime_t getFirstDTS() const = 0;
118 119 120 121 122
        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;
123
        virtual bool isEmpty() const = 0;
124
        virtual bool reinitsOnSeek() const = 0;
125
        virtual bool switchAllowed() const = 0;
126
        virtual bool isSelected() const = 0;
127 128

    protected:
129
        demux_t  *realdemux;
130 131
        mtime_t   pcr;
        int       group;
132
        std::string language;
133
        std::string description;
134 135 136

    private:
        StreamFormat format;
137 138 139 140 141
    };

    class AbstractStreamOutputFactory
    {
        public:
142 143
            virtual ~AbstractStreamOutputFactory() {}
            virtual AbstractStreamOutput *create(demux_t*, const StreamFormat &) const = 0;
144 145 146 147 148
    };

    class BaseStreamOutput : public AbstractStreamOutput
    {
    public:
149
        BaseStreamOutput(demux_t *, const StreamFormat &, const std::string &);
150
        virtual ~BaseStreamOutput();
151
        virtual void pushBlock(block_t *, bool); /* reimpl */
152
        virtual mtime_t getFirstDTS() const; /* reimpl */
153 154 155 156
        virtual int esCount() const; /* reimpl */
        virtual bool seekAble() const; /* reimpl */
        virtual void setPosition(mtime_t); /* reimpl */
        virtual void sendToDecoder(mtime_t); /* reimpl */
157
        virtual bool isEmpty() const; /* reimpl */
158
        virtual bool reinitsOnSeek() const; /* reimpl */
159
        virtual bool switchAllowed() const; /* reimpl */
160
        virtual bool isSelected() const; /* reimpl */
161
        void setTimestampOffset(mtime_t);
162 163

    protected:
164 165 166
        es_out_t *fakeesout; /* to intercept/proxy what is sent from demuxstream */
        stream_t *demuxstream;
        bool      seekable;
167
        std::string name;
168
        bool      restarting;
169
        mtime_t   timestamps_offset;
170

171 172 173 174 175 176
        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();

177
    private:
178 179 180 181 182 183
        /* 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 *);
184 185

        class Demuxed
186
        {
187
            friend class BaseStreamOutput;
188
            Demuxed(es_out_id_t *, const es_format_t *);
189 190 191 192 193
            ~Demuxed();
            void drop();
            es_out_id_t *es_id;
            block_t  *p_queue;
            block_t **pp_queue_last;
194 195
            bool recycle;
            es_format_t fmtcpy;
196
        };
197
        std::list<Demuxed *> queues;
198
        bool b_drop;
199
        vlc_mutex_t lock;
200
        void sendToDecoderUnlocked(mtime_t);
201
        bool restart();
202
    };
203

204 205
}
#endif // STREAMS_HPP