From 432b0f3e54e12c0265e54fcc919a4fa5472044b6 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sat, 10 Jul 2021 21:48:31 +0200 Subject: [PATCH] songloader: Make sure timeout timer is started from correct thread --- src/core/songloader.cpp | 23 ++++++++++++++++++++++- src/core/songloader.h | 3 +++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/songloader.cpp b/src/core/songloader.cpp index e2733c865..545cffcfa 100644 --- a/src/core/songloader.cpp +++ b/src/core/songloader.cpp @@ -112,6 +112,8 @@ SongLoader::~SongLoader() { SongLoader::Result SongLoader::Load(const QUrl &url) { + if (url.isEmpty()) return Error; + url_ = url; if (url_.isLocalFile()) { @@ -425,6 +427,7 @@ void SongLoader::StopTypefind() { QBuffer buf(&buffer_); buf.open(QIODevice::ReadOnly); songs_ = parser_->Load(&buf); + buf.close(); } else if (success_) { @@ -449,7 +452,7 @@ SongLoader::Result SongLoader::LoadRemote() { // Otherwise wait to get 512 bytes of data and do magic on it - if the magic fails then we don't know what it is so return failure. // If the magic succeeds then we know for sure it's a playlist - so read the rest of the file, parse the playlist and return success. - timeout_timer_->start(timeout_); + ScheduleTimeoutAsync(); // Create the pipeline - it gets unreffed if it goes out of scope std::shared_ptr pipeline(gst_pipeline_new(nullptr), std::bind(&gst_object_unref, std::placeholders::_1)); @@ -696,3 +699,21 @@ void SongLoader::StopTypefindAsync(bool success) { } #endif + + +void SongLoader::ScheduleTimeoutAsync() { + + if (QThread::currentThread() == thread()) { + ScheduleTimeout(); + } + else { + metaObject()->invokeMethod(this, "ScheduleTimeout", Qt::QueuedConnection); + } + +} + +void SongLoader::ScheduleTimeout() { + + timeout_timer_->start(timeout_); + +} diff --git a/src/core/songloader.h b/src/core/songloader.h index 2ee292881..50480c412 100644 --- a/src/core/songloader.h +++ b/src/core/songloader.h @@ -92,6 +92,7 @@ class SongLoader : public QObject { void LoadRemoteFinished(); private slots: + void ScheduleTimeout(); void Timeout(); void StopTypefind(); #if defined(HAVE_AUDIOCD) && defined(HAVE_GSTREAMER) @@ -127,6 +128,8 @@ class SongLoader : public QObject { bool IsPipelinePlaying(); #endif + void ScheduleTimeoutAsync(); + private: static QSet sRawUriSchemes;