[vlc-devel] [PATCH 3/3] demux/adaptive: Downloader: forward interrupt
Zhao Zhili
wantlamy at gmail.com
Mon Aug 21 16:24:52 CEST 2017
---
modules/demux/adaptive/http/Downloader.cpp | 24 +++++++++++++++++++++---
modules/demux/adaptive/http/Downloader.hpp | 4 ++++
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/modules/demux/adaptive/http/Downloader.cpp
b/modules/demux/adaptive/http/Downloader.cpp
index b2e64ef..877e2eb 100644
--- a/modules/demux/adaptive/http/Downloader.cpp
+++ b/modules/demux/adaptive/http/Downloader.cpp
@@ -31,21 +31,33 @@ using namespace adaptive::http;
Downloader::Downloader() :
thread_handle_valid(false),
killed(false),
- pending_requests(0)
+ pending_requests(0),
+ interrupt(NULL)
{
vlc_mutex_init(&lock);
vlc_cond_init(&waitcond);
+ interrupt_data[0] = NULL;
+ interrupt_data[1] = NULL;
}
bool Downloader::start()
{
- if(!thread_handle_valid &&
- vlc_clone(&thread_handle, downloaderThread,
+ if(thread_handle_valid)
+ return true;
+
+ interrupt = vlc_interrupt_create();
+ if(unlikely(interrupt == NULL))
+ return false;
+
+ if(vlc_clone(&thread_handle, downloaderThread,
static_cast<void *>(this), VLC_THREAD_PRIORITY_INPUT))
{
+ vlc_interrupt_destroy(interrupt);
+ interrupt = NULL;
return false;
}
thread_handle_valid = true;
+ vlc_interrupt_forward_start(interrupt, interrupt_data);
return true;
}
@@ -60,6 +72,11 @@ Downloader::~Downloader()
vlc_join(thread_handle, NULL);
vlc_mutex_destroy(&lock);
vlc_cond_destroy(&waitcond);
+ if(interrupt)
+ {
+ vlc_interrupt_forward_stop(interrupt_data);
+ vlc_interrupt_destroy(interrupt);
+ }
}
void Downloader::schedule(HTTPChunkBufferedSource *source)
{
@@ -86,6 +103,7 @@ void Downloader::cancel(HTTPChunkBufferedSource *source)
void * Downloader::downloaderThread(void *opaque)
{
Downloader *instance = static_cast<Downloader *>(opaque);
+ vlc_interrupt_set(instance->interrupt);
int canc = vlc_savecancel();
instance->Run();
vlc_restorecancel( canc );
diff --git a/modules/demux/adaptive/http/Downloader.hpp
b/modules/demux/adaptive/http/Downloader.hpp
index ec76b3f..e4cc26f 100644
--- a/modules/demux/adaptive/http/Downloader.hpp
+++ b/modules/demux/adaptive/http/Downloader.hpp
@@ -23,6 +23,8 @@
#include "Chunk.h"
#include <vlc_common.h>
+#include <vlc_interrupt.h>
+
#include <atomic>
#include <list>
@@ -52,6 +54,8 @@ namespace adaptive
std::atomic_bool killed;
std::atomic_int pending_requests;
std::list<HTTPChunkBufferedSource *> chunks;
+ vlc_interrupt_t *interrupt;
+ void *interrupt_data[2];
};
}
--
2.7.4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20170821/08ca0fe3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-demux-adaptive-Downloader-forward-interrupt.patch
Type: application/octet-stream
Size: 2923 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20170821/08ca0fe3/attachment.obj>
More information about the vlc-devel
mailing list