1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-01-31 11:35:24 +01:00

Fix weird interaction between QEventLoop, GMainContext and QtConcurrent.

Fixes issue #1929.
This commit is contained in:
John Maguire 2011-06-25 15:06:21 +00:00
parent 7d6aa42ba3
commit d6bafe88e2
2 changed files with 13 additions and 7 deletions

View File

@ -24,13 +24,12 @@
Fingerprinter::Fingerprinter(const QString& filename)
: filename_(filename),
event_loop_(new QEventLoop),
event_loop_(NULL),
convert_element_(NULL)
{
}
Fingerprinter::~Fingerprinter() {
delete event_loop_;
}
bool Fingerprinter::GstreamerHasOfa() {
@ -60,6 +59,10 @@ GstElement* Fingerprinter::CreateElement(const QString &factory_name,
}
QString Fingerprinter::CreateFingerprint() {
GMainContext* context = g_main_context_new();
g_main_context_push_thread_default(context);
event_loop_ = g_main_loop_new(context, FALSE);
GstElement* pipeline = gst_pipeline_new("pipeline");
GstElement* src = CreateElement("filesrc", pipeline);
GstElement* decode = CreateElement("decodebin2", pipeline);
@ -88,7 +91,9 @@ QString Fingerprinter::CreateFingerprint() {
// Start playing
gst_element_set_state(pipeline, GST_STATE_PLAYING);
event_loop_->exec();
g_main_loop_run(event_loop_);
g_main_loop_unref(event_loop_);
g_main_context_unref(context);
// Cleanup
gst_bus_set_sync_handler(gst_pipeline_get_bus(GST_PIPELINE(pipeline)), NULL, NULL);
@ -130,7 +135,7 @@ gboolean Fingerprinter::BusCallback(GstBus*, GstMessage* msg, gpointer data) {
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_ERROR:
instance->ReportError(msg);
instance->event_loop_->exit();
g_main_loop_quit(instance->event_loop_);
break;
case GST_MESSAGE_TAG:
@ -148,12 +153,12 @@ GstBusSyncReply Fingerprinter::BusCallbackSync(GstBus*, GstMessage* msg, gpointe
switch (GST_MESSAGE_TYPE(msg)) {
case GST_MESSAGE_EOS:
instance->event_loop_->exit();
g_main_loop_quit(instance->event_loop_);
break;
case GST_MESSAGE_ERROR:
instance->ReportError(msg);
instance->event_loop_->exit();
g_main_loop_quit(instance->event_loop_);
break;
case GST_MESSAGE_TAG:

View File

@ -18,6 +18,7 @@
#ifndef FINGERPRINTER_H
#define FINGERPRINTER_H
#include <glib.h>
#include <gst/gst.h>
#include <QString>
@ -58,7 +59,7 @@ private:
private:
QString filename_;
QString fingerprint_;
QEventLoop* event_loop_;
GMainLoop* event_loop_;
GstElement* convert_element_;
};