[vlc-commits] demux: adaptive: properly handle redirection

Francois Cartegnie git at videolan.org
Tue Feb 13 14:07:39 CET 2018


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Feb 13 13:53:25 2018 +0100| [6c36897f7d9e8585af1a1dd0c713892a57e4a690] | committer: Francois Cartegnie

demux: adaptive: properly handle redirection

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

 modules/demux/adaptive/http/Chunk.cpp | 46 ++++++++++++++++++++++-------------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/modules/demux/adaptive/http/Chunk.cpp b/modules/demux/adaptive/http/Chunk.cpp
index 9094322822..5dad106e1a 100644
--- a/modules/demux/adaptive/http/Chunk.cpp
+++ b/modules/demux/adaptive/http/Chunk.cpp
@@ -212,34 +212,46 @@ bool HTTPChunkSource::prepare(int i_redir)
     if(!connManager)
         return false;
 
-    if(!connection)
+    ConnectionParams connparams = params; /* can be changed on 301 */
+
+    while(i_redir++ < 3)
     {
-        connection = connManager->getConnection(params);
         if(!connection)
-            return false;
-    }
+        {
+            connection = connManager->getConnection(connparams);
+            if(!connection)
+                break;
+        }
 
-    int i_ret = connection->request(params.getPath(), bytesRange);
-    if(i_ret != VLC_SUCCESS)
-    {
-        if(i_ret == VLC_ETIMEOUT && i_redir < 3)
+        int i_ret = connection->request(connparams.getPath(), bytesRange);
+        if(i_ret != VLC_SUCCESS)
         {
-            connection->setUsed(false);
-            connection = NULL;
-            return HTTPChunkSource::prepare(i_redir + 1);
+            if(i_ret == VLC_ETIMEOUT) /* redirection */
+            {
+                HTTPConnection *httpconn = dynamic_cast<HTTPConnection *>(connection);
+                if(httpconn)
+                    connparams = httpconn->getRedirection();
+                connection->setUsed(false);
+                connection = NULL;
+                if(httpconn)
+                    continue;
+            }
+            break;
         }
-        return false;
+
+        /* Because we don't know Chunk size at start, we need to get size
+               from content length */
+        contentLength = connection->getContentLength();
+        prepared = true;
+        return true;
     }
-    /* Because we don't know Chunk size at start, we need to get size
-           from content length */
-    contentLength = connection->getContentLength();
-    prepared = true;
 
-    return true;
+    return false;
 }
 
 block_t * HTTPChunkSource::readBlock()
 {
+    printf("READ\n");
     return read(HTTPChunkSource::CHUNK_SIZE);
 }
 



More information about the vlc-commits mailing list