[vlc-devel] [PATCH 1/3] demux: adaptive: do lazy start downloader

Zhao Zhili quinkblack at foxmail.com
Sat Dec 16 16:11:31 CET 2017


Downloader::start() create a new thread. It's overkill to start the
downloader if it won't be used, e.g. class Retrieve. We can add another
ConnectionManager without a downloader, but it's a little overkill too.
---
 modules/demux/adaptive/http/HTTPConnectionManager.cpp | 12 ++++++++++--
 modules/demux/adaptive/http/HTTPConnectionManager.h   |  1 +
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/modules/demux/adaptive/http/HTTPConnectionManager.cpp b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
index 2f10bde..774a58c 100644
--- a/modules/demux/adaptive/http/HTTPConnectionManager.cpp
+++ b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
@@ -63,7 +63,7 @@ HTTPConnectionManager::HTTPConnectionManager    (vlc_object_t *p_object_, Connec
 {
     vlc_mutex_init(&lock);
     downloader = new (std::nothrow) Downloader();
-    downloader->start();
+    downloaderStarted = false;
     factory = factory_;
 }
 
@@ -72,7 +72,7 @@ HTTPConnectionManager::HTTPConnectionManager    (vlc_object_t *p_object_, AuthSt
 {
     vlc_mutex_init(&lock);
     downloader = new (std::nothrow) Downloader();
-    downloader->start();
+    downloaderStarted = false;
     if(var_InheritBool(p_object, "adaptive-use-access"))
         factory = new (std::nothrow) StreamUrlConnectionFactory();
     else
@@ -146,6 +146,14 @@ AbstractConnection * HTTPConnectionManager::getConnection(ConnectionParams &para
 
 void HTTPConnectionManager::start(AbstractChunkSource *source)
 {
+    vlc_mutex_lock(&lock);
+    if(!downloaderStarted)
+    {
+        downloader->start();
+        downloaderStarted = true;
+    }
+    vlc_mutex_unlock(&lock);
+
     HTTPChunkBufferedSource *src = dynamic_cast<HTTPChunkBufferedSource *>(source);
     if(src)
         downloader->schedule(src);
diff --git a/modules/demux/adaptive/http/HTTPConnectionManager.h b/modules/demux/adaptive/http/HTTPConnectionManager.h
index 09e6553..8dc6f11 100644
--- a/modules/demux/adaptive/http/HTTPConnectionManager.h
+++ b/modules/demux/adaptive/http/HTTPConnectionManager.h
@@ -79,6 +79,7 @@ namespace adaptive
             private:
                 void    releaseAllConnections ();
                 Downloader                                         *downloader;
+                bool                                                downloaderStarted;
                 vlc_mutex_t                                         lock;
                 std::vector<AbstractConnection *>                   connectionPool;
                 ConnectionFactory                                  *factory;
-- 
2.7.4





More information about the vlc-devel mailing list