[vlc-commits] demux: adaptive: fix canceling current chunk without full download

Francois Cartegnie git at videolan.org
Tue Mar 30 14:45:58 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Tue Mar 30 15:43:37 2021 +0200| [fbebef63e6cb9f2f200c6012bbdb0dbc4fa3aa9b] | committer: Francois Cartegnie

demux: adaptive: fix canceling current chunk without full download

read data could be infinite (stream)
refs #25562

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

 modules/demux/adaptive/http/Downloader.cpp | 7 ++++++-
 modules/demux/adaptive/http/Downloader.hpp | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/modules/demux/adaptive/http/Downloader.cpp b/modules/demux/adaptive/http/Downloader.cpp
index 2e0bd68b24..8aa7691468 100644
--- a/modules/demux/adaptive/http/Downloader.cpp
+++ b/modules/demux/adaptive/http/Downloader.cpp
@@ -34,6 +34,7 @@ Downloader::Downloader()
     killed = false;
     thread_handle_valid = false;
     current = nullptr;
+    cancel_current = false;
 }
 
 bool Downloader::start()
@@ -75,7 +76,10 @@ void Downloader::cancel(HTTPChunkBufferedSource *source)
 {
     vlc::threads::mutex_locker locker {lock};
     while (current == source)
+    {
+        cancel_current = true;
         updated_cond.wait(lock);
+    }
 
     if(!source->isDone())
     {
@@ -110,11 +114,12 @@ void Downloader::Run()
         lock.unlock();
         current->bufferize(HTTPChunkSource::CHUNK_SIZE);
         lock.lock();
-        if(current->isDone())
+        if(current->isDone() || cancel_current)
         {
             chunks.pop_front();
             current->release();
         }
+        cancel_current = false;
         current = nullptr;
         updated_cond.signal();
         lock.unlock();
diff --git a/modules/demux/adaptive/http/Downloader.hpp b/modules/demux/adaptive/http/Downloader.hpp
index dc05443adb..f9e8e8c6f6 100644
--- a/modules/demux/adaptive/http/Downloader.hpp
+++ b/modules/demux/adaptive/http/Downloader.hpp
@@ -51,6 +51,7 @@ namespace adaptive
                 vlc::threads::condition_variable updated_cond;
                 bool         thread_handle_valid;
                 bool         killed;
+                bool         cancel_current;
                 std::list<HTTPChunkBufferedSource *> chunks;
                 HTTPChunkBufferedSource *current;
         };



More information about the vlc-commits mailing list