[vlc-commits] adaptive: move connection to connection factory

Francois Cartegnie git at videolan.org
Thu Feb 25 23:00:45 CET 2016


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Feb 24 14:27:43 2016 +0100| [422d6a480171c6cde428650759da0b0d7d256294] | committer: Francois Cartegnie

adaptive: move connection to connection factory

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

 modules/demux/adaptive/http/Chunk.h                |    4 +--
 modules/demux/adaptive/http/HTTPConnection.cpp     |   32 +++++++++++++++++
 modules/demux/adaptive/http/HTTPConnection.hpp     |    8 +++++
 .../demux/adaptive/http/HTTPConnectionManager.cpp  |   36 +++++++-------------
 .../demux/adaptive/http/HTTPConnectionManager.h    |   12 ++++---
 5 files changed, 62 insertions(+), 30 deletions(-)

diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index de5b9fe..41ea6aa 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -37,7 +37,7 @@ namespace adaptive
 {
     namespace http
     {
-        class HTTPConnection;
+        class AbstractConnection;
         class HTTPConnectionManager;
         class AbstractChunk;
 
@@ -92,7 +92,7 @@ namespace adaptive
 
             protected:
                 virtual bool      prepare();
-                HTTPConnection     *connection;
+                AbstractConnection    *connection;
                 HTTPConnectionManager *connManager;
                 size_t              consumed; /* read pointer */
                 bool                prepared;
diff --git a/modules/demux/adaptive/http/HTTPConnection.cpp b/modules/demux/adaptive/http/HTTPConnection.cpp
index 60d805f..f9dd3fa 100644
--- a/modules/demux/adaptive/http/HTTPConnection.cpp
+++ b/modules/demux/adaptive/http/HTTPConnection.cpp
@@ -294,3 +294,35 @@ std::string HTTPConnection::extraRequestHeaders() const
     }
     return ss.str();
 }
+
+ConnectionFactory::ConnectionFactory()
+{
+}
+
+ConnectionFactory::~ConnectionFactory()
+{
+}
+
+AbstractConnection * ConnectionFactory::createConnection(vlc_object_t *p_object,
+                                                         const ConnectionParams &params)
+{
+    if((params.getScheme() != "http" && params.getScheme() != "https") || params.getHostname().empty())
+        return NULL;
+
+    const int sockettype = (params.getScheme() == "https") ? TLSSocket::TLS : Socket::REGULAR;
+    Socket *socket = (sockettype == TLSSocket::TLS) ? new (std::nothrow) TLSSocket()
+                                                    : new (std::nothrow) Socket();
+    if(!socket)
+        return NULL;
+
+    /* disable pipelined tls until we have ticket/resume session support */
+    HTTPConnection *conn = new (std::nothrow)
+            HTTPConnection(p_object, socket, sockettype != TLSSocket::TLS);
+    if(!conn)
+    {
+        delete socket;
+        return NULL;
+    }
+
+    return conn;
+}
diff --git a/modules/demux/adaptive/http/HTTPConnection.hpp b/modules/demux/adaptive/http/HTTPConnection.hpp
index 2c45aa0..33683f2 100644
--- a/modules/demux/adaptive/http/HTTPConnection.hpp
+++ b/modules/demux/adaptive/http/HTTPConnection.hpp
@@ -102,6 +102,14 @@ namespace adaptive
             private:
                 Socket *socket;
        };
+
+       class ConnectionFactory
+       {
+           public:
+               ConnectionFactory();
+               virtual ~ConnectionFactory();
+               virtual AbstractConnection * createConnection(vlc_object_t *, const ConnectionParams &);
+       };
     }
 }
 
diff --git a/modules/demux/adaptive/http/HTTPConnectionManager.cpp b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
index e95c3e2..07b4a08 100644
--- a/modules/demux/adaptive/http/HTTPConnectionManager.cpp
+++ b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
@@ -34,17 +34,22 @@
 
 using namespace adaptive::http;
 
-HTTPConnectionManager::HTTPConnectionManager    (vlc_object_t *stream) :
+HTTPConnectionManager::HTTPConnectionManager    (vlc_object_t *stream, ConnectionFactory *factory_) :
                        stream                   (stream),
                        rateObserver             (NULL)
 {
     vlc_mutex_init(&lock);
     downloader = new (std::nothrow) Downloader();
     downloader->start();
+    if(!factory_)
+        factory = new (std::nothrow) ConnectionFactory();
+    else
+        factory = factory_;
 }
 HTTPConnectionManager::~HTTPConnectionManager   ()
 {
     delete downloader;
+    delete factory;
     this->closeAllConnections();
     vlc_mutex_destroy(&lock);
 }
