demux: adaptive: add debugging switch logic
authorFrancois Cartegnie <fcvlcdev@free.fr>
Wed, 13 May 2020 17:32:54 +0000 (19:32 +0200)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Mon, 25 May 2020 14:38:57 +0000 (16:38 +0200)
modules/demux/Makefile.am
modules/demux/adaptive/PlaylistManager.cpp
modules/demux/adaptive/logic/RoundRobinLogic.cpp [new file with mode: 0644]
modules/demux/adaptive/logic/RoundRobinLogic.hpp [new file with mode: 0644]
modules/demux/adaptive/tools/Debug.hpp

index 954d298..1f6d2ff 100644 (file)
@@ -353,6 +353,8 @@ libadaptive_plugin_la_SOURCES = \
     demux/adaptive/logic/RateBasedAdaptationLogic.cpp \
     demux/adaptive/logic/Representationselectors.hpp \
     demux/adaptive/logic/Representationselectors.cpp \
+    demux/adaptive/logic/RoundRobinLogic.cpp \
+    demux/adaptive/logic/RoundRobinLogic.hpp \
     demux/adaptive/mp4/AtomsReader.cpp \
     demux/adaptive/mp4/AtomsReader.hpp \
     demux/adaptive/http/AuthStorage.cpp \
index c12aa3f..bb1ad76 100644 (file)
@@ -38,6 +38,9 @@
 #include "logic/NearOptimalAdaptationLogic.hpp"
 #include "logic/BufferingLogic.hpp"
 #include "tools/Debug.hpp"
+#ifdef ADAPTIVE_DEBUGGING_LOGIC
+# include "logic/RoundRobinLogic.hpp"
+#endif
 #include <vlc_stream.h>
 #include <vlc_demux.h>
 #include <vlc_threads.h>
@@ -800,6 +803,11 @@ AbstractAdaptationLogic *PlaylistManager::createLogic(AbstractAdaptationLogic::L
             break;
         }
         case AbstractAdaptationLogic::Default:
+#ifdef ADAPTIVE_DEBUGGING_LOGIC
+            logic = new (std::nothrow) RoundRobinLogic(obj);
+            msg_Warn(p_demux, "using RoundRobinLogic every %u", RoundRobinLogic::QUANTUM);
+            break;
+#endif
         case AbstractAdaptationLogic::NearOptimal:
         {
             NearOptimalAdaptationLogic *noplogic =
diff --git a/modules/demux/adaptive/logic/RoundRobinLogic.cpp b/modules/demux/adaptive/logic/RoundRobinLogic.cpp
new file mode 100644 (file)
index 0000000..9b3daf5
--- /dev/null
@@ -0,0 +1,34 @@
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "RoundRobinLogic.hpp"
+
+#ifdef ADAPTIVE_DEBUGGING_LOGIC
+
+#include "Representationselectors.hpp"
+#include "../playlist/BaseAdaptationSet.h"
+
+using namespace adaptive::logic;
+using namespace adaptive::playlist;
+
+RoundRobinLogic::RoundRobinLogic    (vlc_object_t *obj) :
+                           AbstractAdaptationLogic      (obj)
+{
+    index = 0;
+    call = 0;
+}
+
+BaseRepresentation *RoundRobinLogic::getNextRepresentation(BaseAdaptationSet *adaptSet,
+                                                           BaseRepresentation *)
+{
+    if(adaptSet->getRepresentations().size() == 0)
+        return nullptr;
+    if((++call % QUANTUM) == 0)
+        index++;
+    if(index >= adaptSet->getRepresentations().size())
+        index = 0;
+    return adaptSet->getRepresentations().at(index);
+}
+
+#endif
diff --git a/modules/demux/adaptive/logic/RoundRobinLogic.hpp b/modules/demux/adaptive/logic/RoundRobinLogic.hpp
new file mode 100644 (file)
index 0000000..ccd890b
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef ROUNDROBINLOGIC_HPP
+#define ROUNDROBINLOGIC_HPP
+
+#include "../tools/Debug.hpp"
+
+#ifdef ADAPTIVE_DEBUGGING_LOGIC
+#include "AbstractAdaptationLogic.h"
+
+namespace adaptive
+{
+    namespace logic
+    {
+        class RoundRobinLogic : public AbstractAdaptationLogic
+        {
+            public:
+                RoundRobinLogic(vlc_object_t *);
+
+                virtual BaseRepresentation* getNextRepresentation(BaseAdaptationSet *,
+                                                                  BaseRepresentation *);
+                static const unsigned QUANTUM = 2;
+            private:
+                size_t index;
+                uint64_t call;
+        };
+    }
+}
+#endif
+
+#endif // ROUNDROBINLOGIC_HPP
index 7b6548b..6474106 100644 (file)
@@ -23,6 +23,7 @@
 //#define ADAPTATIVE_ADVANCED_DEBUG 0
 //#define ADAPTATIVE_BW_DEBUG 0
 //#define ADAPTATIVE_SEEK_DEBUG 0
+//#define ADAPTIVE_DEBUGGING_LOGIC 0
 
 #ifdef ADAPTATIVE_ADVANCED_DEBUG
   #define AdvDebug(code) code