File indexing completed on 2024-05-05 05:30:17

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 #include <kpipewire_export.h>
0015 
0016 class KPIPEWIRE_EXPORT PipeWireCore : public QObject
0017 {
0018     Q_OBJECT
0019 public:
0020     PipeWireCore();
0021 
0022     static void onCoreError(void *data, uint32_t id, int seq, int res, const char *message);
0023     static void onCoreInfo(void *data, const struct pw_core_info *info);
0024 
0025     ~PipeWireCore();
0026 
0027     bool init(int fd);
0028     bool init_core();
0029     QString error() const;
0030     QVersionNumber serverVersion() const
0031     {
0032         return m_serverVersion;
0033     }
0034 
0035     pw_loop *loop() const
0036     {
0037         return m_pwMainLoop;
0038     }
0039 
0040     pw_core *operator*() const
0041     {
0042         return m_pwCore;
0043     };
0044     static QSharedPointer<PipeWireCore> fetch(int fd);
0045 
0046 private:
0047     int m_fd = 0;
0048     pw_core *m_pwCore = nullptr;
0049     pw_context *m_pwContext = nullptr;
0050     pw_loop *m_pwMainLoop = nullptr;
0051     spa_hook m_coreListener;
0052     QString m_error;
0053     QVersionNumber m_serverVersion;
0054 
0055     static pw_core_events s_pwCoreEvents;
0056 
0057 Q_SIGNALS:
0058     void pipewireFailed(const QString &message);
0059 
0060     /**
0061      * Clients should disconnect from the core and reconnect to it on receiving this signal
0062      */
0063     void pipeBroken();
0064 };