[vlc-commits] adaptive: simplify connection factory selection
Francois Cartegnie
git at videolan.org
Mon Dec 28 16:57:23 UTC 2020
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Dec 23 11:26:43 2020 +0100| [f352c422338a5bf68a29c252e4570622c3896400] | committer: Francois Cartegnie
adaptive: simplify connection factory selection
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f352c422338a5bf68a29c252e4570622c3896400
---
modules/demux/adaptive/SharedResources.cpp | 13 +++++++--
modules/demux/adaptive/http/HTTPConnection.cpp | 32 ++--------------------
modules/demux/adaptive/http/HTTPConnection.hpp | 11 --------
.../demux/adaptive/http/HTTPConnectionManager.cpp | 22 ++++++++++-----
.../demux/adaptive/http/HTTPConnectionManager.h | 7 +++--
5 files changed, 32 insertions(+), 53 deletions(-)
diff --git a/modules/demux/adaptive/SharedResources.cpp b/modules/demux/adaptive/SharedResources.cpp
index 05c7a9288f..21606a3e1b 100644
--- a/modules/demux/adaptive/SharedResources.cpp
+++ b/modules/demux/adaptive/SharedResources.cpp
@@ -24,6 +24,7 @@
#include "SharedResources.hpp"
#include "http/AuthStorage.hpp"
#include "http/HTTPConnectionManager.h"
+#include "http/HTTPConnection.hpp"
#include "encryption/Keyring.hpp"
#include <vlc_common.h>
@@ -34,9 +35,15 @@ SharedResources::SharedResources(vlc_object_t *obj, bool local)
{
authStorage = new AuthStorage(obj);
encryptionKeyring = new Keyring(obj);
- HTTPConnectionManager *m = new HTTPConnectionManager(obj, authStorage);
- if(m && local)
- m->setLocalConnectionsAllowed();
+ HTTPConnectionManager *m = new HTTPConnectionManager(obj);
+ if(m)
+ {
+ if(!var_InheritBool(obj, "adaptive-use-access")) /* only use http from access */
+ m->addFactory(new NativeConnectionFactory(authStorage));
+ m->addFactory(new StreamUrlConnectionFactory());
+ if(local)
+ m->setLocalConnectionsAllowed();
+ }
connManager = m;
}
diff --git a/modules/demux/adaptive/http/HTTPConnection.cpp b/modules/demux/adaptive/http/HTTPConnection.cpp
index 36354c5b90..2b1b91f326 100644
--- a/modules/demux/adaptive/http/HTTPConnection.cpp
+++ b/modules/demux/adaptive/http/HTTPConnection.cpp
@@ -602,7 +602,9 @@ NativeConnectionFactory::~NativeConnectionFactory()
AbstractConnection * NativeConnectionFactory::createConnection(vlc_object_t *p_object,
const ConnectionParams ¶ms)
{
- if((params.getScheme() != "http" && params.getScheme() != "https") || params.getHostname().empty())
+ if(params.usesAccess() ||
+ (params.getScheme() != "http" && params.getScheme() != "https") ||
+ params.getHostname().empty())
return NULL;
ConnectionParams proxy;
@@ -645,31 +647,3 @@ AbstractConnection * StreamUrlConnectionFactory::createConnection(vlc_object_t *
{
return new (std::nothrow) StreamUrlConnection(p_object);
}
-
-ConnectionFactory::ConnectionFactory( AuthStorage *authstorage )
-{
- native = new NativeConnectionFactory( authstorage );
- streamurl = new StreamUrlConnectionFactory();
-}
-
-ConnectionFactory::~ConnectionFactory()
-{
- delete native;
- delete streamurl;
-}
-
-AbstractConnection * ConnectionFactory::createConnection(vlc_object_t *p_object,
- const ConnectionParams ¶ms)
-{
- bool b_streamurl = var_InheritBool(p_object, "adaptive-use-access");
- if(!b_streamurl && !params.usesAccess())
- {
- return native->createConnection(p_object, params);
- }
- else
- {
- ConnectionParams paramsaccess = params;
- paramsaccess.setUseAccess(true);
- return streamurl->createConnection(p_object, paramsaccess);
- }
-}
diff --git a/modules/demux/adaptive/http/HTTPConnection.hpp b/modules/demux/adaptive/http/HTTPConnection.hpp
index 630016f987..e41ea5b549 100644
--- a/modules/demux/adaptive/http/HTTPConnection.hpp
+++ b/modules/demux/adaptive/http/HTTPConnection.hpp
@@ -157,17 +157,6 @@ namespace adaptive
virtual ~StreamUrlConnectionFactory() {}
virtual AbstractConnection * createConnection(vlc_object_t *, const ConnectionParams &);
};
-
- class ConnectionFactory : public AbstractConnectionFactory
- {
- public:
- ConnectionFactory( AuthStorage * );
- virtual ~ConnectionFactory();
- virtual AbstractConnection * createConnection(vlc_object_t *, const ConnectionParams &);
- private:
- NativeConnectionFactory *native;
- StreamUrlConnectionFactory *streamurl;
- };
}
}
diff --git a/modules/demux/adaptive/http/HTTPConnectionManager.cpp b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
index d1c5e556ec..617e57c0f5 100644
--- a/modules/demux/adaptive/http/HTTPConnectionManager.cpp
+++ b/modules/demux/adaptive/http/HTTPConnectionManager.cpp
@@ -59,21 +59,24 @@ void AbstractConnectionManager::setDownloadRateObserver(IDownloadRateObserver *o
}
-HTTPConnectionManager::HTTPConnectionManager (vlc_object_t *p_object_, AuthStorage *storage)
+HTTPConnectionManager::HTTPConnectionManager (vlc_object_t *p_object_)
: AbstractConnectionManager( p_object_ ),
localAllowed(false)
{
vlc_mutex_init(&lock);
downloader = new (std::nothrow) Downloader();
downloader->start();
- factory = new ConnectionFactory(storage);
}
HTTPConnectionManager::~HTTPConnectionManager ()
{
delete downloader;
- delete factory;
this->closeAllConnections();
+ while(!factories.empty())
+ {
+ delete factories.front();
+ factories.pop_front();
+ }
}
void HTTPConnectionManager::closeAllConnections ()
@@ -105,22 +108,22 @@ AbstractConnection * HTTPConnectionManager::reuseConnection(ConnectionParams &pa
AbstractConnection * HTTPConnectionManager::getConnection(ConnectionParams ¶ms)
{
- if(unlikely(!factory || !downloader))
+ if(unlikely(factories.empty() || !downloader))
return NULL;
if(params.isLocal())
{
if(!localAllowed)
return NULL;
- /* Only access can read local files */
- params.setUseAccess(true);
}
vlc_mutex_lock(&lock);
AbstractConnection *conn = reuseConnection(params);
if(!conn)
{
- conn = factory->createConnection(p_object, params);
+ for(auto it = factories.begin(); it != factories.end() && !conn; ++it)
+ conn = (*it)->createConnection(p_object, params);
+
if(!conn)
{
vlc_mutex_unlock(&lock);
@@ -159,3 +162,8 @@ void HTTPConnectionManager::setLocalConnectionsAllowed()
{
localAllowed = true;
}
+
+void HTTPConnectionManager::addFactory(AbstractConnectionFactory *factory)
+{
+ factories.push_back(factory);
+}
diff --git a/modules/demux/adaptive/http/HTTPConnectionManager.h b/modules/demux/adaptive/http/HTTPConnectionManager.h
index 39d276d28e..478cf64ee5 100644
--- a/modules/demux/adaptive/http/HTTPConnectionManager.h
+++ b/modules/demux/adaptive/http/HTTPConnectionManager.h
@@ -30,6 +30,7 @@
#include <vlc_common.h>
#include <vector>
+#include <list>
#include <string>
namespace adaptive
@@ -39,7 +40,6 @@ namespace adaptive
class ConnectionParams;
class AbstractConnectionFactory;
class AbstractConnection;
- class AuthStorage;
class Downloader;
class AbstractChunkSource;
@@ -66,7 +66,7 @@ namespace adaptive
class HTTPConnectionManager : public AbstractConnectionManager
{
public:
- HTTPConnectionManager (vlc_object_t *p_object, AuthStorage *);
+ HTTPConnectionManager (vlc_object_t *p_object);
virtual ~HTTPConnectionManager ();
virtual void closeAllConnections () /* impl */;
@@ -75,13 +75,14 @@ namespace adaptive
virtual void start(AbstractChunkSource *) /* impl */;
virtual void cancel(AbstractChunkSource *) /* impl */;
void setLocalConnectionsAllowed();
+ void addFactory(AbstractConnectionFactory *);
private:
void releaseAllConnections ();
Downloader *downloader;
vlc_mutex_t lock;
std::vector<AbstractConnection *> connectionPool;
- AbstractConnectionFactory *factory;
+ std::list<AbstractConnectionFactory *> factories;
bool localAllowed;
AbstractConnection * reuseConnection(ConnectionParams &);
};
More information about the vlc-commits
mailing list