[vlc-commits] demux: adaptive: use custom status for http queries
Francois Cartegnie
git at videolan.org
Mon Mar 30 16:16:24 CEST 2020
vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Fri Oct 12 11:03:43 2018 +0200| [684f317d202126c15e03c3d66fa4e81a5e0f1650] | committer: Francois Cartegnie
demux: adaptive: use custom status for http queries
(cherry picked from commit 4c2ba7cceda69d4e2a558906dec030bcf5167001)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=684f317d202126c15e03c3d66fa4e81a5e0f1650
---
modules/demux/adaptive/http/Chunk.cpp | 7 +++--
modules/demux/adaptive/http/ConnectionParams.hpp | 9 ++++++
modules/demux/adaptive/http/HTTPConnection.cpp | 39 +++++++++++++-----------
modules/demux/adaptive/http/HTTPConnection.hpp | 11 ++++---
4 files changed, 41 insertions(+), 25 deletions(-)
diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index a3d392c817..226e3fe3b1 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -250,10 +250,11 @@ bool HTTPChunkSource::prepare()
break;
}
- int i_ret = connection->request(connparams.getPath(), bytesRange);
- if(i_ret != VLC_SUCCESS)
+ enum RequestStatus status =
+ connection->request(connparams.getPath(), bytesRange);
+ if(status != RequestStatus::Success)
{
- if(i_ret == VLC_ETIMEOUT) /* redirection */
+ if(status == RequestStatus::Redirection)
{
HTTPConnection *httpconn = dynamic_cast<HTTPConnection *>(connection);
if(httpconn)
diff --git a/modules/demux/adaptive/http/ConnectionParams.hpp b/modules/demux/adaptive/http/ConnectionParams.hpp
index 2921f2e2d4..fb9f9d9af1 100644
--- a/modules/demux/adaptive/http/ConnectionParams.hpp
+++ b/modules/demux/adaptive/http/ConnectionParams.hpp
@@ -29,6 +29,15 @@ namespace adaptive
{
class Transport;
+ enum RequestStatus
+ {
+ Success,
+ Redirection,
+ Unauthorized,
+ NotFound,
+ GenericError,
+ };
+
class BackendPrefInterface
{
/* Design Hack for now to force fallback on regular access
diff --git a/modules/demux/adaptive/http/HTTPConnection.cpp b/modules/demux/adaptive/http/HTTPConnection.cpp
index 5fc0144e14..c0bf3fa9ed 100644
--- a/modules/demux/adaptive/http/HTTPConnection.cpp
+++ b/modules/demux/adaptive/http/HTTPConnection.cpp
@@ -137,7 +137,8 @@ void HTTPConnection::disconnect()
transport->disconnect();
}
-int HTTPConnection::request(const std::string &path, const BytesRange &range)
+enum RequestStatus
+ HTTPConnection::request(const std::string &path, const BytesRange &range)
{
queryOk = false;
chunked = false;
@@ -160,7 +161,7 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
else querypath = path;
if(!connected() && ( params.getHostname().empty() || !connect() ))
- return VLC_EGENERIC;
+ return RequestStatus::GenericError;
bytesRange = range;
if(range.isValid() && range.getEndByte() > 0)
@@ -180,19 +181,19 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
connectionClose = true;
return request(path, range);
}
- return VLC_EGENERIC;
+ return RequestStatus::GenericError;
}
- int i_ret = parseReply();
- if(i_ret == VLC_SUCCESS)
+ enum RequestStatus status = parseReply();
+ if(status == RequestStatus::Success)
{
queryOk = true;
}
- else if(i_ret == VLC_ETIMEOUT) /* redir */
+ else if(status == RequestStatus::Redirection)
{
transport->disconnect();
}
- else if(i_ret == VLC_EGENERIC)
+ else if(status == RequestStatus::GenericError)
{
transport->disconnect();
if(!connectionClose)
@@ -202,7 +203,7 @@ int HTTPConnection::request(const std::string &path, const BytesRange &range)
}
}
- return i_ret;
+ return status;
}
ssize_t HTTPConnection::read(void *p_buffer, size_t len)
@@ -248,17 +249,18 @@ bool HTTPConnection::send(const void *buf, size_t size)
return transport->send(buf, size);
}
-int HTTPConnection::parseReply()
+enum RequestStatus
+ HTTPConnection::parseReply()
{
std::string statusline = readLine();
if(statusline.empty())
- return VLC_EGENERIC;
+ return RequestStatus::GenericError;
if (statusline.compare(0, 9, "HTTP/1.1 ")!=0)
{
if(statusline.compare(0, 9, "HTTP/1.0 ")!=0)
- return VLC_ENOOBJ;
+ return RequestStatus::NotFound;
else
connectionClose = true;
}
@@ -291,15 +293,15 @@ int HTTPConnection::parseReply()
!locationparams.getUrl().empty())
{
msg_Info(p_object, "%d redirection to %s", replycode, locationparams.getUrl().c_str());
- return VLC_ETIMEOUT;
+ return RequestStatus::Redirection;
}
else if (replycode != 200 && replycode != 206)
{
msg_Err(p_object, "Failed reading %s: %s", params.getUrl().c_str(), statusline.c_str());
- return VLC_ENOOBJ;
+ return RequestStatus::NotFound;
}
- return VLC_SUCCESS;
+ return RequestStatus::Success;
}
ssize_t HTTPConnection::readChunk(void *p_buffer, size_t len)
@@ -490,7 +492,8 @@ bool StreamUrlConnection::canReuse(const ConnectionParams ¶ms) const
return available && params.usesAccess();
}
-int StreamUrlConnection::request(const std::string &path, const BytesRange &range)
+enum RequestStatus
+ StreamUrlConnection::request(const std::string &path, const BytesRange &range)
{
reset();
@@ -502,7 +505,7 @@ int StreamUrlConnection::request(const std::string &path, const BytesRange &rang
p_streamurl = vlc_stream_NewURL(p_object, params.getUrl().c_str());
if(!p_streamurl)
- return VLC_EGENERIC;
+ return RequestStatus::GenericError;
char *psz_type = stream_ContentType(p_streamurl);
if(psz_type)
@@ -520,7 +523,7 @@ int StreamUrlConnection::request(const std::string &path, const BytesRange &rang
if(vlc_stream_Seek(p_streamurl, range.getStartByte()) != VLC_SUCCESS)
{
vlc_stream_Delete(p_streamurl);
- return VLC_EGENERIC;
+ return RequestStatus::GenericError;
}
bytesRange = range;
contentLength = range.getEndByte() - range.getStartByte() + 1;
@@ -532,7 +535,7 @@ int StreamUrlConnection::request(const std::string &path, const BytesRange &rang
if(!range.isValid() || contentLength > (size_t) i_size)
contentLength = (size_t) i_size;
}
- return VLC_SUCCESS;
+ return RequestStatus::Success;
}
ssize_t StreamUrlConnection::read(void *p_buffer, size_t len)
diff --git a/modules/demux/adaptive/http/HTTPConnection.hpp b/modules/demux/adaptive/http/HTTPConnection.hpp
index 343336f0db..10e8594144 100644
--- a/modules/demux/adaptive/http/HTTPConnection.hpp
+++ b/modules/demux/adaptive/http/HTTPConnection.hpp
@@ -46,7 +46,8 @@ namespace adaptive
virtual bool prepare (const ConnectionParams &);
virtual bool canReuse (const ConnectionParams &) const = 0;
- virtual int request (const std::string& path, const BytesRange & = BytesRange()) = 0;
+ virtual enum RequestStatus
+ request (const std::string& path, const BytesRange & = BytesRange()) = 0;
virtual ssize_t read (void *p_buffer, size_t len) = 0;
virtual size_t getContentLength() const;
@@ -71,7 +72,8 @@ namespace adaptive
virtual ~HTTPConnection();
virtual bool canReuse (const ConnectionParams &) const;
- virtual int request (const std::string& path, const BytesRange & = BytesRange());
+ virtual enum RequestStatus
+ request (const std::string& path, const BytesRange & = BytesRange());
virtual ssize_t read (void *p_buffer, size_t len);
void setUsed( bool );
@@ -91,7 +93,7 @@ namespace adaptive
virtual std::string buildRequestHeader(const std::string &path) const;
ssize_t readChunk (void *p_buffer, size_t len);
- int parseReply();
+ enum RequestStatus parseReply();
std::string readLine();
std::string useragent;
@@ -118,7 +120,8 @@ namespace adaptive
virtual bool canReuse (const ConnectionParams &) const;
- virtual int request (const std::string& path, const BytesRange & = BytesRange());
+ virtual enum RequestStatus
+ request (const std::string& path, const BytesRange & = BytesRange());
virtual ssize_t read (void *p_buffer, size_t len);
virtual void setUsed( bool );
More information about the vlc-commits
mailing list