[vlc-commits] demux: adaptive: create shared resources

Francois Cartegnie git at videolan.org
Thu May 9 18:05:42 CEST 2019


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Apr 18 13:39:24 2019 +0200| [ae68beaea58ef384223dcdcc9452f5292ccce464] | committer: Francois Cartegnie

demux: adaptive: create shared resources

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

 modules/demux/Makefile.am                          |  2 +
 modules/demux/adaptive/PlaylistManager.cpp         | 13 +++---
 modules/demux/adaptive/PlaylistManager.h           |  6 +--
 modules/demux/adaptive/SegmentTracker.cpp          | 10 +++--
 modules/demux/adaptive/SegmentTracker.hpp          |  5 ++-
 modules/demux/adaptive/SharedResources.cpp         | 44 +++++++++++++++++++++
 modules/demux/adaptive/SharedResources.hpp         | 46 ++++++++++++++++++++++
 modules/demux/adaptive/adaptive.cpp                | 38 ++++++++++--------
 .../demux/adaptive/playlist/BaseRepresentation.cpp |  3 +-
 .../demux/adaptive/playlist/BaseRepresentation.h   |  5 ++-
 modules/demux/dash/DASHManager.cpp                 |  8 ++--
 modules/demux/dash/DASHManager.h                   |  2 +-
 modules/demux/hls/HLSManager.cpp                   |  4 +-
 modules/demux/hls/HLSManager.hpp                   |  2 +-
 modules/demux/hls/playlist/M3U8.cpp                | 10 +----
 modules/demux/hls/playlist/M3U8.hpp                |  8 ++--
 modules/demux/hls/playlist/Parser.cpp              | 13 +++---
 modules/demux/hls/playlist/Parser.hpp              | 11 ++----
 modules/demux/hls/playlist/Representation.cpp      |  8 ++--
 modules/demux/hls/playlist/Representation.hpp      |  3 +-
 modules/demux/smooth/SmoothManager.cpp             |  8 ++--
 modules/demux/smooth/SmoothManager.hpp             |  2 +-
 22 files changed, 177 insertions(+), 74 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index a3e1bd6fee..891c6171b9 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -371,6 +371,8 @@ libadaptive_plugin_la_SOURCES = \
     demux/adaptive/PlaylistManager.h \
     demux/adaptive/SegmentTracker.cpp \
     demux/adaptive/SegmentTracker.hpp \
+    demux/adaptive/SharedResources.cpp \
+    demux/adaptive/SharedResources.hpp \
     demux/adaptive/StreamFormat.cpp \
     demux/adaptive/StreamFormat.hpp \
     demux/adaptive/Streams.cpp \
diff --git a/modules/demux/adaptive/PlaylistManager.cpp b/modules/demux/adaptive/PlaylistManager.cpp
index da234d052a..b8cc7f23f1 100644
--- a/modules/demux/adaptive/PlaylistManager.cpp
+++ b/modules/demux/adaptive/PlaylistManager.cpp
@@ -25,12 +25,12 @@
 
 #include "PlaylistManager.h"
 #include "SegmentTracker.hpp"
+#include "SharedResources.hpp"
 #include "playlist/AbstractPlaylist.hpp"
 #include "playlist/BasePeriod.h"
 #include "playlist/BaseAdaptationSet.h"
 #include "playlist/BaseRepresentation.h"
 #include "http/HTTPConnectionManager.h"
-#include "http/AuthStorage.hpp"
 #include "logic/AlwaysBestAdaptationLogic.h"
 #include "logic/RateBasedAdaptationLogic.h"
 #include "logic/AlwaysLowestAdaptationLogic.hpp"
@@ -49,7 +49,7 @@ using namespace adaptive::logic;
 using namespace adaptive;
 
 PlaylistManager::PlaylistManager( demux_t *p_demux_,
-                                  AuthStorage *auth,
+                                  SharedResources *res,
                                   AbstractPlaylist *pl,
                                   AbstractStreamFactory *factory,
                                   AbstractAdaptationLogic::LogicType type ) :
