QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
GstBusPump.h
Go to the documentation of this file.
1#pragma once
2
3#include <functional>
4#include <gst/gst.h>
5
6#include <QtCore/QObject>
7#include <QtCore/QSemaphore>
8
9#include "GstScoped.h"
10
11class QDeadlineTimer;
12
19class GstBusPump : public QObject
20{
21 Q_OBJECT
22
23public:
25 using SyncHandler = std::function<GstBusSyncReply(GstMessage* message)>;
27 using Handler = std::function<void(GstMessage* message)>;
28
29 explicit GstBusPump(QObject* parent = nullptr);
31 ~GstBusPump() override;
32
35 [[nodiscard]] bool attach(GstElement* pipeline, SyncHandler syncHandler, Handler handler);
37 void detach();
38
40 void drain();
44 void pumpUntil(GstMessageType types, const std::function<bool()>& done, const QDeadlineTimer& deadline);
48 GStreamer::GstMessagePtr pop(GstMessageType type);
49
50private:
51 static GstBusSyncReply _onSync(GstBus* bus, GstMessage* message, gpointer data);
52
54 SyncHandler _syncHandler;
55 Handler _handler;
56 QObject* _notifier = nullptr;
57 bool _syncInstalled = false;
59 QSemaphore _syncReleased;
60};
struct _GstElement GstElement
void pumpUntil(GstMessageType types, const std::function< bool()> &done, const QDeadlineTimer &deadline)
Definition GstBusPump.cc:83
void drain()
Handles the messages queued now, as the poll fd does.
Definition GstBusPump.cc:72
std::function< void(GstMessage *message)> Handler
The pump's thread.
Definition GstBusPump.h:27
GstBusPump(QObject *parent=nullptr)
Definition GstBusPump.cc:14
~GstBusPump() override
detach()es.
Definition GstBusPump.cc:18
bool attach(GstElement *pipeline, SyncHandler syncHandler, Handler handler)
Definition GstBusPump.cc:23
GStreamer::GstMessagePtr pop(GstMessageType type)
Definition GstBusPump.cc:95
void detach()
Idempotent.
Definition GstBusPump.cc:52
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.
Definition GstBusPump.h:25
std::unique_ptr< GstBus, GstObjectDeleter > GstBusPtr
Definition GstScoped.h:62
std::unique_ptr< GstMessage, GstMessageDeleter > GstMessagePtr
Definition GstScoped.h:67