[vlc-commits] demux: adaptive: add ConnectionParam class

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


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sun Feb 21 19:04:32 2016 +0100| [871a1f18ca66dde3c1f63b669c96988c8bdb640d] | committer: Francois Cartegnie

demux: adaptive: add ConnectionParam class

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

 modules/demux/Makefile.am                        |    2 +
 modules/demux/adaptive/http/Chunk.cpp            |   39 ++-------
 modules/demux/adaptive/http/Chunk.h              |    7 +-
 modules/demux/adaptive/http/ConnectionParams.cpp |   97 ++++++++++++++++++++++
 modules/demux/adaptive/http/ConnectionParams.hpp |   59 +++++++++++++
 5 files changed, 168 insertions(+), 36 deletions(-)

diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index 5bbc732..11518fe 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -316,6 +316,8 @@ libadaptive_plugin_la_SOURCES = \
     demux/adaptive/http/BytesRange.hpp \
     demux/adaptive/http/Chunk.cpp \
     demux/adaptive/http/Chunk.h \
+    demux/adaptive/http/ConnectionParams.cpp \
+    demux/adaptive/http/ConnectionParams.hpp \
     demux/adaptive/http/Downloader.cpp \
     demux/adaptive/http/Downloader.hpp \
     demux/adaptive/http/HTTPConnection.cpp \
diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index cd5dcf1..f6c9a35 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -31,7 +31,6 @@
 #include "Downloader.hpp"
 
 #include <vlc_common.h>
-#include <vlc_url.h>
 #include <vlc_block.h>
 
 #include <algorithm>
