Streams.hpp 4.59 KB
Newer Older
1 2 3
/*
 * Streams.hpp
 *****************************************************************************
4
 * Copyright (C) 2014 - VideoLAN and VLC authors
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * 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
#include <vlc_common.h>
24
#include "StreamFormat.hpp"
25
#include "ChunksSource.hpp"
26
#include "SegmentTracker.hpp"
27

28
#include "plumbing/CommandsQueue.hpp"
29 30 31 32 33
#include "plumbing/Demuxer.hpp"
#include "plumbing/SourceStream.hpp"
#include "plumbing/FakeESOut.hpp"

#include <string>
34

35
namespace adaptive
36
{
37 38
    class SegmentTracker;

39 40
    namespace http
    {
41
        class AbstractConnectionManager;
42 43
    }

44 45 46 47 48
    namespace playlist
    {
        class SegmentChunk;
    }

49
    using namespace http;
50
    using namespace playlist;
51

52
    class AbstractStream : public ChunksSource,
53 54
                           public ExtraFMTInfoInterface,
                           public SegmentTrackerListenerInterface
55 56
    {
    public:
57
        AbstractStream(demux_t *);
58
        virtual ~AbstractStream();
59
        bool init(const StreamFormat &, SegmentTracker *, AbstractConnectionManager *);
60

61
        void setLanguage(const std::string &);
62
        void setDescription(const std::string &);
63
        mtime_t getPCR() const;
64
        mtime_t getMinAheadTime() const;
65
        mtime_t getFirstDTS() const;
66
        int esCount() const;
67
        bool isSelected() const;
68
        bool canActivate() const;
69
        virtual bool reactivate(mtime_t);
70
        void setDisabled(bool);
71
        bool isDisabled() const;
72 73 74 75 76 77 78 79 80 81 82 83 84 85
        typedef enum {
            status_eof = 0, /* prioritized */
            status_discontinuity,
            status_demuxed,
            status_buffering,
        } status;
        typedef enum {
            buffering_end = 0, /* prioritized */
            buffering_suspended,
            buffering_full,
            buffering_ongoing,
            buffering_lessthanmin,
        } buffering_status;
        buffering_status bufferize(mtime_t, unsigned, unsigned);
86
        buffering_status getLastBufferStatus() const;
87
        mtime_t getDemuxedAmount() const;
88
        status dequeue(mtime_t, mtime_t *);
89
        bool decodersDrained();
90
        virtual bool setPosition(mtime_t, bool);
91
        mtime_t getPlaybackTime() const;
92
        void runUpdates();
93

94
        virtual block_t *readNextBlock(); /* impl */
95 96

        virtual void fillExtraFMTInfo( es_format_t * ) const; /* impl */
97
        virtual void trackerEvent(const SegmentTrackerEvent &); /* impl */
98 99

    protected:
100
        bool seekAble() const;
101
        virtual void setTimeOffset(mtime_t);
102 103 104 105 106
        virtual block_t *checkBlock(block_t *, bool) = 0;
        virtual AbstractDemuxer * createDemux(const StreamFormat &) = 0;
        virtual bool startDemux();
        virtual bool restartDemux();

107
        virtual void prepareRestart(bool = true);
108 109

        bool discontinuity;
110
        bool needrestart;
111
        bool inrestart;
112 113

        demux_t *p_realdemux;
114
        StreamFormat format;
115

116
        AbstractConnectionManager *connManager; /* not owned */
117
        SegmentTracker *segmentTracker;
118

119
        SegmentChunk *currentChunk;
120
        bool eof;
121
        std::string language;
122
        std::string description;
123

124
        CommandsQueue *commandsqueue;
125 126 127
        AbstractDemuxer *demuxer;
        AbstractSourceStream *demuxersource;
        FakeESOut *fakeesout; /* to intercept/proxy what is sent from demuxstream */
128
        vlc_mutex_t lock; /* lock for everything accessed by dequeuing */
129 130

    private:
131 132
        buffering_status doBufferize(mtime_t, unsigned, unsigned);
        buffering_status last_buffer_status;
133 134
        bool dead;
        bool disabled;
135 136
    };

137 138 139 140 141
    class AbstractStreamFactory
    {
        public:
            virtual ~AbstractStreamFactory() {}
            virtual AbstractStream *create(demux_t*, const StreamFormat &,
142
                                   SegmentTracker *, AbstractConnectionManager *) const = 0;
143
    };
144 145
}
#endif // STREAMS_HPP