1 /* 2 * Streams.hpp 3 ***************************************************************************** 4 * Copyright (C) 2014 - VideoLAN and VLC authors 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Lesser General Public License as published 8 * by the Free Software Foundation; either version 2.1 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public License 17 * along with this program; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 19 *****************************************************************************/ 20 #ifndef STREAM_HPP 21 #define STREAM_HPP 22 23 #include <vlc_common.h> 24 #include "StreamFormat.hpp" 25 #include "AbstractSource.hpp" 26 #include "SegmentTracker.hpp" 27 28 #include "plumbing/CommandsQueue.hpp" 29 #include "plumbing/Demuxer.hpp" 30 #include "plumbing/SourceStream.hpp" 31 #include "plumbing/FakeESOut.hpp" 32 33 #include <string> 34 35 namespace adaptive 36 { 37 class SegmentTracker; 38 39 namespace http 40 { 41 class AbstractConnectionManager; 42 } 43 44 namespace playlist 45 { 46 class SegmentChunk; 47 } 48 49 using namespace http; 50 using namespace playlist; 51 52 class AbstractStream : public AbstractSource, 53 public ExtraFMTInfoInterface, 54 public SegmentTrackerListenerInterface, 55 public DemuxerFactoryInterface 56 { 57 public: 58 AbstractStream(demux_t *); 59 virtual ~AbstractStream(); 60 bool init(const StreamFormat &, SegmentTracker *, AbstractConnectionManager *); 61 62 void setLanguage(const std::string &); 63 void setDescription(const std::string &); 64 mtime_t getPCR() const; 65 mtime_t getMinAheadTime() const; 66 mtime_t getFirstDTS() const; 67 int esCount() const; 68 bool isSelected() const; 69 virtual bool reactivate(mtime_t); 70 bool isDisabled() const; 71 bool isValid() const; 72 typedef enum { 73 status_eof = 0, /* prioritized */ 74 status_discontinuity, 75 status_demuxed, 76 status_buffering, 77 } status; 78 typedef enum { 79 buffering_end = 0, /* prioritized */ 80 buffering_suspended, 81 buffering_full, 82 buffering_ongoing, 83 buffering_lessthanmin, 84 } buffering_status; 85 buffering_status bufferize(mtime_t, unsigned, unsigned); 86 buffering_status getLastBufferStatus() const; 87 mtime_t getDemuxedAmount(mtime_t) const; 88 status dequeue(mtime_t, mtime_t *); 89 bool decodersDrained(); 90 virtual bool setPosition(mtime_t, bool); 91 bool getMediaPlaybackTimes(mtime_t *, mtime_t *, mtime_t *, 92 mtime_t *, mtime_t *) const; 93 void runUpdates(); 94 95 /* Used by demuxers fake streams */ 96 virtual std::string getContentType(); /* impl */ 97 virtual block_t *readNextBlock(); /* impl */ 98 99 /**/ 100 virtual void fillExtraFMTInfo( es_format_t * ) const; /* impl */ 101 virtual void trackerEvent(const SegmentTrackerEvent &); /* impl */ 102 103 protected: 104 bool seekAble() const; 105 void setDisabled(bool); 106 virtual block_t *checkBlock(block_t *, bool) = 0; 107 AbstractDemuxer * createDemux(const StreamFormat &); 108 virtual AbstractDemuxer * newDemux(vlc_object_t *, const StreamFormat &, 109 es_out_t *, AbstractSourceStream *) const; /* impl */ 110 virtual bool startDemux(); 111 virtual bool restartDemux(); 112 113 virtual void prepareRestart(bool = true); 114 115 bool discontinuity; 116 bool needrestart; 117 bool inrestart; 118 bool demuxfirstchunk; 119 120 demux_t *p_realdemux; 121 StreamFormat format; 122 123 AbstractConnectionManager *connManager; /* not owned */ 124 SegmentTracker *segmentTracker; 125 126 SegmentChunk *currentChunk; 127 bool eof; 128 std::string language; 129 std::string description; 130 131 AbstractDemuxer *demuxer; 132 AbstractSourceStream *demuxersource; 133 FakeESOut::LockedFakeEsOut fakeEsOut(); 134 FakeESOut::LockedFakeEsOut fakeEsOut() const; 135 FakeESOut *fakeesout; /* to intercept/proxy what is sent from demuxstream */ 136 vlc_mutex_t lock; /* lock for everything accessed by dequeuing */ 137 138 private: 139 void declaredCodecs(); 140 buffering_status doBufferize(mtime_t, mtime_t, mtime_t); 141 buffering_status last_buffer_status; 142 bool valid; 143 bool disabled; 144 unsigned notfound_sequence; 145 }; 146 147 class AbstractStreamFactory 148 { 149 public: ~AbstractStreamFactory()150 virtual ~AbstractStreamFactory() {} 151 virtual AbstractStream *create(demux_t*, const StreamFormat &, 152 SegmentTracker *, AbstractConnectionManager *) const = 0; 153 }; 154 } 155 #endif // STREAMS_HPP 156