[vlc-commits] demux: adaptive: replace tribool with template

Francois Cartegnie git at videolan.org
Tue Mar 24 23:35:10 CET 2020


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Mar 17 13:21:29 2020 +0100| [c5837883498f093bd2ca9348d11a3cc5c1691b70] | committer: Francois Cartegnie

demux: adaptive: replace tribool with template

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c5837883498f093bd2ca9348d11a3cc5c1691b70
---

 modules/demux/adaptive/playlist/BaseAdaptationSet.cpp  | 10 ++++------
 modules/demux/adaptive/playlist/BaseAdaptationSet.h    |  4 ++--
 modules/demux/adaptive/playlist/SegmentInformation.hpp |  7 -------
 modules/demux/adaptive/tools/Properties.hpp            | 18 ++++++++++++++++++
 4 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/modules/demux/adaptive/playlist/BaseAdaptationSet.cpp b/modules/demux/adaptive/playlist/BaseAdaptationSet.cpp
index 228a90ae78..b98022dbad 100644
--- a/modules/demux/adaptive/playlist/BaseAdaptationSet.cpp
+++ b/modules/demux/adaptive/playlist/BaseAdaptationSet.cpp
@@ -45,8 +45,6 @@ BaseAdaptationSet::BaseAdaptationSet(BasePeriod *period) :
     CommonAttributesElements(),
     SegmentInformation( period )
 {
-    segmentAligned = TRIBOOL_UNKNOWN;
-    bitswitchAble = TRIBOOL_UNKNOWN;
 }
 
 BaseAdaptationSet::~BaseAdaptationSet   ()
@@ -105,22 +103,22 @@ void BaseAdaptationSet::setLang( const std::string &lang_ )
 
 void BaseAdaptationSet::setSegmentAligned(bool b)
 {
-    segmentAligned = b ? TRIBOOL_TRUE : TRIBOOL_FALSE;
+    segmentAligned = b;
 }
 
 void BaseAdaptationSet::setBitswitchAble(bool b)
 {
-    bitswitchAble = b ? TRIBOOL_TRUE : TRIBOOL_FALSE;
+    bitswitchAble = b;
 }
 
 bool BaseAdaptationSet::isSegmentAligned() const
 {
-    return segmentAligned != TRIBOOL_FALSE;
+    return segmentAligned.isSet() && segmentAligned.value();
 }
 
 bool BaseAdaptationSet::isBitSwitchable() const
 {
-    return bitswitchAble == TRIBOOL_TRUE;
+    return bitswitchAble.isSet() && segmentAligned.value();
 }
 
 void BaseAdaptationSet::setRole(const Role &r)
diff --git a/modules/demux/adaptive/playlist/BaseAdaptationSet.h b/modules/demux/adaptive/playlist/BaseAdaptationSet.h
index a3b1ca3b72..f1d19b72bc 100644
--- a/modules/demux/adaptive/playlist/BaseAdaptationSet.h
+++ b/modules/demux/adaptive/playlist/BaseAdaptationSet.h
@@ -68,8 +68,8 @@ namespace adaptive
                 Role                            role;
                 std::vector<BaseRepresentation *>   representations;
                 std::string                     lang;
-                Tribool                         segmentAligned;
-                Tribool                         bitswitchAble;
+                Undef<bool>                     segmentAligned;
+                Undef<bool>                     bitswitchAble;
         };
     }
 }
diff --git a/modules/demux/adaptive/playlist/SegmentInformation.hpp b/modules/demux/adaptive/playlist/SegmentInformation.hpp
index 6eff4e035b..5691d1e862 100644
--- a/modules/demux/adaptive/playlist/SegmentInformation.hpp
+++ b/modules/demux/adaptive/playlist/SegmentInformation.hpp
@@ -39,13 +39,6 @@ namespace adaptive
         class AbstractPlaylist;
         class ISegment;
 
-        enum Tribool
-        {
-            TRIBOOL_UNKNOWN,
-            TRIBOOL_FALSE,
-            TRIBOOL_TRUE,
-        };
-
         /* common segment elements for period/adaptset/rep 5.3.9.1,
          * with properties inheritance */
         class SegmentInformation : public ICanonicalUrl,
diff --git a/modules/demux/adaptive/tools/Properties.hpp b/modules/demux/adaptive/tools/Properties.hpp
index 305a108030..3247f8a8ec 100644
--- a/modules/demux/adaptive/tools/Properties.hpp
+++ b/modules/demux/adaptive/tools/Properties.hpp
@@ -39,4 +39,22 @@ template <typename T> class Property
         T value;
 };
 
+template <typename T> class Undef
+{
+    public:
+        Undef() { undef = true; }
+
+        bool isSet() const
+        {
+            return !undef;
+        }
+
+        void operator =(const T &v) { val = v; undef = false; }
+        const T& value() const { return val; }
+
+    private:
+        bool undef;
+        T val;
+};
+
 #endif // PROPERTIES_HPP



More information about the vlc-commits mailing list