@@ -113,8 +112,7 @@ HTTPChunkSource::HTTPChunkSource(const std::string& url, HTTPConnectionManager *
     AbstractChunkSource(),
     connection   (NULL),
     connManager  (manager),
-    consumed     (0),
-    port         (0)
+    consumed     (0)
 {
     prepared = false;
     eof = false;
@@ -130,35 +128,12 @@ HTTPChunkSource::~HTTPChunkSource()
 
 bool HTTPChunkSource::init(const std::string &url)
 {
-    this->url = url;
+    params = ConnectionParams(url);
 
-    std::size_t pos = url.find("://");
-    if(pos != std::string::npos)
-    {
-        scheme = url.substr(0, pos);
-    }
-
-    if(scheme != "http" && scheme != "https")
+    if(params.getScheme() != "http" && params.getScheme() != "https")
         return false;
 
-    vlc_url_t url_components;
-    vlc_UrlParse(&url_components, url.c_str());
-
-    if(url_components.psz_path)
-        path = url_components.psz_path;
-    if(url_components.psz_option)
-    {
-        path += "?";
-        path += url_components.psz_option;
-    }
-    port = url_components.i_port ? url_components.i_port :
-                         ((scheme == "https") ? 443 : 80);
-    if(url_components.psz_host)
-        hostname = url_components.psz_host;
-
-    vlc_UrlClean(&url_components);
-
-    if(path.empty() || hostname.empty())
+    if(params.getPath().empty() || params.getHostname().empty())
         return false;
 
     return true;
@@ -228,12 +203,14 @@ bool HTTPChunkSource::prepare()
 
     if(!connection)
     {
-        connection = connManager->getConnection(scheme, hostname, port);
+        connection = connManager->getConnection(params.getScheme(),
+                                                params.getHostname(),
+                                                params.getPort());
         if(!connection)
             return false;
     }
 
-    if( connection->query(path, bytesRange) != VLC_SUCCESS )
+    if( connection->query(params.getPath(), bytesRange) != VLC_SUCCESS )
         return false;
     /* Because we don't know Chunk size at start, we need to get size
            from content length */
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index 63c6d34..de5b9fe 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -26,6 +26,7 @@
 #define CHUNK_H_
 
 #include "BytesRange.hpp"
+#include "ConnectionParams.hpp"
 #include <vector>
 #include <string>
 #include <stdint.h>
@@ -99,11 +100,7 @@ namespace adaptive
 
             private:
                 bool init(const std::string &);
-                std::string         url;
-                std::string         scheme;
-                std::string         path;
-                std::string         hostname;
-                uint16_t            port;
+                ConnectionParams    params;
         };
 
         class HTTPChunkBufferedSource : public HTTPChunkSource
diff --git a/modules/demux/adaptive/http/ConnectionParams.cpp b/modules/demux/adaptive/http/ConnectionParams.cpp
new file mode 100644
index 0000000..cddbef8
--- /dev/null
+++ b/modules/demux/adaptive/http/ConnectionParams.cpp
@@ -0,0 +1,97 @@
+/*
+ * ConnectionParams.cpp
+ *****************************************************************************
+ * Copyright (C) 2016 - 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.
+ *****************************************************************************/
+#include "ConnectionParams.hpp"
+
+#include <vlc_url.h>
+#include <sstream>
+
+using namespace adaptive::http;
+
+ConnectionParams::ConnectionParams()
+{
+}
+
+ConnectionParams::ConnectionParams(const std::string &uri)
+{
+    this->uri = uri;
+    parse();
+}
+
+const std::string & ConnectionParams::getUrl() const
+{
+    return uri;
+}
+
+const std::string & ConnectionParams::getScheme() const
+{
+    return scheme;
+}
+
+const std::string & ConnectionParams::getHostname() const
+{
+    return hostname;
+}
+
+const std::string & ConnectionParams::getPath() const
+{
+    return path;
+}
+
+void ConnectionParams::setPath(const std::string &path_)
+{
+    path = path_;
+
+    std::ostringstream os;
+    os.imbue(std::locale("C"));
+    os << scheme << "://" << hostname << ":" << port;
+    os << path;
+    uri = os.str();
+}
+
+uint16_t ConnectionParams::getPort() const
+{
+    return port;
+}
+
+void ConnectionParams::parse()
+{
+    std::size_t pos = uri.find("://");
+    if(pos != std::string::npos)
+    {
+        scheme = uri.substr(0, pos);
+    }
+
+    vlc_url_t url_components;
+    vlc_UrlParse(&url_components, uri.c_str());
+
+    if(url_components.psz_path)
+        path = url_components.psz_path;
+    if(url_components.psz_option)
+    {
+        path += "?";
+        path += url_components.psz_option;
+    }
+    port = url_components.i_port ? url_components.i_port :
+                         ((scheme == "https") ? 443 : 80);
+    if(url_components.psz_host)
+        hostname = url_components.psz_host;
+
+    vlc_UrlClean(&url_components);
+}
diff --git a/modules/demux/adaptive/http/ConnectionParams.hpp b/modules/demux/adaptive/http/ConnectionParams.hpp
new file mode 100644
index 0000000..9d182f9
--- /dev/null
+++ b/modules/demux/adaptive/http/ConnectionParams.hpp
@@ -0,0 +1,59 @@
+/*
+ * ConnectionParams.hpp
+ *****************************************************************************
+ * Copyright (C) 2016 - 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 CONNECTIONPARAMS_HPP
+#define CONNECTIONPARAMS_HPP
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <string>
+
+namespace adaptive
+{
+    namespace http
+    {
+        class Socket;
+
+        class ConnectionParams
+        {
+            public:
+                ConnectionParams();
+                ConnectionParams(const std::string &);
+                const std::string & getUrl() const;
+                const std::string & getScheme() const;
+                const std::string & getHostname() const;
+                const std::string & getPath() const;
+                void setPath(const std::string &);
+                uint16_t getPort() const;
+
+            private:
+                void parse();
+                std::string uri;
+                std::string scheme;
+                std::string hostname;
+                std::string path;
+                uint16_t port;
+        };
+    }
+}
+
+#endif // CONNECTIONPARAMS_HPP



More information about the vlc-commits mailing list