Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpipewire_audiocontextmanager_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 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 QPIPEWIRE_AUDIOCONTEXTMANAGER_P_H
5#define QPIPEWIRE_AUDIOCONTEXTMANAGER_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 <QtMultimedia/private/qpipewire_audiodevicemonitor_p.h>
19#include <QtMultimedia/private/qpipewire_registry_support_p.h>
20#include <QtMultimedia/private/qpipewire_support_p.h>
21#include <QtCore/qglobal.h>
22
23#include <pipewire/pipewire.h>
24
25QT_BEGIN_NAMESPACE
26
27namespace QtPipeWire {
28
31
33{
34public:
37
38 static bool minimumRequirementMet();
39
41 bool isConnected() const;
42
43 template <typename Closure>
44 static auto withEventLoopLock(Closure &&c)
45 {
47
48 return self->runWithEventLoopLock(std::forward<Closure>(c));
49 }
50
52
53 static bool isInPwThreadLoop();
54 static pw_loop *getEventLoop();
55
58
59 void syncRegistry();
60
62 void unregisterStreamReference(const std::shared_ptr<QPipewireAudioStream> &);
63
65
66private:
67 template <typename Closure>
68 auto runWithEventLoopLock(Closure &&c)
69 {
70 pw_thread_loop_lock(m_eventLoop.get());
71 auto unlock = qScopeGuard([&] {
72 pw_thread_loop_unlock(m_eventLoop.get());
73 });
74
75 return c();
76 }
77
78 std::shared_ptr<QPipeWireInstance> m_libraryInstance;
79
80 // event loop
81 PwThreadLoopHandle m_eventLoop;
82 void prepareEventLoop();
83 void startEventLoop();
84 void stopEventLoop();
85
86 // pipewire context
87 PwContextHandle m_context;
88 void prepareContext();
89
90 // pw_core connection
91 PwCoreConnectionHandle m_coreConnection;
92 void connectToPipewireInstance();
93
94 // device monitor
95 PwRegistryHandle m_registry;
96 spa_hook m_registryListener{};
97 std::unique_ptr<QAudioDeviceMonitor> m_deviceMonitor;
98
99 void startDeviceMonitor();
100 void stopDeviceMonitor();
101 static void objectAddedCb(void *data, uint32_t id, uint32_t permissions, const char *type,
102 uint32_t version, const struct spa_dict *props);
103 static void objectRemovedCb(void *data, uint32_t id);
104 void objectAdded(ObjectId id, uint32_t permissions, PipewireRegistryType, uint32_t version,
105 const spa_dict &props);
106 void objectRemoved(ObjectId id);
107
108 // default metadata object
109 void startListenDefaultMetadataObject(ObjectId, uint32_t version);
110 void stopListenDefaultMetadataObject();
111 struct MetadataRecord
112 {
113 const char *key;
114 const char *type;
115 const char *value;
116 };
117
118 int handleDefaultMetadataObjectEvent(ObjectId subject, const MetadataRecord &);
119
120 PwMetadataHandle m_defaultMetadataObject;
121 spa_hook m_defaultMetadataObjectListener{};
122
123 QMutex m_activeStreamMutex;
125 void stopActiveStreams();
126};
127
128} // namespace QtPipeWire
129
130QT_END_NAMESPACE
131
132#endif // QPIPEWIRE_AUDIOCONTEXTMANAGER_P_H
void registerStreamReference(std::shared_ptr< QPipewireAudioStream >)
void unregisterStreamReference(const std::shared_ptr< QPipewireAudioStream > &)
const PwCoreConnectionHandle & coreConnection() const
#define __has_include(x)
bool pw_check_library_version(int major, int minor, int micro)