19#include "../QGlib/Signal"
21#include <QtCore/QObject>
22#include <QtCore/QTimerEvent>
23#include <QtCore/QHash>
24#include <QtCore/QBasicTimer>
29class BusWatch :
public QObject
33 : QObject(), m_bus(bus)
35 m_timer.start(50,
this);
44 virtual void timerEvent(QTimerEvent *event)
46 if (event->timerId() == m_timer.timerId()) {
49 QObject::timerEvent(event);
56 gst_object_ref(m_bus);
57 while((message = gst_bus_pop(m_bus)) != NULL) {
59 QGlib::Quark detail = gst_message_type_to_quark(
static_cast<GstMessageType
>(msg->type()));
60 QGlib::emitWithDetail<void>(m_bus,
"message", detail, msg);
62 gst_object_unref(m_bus);
72 void addWatch(GstBus *bus)
74 if (m_watches.contains(bus)) {
75 m_watches[bus].second++;
77 m_watches.insert(bus, qMakePair(
new BusWatch(bus), uint(1)));
78 g_object_weak_ref(G_OBJECT(bus), &BusWatchManager::onBusDestroyed,
this);
82 void removeWatch(GstBus *bus)
84 if (m_watches.contains(bus) && --m_watches[bus].second == 0) {
85 m_watches[bus].first->stop();
86 m_watches[bus].first->deleteLater();
87 m_watches.remove(bus);
88 g_object_weak_unref(G_OBJECT(bus), &BusWatchManager::onBusDestroyed,
this);
93 static void onBusDestroyed(gpointer selfPtr, GObject *busPtr)
95 BusWatchManager *self =
static_cast<BusWatchManager*
>(selfPtr);
96 GstBus *bus =
reinterpret_cast<GstBus*
>(busPtr);
99 self->m_watches[bus].first->stop();
100 self->m_watches[bus].first->deleteLater();
101 self->m_watches.remove(bus);
104 QHash< GstBus*, QPair<BusWatch*, uint> > m_watches;
107Q_GLOBAL_STATIC(Private::BusWatchManager, s_watchManager)
115 GstBus *bus = gst_bus_new();
117 gst_object_ref_sink(bus);
124 return gst_bus_have_pending(object<GstBus>());
134 return MessagePtr::wrap(gst_bus_timed_pop(object<GstBus>(), timeout),
false);
139 return MessagePtr::wrap(gst_bus_timed_pop_filtered(object<GstBus>(), timeout,
140 static_cast<GstMessageType
>(type)),
false);
145 return gst_bus_post(object<GstBus>(), gst_message_copy(message));
150 gst_bus_set_flushing(object<GstBus>(), flush);
155 Private::s_watchManager()->addWatch(object<GstBus>());
160 Private::s_watchManager()->removeWatch(object<GstBus>());
165 gst_bus_enable_sync_message_emission(object<GstBus>());
170 gst_bus_disable_sync_message_emission(object<GstBus>());
Wrapper class for GQuark.
Smart pointer class for working with wrapper classes that support reference counting.
static RefPointer< T > wrap(typename T::CType *nativePtr, bool increaseRef=true)
bool hasPendingMessages() const
bool post(const MessagePtr &message)
void enableSyncMessageEmission()
MessagePtr pop(ClockTime timeout=0)
void setFlushing(bool flush)
void disableSyncMessageEmission()
A datatype to hold a time, measured in nanoseconds.
Wrappers for GStreamer classes.