File indexing completed on 2024-05-19 09:23:10

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     bool init_core();
0027     QString error() const;
0028     QVersionNumber serverVersion() const
0029     {
0030         return m_serverVersion;
0031     }
0032 
0033     pw_loop *loop() const
0034     {
0035         return m_pwMainLoop;
0036     }
0037 
0038     pw_core *operator*() const
0039     {
0040         return m_pwCore;
0041     };
0042     static QSharedPointer<PipeWireCore> fetch(int fd);
0043 
0044 private:
0045     int m_fd = 0;
0046     pw_core *m_pwCore = nullptr;
0047     pw_context *m_pwContext = nullptr;
0048     pw_loop *m_pwMainLoop = nullptr;
0049     spa_hook m_coreListener;
0050     QString m_error;
0051     QVersionNumber m_serverVersion;
0052 
0053     static pw_core_events s_pwCoreEvents;
0054 
0055 Q_SIGNALS:
0056     void pipewireFailed(const QString &message);
0057 
0058     /**
0059      * Clients should disconnect from the core and reconnect to it on receiving this signal
0060      */
0061     void pipeBroken();
0062 };