@@ -59,14 +64,14 @@ void HTTPConnectionManager::closeAllConnections      ()
 
 void HTTPConnectionManager::releaseAllConnections()
 {
-    std::vector<HTTPConnection *>::iterator it;
+    std::vector<AbstractConnection *>::iterator it;
     for(it = connectionPool.begin(); it != connectionPool.end(); ++it)
         (*it)->setUsed(false);
 }
 
-HTTPConnection * HTTPConnectionManager::reuseConnection(ConnectionParams &params)
+AbstractConnection * HTTPConnectionManager::reuseConnection(ConnectionParams &params)
 {
-    std::vector<HTTPConnection *>::const_iterator it;
+    std::vector<AbstractConnection *>::const_iterator it;
     for(it = connectionPool.begin(); it != connectionPool.end(); ++it)
     {
         AbstractConnection *conn = *it;
@@ -76,31 +81,16 @@ HTTPConnection * HTTPConnectionManager::reuseConnection(ConnectionParams &params
     return NULL;
 }
 
-HTTPConnection * HTTPConnectionManager::getConnection(ConnectionParams &params)
+AbstractConnection * HTTPConnectionManager::getConnection(ConnectionParams &params)
 {
-    if((params.getScheme() != "http" && params.getScheme() != "https") || params.getHostname().empty())
+    if(unlikely(!factory || !downloader))
         return NULL;
 
-    const int sockettype = (params.getScheme() == "https") ? TLSSocket::TLS : Socket::REGULAR;
     vlc_mutex_lock(&lock);
-    HTTPConnection *conn = reuseConnection(params);
+    AbstractConnection *conn = reuseConnection(params);
     if(!conn)
     {
-        Socket *socket = (sockettype == TLSSocket::TLS) ? new (std::nothrow) TLSSocket()
-                                                        : new (std::nothrow) Socket();
-        if(!socket)
-        {
-            vlc_mutex_unlock(&lock);
-            return NULL;
-        }
-        /* disable pipelined tls until we have ticket/resume session support */
-        conn = new (std::nothrow) HTTPConnection(stream, socket, sockettype != TLSSocket::TLS);
-        if(!conn)
-        {
-            delete socket;
-            vlc_mutex_unlock(&lock);
-            return NULL;
-        }
+        conn = factory->createConnection(stream, params);
 
         connectionPool.push_back(conn);
 
diff --git a/modules/demux/adaptive/http/HTTPConnectionManager.h b/modules/demux/adaptive/http/HTTPConnectionManager.h
index de606b8..638bc55 100644
--- a/modules/demux/adaptive/http/HTTPConnectionManager.h
+++ b/modules/demux/adaptive/http/HTTPConnectionManager.h
@@ -40,17 +40,18 @@ namespace adaptive
     namespace http
     {
         class ConnectionParams;
-        class HTTPConnection;
+        class ConnectionFactory;
+        class AbstractConnection;
         class Downloader;
 
         class HTTPConnectionManager : public IDownloadRateObserver
         {
             public:
-                HTTPConnectionManager           (vlc_object_t *stream);
+                HTTPConnectionManager           (vlc_object_t *stream, ConnectionFactory * = NULL);
                 virtual ~HTTPConnectionManager  ();
 
                 void    closeAllConnections ();
-                HTTPConnection * getConnection(ConnectionParams &);
+                AbstractConnection * getConnection(ConnectionParams &);
 
                 virtual void updateDownloadRate(size_t, mtime_t); /* reimpl */
                 void setDownloadRateObserver(IDownloadRateObserver *);
@@ -59,10 +60,11 @@ namespace adaptive
             private:
                 void    releaseAllConnections ();
                 vlc_mutex_t                                         lock;
-                std::vector<HTTPConnection *>                       connectionPool;
+                std::vector<AbstractConnection *>                   connectionPool;
                 vlc_object_t                                       *stream;
                 IDownloadRateObserver                              *rateObserver;
-                HTTPConnection * reuseConnection(ConnectionParams &);
+                ConnectionFactory                                  *factory;
+                AbstractConnection * reuseConnection(ConnectionParams &);
         };
     }
 }



More information about the vlc-commits mailing list