mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 03:45:56 +01:00
Stop listening for synchronous bus callbacks from the moodbar pipeline, fixes some weird event loop stalls
This commit is contained in:
parent
b03563f317
commit
4cfa474fb8
@ -35,7 +35,7 @@ MoodbarLoader::MoodbarLoader(QObject* parent)
|
||||
: QObject(parent),
|
||||
cache_(new QNetworkDiskCache(this)),
|
||||
thread_(new QThread(this)),
|
||||
kMaxActiveRequests(QThread::idealThreadCount() / 2 + 1),
|
||||
kMaxActiveRequests(qMax(1, QThread::idealThreadCount() / 2)),
|
||||
save_alongside_originals_(false)
|
||||
{
|
||||
cache_->setCacheDirectory(Utilities::GetConfigPath(Utilities::Path_MoodbarCache));
|
||||
@ -43,6 +43,8 @@ MoodbarLoader::MoodbarLoader(QObject* parent)
|
||||
}
|
||||
|
||||
MoodbarLoader::~MoodbarLoader() {
|
||||
thread_->quit();
|
||||
thread_->wait(1000);
|
||||
}
|
||||
|
||||
QStringList MoodbarLoader::MoodFilenames(const QString& song_filename) {
|
||||
@ -87,7 +89,9 @@ MoodbarLoader::Result MoodbarLoader::Load(
|
||||
if (cache_device) {
|
||||
qLog(Info) << "Loading cached moodbar data for" << filename;
|
||||
*data = cache_device->readAll();
|
||||
return Loaded;
|
||||
if (!data->isEmpty()) {
|
||||
return Loaded;
|
||||
}
|
||||
}
|
||||
|
||||
if (!thread_->isRunning())
|
||||
@ -112,7 +116,7 @@ MoodbarLoader::Result MoodbarLoader::Load(
|
||||
void MoodbarLoader::MaybeTakeNextRequest() {
|
||||
Q_ASSERT(QThread::currentThread() == qApp->thread());
|
||||
|
||||
if (active_requests_.count() > kMaxActiveRequests ||
|
||||
if (active_requests_.count() >= kMaxActiveRequests ||
|
||||
queued_requests_.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@ -156,7 +160,7 @@ void MoodbarLoader::RequestFinished(MoodbarPipeline* request, const QUrl& url) {
|
||||
requests_.remove(url);
|
||||
active_requests_.remove(url);
|
||||
|
||||
QTimer::singleShot(10, request, SLOT(deleteLater()));
|
||||
QTimer::singleShot(1000, request, SLOT(deleteLater()));
|
||||
|
||||
MaybeTakeNextRequest();
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ MoodbarPipeline::MoodbarPipeline(const QString& local_filename)
|
||||
local_filename_(local_filename),
|
||||
pipeline_(NULL),
|
||||
convert_element_(NULL),
|
||||
bus_callback_id_(0),
|
||||
success_(false)
|
||||
{
|
||||
}
|
||||
@ -109,7 +108,6 @@ void MoodbarPipeline::Start() {
|
||||
// Connect signals
|
||||
g_signal_connect(decodebin, "new-decoded-pad", G_CALLBACK(NewPadCallback), this);
|
||||
gst_bus_set_sync_handler(gst_pipeline_get_bus(GST_PIPELINE(pipeline_)), BusCallbackSync, this);
|
||||
bus_callback_id_ = gst_bus_add_watch(gst_pipeline_get_bus(GST_PIPELINE(pipeline_)), BusCallback, this);
|
||||
|
||||
// Set appsink callbacks
|
||||
GstAppSinkCallbacks callbacks;
|
||||
@ -158,21 +156,6 @@ GstFlowReturn MoodbarPipeline::NewBufferCallback(GstAppSink* app_sink, gpointer
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
gboolean MoodbarPipeline::BusCallback(GstBus*, GstMessage* msg, gpointer data) {
|
||||
MoodbarPipeline* self = reinterpret_cast<MoodbarPipeline*>(data);
|
||||
|
||||
switch (GST_MESSAGE_TYPE(msg)) {
|
||||
case GST_MESSAGE_ERROR:
|
||||
self->ReportError(msg);
|
||||
self->Stop(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return GST_BUS_DROP;
|
||||
}
|
||||
|
||||
GstBusSyncReply MoodbarPipeline::BusCallbackSync(GstBus*, GstMessage* msg, gpointer data) {
|
||||
MoodbarPipeline* self = reinterpret_cast<MoodbarPipeline*>(data);
|
||||
|
||||
@ -198,9 +181,11 @@ void MoodbarPipeline::Stop(bool success) {
|
||||
}
|
||||
|
||||
void MoodbarPipeline::Cleanup() {
|
||||
Q_ASSERT(QThread::currentThread() == thread());
|
||||
Q_ASSERT(QThread::currentThread() != qApp->thread());
|
||||
|
||||
if (pipeline_) {
|
||||
gst_bus_set_sync_handler(gst_pipeline_get_bus(GST_PIPELINE(pipeline_)), NULL, NULL);
|
||||
g_source_remove(bus_callback_id_);
|
||||
gst_element_set_state(pipeline_, GST_STATE_NULL);
|
||||
gst_object_unref(pipeline_);
|
||||
pipeline_ = NULL;
|
||||
|
@ -64,8 +64,6 @@ private:
|
||||
GstElement* pipeline_;
|
||||
GstElement* convert_element_;
|
||||
|
||||
guint bus_callback_id_;
|
||||
|
||||
bool success_;
|
||||
QByteArray data_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user