[vlc-devel] [RFC] [PATCH] demux/adaptive: Downloader: faster response to request

Zhao Zhili quinkblack at foxmail.com
Tue Nov 21 08:28:43 CET 2017


---
 modules/demux/adaptive/http/Downloader.cpp | 44 +++++++++++++++++++++++-------
 modules/demux/adaptive/http/Downloader.hpp |  2 ++
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/modules/demux/adaptive/http/Downloader.cpp b/modules/demux/adaptive/http/Downloader.cpp
index ba81727..e1263f7 100644
--- a/modules/demux/adaptive/http/Downloader.cpp
+++ b/modules/demux/adaptive/http/Downloader.cpp
@@ -63,17 +63,34 @@ Downloader::~Downloader()
 void Downloader::schedule(HTTPChunkBufferedSource *source)
 {
     vlc_mutex_lock(&lock);
-    source->hold();
-    chunks.push_back(source);
+    while(control != NULL)
+        vlc_cond_wait(&waitcond, &lock);
+
+    control = [&]() {
+        source->hold();
+        chunks.push_back(source);
+    };
     vlc_cond_signal(&waitcond);
+
+    while(control != NULL)
+        vlc_cond_wait(&waitcond, &lock);
     vlc_mutex_unlock(&lock);
 }
 
 void Downloader::cancel(HTTPChunkBufferedSource *source)
 {
     vlc_mutex_lock(&lock);
-    source->release();
-    chunks.remove(source);
+    while(control != NULL)
+        vlc_cond_wait(&waitcond, &lock);
+
+    control = [&]() {
+        source->release();
+        chunks.remove(source);
+    };
+    vlc_cond_signal(&waitcond);
+
+    while(control != NULL)
+        vlc_cond_wait(&waitcond, &lock);
     vlc_mutex_unlock(&lock);
 }
 
@@ -95,14 +112,16 @@ void Downloader::DownloadSource(HTTPChunkBufferedSource *source)
 void Downloader::Run()
 {
     vlc_mutex_lock(&lock);
-    while(1)
+    while(!killed)
     {
-        while(chunks.empty() && !killed)
-            vlc_cond_wait(&waitcond, &lock);
-
-        if(killed)
-            break;
+        if(control != NULL)
+        {
+            control();
+            control = NULL;
+            vlc_cond_signal(&waitcond);
+        }
 
+        vlc_mutex_unlock(&lock);
         if(!chunks.empty())
         {
             HTTPChunkBufferedSource *source = chunks.front();
@@ -113,6 +132,11 @@ void Downloader::Run()
                 source->release();
             }
         }
+        vlc_mutex_lock(&lock);
+
+        vlc_cond_signal(&waitcond);
+        while(chunks.empty() && !killed && control == NULL)
+            vlc_cond_wait(&waitcond, &lock);
     }
     vlc_mutex_unlock(&lock);
 }
diff --git a/modules/demux/adaptive/http/Downloader.hpp b/modules/demux/adaptive/http/Downloader.hpp
index 1d6cc57..7f40c7d 100644
--- a/modules/demux/adaptive/http/Downloader.hpp
+++ b/modules/demux/adaptive/http/Downloader.hpp
@@ -23,6 +23,7 @@
 #include "Chunk.h"
 
 #include <vlc_common.h>
+#include <functional>
 #include <list>
 
 namespace adaptive
@@ -50,6 +51,7 @@ namespace adaptive
                 bool         thread_handle_valid;
                 bool         killed;
                 std::list<HTTPChunkBufferedSource *> chunks;
+                std::function<void()> control;
         };
 
     }
-- 
2.7.4





More information about the vlc-devel mailing list