@@ -61,7 +61,7 @@ PlaylistManager::PlaylistManager( demux_t *p_demux_,
              p_demux        ( p_demux_ )
 {
     currentPeriod = playlist->getFirstPeriod();
-    authStorage = auth;
+    resources = res;
     failedupdates = 0;
     b_thread = false;
     b_buffering = false;
@@ -86,7 +86,7 @@ PlaylistManager::~PlaylistManager   ()
     delete playlist;
     delete conManager;
     delete logic;
-    delete authStorage;
+    delete resources;
     vlc_cond_destroy(&waitcond);
     vlc_mutex_destroy(&lock);
     vlc_mutex_destroy(&demux.lock);
@@ -117,7 +117,7 @@ bool PlaylistManager::setupPeriod()
         BaseAdaptationSet *set = *it;
         if(set && streamFactory)
         {
-            SegmentTracker *tracker = new (std::nothrow) SegmentTracker(logic, set);
+            SegmentTracker *tracker = new SegmentTracker(resources, logic, set);
             if(!tracker)
                 continue;
 
@@ -156,7 +156,8 @@ bool PlaylistManager::start()
 {
     if(!conManager &&
        !(conManager =
-         new (std::nothrow) HTTPConnectionManager(VLC_OBJECT(p_demux->s), authStorage))
+         new (std::nothrow) HTTPConnectionManager(VLC_OBJECT(p_demux->s),
+                                                  resources->getAuthStorage()))
       )
         return false;
 
diff --git a/modules/demux/adaptive/PlaylistManager.h b/modules/demux/adaptive/PlaylistManager.h
index 56b1ad5d1f..e0e3c899ed 100644
--- a/modules/demux/adaptive/PlaylistManager.h
+++ b/modules/demux/adaptive/PlaylistManager.h
@@ -37,18 +37,16 @@ namespace adaptive
     namespace http
     {
         class AbstractConnectionManager;
-        class AuthStorage;
     }
 
     using namespace playlist;
     using namespace logic;
-    using namespace http;
 
     class PlaylistManager
     {
         public:
             PlaylistManager( demux_t *,
-                             AuthStorage *,
+                             SharedResources *,
                              AbstractPlaylist *,
                              AbstractStreamFactory *,
                              AbstractAdaptationLogic::LogicType type );
@@ -94,7 +92,7 @@ namespace adaptive
             virtual AbstractAdaptationLogic *createLogic(AbstractAdaptationLogic::LogicType,
                                                          AbstractConnectionManager *);
 
-            AuthStorage                         *authStorage;
+            SharedResources                     *resources;
             AbstractConnectionManager           *conManager;
             AbstractAdaptationLogic::LogicType  logicType;
             AbstractAdaptationLogic             *logic;
diff --git a/modules/demux/adaptive/SegmentTracker.cpp b/modules/demux/adaptive/SegmentTracker.cpp
index 2d4fcf332f..8a08d39b82 100644
--- a/modules/demux/adaptive/SegmentTracker.cpp
+++ b/modules/demux/adaptive/SegmentTracker.cpp
@@ -76,8 +76,10 @@ SegmentTrackerEvent::SegmentTrackerEvent(const ID &id, vlc_tick_t duration)
     u.segment.id = &id;
 }
 
-SegmentTracker::SegmentTracker(AbstractAdaptationLogic *logic_, BaseAdaptationSet *adaptSet)
+SegmentTracker::SegmentTracker(SharedResources *res,
+        AbstractAdaptationLogic *logic_, BaseAdaptationSet *adaptSet)
 {
+    resources = res;
     first = true;
     curNumber = next = 0;
     initializing = true;
@@ -109,7 +111,7 @@ StreamFormat SegmentTracker::getCurrentFormat() const
     {
         /* Ensure ephemere content is updated/loaded */
         if(rep->needsUpdate())
-            (void) rep->runLocalUpdates(0, curNumber, false);
+            (void) rep->runLocalUpdates(resources, 0, curNumber, false);
         return rep->getStreamFormat();
     }
     return StreamFormat();
@@ -176,7 +178,7 @@ SegmentChunk * SegmentTracker::getNextChunk(bool switch_allowed,
     bool b_updated = false;
     /* Ensure ephemere content is updated/loaded */
     if(rep->needsUpdate())
-        b_updated = rep->runLocalUpdates(getPlaybackTime(), curNumber, false);
+        b_updated = rep->runLocalUpdates(resources, getPlaybackTime(), curNumber, false);
 
     if(prevRep && !rep->consistentSegmentNumber())
     {
@@ -351,7 +353,7 @@ void SegmentTracker::updateSelected()
 {
     if(curRepresentation && curRepresentation->needsUpdate())
     {
-        curRepresentation->runLocalUpdates(getPlaybackTime(), curNumber, true);
+        curRepresentation->runLocalUpdates(resources, getPlaybackTime(), curNumber, true);
         curRepresentation->scheduleNextUpdate(curNumber);
     }
 }
diff --git a/modules/demux/adaptive/SegmentTracker.hpp b/modules/demux/adaptive/SegmentTracker.hpp
index cb95227d64..03dafa2e53 100644
--- a/modules/demux/adaptive/SegmentTracker.hpp
+++ b/modules/demux/adaptive/SegmentTracker.hpp
@@ -28,6 +28,7 @@
 namespace adaptive
 {
     class ID;
+    class SharedResources;
 
     namespace http
     {
@@ -112,7 +113,8 @@ namespace adaptive
     class SegmentTracker
     {
         public:
-            SegmentTracker(AbstractAdaptationLogic *, BaseAdaptationSet *);
+            SegmentTracker(SharedResources *,
+                           AbstractAdaptationLogic *, BaseAdaptationSet *);
             ~SegmentTracker();
 
             StreamFormat getCurrentFormat() const;
@@ -138,6 +140,7 @@ namespace adaptive
             uint64_t next;
             uint64_t curNumber;
             StreamFormat format;
+            SharedResources *resources;
             AbstractAdaptationLogic *logic;
             BaseAdaptationSet *adaptationSet;
             BaseRepresentation *curRepresentation;
diff --git a/modules/demux/adaptive/SharedResources.cpp b/modules/demux/adaptive/SharedResources.cpp
new file mode 100644
index 0000000000..65016a6843
--- /dev/null
+++ b/modules/demux/adaptive/SharedResources.cpp
@@ -0,0 +1,44 @@
+/*
+ * SharedResources.cpp
+ *****************************************************************************
+ * Copyright © 2019 VideoLabs, VideoLAN and VLC Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "SharedResources.hpp"
+#include "http/AuthStorage.hpp"
+
+#include <vlc_common.h>
+
+using namespace adaptive;
+
+SharedResources::SharedResources(vlc_object_t *obj)
+{
+    authStorage = new AuthStorage(obj);
+}
+
+SharedResources::~SharedResources()
+{
+    delete authStorage;
+}
+
+AuthStorage * SharedResources::getAuthStorage()
+{
+    return authStorage;
+}
diff --git a/modules/demux/adaptive/SharedResources.hpp b/modules/demux/adaptive/SharedResources.hpp
new file mode 100644
index 0000000000..b2fb9316cf
--- /dev/null
+++ b/modules/demux/adaptive/SharedResources.hpp
@@ -0,0 +1,46 @@
+/*
+ * SharedResources.h
+ *****************************************************************************
+ * Copyright © 2019 VideoLabs, VideoLAN and VLC Authors
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+#ifndef SHAREDRESOURCES_H_
+#define SHAREDRESOURCES_H_
+
+#include <vlc_common.h>
+
+namespace adaptive
+{
+    namespace http
+    {
+        class AuthStorage;
+    }
+
+    using namespace http;
+
+    class SharedResources
+    {
+        public:
+            SharedResources(vlc_object_t *);
+            ~SharedResources();
+            AuthStorage *getAuthStorage();
+
+        private:
+            AuthStorage *authStorage;
+    };
+}
+
+#endif
diff --git a/modules/demux/adaptive/adaptive.cpp b/modules/demux/adaptive/adaptive.cpp
index 0c40d55b28..0812e33113 100644
--- a/modules/demux/adaptive/adaptive.cpp
+++ b/modules/demux/adaptive/adaptive.cpp
@@ -32,7 +32,7 @@
 #include <vlc_plugin.h>
 #include <vlc_demux.h>
 
-#include "http/AuthStorage.hpp"
+#include "SharedResources.hpp"
 #include "playlist/BasePeriod.h"
 #include "xml/DOMParser.h"
 
@@ -128,9 +128,11 @@ vlc_module_end ()
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static PlaylistManager * HandleDash(demux_t *, AuthStorage *auth, DOMParser &,
+static PlaylistManager * HandleDash(demux_t *,
+                                    SharedResources *, DOMParser &,
                                     const std::string &, AbstractAdaptationLogic::LogicType);
-static PlaylistManager * HandleSmooth(demux_t *, AuthStorage *auth, DOMParser &,
+static PlaylistManager * HandleSmooth(demux_t *,
+                                      SharedResources *, DOMParser &,
                                       const std::string &, AbstractAdaptationLogic::LogicType);
 
 /*****************************************************************************
@@ -153,7 +155,7 @@ static int Open(vlc_object_t *p_obj)
     }
 
     PlaylistManager *p_manager = NULL;
-    AuthStorage *authStorage = new AuthStorage(p_obj);
+    SharedResources *resources = new SharedResources(p_obj);
 
     char *psz_logic = var_InheritString(p_obj, "adaptive-logic");
     AbstractAdaptationLogic::LogicType logic = AbstractAdaptationLogic::Default;
@@ -177,16 +179,16 @@ static int Open(vlc_object_t *p_obj)
 
     if(!dashmime && !smoothmime && HLSManager::isHTTPLiveStreaming(p_demux->s))
     {
-        M3U8Parser parser(authStorage);
+        M3U8Parser parser(resources);
         M3U8 *p_playlist = parser.parse(VLC_OBJECT(p_demux),p_demux->s, playlisturl);
         if(!p_playlist)
         {
             msg_Err( p_demux, "Could not parse playlist" );
-            delete authStorage;
+            delete resources;
             return VLC_EGENERIC;
         }
 
-        p_manager = new (std::nothrow) HLSManager(p_demux, authStorage, p_playlist,
+        p_manager = new (std::nothrow) HLSManager(p_demux, resources, p_playlist,
                                                   new (std::nothrow) HLSStreamFactory, logic);
     }
     else
@@ -195,11 +197,13 @@ static int Open(vlc_object_t *p_obj)
         DOMParser xmlParser; /* Share that xml reader */
         if(dashmime)
         {
-            p_manager = HandleDash(p_demux, authStorage, xmlParser, playlisturl, logic);
+            p_manager = HandleDash(p_demux, resources,
+                                   xmlParser, playlisturl, logic);
         }
         else if(smoothmime)
         {
-            p_manager = HandleSmooth(p_demux, authStorage, xmlParser, playlisturl, logic);
+            p_manager = HandleSmooth(p_demux, resources,
+                                     xmlParser, playlisturl, logic);
         }
         else
         {
@@ -215,11 +219,13 @@ static int Open(vlc_object_t *p_obj)
                     {
                         if(DASHManager::isDASH(xmlParser.getRootNode()))
                         {
-                            p_manager = HandleDash(p_demux, authStorage, xmlParser, playlisturl, logic);
+                            p_manager = HandleDash(p_demux, resources,
+                                                   xmlParser, playlisturl, logic);
                         }
                         else if(SmoothManager::isSmoothStreaming(xmlParser.getRootNode()))
                         {
-                            p_manager = HandleSmooth(p_demux, authStorage, xmlParser, playlisturl, logic);
+                            p_manager = HandleSmooth(p_demux, resources,
+                                                     xmlParser, playlisturl, logic);
                         }
                     }
                     vlc_stream_Delete(peekstream);
@@ -230,7 +236,7 @@ static int Open(vlc_object_t *p_obj)
 
     if(!p_manager)
     {
-        delete authStorage;
+        delete resources;
         return VLC_EGENERIC;
     }
     else if(!p_manager->start())
@@ -264,7 +270,7 @@ static void Close(vlc_object_t *p_obj)
  *
  *****************************************************************************/
 static PlaylistManager * HandleDash(demux_t *p_demux,
-                                    AuthStorage *auth, DOMParser &xmlParser,
+                                    SharedResources *res, DOMParser &xmlParser,
                                     const std::string & playlisturl,
                                     AbstractAdaptationLogic::LogicType logic)
 {
@@ -282,13 +288,13 @@ static PlaylistManager * HandleDash(demux_t *p_demux,
         return NULL;
     }
 
-    return new (std::nothrow) DASHManager( p_demux, auth, p_playlist,
+    return new (std::nothrow) DASHManager( p_demux, res, p_playlist,
                                  new (std::nothrow) DASHStreamFactory,
                                  logic );
 }
 
 static PlaylistManager * HandleSmooth(demux_t *p_demux,
-                                      AuthStorage *auth, DOMParser &xmlParser,
+                                      SharedResources *res, DOMParser &xmlParser,
                                     const std::string & playlisturl,
                                     AbstractAdaptationLogic::LogicType logic)
 {
@@ -306,7 +312,7 @@ static PlaylistManager * HandleSmooth(demux_t *p_demux,
         return NULL;
     }
 
-    return new (std::nothrow) SmoothManager( p_demux, auth, p_playlist,
+    return new (std::nothrow) SmoothManager( p_demux, res, p_playlist,
                                  new (std::nothrow) SmoothStreamFactory,
                                  logic );
 }
diff --git a/modules/demux/adaptive/playlist/BaseRepresentation.cpp b/modules/demux/adaptive/playlist/BaseRepresentation.cpp
index d51923e001..c632ea7f77 100644
--- a/modules/demux/adaptive/playlist/BaseRepresentation.cpp
+++ b/modules/demux/adaptive/playlist/BaseRepresentation.cpp
@@ -83,7 +83,8 @@ bool BaseRepresentation::needsUpdate() const
     return false;
 }
 
-bool BaseRepresentation::runLocalUpdates(vlc_tick_t, uint64_t, bool)
+bool BaseRepresentation::runLocalUpdates(SharedResources *,
+                                         vlc_tick_t, uint64_t, bool)
 {
     return false;
 }
diff --git a/modules/demux/adaptive/playlist/BaseRepresentation.h b/modules/demux/adaptive/playlist/BaseRepresentation.h
index cbbd8bd831..7d61a91472 100644
--- a/modules/demux/adaptive/playlist/BaseRepresentation.h
+++ b/modules/demux/adaptive/playlist/BaseRepresentation.h
@@ -34,6 +34,8 @@
 
 namespace adaptive
 {
+    class SharedResources;
+
     namespace playlist
     {
         class BaseAdaptationSet;
@@ -64,7 +66,8 @@ namespace adaptive
 
                 virtual vlc_tick_t  getMinAheadTime         (uint64_t) const;
                 virtual bool        needsUpdate             () const;
-                virtual bool        runLocalUpdates         (vlc_tick_t, uint64_t, bool);
+                virtual bool        runLocalUpdates         (SharedResources *,
+                                                             vlc_tick_t, uint64_t, bool);
                 virtual void        scheduleNextUpdate      (uint64_t);
 
                 virtual void        debug                   (vlc_object_t *,int = 0) const;
diff --git a/modules/demux/dash/DASHManager.cpp b/modules/demux/dash/DASHManager.cpp
index 3dcf786af8..dad8ae9c28 100644
--- a/modules/demux/dash/DASHManager.cpp
+++ b/modules/demux/dash/DASHManager.cpp
@@ -34,6 +34,7 @@
 #include "mpd/IsoffMainParser.h"
 #include "xml/DOMParser.h"
 #include "xml/Node.h"
+#include "../adaptive/SharedResources.hpp"
 #include "../adaptive/tools/Helper.h"
 #include "../adaptive/http/HTTPConnectionManager.h"
 #include <vlc_stream.h>
@@ -50,11 +51,11 @@ using namespace dash::mpd;
 using namespace adaptive::logic;
 
 DASHManager::DASHManager(demux_t *demux_,
-                         AuthStorage *auth,
+                         SharedResources *res,
                          MPD *mpd,
                          AbstractStreamFactory *factory,
                          AbstractAdaptationLogic::LogicType type) :
-             PlaylistManager(demux_, auth, mpd, factory, type)
+             PlaylistManager(demux_, res, mpd, factory, type)
 {
 }
 
@@ -102,7 +103,8 @@ bool DASHManager::updatePlaylist()
     {
         std::string url(p_demux->psz_url);
 
-        block_t *p_block = Retrieve::HTTP(VLC_OBJECT(p_demux), authStorage, url);
+        block_t *p_block = Retrieve::HTTP(VLC_OBJECT(p_demux),
+                                          resources->getAuthStorage(), url);
         if(!p_block)
             return false;
 
diff --git a/modules/demux/dash/DASHManager.h b/modules/demux/dash/DASHManager.h
index 992f2fae0e..50e31329d9 100644
--- a/modules/demux/dash/DASHManager.h
+++ b/modules/demux/dash/DASHManager.h
@@ -45,7 +45,7 @@ namespace dash
     {
         public:
             DASHManager( demux_t *,
-                         AuthStorage *,
+                         SharedResources *,
                          mpd::MPD *mpd,
                          AbstractStreamFactory *,
                          logic::AbstractAdaptationLogic::LogicType type);
diff --git a/modules/demux/hls/HLSManager.cpp b/modules/demux/hls/HLSManager.cpp
index 16deeae5cb..b6be5ca059 100644
--- a/modules/demux/hls/HLSManager.cpp
+++ b/modules/demux/hls/HLSManager.cpp
@@ -36,11 +36,11 @@ using namespace hls;
 using namespace hls::playlist;
 
 HLSManager::HLSManager(demux_t *demux_,
-                       AuthStorage *auth,
+                       SharedResources *res,
                        M3U8 *playlist,
                        AbstractStreamFactory *factory,
                        AbstractAdaptationLogic::LogicType type) :
-             PlaylistManager(demux_, auth, playlist, factory, type)
+             PlaylistManager(demux_, res, playlist, factory, type)
 {
 }
 
diff --git a/modules/demux/hls/HLSManager.hpp b/modules/demux/hls/HLSManager.hpp
index eacfece84c..0ec9be7c35 100644
--- a/modules/demux/hls/HLSManager.hpp
+++ b/modules/demux/hls/HLSManager.hpp
@@ -32,7 +32,7 @@ namespace hls
     {
         public:
             HLSManager( demux_t *,
-                        AuthStorage *,
+                        SharedResources *,
                         playlist::M3U8 *,
                         AbstractStreamFactory *,
                         logic::AbstractAdaptationLogic::LogicType type );
diff --git a/modules/demux/hls/playlist/M3U8.cpp b/modules/demux/hls/playlist/M3U8.cpp
index 622783bfee..db61ba2495 100644
--- a/modules/demux/hls/playlist/M3U8.cpp
+++ b/modules/demux/hls/playlist/M3U8.cpp
@@ -33,10 +33,9 @@
 
 using namespace hls::playlist;
 
-M3U8::M3U8 (vlc_object_t *p_object, AuthStorage *auth_) :
+M3U8::M3U8 (vlc_object_t *p_object) :
     AbstractPlaylist(p_object)
 {
-    auth = auth_;
     minUpdatePeriod.Set( VLC_TICK_FROM_SEC(5) );
     vlc_mutex_init(&keystore_lock);
 }
@@ -46,7 +45,7 @@ M3U8::~M3U8()
     vlc_mutex_destroy(&keystore_lock);
 }
 
-std::vector<uint8_t> M3U8::getEncryptionKey(const std::string &uri)
+std::vector<uint8_t> M3U8::getEncryptionKey(AuthStorage *auth, const std::string &uri)
 {
     std::vector<uint8_t> key;
 
@@ -105,11 +104,6 @@ bool M3U8::isLive() const
     return b_live;
 }
 
-AuthStorage * M3U8::getAuth()
-{
-    return auth;
-}
-
 void M3U8::debug()
 {
     std::vector<BasePeriod *>::const_iterator i;
diff --git a/modules/demux/hls/playlist/M3U8.hpp b/modules/demux/hls/playlist/M3U8.hpp
index 5fdcc4a70c..f019044fbc 100644
--- a/modules/demux/hls/playlist/M3U8.hpp
+++ b/modules/demux/hls/playlist/M3U8.hpp
@@ -38,20 +38,20 @@ namespace hls
     namespace playlist
     {
         using namespace adaptive::playlist;
+        using namespace adaptive::http;
 
         class M3U8 : public AbstractPlaylist
         {
             public:
-                M3U8(vlc_object_t *, adaptive::http::AuthStorage * /* ugly data ref, tobefixed */ );
+                M3U8(vlc_object_t *);
                 virtual ~M3U8();
 
-                std::vector<uint8_t>            getEncryptionKey(const std::string &);
+                std::vector<uint8_t>            getEncryptionKey(AuthStorage *auth,
+                                                                 const std::string &);
                 virtual bool                    isLive() const;
                 virtual void                    debug();
-                adaptive::http::AuthStorage *   getAuth(); /* ugly data ref, tobefixed */
 
             private:
-                adaptive::http::AuthStorage *auth; /* ugly data ref, tobefixed */
                 std::string data;
                 vlc_mutex_t keystore_lock;
                 std::map<std::string, std::vector<uint8_t> > keystore;
diff --git a/modules/demux/hls/playlist/Parser.cpp b/modules/demux/hls/playlist/Parser.cpp
index d722a0792c..a5c62220a0 100644
--- a/modules/demux/hls/playlist/Parser.cpp
+++ b/modules/demux/hls/playlist/Parser.cpp
@@ -24,6 +24,7 @@
 #include "Parser.hpp"
 #include "HLSSegment.hpp"
 #include "Representation.hpp"
+#include "../adaptive/SharedResources.hpp"
 #include "../adaptive/playlist/BasePeriod.h"
 #include "../adaptive/playlist/BaseAdaptationSet.h"
 #include "../adaptive/playlist/SegmentList.h"
@@ -45,9 +46,9 @@ using namespace adaptive;
 using namespace adaptive::playlist;
 using namespace hls::playlist;
 
-M3U8Parser::M3U8Parser( AuthStorage *auth_ )
+M3U8Parser::M3U8Parser(SharedResources *res)
 {
-    auth = auth_;
+    resources = res;
 }
 
 M3U8Parser::~M3U8Parser   ()
@@ -171,7 +172,8 @@ void M3U8Parser::createAndFillRepresentation(vlc_object_t *p_obj, BaseAdaptation
 
 bool M3U8Parser::appendSegmentsFromPlaylistURI(vlc_object_t *p_obj, Representation *rep)
 {
-    block_t *p_block = Retrieve::HTTP(p_obj, auth, rep->getPlaylistUrl().toString());
+    block_t *p_block = Retrieve::HTTP(p_obj, resources->getAuthStorage(),
+                                      rep->getPlaylistUrl().toString());
     if(p_block)
     {
         stream_t *substream = vlc_stream_MemoryNew(p_obj, p_block->p_buffer, p_block->i_buffer, true);
@@ -323,7 +325,8 @@ void M3U8Parser::parseSegments(vlc_object_t *, Representation *rep, const std::l
 
                     M3U8 *m3u8 = dynamic_cast<M3U8 *>(rep->getPlaylist());
                     if(likely(m3u8))
-                        encryption.key = m3u8->getEncryptionKey(keyurl.toString());
+                        encryption.key = m3u8->getEncryptionKey(resources->getAuthStorage(),
+                                                                keyurl.toString());
                     if(keytag->getAttributeByName("IV"))
                     {
                         encryption.iv.clear();
@@ -395,7 +398,7 @@ M3U8 * M3U8Parser::parse(vlc_object_t *p_object, stream_t *p_stream, const std::
     }
     free(psz_line);
 
-    M3U8 *playlist = new (std::nothrow) M3U8(p_object, auth);
+    M3U8 *playlist = new (std::nothrow) M3U8(p_object);
     if(!playlist)
         return NULL;
 
diff --git a/modules/demux/hls/playlist/Parser.hpp b/modules/demux/hls/playlist/Parser.hpp
index e46ae15b30..8582184969 100644
--- a/modules/demux/hls/playlist/Parser.hpp
+++ b/modules/demux/hls/playlist/Parser.hpp
@@ -29,6 +29,8 @@
 
 namespace adaptive
 {
+    class SharedResources;
+
     namespace playlist
     {
         class SegmentInformation;
@@ -36,11 +38,6 @@ namespace adaptive
         class BasePeriod;
         class BaseAdaptationSet;
     }
-
-    namespace http
-    {
-        class AuthStorage;
-    }
 }
 
 namespace hls
@@ -57,7 +54,7 @@ namespace hls
         class M3U8Parser
         {
             public:
-                M3U8Parser             (AuthStorage *auth);
+                M3U8Parser             (adaptive::SharedResources *);
                 virtual ~M3U8Parser    ();
 
                 M3U8 *             parse  (vlc_object_t *p_obj, stream_t *p_stream, const std::string &);
@@ -70,7 +67,7 @@ namespace hls
                 void parseSegments(vlc_object_t *, Representation *, const std::list<Tag *>&);
                 void setFormatFromExtension(Representation *rep, const std::string &);
                 std::list<Tag *> parseEntries(stream_t *);
-                AuthStorage *auth;
+                adaptive::SharedResources *resources;
         };
     }
 }
diff --git a/modules/demux/hls/playlist/Representation.cpp b/modules/demux/hls/playlist/Representation.cpp
index 10ada80508..8257bfdf56 100644
--- a/modules/demux/hls/playlist/Representation.cpp
+++ b/modules/demux/hls/playlist/Representation.cpp
@@ -136,16 +136,14 @@ bool Representation::needsUpdate() const
     return !b_loaded || (isLive() && nextUpdateTime < time(NULL));
 }
 
-bool Representation::runLocalUpdates(vlc_tick_t, uint64_t number, bool prune)
+bool Representation::runLocalUpdates(SharedResources *res,
+                                     vlc_tick_t, uint64_t number, bool prune)
 {
     const time_t now = time(NULL);
     AbstractPlaylist *playlist = getPlaylist();
     if(!b_loaded || (isLive() && nextUpdateTime < now))
     {
-        /* ugly hack */
-        M3U8 *m3u = dynamic_cast<M3U8 *>(playlist);
-        M3U8Parser parser((m3u) ? m3u->getAuth() : NULL);
-        /* !ugly hack */
+        M3U8Parser parser(res);
         parser.appendSegmentsFromPlaylistURI(playlist->getVLCObject(), this);
         b_loaded = true;
 
diff --git a/modules/demux/hls/playlist/Representation.hpp b/modules/demux/hls/playlist/Representation.hpp
index ed2da0da8e..7f59cf9bf8 100644
--- a/modules/demux/hls/playlist/Representation.hpp
+++ b/modules/demux/hls/playlist/Representation.hpp
@@ -50,7 +50,8 @@ namespace hls
                 virtual void scheduleNextUpdate(uint64_t); /* reimpl */
                 virtual bool needsUpdate() const;  /* reimpl */
                 virtual void debug(vlc_object_t *, int) const;  /* reimpl */
-                virtual bool runLocalUpdates(vlc_tick_t, uint64_t, bool); /* reimpl */
+                virtual bool runLocalUpdates(SharedResources *,
+                                             vlc_tick_t, uint64_t, bool); /* reimpl */
                 virtual uint64_t translateSegmentNumber(uint64_t, const SegmentInformation *) const; /* reimpl */
 
             private:
diff --git a/modules/demux/smooth/SmoothManager.cpp b/modules/demux/smooth/SmoothManager.cpp
index abb13d493d..ebd71ee448 100644
--- a/modules/demux/smooth/SmoothManager.cpp
+++ b/modules/demux/smooth/SmoothManager.cpp
@@ -26,6 +26,7 @@
 
 #include "SmoothManager.hpp"
 
+#include "../adaptive/SharedResources.hpp"
 #include "../adaptive/tools/Retrieve.hpp"
 #include "playlist/Parser.hpp"
 #include "../adaptive/xml/DOMParser.h"
@@ -40,11 +41,11 @@ using namespace smooth;
 using namespace smooth::playlist;
 
 SmoothManager::SmoothManager(demux_t *demux_,
-                             AuthStorage *auth,
+                             SharedResources *res,
                              Manifest *playlist,
                        AbstractStreamFactory *factory,
                        AbstractAdaptationLogic::LogicType type) :
-             PlaylistManager(demux_, auth, playlist, factory, type)
+             PlaylistManager(demux_, res, playlist, factory, type)
 {
 }
 
@@ -56,7 +57,8 @@ Manifest * SmoothManager::fetchManifest()
 {
     std::string playlisturl(p_demux->psz_url);
 
-    block_t *p_block = Retrieve::HTTP(VLC_OBJECT(p_demux), authStorage, playlisturl);
+    block_t *p_block = Retrieve::HTTP(VLC_OBJECT(p_demux),
+                                      resources->getAuthStorage(), playlisturl);
     if(!p_block)
         return NULL;
 
diff --git a/modules/demux/smooth/SmoothManager.hpp b/modules/demux/smooth/SmoothManager.hpp
index 02fa49feb4..1e32603948 100644
--- a/modules/demux/smooth/SmoothManager.hpp
+++ b/modules/demux/smooth/SmoothManager.hpp
@@ -39,7 +39,7 @@ namespace smooth
     class SmoothManager : public PlaylistManager
     {
         public:
-            SmoothManager( demux_t *, AuthStorage *, playlist::Manifest *,
+            SmoothManager( demux_t *, SharedResources *, playlist::Manifest *,
                         AbstractStreamFactory *,
                         logic::AbstractAdaptationLogic::LogicType type );
             virtual ~SmoothManager();



More information about the vlc-commits mailing list