5#include <QtCore/QDeadlineTimer>
7#include <QtCore/QWinEventNotifier>
9#include <QtCore/QSocketNotifier>
28 qCCritical(GstVideoReceiverLog) <<
"gst_pipeline_get_bus() failed";
31 _syncHandler = std::move(syncHandler);
32 _handler = std::move(handler);
34 gst_bus_set_sync_handler(_bus.get(), _onSync,
this,
35 [](gpointer pump) { static_cast<GstBusPump*>(pump)->_syncReleased.release(); });
36 _syncInstalled =
true;
40 gst_bus_get_pollfd(_bus.get(), &pollFd);
42 auto*
const notifier =
new QWinEventNotifier(
reinterpret_cast<Qt::HANDLE
>(pollFd.fd),
this);
43 (void) connect(notifier, &QWinEventNotifier::activated,
this, &
GstBusPump::drain);
45 auto*
const notifier =
new QSocketNotifier(pollFd.fd, QSocketNotifier::Read,
this);
62 gst_bus_set_sync_handler(_bus.get(),
nullptr,
nullptr,
nullptr);
64 _syncReleased.acquire();
65 _syncInstalled =
false;
68 gst_bus_set_flushing(_bus.get(), TRUE);
79 _handler(message.get());
83void GstBusPump::pumpUntil(GstMessageType types,
const std::function<
bool()>& done,
const QDeadlineTimer& deadline)
85 while (_bus && !done() && !deadline.hasExpired()) {
87 gst_bus_timed_pop_filtered(_bus.get(),
static_cast<GstClockTime
>(deadline.remainingTimeNSecs()), types));
91 _handler(message.get());
100GstBusSyncReply GstBusPump::_onSync(GstBus* , GstMessage* message, gpointer data)
102 return static_cast<GstBusPump*
>(data)->_syncHandler(message);
struct _GstElement GstElement
A pipeline's bus, handled from the thread the pump lives on.
void pumpUntil(GstMessageType types, const std::function< bool()> &done, const QDeadlineTimer &deadline)
void drain()
Handles the messages queued now, as the poll fd does.
std::function< void(GstMessage *message)> Handler
The pump's thread.
GstBusPump(QObject *parent=nullptr)
~GstBusPump() override
detach()es.
bool attach(GstElement *pipeline, SyncHandler syncHandler, Handler handler)
GStreamer::GstMessagePtr pop(GstMessageType type)
std::function< GstBusSyncReply(GstMessage *message)> SyncHandler
Posting threads. Returns GST_BUS_DROP for a message it took (and unreffed), GST_BUS_PASS to queue it.
GstBusPtr adoptBus(GstBus *bus) noexcept
std::unique_ptr< GstMessage, GstMessageDeleter > GstMessagePtr
GstMessagePtr adoptMessage(GstMessage *message) noexcept