[vlc-commits] demux: adaptive: handle redirections
Francois Cartegnie
git at videolan.org
Wed Jan 25 19:57:18 CET 2017
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jan 25 19:51:31 2017 +0100| [65393c1ba96180459105f3a69870a303bb03122d] | committer: Francois Cartegnie
demux: adaptive: handle redirections
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=65393c1ba96180459105f3a69870a303bb03122d
---
modules/demux/adaptive/http/Chunk.cpp | 9 ++++++--
modules/demux/adaptive/http/Chunk.h | 2 +-
modules/demux/adaptive/http/HTTPConnection.cpp | 31 +++++++++++++++++++++-----
modules/demux/adaptive/http/HTTPConnection.hpp | 1 +
4 files changed, 35 insertions(+), 8 deletions(-)
diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index 270c0e2..176701b 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -203,7 +203,7 @@ block_t * HTTPChunkSource::read(size_t readsize)
return p_block;
}
-bool HTTPChunkSource::prepare()
+bool HTTPChunkSource::prepare(int i_redir)
{
if(prepared)
return true;
@@ -218,8 +218,13 @@ bool HTTPChunkSource::prepare()
return false;
}
- if( connection->request(params.getPath(), bytesRange) != VLC_SUCCESS )
+ int i_ret = connection->request(params.getPath(), bytesRange);
+ if(i_ret != VLC_SUCCESS)
+ {
+ if(i_ret == VLC_ETIMEOUT && i_redir < 3)
+ return HTTPChunkSource::prepare(i_redir + 1);
return false;
+ }
/* Because we don't know Chunk size at start, we need to get size
from content length */
contentLength = connection->getContentLength();
diff --git a/modules/demux/adaptive/http/Chunk.h b/modules/demux/adaptive/http/Chunk.h
index cfc971c..bbb56d2 100644
--- a/modules/demux/adaptive/http/Chunk.h
+++ b/modules/demux/adaptive/http/Chunk.h
@@ -94,7 +94,7 @@ namespace adaptive
static const size_t CHUNK_SIZE = 32768;
protected:
- virtual bool prepare();
+ virtual bool prepare(int = 0);
AbstractConnection *connection;
AbstractConnectionManager *connManager;
size_t consumed; /* read pointer */
diff --git a/modules/demux/adaptive/http/HTTPConnection.cpp b/modules/demux/adaptive/http/HTTPConnection.cpp
index 79ce1be..ee7ee72 100644
--- a/modules/demux/adaptive/http/HTTPConnection.cpp
+++ b/modules/demux/adaptive/http/HTTPConnection.cpp
@@ -150,6 +150,15 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
{
queryOk = true;
}
+ else if(i_ret == VLC_ETIMEOUT) /* redir */
+ {
+ socket->disconnect();
+ if(locationparams.getScheme().empty())
+ params.setPath(locationparams.getPath());
+ else
+ params = locationparams;
+ locationparams = ConnectionParams();
+ }
else if(i_ret == VLC_EGENERIC)
{
socket->disconnect();
@@ -225,11 +234,7 @@ int HTTPConnection::parseReply()
ss.imbue(std::locale("C"));
int replycode;
ss >> replycode;
- if (replycode != 200 && replycode != 206)
- {
- msg_Err(p_object, "Failed reading %s: %s", params.getUrl().c_str(), line.c_str());
- return VLC_ENOOBJ;
- }
+
line = readLine();
@@ -245,6 +250,18 @@ int HTTPConnection::parseReply()
line = readLine();
}
+ if((replycode == 301 || replycode == 307) &&
+ !locationparams.getUrl().empty())
+ {
+ msg_Info(p_object, "%d redirection to %s", replycode, locationparams.getUrl().c_str());
+ return VLC_ETIMEOUT;
+ }
+ else if (replycode != 200 && replycode != 206)
+ {
+ msg_Err(p_object, "Failed reading %s: %s", params.getUrl().c_str(), line.c_str());
+ return VLC_ENOOBJ;
+ }
+
return VLC_SUCCESS;
}
@@ -337,6 +354,10 @@ void HTTPConnection::onHeader(const std::string &key,
{
chunked = true;
}
+ else if(key == "Location")
+ {
+ locationparams = ConnectionParams( value );
+ }
}
std::string HTTPConnection::buildRequestHeader(const std::string &path) const
diff --git a/modules/demux/adaptive/http/HTTPConnection.hpp b/modules/demux/adaptive/http/HTTPConnection.hpp
index 1a1a955..85ca53b 100644
--- a/modules/demux/adaptive/http/HTTPConnection.hpp
+++ b/modules/demux/adaptive/http/HTTPConnection.hpp
@@ -89,6 +89,7 @@ namespace adaptive
std::string readLine();
char * psz_useragent;
+ ConnectionParams locationparams;
bool connectionClose;
bool chunked;
bool chunked_eof;
More information about the vlc-commits
mailing list