demux: adaptive: add inheritable wrapper deleter
[vlc.git] / modules / demux / adaptive / playlist / Inheritables.hpp
blob51ac6731d96ed97dbd11981187095716fa3836d5
1 /*****************************************************************************
2 * Inheritables.hpp Nodes inheritables properties
3 *****************************************************************************
4 * Copyright (C) 2016-2020 VideoLabs, VLC authors and VideoLAN
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 by
8 * 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 INHERITABLES_H
21 #define INHERITABLES_H
23 #include <list>
24 #include <limits>
25 #include <stdint.h>
26 #include "../Time.hpp"
28 namespace adaptive
30 namespace playlist
32 class AttrsNode;
33 class SegmentTimeline;
34 class SegmentTemplate;
35 class SegmentList;
36 class SegmentBase;
38 class AbstractAttr
40 public:
41 enum class Type
43 None,
44 Playlist,
45 SegmentInformation,
46 SegmentList,
47 SegmentBase,
48 SegmentTemplate,
49 Timescale,
50 Timeline,
51 Duration,
52 StartNumber,
53 AvailabilityTimeOffset,
54 AvailabilityTimeComplete,
56 AbstractAttr(enum Type);
57 virtual ~AbstractAttr();
58 AbstractAttr(const AbstractAttr &) = delete;
59 AbstractAttr & operator=(const AbstractAttr &) = delete;
60 Type getType() const;
61 bool operator ==(const AbstractAttr &t) const { return type == t.getType(); }
62 bool operator !=(const AbstractAttr &t) const { return type != t.getType(); }
63 virtual bool isValid() const { return true; }
64 void setParentNode(AttrsNode *n) { parentNode = n; }
66 protected:
67 Type type;
68 AttrsNode *parentNode;
71 class AttrsNode : public AbstractAttr
73 public:
74 AttrsNode( Type, AttrsNode * = nullptr );
75 ~AttrsNode();
76 AttrsNode(const AttrsNode &) = delete;
77 AttrsNode & operator=(const AttrsNode &) = delete;
78 void addAttribute( AbstractAttr * );
79 void replaceAttribute( AbstractAttr * );
80 AbstractAttr * inheritAttribute(AbstractAttr::Type);
81 AbstractAttr * inheritAttribute(AbstractAttr::Type) const;
82 /* helpers */
83 uint64_t inheritStartNumber() const;
84 stime_t inheritDuration() const;
85 Timescale inheritTimescale() const;
86 vlc_tick_t inheritAvailabilityTimeOffset() const;
87 bool inheritAvailabilityTimeComplete() const;
88 SegmentTimeline * inheritSegmentTimeline() const;
89 SegmentTemplate * inheritSegmentTemplate() const;
90 SegmentList * inheritSegmentList() const;
91 SegmentBase * inheritSegmentBase() const;
93 protected:
94 AttrsNode * matchPath(std::list<AbstractAttr::Type>&);
95 AbstractAttr * getAttribute(AbstractAttr::Type,
96 std::list<AbstractAttr::Type>&);
97 AbstractAttr * getAttribute(AbstractAttr::Type);
98 AbstractAttr * getAttribute(AbstractAttr::Type) const;
99 std::list<AbstractAttr *> props;
100 bool is_canonical_root;
103 template<enum AbstractAttr::Type e, typename T>
104 class AttrWrapper : public AbstractAttr
106 public:
107 AttrWrapper(T v) : AbstractAttr(e) { value = v; }
108 virtual ~AttrWrapper() { condDeleteValue(value); }
109 AttrWrapper(const AttrWrapper &) = delete;
110 AttrWrapper<e, T> & operator=(const AttrWrapper<e, T> &) = delete;
111 operator const T&() const { return value; }
113 protected:
114 void condDeleteValue(const T &) {}
115 void condDeleteValue(T* &v) { delete v; }
116 T value;
119 using AvailabilityTimeOffsetAttr = AttrWrapper<AbstractAttr::Type::AvailabilityTimeOffset, vlc_tick_t>;
120 using AvailabilityTimeCompleteAttr = AttrWrapper<AbstractAttr::Type::AvailabilityTimeComplete, bool>;
121 using StartnumberAttr = AttrWrapper<AbstractAttr::Type::StartNumber, uint64_t>;
123 class TimescaleAttr:
124 public AttrWrapper<AbstractAttr::Type::Timescale, Timescale>
126 public:
127 TimescaleAttr(Timescale v) :
128 AttrWrapper<AbstractAttr::Type::Timescale, Timescale>( v ) {}
129 virtual bool isValid() const { return value.isValid(); }
132 class DurationAttr:
133 public AttrWrapper<AbstractAttr::Type::Duration, stime_t>
135 public:
136 DurationAttr(stime_t v) :
137 AttrWrapper<AbstractAttr::Type::Duration, stime_t>( v ) {}
138 virtual bool isValid() const { return value > 0; }
143 #endif // INHERITABLES_H