demux: adaptive: remove left indirect returns since lock removal
[vlc.git] / modules / demux / adaptive / SegmentTracker.hpp
blobc131d333bc6ef84e5e17833d597e601cef9a7a2b
1 /*
2 * SegmentTracker.hpp
3 *****************************************************************************
4 * Copyright (C) 2014 - VideoLAN and VLC authors
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.
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.
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 SEGMENTTRACKER_HPP
21 #define SEGMENTTRACKER_HPP
23 #include "StreamFormat.hpp"
24 #include "playlist/CodecDescription.hpp"
25 #include "playlist/Role.hpp"
27 #include <vlc_common.h>
28 #include <list>
30 namespace adaptive
32 class ID;
33 class SharedResources;
35 namespace http
37 class AbstractConnectionManager;
38 class ChunkInterface;
41 namespace logic
43 class AbstractAdaptationLogic;
44 class AbstractBufferingLogic;
47 namespace playlist
49 class BaseAdaptationSet;
50 class BaseRepresentation;
51 class SegmentChunk;
54 using namespace playlist;
55 using namespace logic;
56 using namespace http;
58 class TrackerEvent
60 public:
61 enum class Type
63 Discontinuity,
64 RepresentationSwitch,
65 FormatChange,
66 SegmentChange,
67 BufferingStateUpdate,
68 BufferingLevelChange,
69 PositionChange,
71 TrackerEvent() = delete;
72 virtual ~TrackerEvent() = 0;
73 Type getType() const;
75 protected:
76 TrackerEvent(Type t);
78 private:
79 Type type;
82 class DiscontinuityEvent : public TrackerEvent
84 public:
85 DiscontinuityEvent();
86 virtual ~DiscontinuityEvent() = default;
89 class RepresentationSwitchEvent : public TrackerEvent
91 public:
92 RepresentationSwitchEvent() = delete;
93 RepresentationSwitchEvent(BaseRepresentation *, BaseRepresentation *);
94 virtual ~RepresentationSwitchEvent() = default;
96 BaseRepresentation *prev;
97 BaseRepresentation *next;
100 class FormatChangedEvent : public TrackerEvent
102 public:
103 FormatChangedEvent() = delete;
104 FormatChangedEvent(const StreamFormat *);
105 virtual ~FormatChangedEvent() = default;
107 const StreamFormat *format;
110 class SegmentChangedEvent : public TrackerEvent
112 public:
113 SegmentChangedEvent() = delete;
114 SegmentChangedEvent(const ID &, vlc_tick_t);
115 virtual ~SegmentChangedEvent() = default;
117 const ID *id;
118 vlc_tick_t duration;
121 class BufferingStateUpdatedEvent : public TrackerEvent
123 public:
124 BufferingStateUpdatedEvent() = delete;
125 BufferingStateUpdatedEvent(const ID &, bool);
126 virtual ~BufferingStateUpdatedEvent() = default;
128 const ID *id;
129 bool enabled;
132 class BufferingLevelChangedEvent : public TrackerEvent
134 public:
135 BufferingLevelChangedEvent() = delete;
136 BufferingLevelChangedEvent(const ID &,
137 vlc_tick_t, vlc_tick_t, vlc_tick_t, vlc_tick_t);
138 virtual ~BufferingLevelChangedEvent() = default;
140 const ID *id;
141 vlc_tick_t minimum;
142 vlc_tick_t maximum;
143 vlc_tick_t current;
144 vlc_tick_t target;
147 class PositionChangedEvent : public TrackerEvent
149 public:
150 PositionChangedEvent();
151 virtual ~PositionChangedEvent() = default;
154 class SegmentTrackerListenerInterface
156 public:
157 virtual void trackerEvent(const TrackerEvent &) = 0;
158 virtual ~SegmentTrackerListenerInterface() = default;
161 class SegmentTracker
163 public:
164 SegmentTracker(SharedResources *,
165 AbstractAdaptationLogic *,
166 const AbstractBufferingLogic *,
167 BaseAdaptationSet *);
168 ~SegmentTracker();
170 class Position
172 public:
173 Position();
174 Position(BaseRepresentation *, uint64_t);
175 Position & operator++();
176 bool isValid() const;
177 std::string toString() const;
178 uint64_t number;
179 BaseRepresentation *rep;
180 bool init_sent;
181 bool index_sent;
184 StreamFormat getCurrentFormat() const;
185 void getCodecsDesc(CodecDescriptionList *) const;
186 const Role & getStreamRole() const;
187 void reset();
188 ChunkInterface* getNextChunk(bool, AbstractConnectionManager *);
189 bool setPositionByTime(vlc_tick_t, bool, bool);
190 void setPosition(const Position &, bool);
191 bool setStartPosition();
192 Position getStartPosition() const;
193 vlc_tick_t getPlaybackTime(bool = false) const; /* Current segment start time if selected */
194 bool getMediaPlaybackRange(vlc_tick_t *, vlc_tick_t *, vlc_tick_t *) const;
195 vlc_tick_t getMinAheadTime() const;
196 void notifyBufferingState(bool) const;
197 void notifyBufferingLevel(vlc_tick_t, vlc_tick_t, vlc_tick_t, vlc_tick_t) const;
198 void registerListener(SegmentTrackerListenerInterface *);
199 void updateSelected();
200 bool bufferingAvailable() const;
202 private:
203 class ChunkEntry
205 public:
206 ChunkEntry();
207 ChunkEntry(SegmentChunk *c, Position p, vlc_tick_t d);
208 bool isValid() const;
209 SegmentChunk *chunk;
210 Position pos;
211 vlc_tick_t duration;
213 std::list<ChunkEntry> chunkssequence;
214 ChunkEntry prepareChunk(bool switch_allowed, Position pos,
215 AbstractConnectionManager *connManager) const;
216 void resetChunksSequence();
217 void setAdaptationLogic(AbstractAdaptationLogic *);
218 void notify(const TrackerEvent &) const;
219 bool first;
220 bool initializing;
221 Position current;
222 Position next;
223 StreamFormat format;
224 SharedResources *resources;
225 AbstractAdaptationLogic *logic;
226 const AbstractBufferingLogic *bufferingLogic;
227 BaseAdaptationSet *adaptationSet;
228 std::list<SegmentTrackerListenerInterface *> listeners;
232 #endif // SEGMENTTRACKER_HPP