File indexing completed on 2024-04-14 15:33:29

0001 /*
0002     SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
0003     SPDX-FileContributor: Jan Grulich <jgrulich@redhat.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0006 */
0007 
0008 #pragma once
0009 
0010 #include <QObject>
0011 #include <QVersionNumber>
0012 #include <pipewire/pipewire.h>
0013 
0014 class PipeWireCore : public QObject
0015 {
0016     Q_OBJECT
0017 public:
0018     PipeWireCore();
0019 
0020     static void onCoreError(void *data, uint32_t id, int seq, int res, const char *message);
0021     static void onCoreInfo(void *data, const struct pw_core_info *info);
0022 
0023     ~PipeWireCore();
0024 
0025     bool init(int fd);
0026     QString error() const;
0027     QVersionNumber serverVersion() const
0028     {
0029         return m_serverVersion;
0030     }
0031 
0032     pw_loop *loop() const
0033     {
0034         return m_pwMainLoop;
0035     }
0036 
0037     pw_core *operator*() const { return m_pwCore; };
0038     static QSharedPointer<PipeWireCore> fetch(int fd);
0039 
0040 private:
0041     pw_core *m_pwCore = nullptr;
0042     pw_context *m_pwContext = nullptr;
0043     pw_loop *m_pwMainLoop = nullptr;
0044     spa_hook m_coreListener;
0045     QString m_error;
0046     QVersionNumber m_serverVersion;
0047 
0048     static pw_core_events s_pwCoreEvents;
0049 
0050 Q_SIGNALS:
0051     void pipewireFailed(const QString &message);
0052 };