diff options
author | Sergio Martins <iamsergio@gmail.com> | 2016-03-02 12:48:39 +0000 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2016-03-02 17:13:21 +0000 |
commit | d2d0d93f7654fdcca118dd17a745e560d524496b (patch) | |
tree | 2c3c15808babf8f9d24d74ec4c06870b1eca499e | |
parent | 176179fb32277f50b86d86e4870affaf74bc6fa0 (diff) |
Fix gstreamer camera when env var QT_NO_GLIB is set
It would fall into the glib code path because it was only checking
if QT_NO_GLIB was defined, but ignoring the env variable.
gst_bus_add_watch_full only works with a glib event loop running.
Task-Id: QTBUG-51607
Change-Id: I726afd5d6e114eacea6e5bc71e7a6e2d1c5bbd74
Reviewed-by: Yoann Lopes <yoann.lopes@theqtcompany.com>
-rw-r--r-- | src/gsttools/qgstreamerbushelper.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/gsttools/qgstreamerbushelper.cpp b/src/gsttools/qgstreamerbushelper.cpp index 7db62b83c..03cf64ba8 100644 --- a/src/gsttools/qgstreamerbushelper.cpp +++ b/src/gsttools/qgstreamerbushelper.cpp @@ -35,6 +35,8 @@ #include <QtCore/qtimer.h> #include <QtCore/qmutex.h> #include <QtCore/qlist.h> +#include <QtCore/qabstracteventdispatcher.h> +#include <QtCore/qcoreapplication.h> #include "qgstreamerbushelper_p.h" @@ -47,31 +49,31 @@ class QGstreamerBusHelperPrivate : public QObject public: QGstreamerBusHelperPrivate(QGstreamerBusHelper *parent, GstBus* bus) : QObject(parent), + m_tag(0), m_bus(bus), - m_helper(parent) + m_helper(parent), + m_intervalTimer(nullptr) { -#ifdef QT_NO_GLIB - Q_UNUSED(bus); - - m_intervalTimer = new QTimer(this); - m_intervalTimer->setInterval(250); - - connect(m_intervalTimer, SIGNAL(timeout()), SLOT(interval())); - m_intervalTimer->start(); -#else - m_tag = gst_bus_add_watch_full(bus, 0, busCallback, this, NULL); -#endif - + // glib event loop can be disabled either by env variable or QT_NO_GLIB define, so check the dispacher + QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher(); + const bool hasGlib = dispatcher && dispatcher->inherits("QEventDispatcherGlib"); + if (!hasGlib) { + m_intervalTimer = new QTimer(this); + m_intervalTimer->setInterval(250); + connect(m_intervalTimer, SIGNAL(timeout()), SLOT(interval())); + m_intervalTimer->start(); + } else { + m_tag = gst_bus_add_watch_full(bus, G_PRIORITY_DEFAULT, busCallback, this, NULL); + } } ~QGstreamerBusHelperPrivate() { m_helper = 0; -#ifdef QT_NO_GLIB - m_intervalTimer->stop(); -#else - g_source_remove(m_tag); -#endif + delete m_intervalTimer; + + if (m_tag) + g_source_remove(m_tag); } GstBus* bus() const { return m_bus; } @@ -110,9 +112,7 @@ private: guint m_tag; GstBus* m_bus; QGstreamerBusHelper* m_helper; -#ifdef QT_NO_GLIB QTimer* m_intervalTimer; -#endif private slots: void doProcessMessage(const QGstreamerMessage& msg) |