Commit 871a1f18 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptive: add ConnectionParam class

parent 287c67fc
......@@ -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 \
......
......@@ -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 */
......
......@@ -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
......
/*
* 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);
}
/*
* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment