| 1 | // Copyright (C) 2024 The Qt Company Ltd. | 
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | 
| 3 | |
| 4 | #ifndef QGST_BUS_OBSERVER_P_H | 
| 5 | #define QGST_BUS_OBSERVER_P_H | 
| 6 | |
| 7 | // | 
| 8 | // W A R N I N G | 
| 9 | // ------------- | 
| 10 | // | 
| 11 | // This file is not part of the Qt API. It exists purely as an | 
| 12 | // implementation detail. This header file may change from version to | 
| 13 | // version without notice, or even be removed. | 
| 14 | // | 
| 15 | // We mean it. | 
| 16 | // | 
| 17 | |
| 18 | #include <QtCore/qsocketnotifier.h> | 
| 19 | #include <QtCore/qwineventnotifier.h> | 
| 20 | #include <QtCore/qmutex.h> | 
| 21 | |
| 22 | #include "qgst_p.h" | 
| 23 | #include "qgstreamermessage_p.h" | 
| 24 | |
| 25 | QT_BEGIN_NAMESPACE | 
| 26 | |
| 27 | class QGstreamerBusMessageFilter | 
| 28 | { | 
| 29 | public: | 
| 30 | // returns true if message was processed and should be dropped, false otherwise | 
| 31 | virtual bool processBusMessage(const QGstreamerMessage &message) = 0; | 
| 32 | }; | 
| 33 | |
| 34 | class QGstBusObserver : private QGstBusHandle | 
| 35 | { | 
| 36 | public: | 
| 37 | using QGstBusHandle::get; | 
| 38 | using QGstBusHandle::HasRef; | 
| 39 | using QGstBusHandle::RefMode; | 
| 40 | |
| 41 | explicit QGstBusObserver(QGstBusHandle); | 
| 42 | |
| 43 | ~QGstBusObserver(); | 
| 44 | QGstBusObserver(const QGstBusObserver &) = delete; | 
| 45 | QGstBusObserver(QGstBusObserver &&) = delete; | 
| 46 | QGstBusObserver &operator=(const QGstBusObserver &) = delete; | 
| 47 | QGstBusObserver &operator=(QGstBusObserver &&) = delete; | 
| 48 | |
| 49 | void close(); | 
| 50 | |
| 51 | void installMessageFilter(QGstreamerBusMessageFilter *); | 
| 52 | void removeMessageFilter(QGstreamerBusMessageFilter *); | 
| 53 | |
| 54 | bool processNextPendingMessage(GstMessageType type = GST_MESSAGE_ANY, | 
| 55 | std::optional<std::chrono::nanoseconds> timeout = {}); | 
| 56 | |
| 57 | bool currentThreadIsNotifierThread() const; | 
| 58 | |
| 59 | private: | 
| 60 | void processAllPendingMessages(); | 
| 61 | |
| 62 | #ifndef Q_OS_WIN | 
| 63 | QSocketNotifier m_socketNotifier{ QSocketNotifier::Read }; | 
| 64 | #else | 
| 65 | QWinEventNotifier m_socketNotifier{}; | 
| 66 | #endif | 
| 67 | QList<QGstreamerBusMessageFilter *> busFilters; | 
| 68 | }; | 
| 69 | |
| 70 | QT_END_NAMESPACE | 
| 71 | |
| 72 | #endif // QGST_BUS_OBSERVER_P_H | 
| 73 | 
